<template>
  <div style="height: 680px;overflow: auto">
    <Card style="height: 95%">
      <Row style="margin: 10px 0;" type="flex">
        <Col span="10" order="1">
          <!--高级检索-->
          <!--<seniorModal ref="senior" keyValue2 clear :pageName="$options.name" :fieldList="fieldList"
                       :commonList="commonList"
                       @seniorFind="reloadData" :item.sync="searchForm"></seniorModal>-->
        </Col>
        <Col span="4" order="2" style="text-align: left">
          <!--复合排序-->
          <!--<customSort ref="customSort" :sortParams.sync="sortParams" @reload-data="reloadData"
                      :searchForm.sync="searchForm"></customSort>-->
        </Col>
        <Col span="10" order="3" style="text-align: right">
          <!--<Button @click="workflowDraftBoxBatchDelete"  type="primary">批量删除</Button>-->
          <!--通用导出excel组件-->
          <!--<exportExcel :dataColumns="dataColumns" :selectedData="selectedData" :tableData="tableData" :excelName="'workflowDraftBoxExcel'"
                       :searchForm="searchForm" @export-data="exportData" :getData="this.getList"></exportExcel>-->
        </Col>
      </Row>
      <Table ref="tables" searchable search-place="top" :data="tableData" :columns="columns" size="small"
             :loading="loading" @on-sort-change="sortChange" @on-selection-change="selectedChange"
             highlight-row @on-current-change="onCurrentChange">
        <template slot="actions" slot-scope="{ row }">
          <Button type="primary" size="small" @click="workflowDetailsView(row)" ghost style="margin-right: 5px">详情</Button>
          <Poptip confirm transfer size="small"
                  placement="bottom"
                  width="180"
                  title="你确定要删除吗?"
                  @on-ok="workflowDraftBoxDelete(row)">
            <Button type="primary" size="small" ghost>删除</Button>
          </Poptip>
        </template>
      </Table>
      <bc-page ref="workflowDraftBox-list-page" @reload-data="reloadData" :dataCount="dataCount" size="small"
            :pageSize.sync="pageSize"></bc-page>
      <workflowDoSomething ref="workflowDoSomething"  :show.sync="showModal1" :bean="modalParams1"
                           type="view"  @reload-data="reloadData"></workflowDoSomething>
    </Card>
  </div>
</template>

<script>
  import {getWorkflowDraftBoxPage, getWorkflowDraftBoxList, deleteWorkflowDraftBox} from '../workflow-api'
  import workflowDoSomething from '../workflow-dosomething-index'

  let $this;
  export default {
    name: 'workflowDraftBoxList',
    components: {
      workflowDoSomething
    },
    data() {
      return {
        showModal1: false,
        modalParams1: {},
        searchForm: {},
        showModal: false,
        showWorkflowDetailsModal: false,
        modalParams: {},
        workflowDetailsModalParams: {},
        nowWorkflowDraftBox: {},
        dataCount: 0,
        pageSize: 10,
        columns: [
          { title: '分类名称', key: 'groupName', sortable: true, show: true },
          { title: '业务id', key: 'thisBusId', sortable: true, show: true },
          { title: '业务名称', key: 'thisBusName', sortable: true, show: true },
          { title: '业务编码', key: 'busCode', sortable: true, show: true },
          /*{ title: '业务类型 字典或枚举', key: 'busType', sortable: true, show: true },*/
          { title: '说明', key: 'description', sortable: true, show: true },
          { title: '操作', key: 'action', width: 200, align: 'center',slot:'actions', show: true }
        ],
        tableData: [],
        selectedData: [],
        loading: true,
        sortParams: [], //[{title: 姓名, orderStr: 降序, sortKey: name, order: -}]
        getList: getWorkflowDraftBoxList,
        commonList: [
          /*{id: 1, label: '常用固化查询条件1', findItem: [{field: 'fieldName', judge: 'eq', value: 'fieldValue'}]},
          {id: 2, label: '常用固化查询条件2', findItem: [
                  {field: 'fieldName1', judge: 'eq', value: 'fieldValue2'},
                  {field: 'fieldName2', judge: 'eq', value: 'fieldValue2'},
                  ]},*/

        ],//固化常用列表
        fieldList: [//用户可以自行选择查询的字段列表及配置
        ]
      }
    },
    methods: {
      workflowDetailsView (row) {
        /*this.showWorkflowDetailsModal = true;
        this.workflowDetailsModalParams = {title:'详情',flag:'view',bean:row};*/
        this.showModal1 = true;
        this.modalParams1 = {busId: row.thisBusId, busData: {},
          draftBoxUrl: row.draftBoxUrl, draftBoxUrlType: row.draftBoxUrlType, taskId: null, type: 'do'};
      },
      workflowDraftBoxDelete (row) {
        deleteWorkflowDraftBox(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); // 这样不会改变原对象
        params.createBy = this.$store.state.user.userId
        //加入系统条件,现在只能查询当前系统的流程
        params.systemCode = this.$config.systemCode
        getWorkflowDraftBoxPage(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.nowWorkflowDraftBox = currentRow;
      },
    },
    mounted() {
      this.reloadData();
      $this = this;
    }
  }
</script>

<style>

</style>
