<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="name">-->
<!--        <el-input size="small" v-model="searchForm.name" placeholder="请输入档案名称" clearable></el-input>-->
<!--      </el-form-item>-->
      <el-form-item label="档案号" prop="fileNumber">
        <el-input size="small" v-model="searchForm.fileNumber" placeholder="请输入档案号" clearable></el-input>
      </el-form-item>
      <el-form-item label="项目名称" prop="cwProjectRecordsDTO.projectName">
        <el-input size="small" v-model="searchForm.cwProjectRecordsDTO.projectName" placeholder="请输入项目名称" clearable></el-input>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="项目经理1" prop="cwProjectRecordsDTO.projectMasterName">
<!--        <el-input size="small" v-model="searchForm.cwProjectRecordsDTO.projectMasterName" placeholder="请输入项目经理" clearable></el-input>-->
        <UserSelect :limit='1' :userName="searchForm.cwProjectRecordsDTO.projectMasterName" @getValue='(value, label) => {searchForm.cwProjectRecordsDTO.projectMasterName = label}'></UserSelect>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="项目经理2" prop="cwProjectRecordsDTO.realHeaderName">
        <!--        <el-input size="small" v-model="searchForm.cwProjectRecordsDTO.projectMasterName" placeholder="请输入项目经理" clearable></el-input>-->
        <UserSelect :limit='1' :userName="searchForm.cwProjectRecordsDTO.realHeaderName" @getValue='(value, label) => {searchForm.cwProjectRecordsDTO.realHeaderName = label}'></UserSelect>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="档案年度" prop="year">
        <el-date-picker
          size="small"
          v-model="searchForm.year"
          type="year"
          value-format="yyyy"
          placeholder="选择档案年度"
          style="width:100%"
          placement="bottom-start"
          clearable>
        </el-date-picker>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="案卷号" prop="number">
        <el-input size="small" v-model="searchForm.number" placeholder="请输入案卷号" clearable></el-input>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="归档时间" prop="auditDates">
        <el-date-picker
          placement="bottom-start"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          v-model="searchForm.auditDates"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          clearable>
        </el-date-picker>
      </el-form-item>

      <el-form-item v-if="showHideItem" label="创建人" prop="createBy.name">
<!--        <el-input size="small" v-model="searchForm.createBy.name" placeholder="请输入创建人" clearable></el-input>-->
        <UserSelect :limit='1' :userName="searchForm.createBy.name" @getValue='(value, label) => {searchForm.createBy.name = label}'></UserSelect>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="创建时间" prop="createDates">
        <el-date-picker
          placement="bottom-start"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          v-model="searchForm.createDates"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          clearable>
        </el-date-picker>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="报告文号" prop="reportNo">
        <el-input size="small" v-model="searchForm.reportNo" placeholder="请输入报告文号" clearable></el-input>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="状态" prop="status">
        <el-select size="small" v-model="searchForm.status" 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 v-if="showHideItem" label="归档状态" prop="archiveSta">
        <el-select v-model="searchForm.archiveSta" placeholder="请选择归档状态" clearable style="width: 100%">
          <el-option-group
            v-for="(type,index) in typeDictList"
            :key="type.key"
            :label="type.label">
            <el-option
              v-for="item in typeDictList[index].childrenList"
              :key="item.key"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-option-group>
        </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}" export custom>
        <template #buttons>
