<template>
  <div>
    <a-card>
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-model-item prop="key" label="流程实例编号">
                <a-input v-model="queryParam.processInstanceId" allowClear placeholder="请输入流程实例编号" ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button @click="searchQuery" type="primary" icon="search" style="margin-right: 8px">查询</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <a-table
        :columns="columns"
        :dataSource="dataSource"
        rowKey="id"
        :loading="loading"
        class="j-table-force-nowrap"
        :pagination="ipagination"
        @change="handleTableChange"
      >

        <span slot="action" slot-scope="text, record">

          <a @click="handleDetail1(record)">查看流程进度</a>

        </span>
        <a-divider type="vertical" />
      </a-table>

      <activiti-file-model ref="ativitiFileModel" ></activiti-file-model>
      <pic-form1 ref="picForm" @ok="modalFormOk" ></pic-form1>
    </a-card>
  </div>

</template>

<script>

import {getAction, deleteAction, banli, postAction} from '@/api/manage'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ActivitiFileModel from './ActivitiFileModel'
  import { getModelList } from '@/api/activiti/activiti'
  import {filterObj} from "@/utils/util";
  import store from '@/store/'
  import PicForm1 from "@views/activiti/PicForm1";

  export default {
    name: 'ActivitiHisList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      PicForm1,
      ActivitiFileModel
    },
    data() {
      return {
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            }
          }, {
            dataIndex: 'name',
            title: '任务名称',
            align: 'center'
          },
          {
            dataIndex: 'processInstanceId',
            title: '流程实例编号',
            align: 'center'
          },
          // {
          //   dataIndex: 'executionId',
          //   title: '执行实例编号',
          //   align: 'center'
          // },
          {
            dataIndex: 'businessKey',
            title: '业务号',
            align: 'center'
          },
          {
            title: '开始时间',
            dataIndex: 'startTime',
            align: 'center'
          },
          {
            title: '结束时间',
            dataIndex: 'endTime',
            align: 'center'
          },
          {
            title: '当前步骤',
            dataIndex: 'currentTask',
            align: 'center'
          },
          {
            title: '当前步骤审批人id',
            dataIndex: 'assignee',
            align: 'center'
          },
          {
            title: '是否结束',
            dataIndex: 'ended',
            align: 'center',
            customRender:function (text) {
              if(text){
                return "是";
              }else{
                return "否";
              }
            }
          },
          {
            title: '发起人id',
            dataIndex: 'startUserId',
            align: 'center'
          },
          {
            title: '操作',
            dataIndex: 'action',
            width: '150px',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }],
        url: {
          list: '/service/listHistoryProcess',
          delete: '/act/reprocdef/deleteByDeploymentId',
          convertToModel: '/act/reprocdef/convertToModel',
          updateHandle: '/act/reprocdef/update',
          banli: '/service/completeTask',
        },
        queryParam: {
          category: '',
          key: '',
          name: ''
        }
       }
    },
   created() {
     console.log("----------------------")
     console.log(store.getters.userInfo)
     // this.getDataList()
   },
   methods: {
     handleDetail1:function(record){
       this.$refs.picForm.edit(record);
       this.$refs.picForm.title="流程";
       this.$refs.picForm.disableSubmit = true;
     },
     handleBanli:function (record){
       banli(this.url.banli+"/"+record.taskId).then(res => {
         console.log('转为模型', res)
         if (res.code == 0) {
           this.$message.success(res.msg);
         } else {
           this.$message.warning(res.msg);
         }
       })
     },
     // 删除
     actDelete(deploymentId) {
        deleteAction(this.url.delete, { deploymentId: deploymentId }).then(res => {
            if (res.success) {
              this.$message.success(res.message)
              this.searchQuery()
            } else {
              this.$message.warning(res.message)
            }
        })
     },
     // 转为模型
     convertToModel(id) {
       getAction(this.url.convertToModel, { id: id }).then(res => {
         console.log('转为模型', res)
        if (res.success) {
          this.$message.success('操作成功，流程编号:' + res.result.deploymentId)
           this.searchQuery()
        } else {
          this.$message.warning('操作失败，流程编号:' + res.result.deploymentId)
        }
       })
     },
     // 挂起和激活
     updateHandle(id, state) {
       getAction(this.url.updateHandle, { id: id, state: state }).then(res => {
         console.log('挂起和激活', res)
         if (res.success) {
           this.$message.success(res.message)
            this.searchQuery()
         } else {
           this.$message.warning(res.message)
         }
       })
     },

     searchQuery() {
       this.selectedRowKeys = [];
       this.selectionRows = [];
       this.loadData(1);
     },
     loadData(arg) {
       if(!this.url.list){
         this.$message.error("请设置url.list属性!")
         return
       }
       //加载数据 若传入参数1则加载第一页的内容
       if (arg === 1) {
         this.ipagination.current = 1;
       }
       var params = this.getQueryParams();//查询条件
       this.loading = true;
       getAction(this.url.list, params).then((res) => {
         if (res.success) {
           //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
           this.dataSource = res.result.records||res.result;
           this.totalOrderPrice = res.message
           if(res.result.total)
           {
             this.ipagination.total = res.result.total;
           }else{
             this.ipagination.total = 0;
           }
           //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
         }else{
           this.$message.warning(res.message)
         }
       }).finally(() => {
         this.loading = false
       })
     },
      // 查询
      getDataList() {
       this.loading = true
        let params = this.queryParam
        getModelList(this.url.list, params).then(res => {
          console.log('查询数据', res)
          this.dataSource = res.result.records
          this.total = res.result.total
          this.ipagination.total = res.result.total
          this.loading = false
        })
      },
     openModeler() {
          this.$refs.ativitiFileModel.openModel()
       },

      deployProcess(id) {
        getAction(this.url.deploy, { id: id }).then(res => {
          if (res.success) {
            this.$message.success(res.message)
             this.searchQuery()
          } else {
            this.$message.error(res.message)
          }
        })
      }
    }
   }
</script>

<style lang="less" scoped>
 .table-operator .ant-btn {
        margin: 3px 8px 4px 0;
    }
</style>
