<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="collectNo">
        <el-input size="small" v-model="searchForm.collectNo" placeholder="请输入领用编号" clearable></el-input>
      </el-form-item>
      <el-form-item label="领用物品名称" prop="goodsName">
        <el-input size="small" v-model="searchForm.goodsName" placeholder="请输入领用物品名称" clearable></el-input>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="经办人" prop="handledBy">
        <UserSelect :limit='1' :userName="searchForm.handledBy" @getValue='(value, label) => {searchForm.handledBy = label}'></UserSelect>
<!--        <SelectUserTree-->
<!--          ref="companyTree"-->
<!--          :props="{-->
<!--                  value: 'id',             // ID字段名-->
<!--                  label: 'name',         // 显示名称-->
<!--                  children: 'children'    // 子级字段名-->
<!--                }"-->
<!--          :url="`/sys/user/treeUserDataAllOffice?type=2`"-->
<!--          :value="searchForm.handledBy"-->
<!--          :clearable="true"-->
<!--          :accordion="true"-->
<!--          @getValue="(value) => {searchForm.handledBy=value}"/>-->
      </el-form-item>
      <el-form-item v-if="showHideItem" prop="handledByOffice" label="经办人部门">
        <SelectTree
          ref="officeTree"
          :props="{
                  value: 'id',             // ID字段名
                  label: 'name',         // 显示名称
                  children: 'children'    // 子级字段名
                }"

          :url="`/sys/office/treeData?type=1`"
          :value="searchForm.handledByOffice"
          :accordion="true"
          @getValue="(value) => {searchForm.handledByOffice=value}"/>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="领用时间" prop="collectDates">
        <el-date-picker
          placement="bottom-start"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          v-model="searchForm.collectDates"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="退回状态" prop="statusReturn">
        <el-select v-model="searchForm.statusReturn" placeholder="请选择" style="width:100%;" clearable>
          <el-option
            v-for="item in $dictUtils.getDictList('cw_status')"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="default" @click="showHide" size="small" :icon="showHideIcon">{{showHideName}}</el-button>
        <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" style="">
      <vxe-toolbar :refresh="{query: refreshList}" custom>
        <template #buttons>
          <el-button v-if="hasPermission('material:add')" type="primary" size="small" icon="el-icon-plus" @click="start()">新建</el-button>
        </template>
      </vxe-toolbar>
      <div style="height: calc(100% - 90px)">
        <vxe-table
          :key="tableKey"
          border="inner"
          auto-resize
          resizable
          height="auto"
          :loading="loading"
          size="small"
          ref="clientTable"
          show-header-overflow
          show-overflow
          highlight-hover-row
          :menu-config="{}"
          @sort-change="sortChangeHandle"
          :sort-config="{remote:true}"
          :data="dataList"
          :checkbox-config="{}">
          <vxe-column type="seq" width="60" title="序号"></vxe-column>
          <vxe-column min-width="160" align="center" title="领用编号" field="collectNo">
            <template slot-scope="scope">
              <el-link  type="primary" :underline="false" v-if="hasPermission('material:list')" @click="view(scope.row.id)">{{scope.row.collectNo}}</el-link>
              <el-link  type="primary" :underline="false" v-else-if="hasPermission('material:list')"  @click="view(scope.row.id,)">{{scope.row.collectNo}}</el-link>
              <span v-else>{{scope.row.collectNo}}</span>
            </template>
          </vxe-column>
          <vxe-column min-width="160" align="center" title="领用物品名称" field="goodsName">
            <template slot-scope="scope">
              <span v-if="commonJS.isEmpty(scope.row.detailId)" style="color: #F56C6C">领用物品已全部退回</span>
              <span v-else>{{scope.row.goodsName}}</span>
            </template>
          </vxe-column>
          <vxe-column min-width="160" align="center" title="经办人" field="handledByName"></vxe-column>
          <vxe-column min-width="160" align="center" title="经办人部门" field="handledByOfficeName"></vxe-column>
          <vxe-column min-width="160" align="center" title="领用时间" field="collectDate"></vxe-column>
          <vxe-column  min-width="100px"align="center" fixed="right" title="状态" field="status" >
            <template slot-scope="scope">
              <el-button  type="text" @click="detail(scope.row)" effect="dark" size="mini"
                          :type="$dictUtils.getDictLabel('cw_status_flag', scope.row.status, '-')">
                {{$dictUtils.getDictLabel("cw_status", scope.row.status, '-')}}
              </el-button>
            </template>
          </vxe-column>
          <vxe-column  min-width="100px"align="center" fixed="right" title="退回状态" field="statusReturn" >
            <template slot-scope="scope">
              <el-button  type="text" @click="detailReturn(scope.row)" effect="dark" size="mini"
                          :type="$dictUtils.getDictLabel('cw_status_flag', scope.row.statusReturn, '-')">
                {{$dictUtils.getDictLabel("cw_status", scope.row.statusReturn, '未发起')}}
              </el-button>
            </template>
          </vxe-column>

          <vxe-column title="操作" width="220px" fixed="right" align="center">
            <template  slot-scope="scope">
              <el-button v-if="hasPermission('material:edit')&&scope.row.createBy === $store.state.user.id&&(scope.row.status==='1'||scope.row.status==='3')" type="text"  size="small" @click="push(scope.row)">修改</el-button>
              <el-button v-else-if="hasPermission('material:edit')&&isAdmin&&(scope.row.status==='1'||scope.row.status==='3'||scope.row.status==='4'||scope.row.status==='5')" type="text"  size="small" @click="edit(scope.row.id)">修改</el-button>
              <el-button v-if="hasPermission('material:edit')&&scope.row.createBy === $store.state.user.id&&scope.row.status==='2'" type="text"  size="small" @click="reback(scope.row)">撤回</el-button>
              <el-button v-if="hasPermission('material:del')&&scope.row.createBy === $store.state.user.id&&(scope.row.status==='1'||scope.row.status==='3')" type="text"   size="small" @click="del(scope.row.id)">删除</el-button>
              <el-button v-else-if="hasPermission('material:del')&&isAdmin&&(scope.row.status==='1'||scope.row.status==='3'||scope.row.status==='4'||scope.row.status==='5')" type="text"   size="small" @click="del(scope.row.id)">删除</el-button>
              <el-button v-if="scope.row.status==='2' && checkIsAudit(scope.row)" type="text"  size="small" @click="examine(scope.row)">审核</el-button>
              <el-button v-if="hasPermission('material:edit')&&scope.row.status === '4'&&scope.row.createBy === $store.state.user.id" type="text"  size="small" @click="adjust(scope.row)">驳回调整</el-button>

              <el-button v-if="hasPermission('material:edit')&&scope.row.status === '5'&&scope.row.createBy === $store.state.user.id && commonJS.isNotEmpty(scope.row.detailId) &&
              (commonJS.isEmpty(scope.row.statusReturn) || scope.row.statusReturn === '0' || scope.row.statusReturn === '1' || scope.row.statusReturn === '3' || scope.row.statusReturn === '5')"
                         type="text"  size="small" @click="returnPush(scope.row)">退回</el-button>
              <el-button v-if="hasPermission('material:edit')&&scope.row.statusReturn === '2'&&scope.row.createBy === $store.state.user.id"
                         type="text"  size="small" @click="rebackReturn(scope.row)">撤回</el-button>
              <el-button v-if="hasPermission('material:edit')&&scope.row.statusReturn === '3'&&scope.row.createBy === $store.state.user.id"
                         type="text"  size="small" @click="returnRequest(scope.row)">取消申请</el-button>
              <el-button v-if="scope.row.statusReturn==='2' && checkIsAuditReturn(scope.row)"
                         type="text"  size="small" @click="examineReturn(scope.row)">退回审核</el-button>
              <el-button v-if="hasPermission('material:edit')&&scope.row.statusReturn === '4'&&scope.row.createBy === $store.state.user.id"
                         type="text"  size="small" @click="adjustReturn(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>
        <UpdateCollectInfoForm ref="updateCollectInfoForm" @refreshList="refreshList"></UpdateCollectInfoForm>
      </div>
    </div>
  </div>
