<template>
  <div class="page">
      <el-form size="small" :inline="true" class="query-form" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()" @submit.native.prevent>
       <!-- 搜索框-->
       <el-form-item label="客户名称" prop="clientName">
              <el-input size="small" v-model="searchForm.clientName" placeholder="请输入客户名称" clearable></el-input>
       </el-form-item>

        <el-form-item label="合同名称" prop="name">
          <el-input size="small" v-model="searchForm.name" placeholder="请输入合同名称" clearable></el-input>
        </el-form-item>

        <el-form-item label="签订日期" prop="contractDates">
          <el-date-picker
            placement="bottom-start"
            v-model="searchForm.contractDates"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="合同状态" prop="status">
          <el-select v-model="searchForm.status" placeholder="请选择" style="width:100%;">
            <el-option
              v-for="item in $dictUtils.getDictList('approval_type')"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="归档状态" prop="filedType">
          <el-select v-model="searchForm.filedType" placeholder="请选择" style="width:100%;">
            <el-option
              v-for="item in $dictUtils.getDictList('filed_type')"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="合同金额" prop="contractAmounts">
          <InputNumber :disabled="false" :precision="num" v-model="searchForm.contractAmounts"></InputNumber>
        </el-form-item>

        <el-form-item label="创建人" prop="createBy">
          <SelectUserTree
            ref="companyTree"
            :props="{
                  value: 'id',             // ID字段名
                  label: 'name',         // 显示名称
                  children: 'children'    // 子级字段名
                }"
            :url="`/sys/user/treeUserDataAllOffice?type=2`"
            :value="searchForm.createBy"
            :clearable="true"
            :accordion="true"
            @getValue="(value) => {searchForm.createBy=value}"/>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="refreshList()" size="small" icon="el-icon-search">查询</el-button>
          <el-button @click="resetSearch()" size="small" icon="el-icon-refresh-right">重置</el-button>
        </el-form-item>
      </el-form>

     <div class="bg-white top">
        <vxe-toolbar :refresh="{query: refreshList}" import export print custom>
          <template #buttons>
            <el-button v-if="hasPermission('sys:project:add')" type="primary" size="small" icon="el-icon-plus" @click="add()">新建</el-button>
            <el-button v-if="hasPermission('sys:project:del')" type="danger"   size="small" icon="el-icon-delete" @click="del()" plain>删除</el-button>
          </template>
        </vxe-toolbar>
        <div style="height: calc(100% - 80px);">
            <vxe-table
                border="inner"
                auto-resize
                resizable
                height="auto"
                :loading="loading"
                size="small"
                ref="workContractTable"
                show-header-overflow
                show-overflow
                highlight-hover-row
                :menu-config="{}"
                :print-config="{}"
                @sort-change="sortChangeHandle"
                :sort-config="{remote:true}"
                :data="dataList"
                :checkbox-config="{}">
                <vxe-column type="seq" width="60" title="序号"></vxe-column>
                <vxe-column type="checkbox" width="40px"></vxe-column>

                <vxe-column width="200px" title="合同编号" field="no"></vxe-column>
                <vxe-column width="200px" title="合同名称" field="name">
                  <template slot-scope="scope">
                    <el-link  type="primary" :underline="false" v-if="hasPermission('sys:workContract:edit')" @click="view(scope.row.id)">{{scope.row.name}}</el-link>
                    <el-link  type="primary" :underline="false" v-else-if="hasPermission('sys:workContract:view')" @click="view(scope.row.id)">{{scope.row.name}}</el-link>
                    <span v-else>{{scope.row.name}}</span>
                  </template>
                </vxe-column>
                <vxe-column width="100px" title="案卷号" field="filedNo" >
                  <template slot-scope="scope">
                    <el-link  type="primary" :underline="false" v-if="hasPermission('sys:workContract:edit')" @click="view(scope.row.id)">{{scope.row.filedNo}}</el-link>
                    <el-link  type="primary" :underline="false" v-else-if="hasPermission('sys:workContract:view')" @click="view(scope.row.id)">{{scope.row.filedNo}}</el-link>
                    <span v-else>{{scope.row.filedNo}}</span>
                  </template>
                </vxe-column>
                <vxe-column width="200px" title="客户名称" field="clientName" >
                  <template slot-scope="scope">
                    <el-link  type="primary" :underline="false" v-if="hasPermission('sys:work_client:edit')" @click="viewInfo(scope.row.clientId)">{{scope.row.clientName}}</el-link>
                    <el-link  type="primary" :underline="false" v-else-if="hasPermission('sys:work_client:view')" @click="viewInfo(scope.row.clientId)">{{scope.row.clientName}}</el-link>
                    <span v-else>{{scope.row.clientName}}</span>
                  </template>
                </vxe-column>
                <vxe-column width="100px" title="合同金额(元)" field="contractAmount"></vxe-column>
                <vxe-column width="100px" title="创建人" field="createBy"></vxe-column>
                <vxe-column width="150px" title="签订日期" field="contractDate"></vxe-column>
                <vxe-column  width="120px" title="登记状态" field="status" >
                  <template slot-scope="scope">
                    <el-button  type="text" @click="detail(scope.row)" :type="$dictUtils.getDictLabel('approval_type_status', scope.row.status, '-')" effect="dark" size="mini">{{$dictUtils.getDictLabel("approval_type", scope.row.status, '-')}} </el-button>
                  </template>
                </vxe-column>
                <vxe-column width="100px"  title="归档状态" field="filedType" >
                  <template slot-scope="scope">
                    <el-button  type="text" @click="detailFiled(scope.row)" :type="$dictUtils.getDictLabel('filed_type_status', scope.row.filedType, '-')" effect="dark" size="mini">{{$dictUtils.getDictLabel("filed_type", scope.row.filedType, '未归档')}} </el-button>
                  </template>
                </vxe-column>
                <vxe-column width="100px"  title="借用状态" field="borrowType" >
                  <template slot-scope="scope">
                    <el-button  type="text" @click="detailBorrow(scope.row)" :type="$dictUtils.getDictLabel('borrow_type_status', scope.row.borrowType, '-')" effect="dark" size="mini">{{$dictUtils.getDictLabel("borrow_type", scope.row.borrowType, '未借用')}} </el-button>
                  </template>
                </vxe-column>

                <vxe-column title="操作" width="200px" fixed="right" align="center">
                    <template  slot-scope="scope">
                      <el-button v-if="hasPermission('sys:workContract:view')" type="text" size="small" @click="view(scope.row.id)">查看</el-button>
                      <el-button v-if="hasPermission('sys:workContract:edit') && scope.row.status !== '2' && scope.row.status !== '5' && scope.row.createId === create" type="text" size="small" @click="edit(scope.row)">修改</el-button>
                      <el-button v-if="hasPermission('sys:workContract:edit') && scope.row.status === '5' && isAdmin" type="text" size="small" @click="editForm(scope.row.id)">修改</el-button>
                      <el-button v-if="hasPermission('sys:workContract:del') && (scope.row.status === '1' || scope.row.status === '3' || scope.row.status === '4')  && scope.row.createId === create" type="text" size="small" @click="del(scope.row.id)">删除</el-button>
                      <el-button v-if="hasPermission('sys:workContract:back') && scope.row.status === '2'" type="text" size="small" @click="reback(scope.row)">撤回</el-button>
                      <el-button v-if="hasPermission('sys:workContract:filed') && scope.row.status === '5' && scope.row.createId === create && (scope.row.filedType === '0' || scope.row.filedType === undefined)" type="text" size="small" @click="filed(scope.row.id)">归档</el-button>
                      <!--归档暂存修改-->
                      <el-button v-if="hasPermission('sys:workContract:filed') && scope.row.status === '5' && scope.row.createId === create && scope.row.filedType === '1'" type="text" size="small" @click="filed(scope.row.id)">修改</el-button>
                      <!--归档撤回驳回修改-->
                      <el-button v-if="hasPermission('sys:workContract:filed') && scope.row.status === '5' && scope.row.createId === create && (scope.row.filedType === '3' || scope.row.filedType === '4')" type="text" size="small" @click="filedAndClose(scope.row.id)">修改</el-button>
                      <!--归档撤回-->
                      <el-button v-if="hasPermission('sys:workContract:back') && scope.row.status === '5' && scope.row.filedType === '2'" type="text"  size="small" @click="rebackFiled(scope.row)">撤回</el-button>
                      <!--合同借用-->
                      <el-button v-if="hasPermission('sys:workContract:borrow') && scope.row.status === '5' && scope.row.filedType === '5' && (scope.row.borrowType === undefined || scope.row.borrowType === '0' || scope.row.borrowType === '1')" type="text" size="small" @click="borrow(scope.row.id)">借用</el-button>
                      <!--借用撤回-->
                      <el-button v-if="hasPermission('sys:workContract:back') && scope.row.status === '5' && scope.row.filedType === '5' && scope.row.borrowType === '2'" type="text" size="small" @click="rebackBorrow(scope.row)">撤回</el-button>
                      <!--借用归还-->
                      <el-button v-if="hasPermission('sys:workContract:reture') && scope.row.status === '5' && scope.row.filedType === '5' && scope.row.borrowType === '5'" type="text" size="small" @click="retureBorrow(scope.row)">归还合同</el-button>
                    </template>
                </vxe-column>
            </vxe-table>
          <vxe-pager
            background
            size="small"
            :current-page="tablePage.currentPage"
            :page-size="tablePage.pageSize"
            :total="tablePage.total"
            :page-sizes="[10, 20, 100, 1000, {label: '全量数据', value: 1000000}]"
            :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
            @page-change="currentChangeHandle">
          </vxe-pager>
        </div>
     </div>
        <!-- 弹窗, 新增 / 修改 -->
    <ContractNameForm ref="contractNameForm" @refreshDataList="refreshList"></ContractNameForm>
    <WorkClientForm ref="workClientForm" @refreshDataList="refreshList"></WorkClientForm>
    <WorkContractBorrowMessageForm ref="workContractBorrowMessageForm" @refreshDataList="refreshList"></WorkContractBorrowMessageForm>
  </div>
