<template>
  <div>
    <Card style="height: 95%">
      <Row style="margin: 0px 0;" type="flex">
        <Col span="7" order="1">
          <!--高级检索-->
          <bc-senior ref="senior"  senior keyValue2 clear :pageName="$options.name" :fieldList="fieldList"
                   :commonList="commonList" @seniorFind="reloadData" :item.sync="searchForm"></bc-senior>

        </Col>
        <Col span="6" order="1">
        <Select v-model="searchForm.systemCode" style="width: 243px" placeholder="请选择业务系统">
          <Option v-for="item in systems" :value="item.code" :key="item.id" :tag="item.code" >{{ item.name }}</Option>
        </Select>
        </Col>
        <Col span="10"  order="2" style="text-align: right">
          <div style="width: 55px;float: right;margin-top: 10px">
            <bc-custom-sort ref="customSort" :sortParams.sync="sortParams" :searchForm="searchForm"
                            @reload-data="reloadData"></bc-custom-sort>
          </div>
          <div style="width: 65px;float: right;margin-top: 10px">
            <bc-table-ex :dataColumns.sync='dataColumns' :columnsShow.sync="columnsShow" firstColumn="selection"
                         :pageKey="this.$options.name"
                         layout ex></bc-table-ex>
          </div>
          <div style="width: 60px;float: right;margin-top: 10px">
            <bc-export-excel :dataColumns="columnsShow" :selectedData="selectedData" :tableData="tableData"
                             :excelName="'sysLogExcel'"
                             :searchForm="searchForm" @export-data="exportData"
                             :getData="this.getList"></bc-export-excel>
          </div>
          <div style="width: 90px;float: right">
            <Button @click="showUpload" type="primary">批量导入</Button>
            <bc-upload :show.sync="uploadSysLog" :import-url="importUrl" ></bc-upload>
          </div>
          <div style="width: 90px;float: right">
            <Button @click="sysLogAdd" type="primary">添加</Button>
          </div>
        </Col>
      </Row>
      <Table ref="tables" searchable search-place="top" :data="tableData" :columns="columnsShow" size="small"
             :loading="loading" @on-sort-change="sortChange" @on-selection-change="selectedChange"
             highlight-row @on-current-change="onCurrentChange" style="min-height: 550px;margin-top: 10px;" border>
        <template slot="actions" slot-scope="{ row }">
          <Button type="primary" size="small" @click="sysLogView(row)" ghost style="margin-right: 5px">查看</Button>
          <!--<Button type="primary" size="small" @click="sysLogEdit($event,row)" ghost style="margin-right: 5px">修改
          </Button>-->
          <Poptip confirm transfer size="small"
                  placement="bottom"
                  width="180"
                  title="你确定要删除吗?"
                  @on-ok="sysLogDelete(row)">
            <Button type="primary" size="small" ghost>删除</Button>
          </Poptip>
        </template>
      </Table>
      <bcPage ref="sysLog-list-page" @reload-data="reloadData" :dataCount="dataCount" size="small" :pageSize.sync="pageSize" ></bcPage>
    </Card>
  </div>
</template>

<script>
import { getSysLogPage,getSysLogList,deleteSysLog } from '../../../../api/base/sysLog-api'
import { getList } from '../../../../api/rbac/res-manage'
let $this;
export default {
  name: 'sysLogPage',
  components: {
  },
  data () {
    return {
      systems: [],
      importUrl: '',
      uploadSysLog:false,
      searchForm:{},
      showModal: false,
      modalParams: {},
      nowSysLog:{},
      dataCount:0,
      pageSize:10,
      columnsShow: [],
      dataColumns: [
              { title: '功能名称', key: 'functionName', sortable: true, show: true },
              { title: '功能类型', key: 'functionType', sortable: true, show: true },
              /*{ title: '包名', key: 'packageName', sortable: true, show: true },
              { title: '类名', key: 'className', sortable: true, show: true },
              { title: '方法名', key: 'methodName', sortable: true, show: true },*/
              { title: 'IP地址', key: 'ipAddress', sortable: true, show: true },
              { title: 'ip地区名称', key: 'ipArea', sortable: true, show: true },
              { title: '响应编码', key: 'responseCode', sortable: true, show: true },
              { title: '响应情况', key: 'responseState', sortable: true, show: true },
              { title: '请求路径', key: 'requestUrl', sortable: true, show: true },
              { title: '请求参数', key: 'requestParams', sortable: true, show: true },
              { title: '请求时间', key: 'requestTime', sortable: true, show: true },
              { title: '用时', key: 'useTime', sortable: true, show: true },
              /*{ title: '单位ID', key: 'companyId', sortable: true, show: true },
              { title: '单位名称', key: 'companyName', sortable: true, show: true },
              { title: '区域ID', key: 'areaId', sortable: true, show: true },
              { title: '区域名称', key: 'areaName', sortable: true, show: true },*/
              { title: '是否错误', key: 'isError', sortable: true, show: true },
              { title: '操作', key: 'action', width: 200, align: 'center',slot:'actions', show: true }
      ],
      tableData: [],
      selectedData: [],
      loading: false,
      sortParams: [], //[{title: 姓名, orderStr: 降序, sortKey: name, order: -}]
      getList: getSysLogList,
      commonList: [

      ],//固化常用列表
      fieldList: [//用户可以自行选择查询的字段列表及配置

      ]
    }
  },
  methods: {
    showUpload(){
      this.uploadSysLog=true;
    },
    sysLogView (row) {
      this.showModal = true;
      this.modalParams = {title:'查看',flag:'view',bean:row};
    },
    sysLogAdd () {
      this.showModal = true;
      this.modalParams = {title: '添加', flag: 'add', bean: null};
    },
    sysLogEdit (e, row) {
      e.stopPropagation();
      this.showModal = true;
      this.modalParams = {title:'修改',flag:'edit',bean:row};
    },
    sysLogDelete (row) {
      deleteSysLog(row.id).then( data => {
        this.$Message.success( "操作成功！");
        this.tableData.splice(row._index, 1);
      }).catch(err =>{
        this.$Message.error( "操作失败！");
        console.log(err);
      })
    },
        selectedChange(selection) {
      this.selectedData = selection;
    },
    sortChange(column) {
      this.$refs.customSort.sortChange(column);
    },
    exportData(params) {
      this.$refs.tables.exportCsv(params);
    },
    reloadData (pageSize,pageNo) {
      //表格加载中效果
      this.loading = true;
      //处理表单查询参数及分页
      if (!pageNo) {
        this.dataCount = 0
      }
      if (!pageSize) {
        pageSize = this.pageSize;
      }
      let page_params = {'pageSize':pageSize,'pageNo':pageNo};
      let params = Object.assign({},page_params,this.searchForm); // 这样不会改变原对象
      getSysLogPage(params).then(res => {
        if (res.data.result.totalSize) {
            this.dataCount = parseInt(res.data.result.totalSize)
        }
        if (res.data.result.datas && res.data.result.datas.length > 0) {
          this.tableData = res.data.result.datas;
          this.tableData[0]._highlight = true;
          this.nowSysLog = this.tableData[0];
        } else {
            this.tableData = [];
        }
        this.loading = false;
      }).catch(err => {
        this.tableData = [];
        this.$Message.error('查询失败！')
        console.log(err)
      })
    },
    onCurrentChange (currentRow,oldCurrentRow) {
      this.nowSysLog = currentRow;
    },
  },
  mounted () {
    this.reloadData();
    $this = this;
    //初始化系统下拉框集合
    getList({type: 0}).then(res => {
      this.systems = res.data.result;
    });
  }
}
</script>

<style>

</style>