</template>

<script>
  import UserSelect from '@/components/userSelect'
  import CollectService from '@/api/materialManagement/CollectService'
  import UpdateCollectInfoForm from './UpdateCollectInfoForm'
  import InputNumber from '@/views/modules/cw/workContract/InputNumber.vue'
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  import WorkClientService from '@/api/cw/workClientInfo/WorkClientService'
  import TaskService from '@/api/flowable/TaskService'
  import ProcessService from '@/api/flowable/ProcessService'
  import pick from 'lodash.pick'
  import UserService from '@/api/sys/UserService'
  import SelectUserTree from '@/views/modules/utils/treeUserSelect'
  export default {
    data () {
      return {
        showHideItem: false,
        showHideIcon: 'el-icon-arrow-down',
        showHideName: '展示',
        num: 0,
        searchForm: {
          handledBy: '',
          handledByOffice: '',
          collectNo: '',
          goodsName: '',
          collectDates: [],
          statusReturn: ''
        },
        dataList: [],
        tablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: []
        },
        tableKey: '',
        loading: false,
        processDefinitionAuditId: '',
        procDefAuditKey: '',
        isAdmin: false,
        create: '',
        processDefinitionAuditIdReturn: '',
        procDefAuditKeyReturn: ''
      }
    },
    workClientService: null,
    collectService: null,
    taskService: null,
    processService: null,
    userService: null,
    created () {
      this.workClientService = new WorkClientService()
      this.collectService = new CollectService()
      this.taskService = new TaskService()
      this.processService = new ProcessService()
      this.userService = new UserService()
    },
    components: {
      UserSelect,
      InputNumber,
      SelectUserTree,
      SelectTree,
      UpdateCollectInfoForm
    },
    computed: {
      userName () {
        return JSON.parse(localStorage.getItem('user')).name
      },
      user () {
        this.createName = JSON.parse(localStorage.getItem('user')).name
        return JSON.parse(localStorage.getItem('user'))
      }
    },
    mounted () {
      this.refreshList()
    },
    activated () {
      this.refreshList()
    },
    methods: {
      showHide () {
        if (this.showHideItem === false) {
          this.showHideItem = true
          this.showHideIcon = 'el-icon-arrow-up'
          this.showHideName = '隐藏'
        } else {
          this.showHideItem = false
          this.showHideIcon = 'el-icon-arrow-down'
          this.showHideName = '展示'
        }
      },
      // 新增
      add () {
        // this.$refs.reportManagementForm.init('add', '')
      },
      // 修改
      edit (id) {
        id = id || this.$refs.clientTable.getCheckboxRecords().map(item => {
          return item.id
        })[0]
        this.$refs.updateCollectInfoForm.init('edit', id)
      },
      // 查看
      view (id) {
        this.$refs.updateCollectInfoForm.init('view', id)
      },
      // 查询当前用户是否是管理员用户
      checkIsAdmin () {
        this.userService.is().then(({data}) => {
          this.isAdmin = data
        })
      },
      // 获取数据列表
      refreshList () {
        this.loading = true
        this.collectService.list({
          'current': this.tablePage.currentPage,
          'size': this.tablePage.pageSize,
          'orders': this.tablePage.orders,
          ...this.searchForm
        }).then(({data}) => {
          this.dataList = data.records
          this.tablePage.total = data.total
          this.tableKey = Math.random()
          this.loading = false
        })
        this.checkIsAdmin()
        this.processService.getByName('物资管理-领用申请').then(({data}) => {
          if (!this.commonJS.isEmpty(data.id)) {
            this.processDefinitionAuditId = data.id
            this.procDefAuditKey = data.key
          }
        })
        this.processService.getByName('物资管理-领用退回申请').then(({data}) => {
          if (!this.commonJS.isEmpty(data.id)) {
            this.processDefinitionAuditIdReturn = data.id
            this.procDefAuditKeyReturn = 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()
      },
      // 删除
      del (id) {
        let ids = id || this.$refs.clientTable.getCheckboxRecords().map(item => {
          return item.id
        }).join(',')
        this.$confirm(`确定删除所选项吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.collectService.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.processDefinitionAuditId,
          status: 'startAndHold'}).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskForm',
              query: {
                ...pick(data.data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
                procDefId: this.processDefinitionAuditId,
                procDefKey: this.procDefAuditKey,
                status: 'startAndHold',
                title: tabTitle,
                formType: data.data.formType,
                formUrl: data.data.formUrl,
                formTitle: processTitle,
                businessId: 'false',
                isShow: false,
                routePath: '/materialManagement/collect/CollectList'
              }
            })
          })
      },
      // 发起领用申请
      push (row) {
        // 读取流程表单
        let title = `发起流程【领用申请】`
        let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了[领用申请]`
        let status = 'startAndHold'
        if (row.status === '3') {
          status = 'startAndClose'
        } else if (row.status === '4') {
          status = 'reapplyFlag'
        }
        this.taskService.getTaskDef({ procDefId: this.processDefinitionAuditId,
          businessId: row.id,
          businessTable: 'material_management_collect_basics'}).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskForm',
              query: {
                ...pick(data.data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
                procDefId: this.processDefinitionAuditId,
                procDefKey: this.procDefAuditKey,
                title: title,
                formType: data.data.formType,
                formUrl: data.data.formUrl,
                formTitle: processTitle,
                businessTable: 'material_management_collect_basics',
                businessId: row.id,
                isShow: 'false',
                status: status,
                routePath: '/materialManagement/collect/CollectList'
              }
            })
          })
      },
      // 查看客户登记流程结果
      detail (row) {
        if (row.status !== '0' && row.status !== '1') {
          // eslint-disable-next-line eqeqeq
          this.taskService.getTaskDef({
            procInsId: row.procInsId,
            procDefId: this.processDefinitionAuditId
          }).then(({data}) => {
            this.$router.push({
              path: '/flowable/task/TaskFormDetail',
              query: {
                ...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
                isShow: 'false',
                readOnly: true,
                title: '领用申请' + '流程详情',
                formTitle: '领用申请' + '流程详情',
                businessId: row.id,
                status: 'reback'
              }
            })
          })
        }
      },
      // 撤回报告流程
      reback (row) {
        this.$confirm(`确定要撤回该申请吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          await this.collectService.findById(row.id).then(({data}) => {
            if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
              this.$message.error('数据已发生改变或不存在，请刷新数据')
              this.refreshList()
            } else {
              this.processService.revokeProcIns(row.procInsId).then(({data}) => {
                let form = {status: '3', id: row.id}
                this.collectService.updateStatusById(form)
                this.$message.success(data)
                this.refreshList()
              })
            }
          })
          // await this.reportCancellApplyService.queryById(row.id).then(({data}) => {
          //   if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
          //     this.$message.error('数据已发生改变或不存在，请刷新数据')
          //     this.refreshList()
          //   } else {
          //     this.processService.revokeProcIns(row.procInsId).then(({data}) => {
          //       let form = {status: '3', id: row.id}
          //       this.reportCancellApplyService.updateStatusById(form)
          //       this.$message.success(data)
          //       this.refreshList()
          //     })
          //   }
          // })
        })
      },
      // 驳回后调整
      adjust (row) {
        this.collectService.findById(row.id).then(({data}) => {
          if (data.status !== '4') { // status的值不等于“驳回”，就弹出提示
            this.$message.error('数据已发生改变或不存在，请刷新数据')
            this.refreshList()
          } else {
            this.todo(row)
          }
        })
      },
      // 审核
      examine (row) {
        this.collectService.findById(row.id).then(({data}) => {
          if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
            this.$message.error('数据已发生改变或不存在，请刷新数据')
            this.refreshList()
          } else {
            this.todo(row)
          }
        })
      },
      // 审核或重新调整跳转
      todo (row) {
        let cUser = false
        this.taskService.getTaskDefInfo({
          taskId: row.taskId
        }).then(({data}) => {
          this.$router.push({
            path: '/flowable/task/TaskForm',
            query: {
              ...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title', 'businessId'),
              isShow: false,
              formReadOnly: true,
              formTitle: `${data.taskName}`,
              cUser: cUser,
              title: `审批【${data.taskName || ''}】`,
              routePath: '/materialManagement/collect/CollectList'   // 数据处理后需要跳转的页面路径
            }
          })
        })
      },
      // 查询当前登录人是否是数据的审核人
      checkIsAudit (row) {
        let loginUserId = this.$store.state.user.id  // 获取当前登录用户id
        if (this.commonJS.isNotEmpty(row.auditUserIds)) {
          for (const userId of row.auditUserIds) {
            if (userId === loginUserId) {  // 当数据的审核人中包含当前登录人id时，返回true
              return true
            }
          }
        }
        return false
      },
      // 发起领用-退回申请
      async returnPush (row) {
        if (this.commonJS.isEmpty(row.returnId)) {
          this.loading = true
          // 由于退回数据表中没有数据，需要生成一条默认数据
          let resp = await this.collectService.createReturnData({id: row.id})
          if (resp.data) {
            this.loading = false
            row.returnId = resp.data.returnId
            this.returnPushTrue(row)
          } else {
            this.loading = false
            this.$message.error('无法退回数据，联系管理员解决')
          }
        } else {
          this.returnPushTrue(row)
        }
      },
      returnPushTrue (row) {
        // 读取流程表单
        let title = `发起流程【领用-退回申请】`
        let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了[领用-退回申请]`
        let status = 'startAndHold'
        if (row.statusReturn === '3') {
          status = 'startAndClose'
        } else if (row.statusReturn === '4') {
          status = 'reapplyFlag'
        }
        this.taskService.getTaskDef({ procDefId: this.processDefinitionAuditIdReturn,
          businessId: row.returnId,
          businessTable: 'material_management_collect_basics_return'}).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskForm',
              query: {
                ...pick(data.data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
                procDefId: this.processDefinitionAuditIdReturn,
                procDefKey: this.procDefAuditKeyReturn,
                title: title,
                formType: data.data.formType,
                formUrl: data.data.formUrl,
                formTitle: processTitle,
                businessTable: 'material_management_collect_basics_return',
                businessId: row.returnId,
                isShow: 'false',
                status: status,
                routePath: '/materialManagement/collect/CollectList',
                returnId: row.returnId
              }
            })
          })
      },
      detailReturn (row) {
        if (this.commonJS.isNotEmpty(row.statusReturn) && row.statusReturn !== '0' && row.statusReturn !== '1') {
          // eslint-disable-next-line eqeqeq
          this.taskService.getTaskDef({
            procInsId: row.procInsIdReturn,
            procDefId: this.processDefinitionAuditIdReturn
          }).then(({data}) => {
            this.$router.push({
              path: '/flowable/task/TaskFormDetail',
              query: {
                ...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
                isShow: 'false',
                readOnly: true,
                title: '领用-退回申请' + '流程详情',
                formTitle: '领用-退回申请' + '流程详情',
                businessId: row.returnId,
                status: 'reback',
                returnId: row.returnId
              }
            })
          })
        }
      },
      // 撤回退回流程
      rebackReturn (row) {
        this.$confirm(`确定要撤回该申请吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.collectService.findById(row.id).then(({data}) => {
            if (data.statusReturn !== '2') { // status的值不等于“审核中”，就弹出提示
              this.$message.error('数据已发生改变或不存在，请刷新数据')
              this.refreshList()
            } else {
              this.processService.revokeProcIns(row.procInsIdReturn).then(({data}) => {
                let form = {status: '3', id: row.id}
                this.collectService.updateStatusByIdReturn(form)
                this.$message.success(data)
                this.refreshList()
              })
            }
          })
        })
      },
      returnRequest (row) {
        this.$confirm(`确定要取消该申请吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.collectService.findById(row.id).then(({data}) => {
            if (data.statusReturn !== '3') { // status的值不等于“已撤回”，就弹出提示
              this.$message.error('数据已发生改变或不存在，请刷新数据')
              this.refreshList()
            } else {
              this.collectService.returnRequest({id: row.id}).then(({data}) => {
                this.$message.success(data)
                this.refreshList()
              })
            }
          })
        })
      },
      // 驳回后调整
      adjustReturn (row) {
        this.collectService.findById(row.id).then(({data}) => {
          if (data.statusReturn !== '4') { // status的值不等于“驳回”，就弹出提示
            this.$message.error('数据已发生改变或不存在，请刷新数据')
            this.refreshList()
          } else {
            this.todoReturn(row)
          }
        })
      },
      // 审核
      examineReturn (row) {
        this.collectService.findById(row.id).then(({data}) => {
          if (data.statusReturn !== '2') { // status的值不等于“审核中”，就弹出提示
            this.$message.error('数据已发生改变或不存在，请刷新数据')
            this.refreshList()
          } else {
            this.todoReturn(row)
          }
        })
      },
      // 审核或重新调整跳转
      todoReturn (row) {
        let cUser = false
        this.taskService.getTaskDefInfo({
          taskId: row.taskIdReturn
        }).then(({data}) => {
          this.$router.push({
            path: '/flowable/task/TaskForm',
            query: {
              ...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title', 'businessId'),
              isShow: false,
              formReadOnly: true,
              formTitle: `${data.taskName}`,
              cUser: cUser,
              title: `审批【${data.taskName || ''}】`,
              routePath: '/materialManagement/collect/CollectList'   // 数据处理后需要跳转的页面路径
            }
          })
        })
      },
      // 查询当前登录人是否是数据的审核人
      checkIsAuditReturn (row) {
        let loginUserId = this.$store.state.user.id  // 获取当前登录用户id
        if (this.commonJS.isNotEmpty(row.auditUserIdsReturn)) {
          for (const userId of row.auditUserIdsReturn) {
            if (userId === loginUserId) {  // 当数据的审核人中包含当前登录人id时，返回true
              return true
            }
          }
        }
        return false
      }
    }
  }
</script>