</template>

<script>
  import InputNumber from './InputNumber.vue'
  import ContractNameForm from './ContractNameForm'
  import WorkClientForm from '../../workClient/WorkClientForm'
  import WorkContractBorrowMessageForm from './WorkContractBorrowMessageForm'
  import WorkContractService from '@/api/sys/WorkContractService'
  import WorkContractFileService from '@/api/sys/WorkContractFileService'
  import WorkContractBorrowService from '@/api/sys/WorkContractBorrowService'
  import SelectUserTree from '@/views/utils/treeUserSelect'
  import TaskService from '@/api/flowable/TaskService'
  import ProcessService from '@/api/flowable/ProcessService'
  import pick from 'lodash.pick'
  import UserService from '@/api/sys/UserService'
  export default {
    data () {
      return {
        visible: false,
        num: 0,
        searchForm: {
          clientName: '',
          name: '',
          contractDates: [],
          type: '',
          filedType: '',
          contractAmounts: [],
          createBy: '',
          procInsId: '',
          processDefinitionId: ''
        },
        dataList: [],
        tablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: []
        },
        processDefinitionId: '',
        procDefKey: '',
        loading: false,
        create: '',
        isAdmin: false
      }
    },
    workContractService: null,
    workContractFileService: null,
    workContractBorrowService: null,
    taskService: null,
    processService: null,
    userService: null,
    created () {
      this.workContractService = new WorkContractService()
      this.workContractFileService = new WorkContractFileService()
      this.workContractBorrowService = new WorkContractBorrowService()
      this.taskService = new TaskService()
      this.processService = new ProcessService()
      this.userService = new UserService()
    },
    components: {
      InputNumber,
      ContractNameForm,
      WorkClientForm,
      WorkContractBorrowMessageForm,
      SelectUserTree
    },
    activated () {
      this.is()
      this.refreshList()
    },
    computed: {
      userName () {
        return JSON.parse(localStorage.getItem('user')).name
      },
      user () {
        this.create = JSON.parse(localStorage.getItem('user')).id
        console.log('createId', this.create)
        return JSON.parse(localStorage.getItem('user'))
      }
    },

    methods: {
      // 获取数据列表
      refreshList () {
        console.log('user', this.user)
        this.loading = true
        this.workContractService.list({
          'current': this.tablePage.currentPage,
          'size': this.tablePage.pageSize,
          'orders': this.tablePage.orders,
          'itemType': '1',
          ...this.searchForm
        }).then(({data}) => {
          this.dataList = data.records
          this.tablePage.total = data.total
          this.loading = false
        })
        this.processService.getByName('合同登记新建').then(({data}) => {
          if (!this.commonJS.isEmpty(data.id)) {
            this.processDefinitionId = data.id
            this.procDefKey = data.key
          }
        })
      },
      // 当前页
      currentChangeHandle ({currentPage, pageSize}) {
        this.tablePage.currentPage = currentPage
        this.tablePage.pageSize = pageSize
        this.refreshList()
      },
      // 排序
      sortChangeHandle (column) {
        this.tablePage.orders = []
        if (column.order != null) {
          this.tablePage.orders.push({column: this.$utils.toLine(column.property), asc: column.order === 'asc'})
        }
        this.refreshList()
      },
      // 新增
      add () {
        this.start()
      },
      // 详情
      detail (row) {
        // eslint-disable-next-line eqeqeq
        if (!this.commonJS.isEmpty(row.status) && row.status != '1') {
          this.taskService.getTaskDef({
            procInsId: row.procInsId,
            procDefId: row.processDefinitionId
          }).then(({data}) => {
            this.$router.push({
              path: '/flowable/task/TaskFormDetail',
              query: {
                readOnly: true,
                title: '流程详情',
                formTitle: '流程详情',
                businessId: row.id,
                ...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title', 'businessId')}
            })
          })
        }
      },
      // 修改
      edit (row) {
        if (row.status === '3' || row.status === '4') {
          this.editWithClose(row)
        } else {
          this.editWithHold(row)
        }
      },
      // 管理员修改
      editForm (id) {
        id = id || this.$refs.workClientTable.getCheckboxRecords().map(item => {
          return item.id
        })[0]
        this.$refs.contractNameForm.init('edit', id)
      },
      // 查看
      view (id) {
        this.$refs.contractNameForm.init('view', id)
      },
      // 客户信息查看
      viewInfo (id) {
        this.$refs.workClientForm.init('view', id)
      },
      // 删除
      del (id) {
        let ids = id || this.$refs.workContractTable.getCheckboxRecords().map(item => {
          return item.id
        }).join(',')
        this.$confirm(`确定删除所选项吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.workContractService.remove(ids).then(({data}) => {
            this.$message.success(data)
            this.refreshList()
            this.loading = false
          })
        })
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.refreshList()
      },
      start () {
        // 读取流程表单
        let tabTitle = `发起流程【合同登记新建】`
        let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了 [合同登记新建]`
        this.taskService.getTaskDef({ procDefId: this.processDefinitionId,
          status: 'startAndHold'}).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskForm',
              query: {
                procDefId: this.processDefinitionId,
                procDefKey: this.procDefKey,
                status: 'startAndHold',
                title: tabTitle,
                formType: data.data.formType,
                formUrl: data.data.formUrl,
                formTitle: processTitle,
                businessId: 'false',
                isShow: false,
                routePath: '/sys/workContract/WorkContractList'
              }
            })
          })
      },
      editWithHold (row) {
        // 读取流程表单
        let tabTitle = `发起流程【合同登记新建】`
        let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了 [合同登记新建]`
        this.taskService.getTaskDef({ procDefId: this.processDefinitionId,
          businessId: row.id,
          businessTable: 'work_contract_info',
          status: 'startAndHold'}).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskForm',
              query: {
                procDefId: this.processDefinitionId,
                procDefKey: this.procDefKey,
                status: 'startAndHold',
                title: tabTitle,
                formType: data.data.formType,
                formUrl: data.data.formUrl,
                formTitle: processTitle,
                businessTable: 'work_contract_info',
                businessId: row.id,
                isShow: false,
                routePath: '/sys/workContract/WorkContractList'
              }
            })
          })
      },
      editWithClose (row) {
        // 读取流程表单
        let tabTitle = `发起流程【合同登记新建】`
        let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了 [合同登记新建]`
        this.taskService.getTaskDef({ procDefId: this.processDefinitionId,
          businessId: row.id,
          businessTable: 'work_contract_info',
          status: 'startAndClose'
        }).then((data) => {
          this.$router.push({
            path: '/flowable/task/TaskForm',
            query: {
              procDefId: this.processDefinitionId,
              procDefKey: this.procDefKey,
              status: 'startAndClose',
              title: tabTitle,
              formType: data.data.formType,
              formUrl: data.data.formUrl,
              formTitle: processTitle,
              businessTable: 'work_contract_info',
              businessId: row.id,
              isShow: false,
              routePath: '/sys/workContract/WorkContractList'
            }
          })
        })
      },
      reback (row) {
        this.$confirm(`确定撤回流程吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          taskId: row.procInsId,
          type: 'warning'
        }).then(() => {
          this.taskService.backNodes(row.taskId).then(({data}) => {
            let backNodes = data
            if (backNodes.length > 0) {
              let backTaskDefKey = backNodes[0].taskDefKey
              this.taskService.back({
                taskId: row.taskId,
                backTaskDefKey: backTaskDefKey,
                isShow: false,
                ...this.auditForm
              }).then(({data}) => {
                this.updateStatusById(row, 'reback')
                this.$message.success('回退成功')
              })
            }
          })
        })
      },
      rebackFiled (row) {
        this.$confirm(`确定撤回流程吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          taskId: row.taskFiledId,
          type: 'warning'
        }).then(() => {
          console.log('datas', row.taskFiledId)
          this.taskService.backNodes(row.taskFiledId).then(({data}) => {
            let backNodes = data
            if (backNodes.length > 0) {
              let backTaskDefKey = backNodes[0].taskDefKey
              this.taskService.back({
                taskId: row.taskFiledId,
                backTaskDefKey: backTaskDefKey,
                isShow: false,
                ...this.auditForm
              }).then(({data}) => {
                this.updateStatusById(row, 'rebackFiled')
                this.$message.success('回退成功')
              })
            }
          })
        })
      },
      updateStatusById (row, type) {
        if (type === 'agree') {
          row.status = '5'
          this.workContractService.updateStatusById(row)
        }
        if (type === 'reject') {
          row.status = '4'
          this.workContractService.updateStatusById(row)
        }
        if (type === 'reback') {
          row.status = '3'
          this.workContractService.updateStatusById(row)
        }
        if (type === 'rebackFiled') {
          row.filedType = '3'
          this.workContractFileService.updateStatusById(row)
        }
        if (type === 'rebackBorrow') {
          row.borrowType = '0'
          this.workContractBorrowService.updateStatusByContractInfoId(row).then(() => {
            this.workContractBorrowService.deleteById(row.id)
          })
        }
        if (type === 'retureBorrow') {
          row.borrowType = '0'
          this.workContractBorrowService.updateStatusByContractInfoId(row).then(() => {
            row.type = 'reture'
            row.borrowType = '5'
            this.workContractBorrowService.updateMessageStatusById(row)
          })
        }
      },
      is () {
        this.userService.is().then(({data}) => {
          this.isAdmin = data
        })
      },
      // 归档
      filed (id) {
        this.processService.getByName('评估-合同归档').then(({data}) => {
          if (!this.commonJS.isEmpty(data.id)) {
            console.log('data', data)
            // 读取流程表单
            let tabTitle = `发起流程【评估-合同归档】`
            let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了 [评估-合同归档]`
            this.taskService.getTaskDef({ procDefId: data.id,
              businessId: id,
              businessTable: 'work_contract_file',
              status: 'startAndHoldFiled'}).then((reture) => {
                this.$router.push({
                  path: '/flowable/task/TaskForm',
                  query: {
                    procDefId: data.id,
                    procDefKey: data.key,
                    status: 'startAndHoldFiled',
                    title: tabTitle,
                    formType: reture.data.formType,
                    formUrl: reture.data.formUrl,
                    formTitle: processTitle,
                    businessTable: 'work_contract_file',
                    businessId: id,
                    isShow: false,
                    routePath: '/sys/workContract/WorkContractList'
                  }
                })
              })
          }
        })
      },
      // 归档
      filedAndClose (id) {
        this.processService.getByName('评估-合同归档').then(({data}) => {
          if (!this.commonJS.isEmpty(data.id)) {
            console.log('data', data)
            // 读取流程表单
            let tabTitle = `发起流程【评估-合同归档】`
            let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了 [评估-合同归档]`
            this.taskService.getTaskDef({ procDefId: data.id,
              businessId: id,
              businessTable: 'work_contract_file',
              status: 'startAndCloseFiled'}).then((reture) => {
                this.$router.push({
                  path: '/flowable/task/TaskForm',
                  query: {
                    procDefId: data.id,
                    procDefKey: data.key,
                    status: 'startAndCloseFiled',
                    title: tabTitle,
                    formType: reture.data.formType,
                    formUrl: reture.data.formUrl,
                    formTitle: processTitle,
                    businessTable: 'work_contract_file',
                    businessId: id,
                    isShow: false,
                    routePath: '/sys/workContract/WorkContractList'
                  }
                })
              })
          }
        })
      },
      // 归档详情
      detailFiled (row) {
        if (row.filedType !== '4') {
          this.workContractFileService.findByContractInfoId(row.id).then(({data}) => {
            if (!this.commonJS.isEmpty(data.id)) {
              console.log('data', data)
              this.taskService.getTaskDef({
                procInsId: data.procInsId,
                procDefId: data.processDefinitionId
              }).then(({data}) => {
                this.$router.push({
                  path: '/flowable/task/TaskFormDetail',
                  query: {
                    readOnly: true,
                    title: '归档流程详情',
                    formTitle: '归档流程详情',
                    businessId: row.id,
                    ...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title', 'businessId')}
                })
              })
            }
          })
        }
      },
      // 借用
      borrow (id) {
        this.processService.getByName('合同登记借用').then(({data}) => {
          if (!this.commonJS.isEmpty(data.id)) {
            console.log('data', data)
            // 读取流程表单
            let tabTitle = `发起流程【合同登记借用】`
            let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了 [合同登记借用]`
            this.taskService.getTaskDef({ procDefId: data.id,
              businessId: id,
              businessTable: 'work_contract_borrow',
              status: 'startAndCloseBorrow'}).then((reture) => {
                this.$router.push({
                  path: '/flowable/task/TaskForm',
                  query: {
                    procDefId: data.id,
                    procDefKey: data.key,
                    status: 'startAndCloseBorrow',
                    title: tabTitle,
                    formType: reture.data.formType,
                    formUrl: reture.data.formUrl,
                    formTitle: processTitle,
                    businessTable: 'work_contract_borrow',
                    businessId: id,
                    isShow: false,
                    routePath: '/sys/workContract/WorkContractList'
                  }
                })
              })
          }
        })
      },
      // 借用详情
      detailBorrow (row) {
        this.$refs.workContractBorrowMessageForm.findList(row.id)
      },
      // 借用撤回
      rebackBorrow (row) {
        this.$confirm(`确定撤回流程吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          taskId: row.taskBorrowId,
          type: 'warning'
        }).then(() => {
          console.log('datas', row.taskBorrowId)
          this.taskService.backNodes(row.taskBorrowId).then(({data}) => {
            let backNodes = data
            if (backNodes.length > 0) {
              let backTaskDefKey = backNodes[0].taskDefKey
              this.taskService.back({
                taskId: row.taskBorrowId,
                backTaskDefKey: backTaskDefKey,
                isShow: false,
                ...this.auditForm
              }).then(({data}) => {
                this.updateStatusById(row, 'rebackBorrow')
                this.$message.success('回退成功')
              })
            }
          })
        })
      },
      // 归还合同
      retureBorrow (row) {
        this.$confirm(`确定归还合同吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.updateStatusById(row, 'retureBorrow')
          this.refreshList()
        })
      }
    }
  }
</script>