<!--          <el-button v-if="hasPermission('cwProjectReportArchive: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="projectTable"
          show-header-overflow
          show-overflow
          :export-config="{
                    remote: true,
                    filename: `报告归档数据${moment(new Date()).format('YYYY-MM-DD')}`,
                    sheetName: `报告归档数据${moment(new Date()).format('YYYY-MM-DD')}`,
                    exportMethod: exportMethod,
                    types: ['xlsx'],
                    modes: ['current', 'selected', 'all']
                  }"
          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 type="checkbox" width="40" ></vxe-column>
          <vxe-column min-width="150" align="center" title="档案号" field="fileNumber">
            <template slot-scope="scope">
              <el-link  type="primary" :underline="false" v-if="hasPermission('cwProjectReportArchive:view')" @click="view(scope.row.id)">{{scope.row.fileNumber}}</el-link>
              <span v-else>{{scope.row.fileNumber}}</span>
            </template>
          </vxe-column>
          <vxe-column min-width="230" align="center" title="项目名称" field="cwProjectRecordsDTO.projectName">
            <template slot-scope="scope">
              <el-link  type="primary" :underline="false" v-if="hasPermission('cwProjectRecords:view')" @click="viewProject(scope.row.projectId)">{{commonJS.isNotEmpty(scope.row.cwProjectRecordsDTO)?scope.row.cwProjectRecordsDTO.projectName:''}}</el-link>
              <span v-else>{{commonJS.isNotEmpty(scope.row.cwProjectRecordsDTO)?scope.row.cwProjectRecordsDTO.projectName:''}}</span>
            </template>
          </vxe-column>
          <vxe-column min-width="220" align="center" title="报告文号" field="reportNo"></vxe-column>
          <vxe-column min-width="150" align="center" title="项目经理1" field="cwProjectRecordsDTO.projectMasterName"></vxe-column>
          <vxe-column min-width="150" align="center" title="项目经理2" field="cwProjectRecordsDTO.realHeaderName"></vxe-column>
          <vxe-column min-width="230" align="center" title="被审计单位" field="auditedUnitsName"></vxe-column>
          <vxe-column min-width="150" align="center" title="报告册数" field="reportNum"></vxe-column>
          <vxe-column min-width="150" align="center" title="底稿册数" field="papersNum"></vxe-column>
          <vxe-column min-width="150" align="center" title="档案年度" field="year"></vxe-column>
          <vxe-column min-width="230" align="center" title="案卷号" field="number"></vxe-column>
          <vxe-column min-width="150" align="center" title="报告日期" :formatter="formatDate" field="reportDate"></vxe-column>
          <vxe-column min-width="200" align="center" title="归档时间" :formatter="formatDate" field="auditDate"></vxe-column>
          <vxe-column min-width="150" align="center" title="归档状态" field="archiveSta">
            <template slot-scope="scope">
              <span style="color:#5bc0de; font-weight: bold;" v-if="scope.row.archiveSta === '暂时未归档'">暂时未归档</span>
              <span style="color:#de6764; font-weight: bold;" v-if="scope.row.archiveSta === '超期未归档'">超期未归档</span>
              <span style="color:#5cb85c; font-weight: bold;" v-if="scope.row.archiveSta === '已按时归档'">已按时归档</span>
              <span style="color:#f0ad4e; font-weight: bold;" v-if="scope.row.archiveSta === '已超期归档'">已超期归档</span>
            </template>
          </vxe-column>
          <vxe-column min-width="150" align="center" title="超期（天）" field="overdueDay">
            <template slot-scope="scope">
              <span style="color:#5bc0de; font-weight: bold;" v-if="scope.row.archiveSta === '暂时未归档'">{{scope.row.overdueDay}}</span>
              <span style="color:#de6764; font-weight: bold;" v-if="scope.row.archiveSta === '超期未归档'">{{scope.row.overdueDay}}</span>
              <span style="color:#5cb85c; font-weight: bold;" v-if="scope.row.archiveSta === '已按时归档'">{{scope.row.overdueDay}}</span>
              <span style="color:#f0ad4e; font-weight: bold;" v-if="scope.row.archiveSta === '已超期归档'">{{scope.row.overdueDay}}</span>
            </template></vxe-column>
          <vxe-column min-width="150" align="center" title="罚款金额（元）" field="fineMoney"></vxe-column>
          <vxe-column min-width="150" align="center" title="创建人" field="createBy.name"></vxe-column>
          <vxe-column min-width="200" align="center" title="创建时间" field="createDate"></vxe-column>
          <vxe-column  min-width="110px"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 title="操作" width="100px" fixed="right" align="center">
            <template  slot-scope="scope">
              <div v-if="isAdmin">
                <el-button v-if="scope.row.status==='5'" type="text"  size="small" @click="edit(scope.row.id)">修改</el-button>
              </div>
              <div v-else>
              <el-button v-if="hasPermission('cwProjectReportArchive:edit')&&(scope.row.createBy.id === $store.state.user.id||haveProjectIds.includes(scope.row.projectId))&&(scope.row.status==='0'||scope.row.status==='1'||scope.row.status==='3')" type="text"  size="small" @click="push(scope.row)">归档</el-button>
              <el-button v-if="hasPermission('cwProjectReportArchive:edit')&&(scope.row.createBy.id === $store.state.user.id||haveProjectIds.includes(scope.row.projectId))&&scope.row.status==='2'" type="text"  size="small" @click="reback(scope.row)">撤回</el-button>
<!--              <el-button v-if="hasPermission('cwProjectReportArchive:del')&&scope.row.createBy.id === $store.state.user.id&&(scope.row.status==='1'||scope.row.status==='3'||scope.row.status==='4')" type="text"   size="small" @click="del(scope.row.id)">删除</el-button>-->
<!--              <el-button v-else-if="hasPermission('cwProjectReportArchive:del')&&isAdmin&&(scope.row.status==='1'||scope.row.status==='3'||scope.row.status==='5'||scope.row.status==='4')" 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="scope.row.createBy.id === $store.state.user.id&&scope.row.status === '4'" type="text"  size="small" @click="adjust(scope.row)">驳回调整</el-button>
              </div>
            </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>
      <ProjectRecordsForm ref="projectRecordsForm"></ProjectRecordsForm>
      <ProjectReportArchiveForm ref="projectReportArchiveForm" @refreshList="refreshList"></ProjectReportArchiveForm>
    </div>
  </div>
</template>

<script>
  import ProjectReportArchiveService from '@/api/cw/projectRecords/ProjectReportArchiveService'
  import TaskService from '@/api/flowable/TaskService'
  import ProcessService from '@/api/flowable/ProcessService'
  import pick from 'lodash.pick'
  import UserService from '@/api/sys/UserService'
  import ProjectRecordsForm from '../projectRecords/ProjectRecordsForm'
  import ProjectReportArchiveForm from './ProjectReportArchiveForm'
  import UserSelect from '@/components/userSelect'
  import ProjectRecordsService from '@/api/cw/projectRecords/ProjectRecordsService'
  import XEUtils from 'xe-utils'
  import OfficeService from '@/api/sys/OfficeService'
  export default {
    data () {
      return {
        showHideItem: false,
        showHideIcon: 'el-icon-arrow-down',
        showHideName: '展示',
        searchForm: {
          name: '',
          cwProjectRecordsDTO: {
            projectName: '',
            projectMasterName: '',
            realHeaderName: ''
          },
          year: '',
          number: '',
          auditDates: [],
          status: '',
          createBy: {
            name: ''
          },
          createDates: [],
          reportNo: '',
          fileNumber: '',
          archiveSta: ''
        },
        dataList: [],
        tablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: []
        },
        tableKey: '',
        loading: false,
        processDefinitionAuditId: '',
        procDefAuditKey: '',
        processDefinitionAuditIdSZ: '',
        procDefAuditKeySZ: '',
        isAdmin: false,
        haveProjectIds: '',
        typeDictList: [
          {
            key: '已归档',
            label: '已归档',
            childrenList: [
              {
                key: '已按时归档',
                value: '已按时归档',
                label: '已按时归档'
              },
              {
                key: '已超期归档',
                value: '已超期归档',
                label: '已超期归档'
              }
            ]
          }, {
            key: '未归档',
            label: '未归档',
            childrenList: [
              {
                key: '暂时未归档',
                value: '暂时未归档',
                label: '暂时未归档'
              },
              {
                key: '超期未归档',
                value: '超期未归档',
                label: '超期未归档'
              }
            ]
          }
        ]
      }
    },
    projectReportArchiveService: null,
    taskService: null,
    processService: null,
    userService: null,
    projectRecordsService: null,
    officeService: null,
    created () {
      this.projectRecordsService = new ProjectRecordsService()
      this.projectReportArchiveService = new ProjectReportArchiveService()
      this.taskService = new TaskService()
      this.processService = new ProcessService()
      this.userService = new UserService()
      this.officeService = new OfficeService()
    },
    components: {
      ProjectRecordsForm,
      ProjectReportArchiveForm,
      UserSelect
    },
    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 = '展示'
        }
      },
      formatDate ({ cellValue }) {
        return XEUtils.toDateString(cellValue, 'yyyy-MM-dd')
      },
      // 新增
      add () {
        // this.$refs.projectRecordsForm.init('add', '')
      },
      // 修改
      edit (id) {
        id = id || this.$refs.projectTable.getCheckboxRecords().map(item => {
          return item.id
        })[0]
        this.$refs.projectReportArchiveForm.init('edit', id)
      },
      // 查看
      view (id) {
        this.$refs.projectReportArchiveForm.init('view', id)
      },
      viewProject (id) {
        this.$refs.projectRecordsForm.init('view', id)
      },
      // 查询当前用户是否是管理员用户
      checkIsAdmin () {
        this.userService.is().then(({data}) => {
          this.isAdmin = data
        })
      },
      // 获取数据列表
      refreshList () {
        this.loading = true
        this.projectReportArchiveService.list({
          'current': this.tablePage.currentPage,
          'size': this.tablePage.pageSize,
          'orders': this.tablePage.orders,
          ...this.searchForm
        }).then(({data}) => {
          this.projectRecordsService.getHaveProjectIds().then(({data}) => {
            if (this.commonJS.isNotEmpty(data)) {
              this.haveProjectIds = data.map(i => {
                if (this.commonJS.isNotEmpty(i)) {
                  return i
                }
              }).join(',')
            }
          })
          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.processDefinitionAuditIdSZ = data.id
            this.procDefAuditKeySZ = 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.projectTable.getCheckboxRecords().map(item => {
          return item.id
        }).join(',')
        this.$confirm(`确定删除所选项吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.projectReportArchiveService.delete(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.$store.state.user.name} 在 ${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: '/cw/projectReportArchive/ProjectReportArchiveList'
              }
            })
          })
      },
      // 发起项目归档
      push (row) {
        // 读取流程表单
        let title = `发起流程【会计-项目报告归档】`
        let processTitle = `${this.$store.state.user.name} 发起了 ${row.reportNo} - ${row.projectName} [会计-项目报告归档]`
        let status = 'startAndHold'
        if (row.status === '3' || row.status === '4') {
          status = 'startAndClose'
        }
        this.taskService.getTaskDef({ procDefId: this.processDefinitionAuditId,
          businessId: row.id,
          businessTable: 'cw_project_archive'}).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: 'cw_project_archive',
                businessId: row.id,
                isShow: 'false',
                status: status,
                routePath: '/cw/projectReportArchive/ProjectReportArchiveList'
              }
            })
          })
      },
      // 查看项目归档流程结果
      detail (row) {
        if (row.status !== '0' && row.status !== '1') {
          let procInsId = row.procInsId
          let procDefId = this.processDefinitionAuditId
          this.officeService.queryById(this.$store.state.user.office.id).then((byId) => {
            // 判断当前人的所属部门是否为苏州分部，根据部门的机构编码(szfb)来判断是不是苏州分部
            if (byId.data.code === 'szfb') {
              procDefId = this.processDefinitionAuditIdSZ
              this.getTaskDef(row, procInsId, procDefId)
            } else {
              this.getTaskDef(row, procInsId, procDefId)
            }
          })
        }
      },
      getTaskDef (row, procInsId, procDefId) {
        // eslint-disable-next-line eqeqeq
        this.taskService.getTaskDef({
          procInsId: procInsId,
          procDefId: procDefId
        }).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.projectReportArchiveService.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.projectReportArchiveService.updateStatusById(form)
                this.$message.success(data)
                this.refreshList()
              })
            }
          })
        })
      },
      // 自定义服务端导出
      exportMethod ({ options }) {
        // 传给服务端的参数
        const params = {
          'current': this.tablePage.currentPage,
          'size': this.tablePage.pageSize,
          'orders': this.tablePage.orders,
          ...this.searchForm,
          filename: options.filename,
          sheetName: options.sheetName,
          isHeader: options.isHeader,
          original: options.original,
          mode: options.mode,
          selectIds: options.mode === 'selected' ? options.data.map(item => item.id) : [],
          exportFields: options.columns.map(column => column.property)
        }
        return this.projectReportArchiveService.exportFile(params).then((res) => {
          // 将二进制流文件写入excel表，以下为重要步骤
          this.$utils.downloadExcel(res.data, options.filename)
        }).catch(function (err) {
          if (err.response) {
            console.log(err.response)
          }
        })
      },
      // 驳回后调整
      adjust (row) {
        this.projectReportArchiveService.queryById(row.id).then(({data}) => {
          if (data.status !== '4') { // status的值不等于“驳回”，就弹出提示
            this.$message.error('数据已发生改变或不存在，请刷新数据')
            this.refreshList()
          } else {
            this.todo(row)
          }
        })
      },
      // 审核
      examine (row) {
        this.projectReportArchiveService.queryById(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: '/cw/projectReportArchive/ProjectReportArchiveList'   // 数据处理后需要跳转的页面路径
            }
          })
        })
      },
      // 查询当前登录人是否是数据的审核人
      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
      }
    }
  }
</script>
