<template>
  <div class="page">
    <el-form :inline="true" class="query-form" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()" @submit.native.prevent>
      <!-- 搜索框-->
      <el-form-item label="项目名称" prop="name">
        <el-input v-model="searchForm.name" placeholder="请输入项目名称" clearable></el-input>
      </el-form-item>
      <el-form-item label="项目编号" prop="no">
        <el-input v-model="searchForm.no" placeholder="请输入项目编号" clearable></el-input>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="登记人" prop="createBy">
        <SelectUserTree
          ref="companyTree"
          :props="{
                  value: 'id',             // ID字段名
                  label: 'name',         // 显示名称
                  children: 'children'    // 子级字段名
                }"
          :url="`/system-server/sys/user/treeUserDataAllOffice?type=2`"
          :value="searchForm.createBy"
          :clearable="true"
          :accordion="true"
		  size="default"
          @getValue="(value) => {searchForm.createBy=value}"/>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="项目负责人" prop="projectManagerName">
        <el-input v-model="searchForm.projectManagerName" placeholder="请输入项目负责人" clearable></el-input>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="合同名称" prop="contractName">
        <el-input v-model="searchForm.contractName" placeholder="请输入合同名称" clearable></el-input>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="委托方" prop="clientName">
        <el-input v-model="searchForm.clientName" placeholder="请输入委托方" clearable></el-input>
      </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="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item v-if="showHideItem" label="状态" prop="status">
        <el-select v-model="searchForm.status" placeholder="请选择" style="width:100%;">
          <el-option
            v-for="item in $dictUtils.getDictList('program_project_list_info_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" :icon="showHideIcon">{{showHideName}}</el-button>
        <el-button type="primary" @click="refreshList()" icon="el-icon-search">查询</el-button>
        <el-button @click="resetSearch()" icon="el-icon-refresh-right">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="jp-table">
      <vxe-toolbar :refresh="{query: refreshList}" custom>
        <template #buttons>
          <el-button v-if="hasPermission('program:registered:add')" type="primary" icon="el-icon-plus" @click="add()">新建</el-button>
<!--          <el-button v-if="hasPermission('program:registered:add')" type="primary" icon="el-icon-plus" @click="start()">新建</el-button>-->
          <el-button v-if="hasPermission('program:registered:del')" type="danger"   icon="el-icon-delete" @click="deleteAll()" :disabled="$refs.typeDictTable && $refs.typeDictTable.getCheckboxRecords().length === 0" plain>删除</el-button>
          <el-button v-if="hasPermission('program:registered:export')"  type="warning" plain @click="exportFile()">导出</el-button>
        </template>
      </vxe-toolbar>
      <div class="jp-table-body">
        <vxe-table
          border="inner"
          auto-resize
          resizable
          height="auto"
          :loading="loading"
          size="small"
          ref="typeDictTable"
          show-header-overflow
          show-overflow
          highlight-hover-row
          :menu-config="{}"
          @sort-change="sortChangeHandle"
          :sort-config="{remote:true}"
          :data="dataList"
          :tree-config="{transform: true, rowField: 'id', parentField: 'parentId'}"
          :checkbox-config="{}">
          <vxe-column type="seq" width="60" title="序号"></vxe-column>
          <vxe-column type="checkbox" width="50" ></vxe-column>
          <vxe-column min-width="170" align="center" title="项目名称" field="name" >
            <template #default="scope">
              <el-link  type="primary" :underline="false" v-if="hasPermission('program:registered:view')" @click="view(scope.row)">{{scope.row.name}}</el-link>
              <el-link  type="primary" :underline="false" v-else-if="hasPermission('program:registered:view')" @click="view(scope.row)">{{scope.row.name}}</el-link>
              <span v-else>{{scope.row.name}}</span>
            </template>
          </vxe-column>
          <vxe-column min-width="100" align="center" title="项目编号" field="no"></vxe-column>
          <vxe-column min-width="180" align="center" title="合同名称" field="contractName">
            <template #default="scope">
              <el-link  type="primary" :underline="false" v-if="hasPermission('program:registered:view')" @click="viewContract(scope.row.contractId)">{{scope.row.contractName}}</el-link>
              <el-link  type="primary" :underline="false" v-else-if="hasPermission('program:registered:view')" @click="viewContract(scope.row.contractId)">{{scope.row.contractName}}</el-link>
              <span v-else>{{scope.row.name}}</span>
            </template>
          </vxe-column>
          <vxe-column min-width="100" align="center" title="项目负责人" field="projectManagerName"></vxe-column>
          <vxe-column min-width="180" align="center" title="委托方" field="clientName"></vxe-column>
          <vxe-column min-width="210" align="center" title="报告号" field="reportNo"></vxe-column>
          <vxe-column min-width="100" align="center" title="登记人" field="createById"></vxe-column>
          <vxe-column min-width="120" align="center" title="创建日期" field="createTime"></vxe-column>

          <vxe-column  min-width="110px" align="center" fixed="right" title="状态" field="status" >
            <template #default="scope">
<!--              <el-button  type="text" @click="registeredDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.status, '-')" effect="dark" size="mini">{{$dictUtils.getDictLabel("program_project_list_info_status", scope.row.status, '-')}} </el-button>-->
              <el-button size="small" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.status, '')" effect="dark" >{{$dictUtils.getDictLabel("program_project_list_info_status", scope.row.status, '-')}} </el-button>
            </template>
          </vxe-column>
<!--          <vxe-column min-width="120"align="center" title="一级校审" field="status1">-->
<!--            <template slot-scope="scope">-->
<!--              <el-button  type="text" @click="firstAuditDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.status1, '-')" effect="dark" size="mini">{{$dictUtils.getDictLabel("program_project_list_info_status", scope.row.status1, '-')}} </el-button>-->
<!--            </template>-->
<!--          </vxe-column>-->
<!--          <vxe-column min-width="120"align="center" title="二级校审" field="status2">-->
<!--            <template slot-scope="scope">-->
<!--              <el-button  type="text" @click="secondAuditDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.status2, '-')" effect="dark" size="mini">{{$dictUtils.getDictLabel("program_project_list_info_status", scope.row.status2, '-')}} </el-button>-->
<!--            </template>-->
<!--          </vxe-column>-->
<!--          <vxe-column min-width="120"align="center" title="三级校审" field="status3">-->
<!--            <template slot-scope="scope">-->
<!--              <el-button  type="text" @click="thirdAuditDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.status3, '-')" effect="dark" size="mini">{{$dictUtils.getDictLabel("program_project_list_info_status", scope.row.status3, '-')}} </el-button>-->
<!--            </template>-->
<!--          </vxe-column>-->
<!--          <vxe-column  min-width="150px"align="center" title="签发单状态" field="issuedStatus" >-->
<!--            <template slot-scope="scope">-->
<!--              <el-button  type="text" @click="issuedDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.issuedStatus, '-')" effect="dark" size="mini">{{$dictUtils.getDictLabel("program_project_list_info_status", scope.row.issuedStatus, '未登记')}} </el-button>-->
<!--            </template>-->
<!--          </vxe-column>-->
          <vxe-column min-width="110" align="center" fixed="right" title="项目归档" field="archiveStatus">
            <template #default="scope">
<!--              <el-button  type="text" @click="archiveDetail(scope.row)" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.archiveStatus, '-')" effect="dark" size="mini">{{$dictUtils.getDictLabel("program_project_list_info_status", scope.row.archiveStatus, '-')}} </el-button>-->
              <el-button size="small" :type="$dictUtils.getDictLabel('program_project_list_info_status_info', scope.row.archiveStatus, '')" effect="dark">{{$dictUtils.getDictLabel("program_project_list_info_status", scope.row.archiveStatus, '-')}} </el-button>
            </template>
          </vxe-column>
          <vxe-column title="操作" min-width="200px" fixed="right" align="center">
            <template  #default="scope">
              <el-button v-if="hasPermission('program:registered:edit')&&(scope.row.createBy === createName&&scope.row.archiveStatus!=='5') || isAdmin" text type="primary" @click="edit(scope.row.id)">修改</el-button>
              <el-button v-if="hasPermission('program:registered:del')&&(scope.row.createBy === createName&&scope.row.archiveStatus!=='5') || isAdmin" text type="primary" @click="del(scope.row.id)">删除</el-button>
              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.status === '5' && commonJS.isEmpty(scope.row.reportNo) && scope.row.createBy === createName" text type="primary" @click="saveReportNo(scope.row.id)">生成报告号</el-button>
              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.status === '5' && commonJS.isNotEmpty(scope.row.reportNo) && scope.row.createBy === createName && scope.row.archiveStatus !== '5'" text type="primary" @click="archive(scope.row)">项目归档</el-button>


<!--              <el-button v-if="hasPermission('program:registered:edit')&&(scope.row.status === '1' || scope.row.status === '3'||scope.row.status === '4')&&scope.row.createBy === createName" type="text" size="small" @click="registeredPush(scope.row)">修改</el-button>-->
<!--              &lt;!&ndash;管理员角色登记完成后可修改&ndash;&gt;-->
<!--              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.status === '5' && isAdmin" type="text" size="small" @click="edit(scope.row.id)">修改</el-button>-->
<!--              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.status === '2'&&scope.row.createBy === createName" type="text" size="small" @click="registeredReback(scope.row)">撤回</el-button>-->
<!--              <el-button v-if="hasPermission('program:registered:del')&&scope.row.status !== '2' && scope.row.status !== '5'&&scope.row.createBy === createName" type="text" size="small" @click="del(scope.row.id)">删除</el-button>-->
<!--              &lt;!&ndash;管理员角色登记完成后可删除&ndash;&gt;-->
<!--              <el-button v-if="hasPermission('program:registered:del')&&scope.row.status === '5' && isAdmin" type="text" size="small" @click="del(scope.row.id)">删除</el-button>-->

<!--              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.status === '5' && commonJS.isEmpty(scope.row.reportNo) && scope.row.createBy === createName" type="text" size="small" @click="saveReportNo(scope.row.id)">生成报告号</el-button>-->

<!--              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.status === '5' &&scope.row.createBy === createName && commonJS.isNotEmpty(scope.row.reportNo)&&(scope.row.status1 === '0'||scope.row.status1 === '1'||scope.row.status1 === '3'||scope.row.status1 === '4')" type="text" size="small" @click="firstAuditPush(scope.row)">一级校审</el-button>-->
<!--              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.status1 === '2' &&scope.row.createBy === createName && commonJS.isNotEmpty(scope.row.reportNo)" type="text" size="small" @click="firstAuditReback(scope.row)">校审撤回</el-button>-->

<!--              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.createBy === createName&&scope.row.status1 === '5'&&(scope.row.status2 === '0'||scope.row.status2 === '1'||scope.row.status2 === '3'||scope.row.status2 === '4')" type="text" size="small" @click="secondAuditPush(scope.row)">二级校审</el-button>-->
<!--              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.status2 === '2'&&scope.row.createBy === createName" type="text" size="small" @click="secondAuditReback(scope.row)">校审撤回</el-button>-->

<!--              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.createBy === createName&&scope.row.status2 === '5' &&(scope.row.status3 === '0'||scope.row.status3 === '1'||scope.row.status3 === '3'||scope.row.status3 === '4')" type="text" size="small" @click="thirdAuditPush(scope.row)">三级校审</el-button>-->
<!--              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.createBy === createName&&scope.row.status3 === '2'" type="text" size="small" @click="thirdAuditReback(scope.row)">校审撤回</el-button>-->

<!--              &lt;!&ndash;三神结束后，评估报告签发前进行资产评估项目（校对）&ndash;&gt;-->
<!--              <el-button v-if="hasPermission('program:registered:proo')&&scope.row.createBy === createName&&scope.row.status3 === '5'&&commonJS.isEmpty(scope.row.issuedStatus)" type="text" size="small" @click="proofread(scope.row.id)">校对</el-button>-->
<!--              &lt;!&ndash;报告签发&ndash;&gt;-->
<!--              <el-button v-if="hasPermission('program:registered:browse')&&scope.row.createBy === createName &&scope.row.status3 === '5' && scope.row.issuedStatus !== '2' && scope.row.issuedStatus !== '5'" type="text" size="small" @click="issued(scope.row)">签发</el-button>-->
<!--              &lt;!&ndash;报告签发撤回&ndash;&gt;-->
<!--              <el-button v-if="hasPermission('program:registered:browse')&&scope.row.createBy === createName && scope.row.issuedStatus === '2'" type="text" size="small" @click="issuedReback(scope.row)">签发撤回</el-button>-->
<!--              &lt;!&ndash;评估报告装订后的审核&ndash;&gt;-->
<!--              <el-button v-if="hasPermission('program:registered:browse')&&scope.row.createBy === createName&&scope.row.issuedStatus === '5'&&scope.row.archiveStatus === '0'" type="text" size="small" @click="browse(scope.row.id)">装订自校</el-button>-->

<!--              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.createBy === createName&&scope.row.issuedStatus === '5' &&(scope.row.archiveStatus === '0'||scope.row.archiveStatus === '1'||scope.row.archiveStatus === '3'||scope.row.archiveStatus === '4')" type="text" size="small" @click="archivePush(scope.row)">项目归档</el-button>-->
<!--              <el-button v-if="hasPermission('program:registered:edit')&&scope.row.createBy === createName&&scope.row.archiveStatus === '2'" type="text" size="small" @click="archiveReback(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>
    <ProjectForm2022 ref="projectForm2022" @refreshDataList="refreshList"></ProjectForm2022>
    <ProjectForm  ref="projectForm" @refreshDataList="refreshList"></ProjectForm>
    <ProjectFormUpdate ref="projectFormUpdate" @refreshDataList="refreshList"></ProjectFormUpdate>
    <ProofreadForm  ref="proofreadForm" @refreshDataList="refreshList"></ProofreadForm>
    <ProofreadBrowseForm  ref="proofreadBrowseForm" @refreshDataList="refreshList"></ProofreadBrowseForm>
    <WorkContractForm2 ref="workContractForm2" @refreshDataList="refreshList"></WorkContractForm2>
    <ProjectArchiveFormDialog ref="projectArchiveFormDialog" @refreshDataList="refreshList"></ProjectArchiveFormDialog>
    <ProjectForm2022Tab ref="projectForm2022Tab" @refreshDataList="refreshList"></ProjectForm2022Tab>
  </div>
</template>

<script>
  import ProgramProjectListInfoService from '@/api/program/ProgramProjectListInfoService'
  import ProjectForm from './ProjectForm'
  import ProjectForm2022Tab from './ProjectForm2022Tab'
  import ProjectFormUpdate from './ProjectFormUpdate'
  import ProjectForm2022 from './ProjectForm2022'
  import ProjectArchiveFormDialog from './ProjectArchiveFormDialog'
  import ProofreadForm from './ProofreadForm'
  import ProofreadBrowseForm from './ProofreadBrowseForm'
  import WorkContractForm2 from '@/views/workContract/WorkContractForm2'
  import SelectUserTree from '@/views/utils/treeUserSelect'
  import pick from 'lodash.pick'
  import taskService from '@/api/flowable/taskService'
  import processService from '@/api/flowable/processService'
  import userService from '@/api/sys/userService'
  import ProofreadIssuedService from '@/api/sys/ProofreadIssuedService'
  export default {
    data () {
      return {
        showHideItem: false,
        showHideIcon: 'el-icon-arrow-down',
        showHideName: '展示',
        searchForm: {
          name: '',
          no: '',
          createBy: '',
          projectManager: '',
          contractName: '',
          clientName: '',
          createDates: [],
          status: ''
        },
        dataList: [],
        tablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: []
        },
        createName: '',
        loading: false,
        processDefinitionAuditId: '',
        procDefAuditKey: '',
        isAdmin: false,
        processDefinitionId1: '',
        procDefKey1: '',
        processDefinitionId2: '',
        procDefKey2: '',
        processDefinitionId3: '',
        procDefKey3: '',
        processDefinitionIdArchive: '',
        procDefKeyArchive: '',
        processDefinitionId4: '',
        procDefKey4: ''
      }
    },
    programProjectListInfoService: null,
    // taskService: null,
    // processService: null,
    // userService: null,
    proofreadIssuedService: null,
    created () {
      this.programProjectListInfoService = new ProgramProjectListInfoService()
      // this.taskService = new TaskService()
      // this.processService = new ProcessService()
      // this.userService = new UserService()
      this.proofreadIssuedService = new ProofreadIssuedService()
    },
    components: {
      ProjectForm,
      WorkContractForm2,
      SelectUserTree,
      ProofreadForm,
      ProofreadBrowseForm,
      ProjectFormUpdate,
      ProjectForm2022,
      ProjectArchiveFormDialog,
      ProjectForm2022Tab
    },
    mounted () {
      this.refreshList()
    },
    activated () {
      this.is()
      this.refreshList()
    },
    computed: {
      userName () {
        return this.$store.state.user.name
      },
      user () {
        this.createName = this.$store.state.user.name
        return this.$store.state.user
      }
    },
    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.projectForm2022.init('add', '')
      },
      // 修改
      edit (id) {
        id = id || this.$refs.typeDictTable.getCheckboxRecords().map(item => {
          return item.id
        })[0]
        this.$refs.projectForm2022.init('edit', id)
      },
      // 查看
      view (row) {
        this.$refs.projectForm2022Tab.init('view', row.id, row.archiveId)
      },
      // 项目归档
      archive (row) {
        this.$refs.projectArchiveFormDialog.init(null, row.archiveId)
      },
      // 获取数据列表
      refreshList () {
        this.loading = true
        this.createName = this.$store.state.user.name
        this.programProjectListInfoService.list2022({
          '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.loading = false
        })
        // 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.processDefinitionId1 = data.id
        //     this.procDefKey1 = data.key
        //   }
        // })
        // this.processService.getByName('项目二级校审').then((data) => {
        //   if (!this.commonJS.isEmpty(data.id)) {
        //     this.processDefinitionId2 = data.id
        //     this.procDefKey2 = data.key
        //   }
        // })
        // this.processService.getByName('项目三级校审').then((data) => {
        //   if (!this.commonJS.isEmpty(data.id)) {
        //     this.processDefinitionId3 = data.id
        //     this.procDefKey3 = data.key
        //   }
        // })
        // this.processService.getByName('项目登记归档').then((data) => {
        //   if (!this.commonJS.isEmpty(data.id)) {
        //     this.processDefinitionIdArchive = data.id
        //     this.procDefKeyArchive = data.key
        //   }
        // })
        // this.processService.getByName('报告签发审批').then((data) => {
        //   if (!this.commonJS.isEmpty(data.id)) {
        //     this.processDefinitionId4 = data.id
        //     this.procDefKey4 = 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.typeDictTable.getCheckboxRecords().map(item => {
          return item.id
        }).join(',')
        this.$confirm(`确定删除所选项吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.programProjectListInfoService.delete(ids).then((data) => {
            this.$message.success(data)
            this.refreshList()
            this.loading = false
          })
        })
      },

      // 删除
      deleteAll (id) {
        let ids = id || this.$refs.typeDictTable.getCheckboxRecords().map(item => {
          return item.id
        }).join(',')
        this.$confirm(`确定删除所选项吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.programProjectListInfoService.deleteAll(ids).then((data) => {
            this.$message.success(data)
            this.refreshList()
            this.loading = false
          })
        })
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.refreshList()
      },
      viewContract (id) {
        this.$refs.workContractForm2.init('view', id)
      },
      start () {
        // 读取流程表单
        let tabTitle = `发起流程【评估-项目登记】`
        let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了 [评估-项目登记]`
        taskService.getTaskDef({ procDefId: this.processDefinitionAuditId,
          status: 'startAndHold'}).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskForm',
              query: {
                procDefId: this.processDefinitionAuditId,
                procDefKey: this.procDefAuditKey,
                status: 'startAndHold',
                title: tabTitle,
                formType: data.formType,
                formUrl: data.formUrl,
                formTitle: processTitle,
                businessId: 'false',
                isShow: false,
                routePath: '/program/registered/ProjectList'
              }
            })
          })
      },
      // 发起项目登记审批
      registeredPush (row) {
        // 读取流程表单
        let title = `发起流程【项目登记审批】`
        let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了[项目登记审批]`
        let status = 'startAndHold'
        if (row.status === '3' || row.status === '4') {
          status = 'startAndClose'
        }
        taskService.getTaskDef({ procDefId: this.processDefinitionAuditId,
          businessId: row.id,
          businessTable: 'program_project_list_info'}).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskForm',
              query: {
                procDefId: this.processDefinitionAuditId,
                procDefKey: this.procDefAuditKey,
                title: title,
                formType: data.formType,
                formUrl: data.formUrl,
                formTitle: processTitle,
                businessTable: 'program_project_list_info',
                businessId: row.id,
                isShow: 'false',
                status: status,
                routePath: '/program/registered/ProjectList'
              }
            })
          })
      },
      // 查看项目登记审批流程结果
      registeredDetail (row) {
        if (row.status !== '0' && row.status !== '1') {
          // eslint-disable-next-line eqeqeq
          taskService.getTaskDef({
            procInsId: row.procInsId,
            procDefId: this.processDefinitionAuditId
          }).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskFormDetail',
              query: {
                isShow: 'false',
                readOnly: true,
                title: '项目登记' + '流程详情',
                formTitle: '项目登记' + '流程详情',
                businessId: row.id,
                status: 'reback',
                ...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'title', 'businessId')
              }
            })
          })
        }
      },
      // 撤回项目登记审批
      registeredReback (row) {
        this.$confirm(`确定要撤回该申请吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          await this.programProjectListInfoService.queryById(row.id).then((data) => {
            if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
              this.$message.error('数据已发生改变或不存在，请刷新数据')
              this.refreshList()
            } else {
              processService.revokeProcIns(row.procInsId).then((data) => {
                let form = {status: '3', id: row.id}
                this.programProjectListInfoService.updateStatusById(form)
                this.$message.success(data)
                this.refreshList()
              })
            }
          })
        })
      },
      // 发起一级校审
      firstAuditPush (row) {
        // 读取流程表单
        let title = `发起流程【评估-项目一级校审】`
        let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了[评估-项目一级校审]`
        let status = 'startAndHold'
        if (row.status1 === '3' || row.status1 === '4') {
          status = 'startAndClose'
        }
        taskService.getTaskDef({ procDefId: this.processDefinitionId1,
          businessId: row.auditId1,
          businessTable: 'program_audit'}).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskForm',
              query: {
                procDefId: this.processDefinitionId1,
                procDefKey: this.procDefKey1,
                title: title,
                formType: data.formType,
                formUrl: data.formUrl,
                formTitle: processTitle,
                businessTable: 'program_audit',
                businessId: row.auditId1,
                isShow: 'false',
                status: status,
                routePath: '/program/registered/ProjectList'
              }
            })
          })
      },
      // 查看一级校审审批流程结果
      firstAuditDetail (row) {
        if (row.status1 !== '0' && row.status1 !== '1') {
          // eslint-disable-next-line eqeqeq
          taskService.getTaskDef({
            procInsId: row.procInsId1,
            procDefId: this.processDefinitionId1
          }).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskFormDetail',
              query: {
                isShow: 'false',
                readOnly: true,
                title: '一级校审' + '流程详情',
                formTitle: '一级校审' + '流程详情',
                businessId: row.auditId1,
                status: 'reback',
                ...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'title', 'businessId')
              }
            })
          })
        }
      },
      // 撤回一级校审
      firstAuditReback (row) {
        this.$confirm(`确定要撤回该申请吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          await this.programProjectListInfoService.findByIdAudit(row.auditId1).then((data) => {
            if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
              this.$message.error('数据已发生改变或不存在，请刷新数据')
              this.refreshList()
            } else {
              processService.revokeProcIns(row.procInsId1).then((data) => {
                let form = {status: '3', id: row.auditId1}
                this.programProjectListInfoService.updateStatusByAuditId(form)
                this.$message.success(data)
                this.refreshList()
              })
            }
          })
        })
      },
      // 发起二级校审
      secondAuditPush (row) {
        // 读取流程表单
        let title = `发起流程【评估-项目二级校审】`
        let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了[评估-项目二级校审]`
        let status = 'startAndHold'
        if (row.status2 === '3' || row.status2 === '4') {
          status = 'startAndClose'
        }
        taskService.getTaskDef({ procDefId: this.processDefinitionId2,
          businessId: row.auditId2,
          businessTable: 'program_audit'}).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskForm',
              query: {
                procDefId: this.processDefinitionId2,
                procDefKey: this.procDefKey2,
                title: title,
                formType: data.formType,
                formUrl: data.formUrl,
                formTitle: processTitle,
                businessTable: 'program_audit',
                businessId: row.auditId2,
                isShow: 'false',
                status: status,
                routePath: '/program/registered/ProjectList'
              }
            })
          })
      },
      // 查看二级校审审批流程结果
      secondAuditDetail (row) {
        if (row.status2 !== '0' && row.status2 !== '1') {
          // eslint-disable-next-line eqeqeq
          taskService.getTaskDef({
            procInsId: row.procInsId2,
            procDefId: this.processDefinitionId2
          }).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskFormDetail',
              query: {
                isShow: 'false',
                readOnly: true,
                title: '二级校审' + '流程详情',
                formTitle: '二级校审' + '流程详情',
                businessId: row.auditId2,
                status: 'reback',
                ...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'title', 'businessId')
              }
            })
          })
        }
      },
      // 撤回二级校审
      secondAuditReback (row) {
        this.$confirm(`确定要撤回该申请吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          await this.programProjectListInfoService.findByIdAudit(row.auditId2).then((data) => {
            if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
              this.$message.error('数据已发生改变或不存在，请刷新数据')
              this.refreshList()
            } else {
              processService.revokeProcIns(row.procInsId2).then((data) => {
                let form = {status: '3', id: row.auditId2}
                this.programProjectListInfoService.updateStatusByAuditId(form)
                this.$message.success(data)
                this.refreshList()
              })
            }
          })
        })
      },
      // 发起三级校审
      thirdAuditPush (row) {
        // 读取流程表单
        let title = `发起流程【评估-项目三级校审】`
        let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了[评估-项目三级校审]`
        let status = 'startAndHold'
        if (row.status3 === '3' || row.status3 === '4') {
          status = 'startAndClose'
        }
        taskService.getTaskDef({ procDefId: this.processDefinitionId3,
          businessId: row.auditId3,
          businessTable: 'program_audit'}).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskForm',
              query: {
                procDefId: this.processDefinitionId3,
                procDefKey: this.procDefKey3,
                title: title,
                formType: data.formType,
                formUrl: data.formUrl,
                formTitle: processTitle,
                businessTable: 'program_audit',
                businessId: row.auditId3,
                isShow: 'false',
                status: status,
                routePath: '/program/registered/ProjectList'
              }
            })
          })
      },
      // 查看三级校审审批流程结果
      thirdAuditDetail (row) {
        if (row.status3 !== '0' && row.status3 !== '1') {
          // eslint-disable-next-line eqeqeq
          taskService.getTaskDef({
            procInsId: row.procInsId3,
            procDefId: this.processDefinitionId3
          }).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskFormDetail',
              query: {
                isShow: 'false',
                readOnly: true,
                title: '三级校审' + '流程详情',
                formTitle: '三级校审' + '流程详情',
                businessId: row.auditId3,
                status: 'reback',
                ...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'title', 'businessId')
              }
            })
          })
        }
      },
      // 撤回三级校审
      thirdAuditReback (row) {
        this.$confirm(`确定要撤回该申请吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          await this.programProjectListInfoService.findByIdAudit(row.auditId3).then((data) => {
            if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
              this.$message.error('数据已发生改变或不存在，请刷新数据')
              this.refreshList()
            } else {
              processService.revokeProcIns(row.procInsId3).then((data) => {
                let form = {status: '3', id: row.auditId3}
                this.programProjectListInfoService.updateStatusByAuditId(form)
                this.$message.success(data)
                this.refreshList()
              })
            }
          })
        })
      },
      // 发起项目登记归档
      archivePush (row) {
        // 读取流程表单
        let title = `发起流程【评估-项目归档】`
        let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了[评估-项目归档]`
        let status = 'startAndHold'
        if (row.archiveStatus === '3' || row.archiveStatus === '4') {
          status = 'startAndClose'
        }
        taskService.getTaskDef({ procDefId: this.processDefinitionIdArchive,
          businessId: row.archiveId,
          businessTable: 'program_archive'}).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskForm',
              query: {
                procDefId: this.processDefinitionIdArchive,
                procDefKey: this.procDefKeyArchive,
                title: title,
                formType: data.formType,
                formUrl: data.formUrl,
                formTitle: processTitle,
                businessTable: 'program_archive',
                businessId: row.archiveId,
                isShow: 'false',
                status: status,
                routePath: '/program/registered/ProjectList'
              }
            })
          })
      },
      // 查看三级校审审批流程结果
      archiveDetail (row) {
        if (row.archiveStatus !== '0' && row.archiveStatus !== '1') {
          // eslint-disable-next-line eqeqeq
          taskService.getTaskDef({
            procInsId: row.procInsIdArchive,
            procDefId: this.processDefinitionIdArchive
          }).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskFormDetail',
              query: {
                isShow: 'false',
                readOnly: true,
                title: '评估-项目归档' + '流程详情',
                formTitle: '评估-项目归档' + '流程详情',
                businessId: row.archiveId,
                status: 'reback',
                ...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'title', 'businessId')
              }
            })
          })
        }
      },
      // 撤回三级校审
      archiveReback (row) {
        this.$confirm(`确定要撤回该申请吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          await this.programProjectListInfoService.findByIdArchive(row.archiveId).then((data) => {
            if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
              this.$message.error('数据已发生改变或不存在，请刷新数据')
              this.refreshList()
            } else {
              processService.revokeProcIns(row.procInsIdArchive).then((data) => {
                let form = {status: '3', id: row.archiveId}
                this.programProjectListInfoService.updateStatusByArchiveId(form)
                this.$message.success(data)
                this.refreshList()
              })
            }
          })
        })
      },
      // 下载一级校审
      downloadFirstAuditTpl (row) {
        // this.$utils.downloadExcel('/sys/project/import/template')
        this.loading = true
        this.programProjectListInfoService.downloadFirstAuditTpl(row.id, row.auditId1).then((res) => {
          // 将二进制流文件写入excel表，以下为重要步骤
          this.$utils.downloadWord(res, '一级校审')
          this.loading = false
        }).catch(function (err) {
          this.loading = false
          if (err.response) {
            console.log(err.response)
          }
        })
      },
      // 下载二级校审
      downloadSecondAuditTpl (row) {
        // this.$utils.downloadExcel('/sys/project/import/template')
        this.loading = true
        this.programProjectListInfoService.downloadSecondAuditTpl(row.id, row.auditId2).then((res) => {
          // 将二进制流文件写入excel表，以下为重要步骤
          this.$utils.downloadWord(res, '二级校审')
          this.loading = false
        }).catch(function (err) {
          this.loading = false
          if (err.response) {
            console.log(err.response)
          }
        })
      },
      // 下载三级校审
      downloadThirdlyAuditTpl (row) {
        // this.$utils.downloadExcel('/sys/project/import/template')
        this.loading = true
        this.programProjectListInfoService.downloadThirdlyAuditTpl(row.id, row.auditId3).then((res) => {
          // 将二进制流文件写入excel表，以下为重要步骤
          this.$utils.downloadWord(res, '三级校审')
          this.loading = false
        }).catch(function (err) {
          this.loading = false
          if (err.response) {
            console.log(err.response)
          }
        })
      },
      // 下载资产评估项目（校对）审核记录表
      downloadProofreadAuditTpl (row) {
      // this.$utils.downloadExcel('/sys/project/import/template')
        this.loading = true
        this.programProjectListInfoService.downloadProofreadAuditTpl(row.id).then((res) => {
          // 将二进制流文件写入excel表，以下为重要步骤
          this.$utils.downloadExcel(res, '资产评估项目（校对）审核记录表.xls')
          this.loading = false
        }).catch(function (err) {
          this.loading = false
          if (err.response) {
            console.log(err.response)
          }
        })
      },
      // 下载评估报告装订后浏览审核记录表
      downloadAuditRecordFormAfterBindingTpl (row) {
        // this.$utils.downloadExcel('/sys/project/import/template')
        this.loading = true
        this.programProjectListInfoService.downloadAuditRecordFormAfterBindingTpl(row.id).then((res) => {
          // 将二进制流文件写入excel表，以下为重要步骤
          this.$utils.downloadExcel(res, '评估报告装订后浏览审核记录表.xls')
          this.loading = false
        }).catch(function (err) {
          this.loading = false
          if (err.response) {
            console.log(err.response)
          }
        })
      },
      // 下载报告签发单
      downloadReportAusstellungTpl (row) {
        // this.$utils.downloadExcel('/sys/project/import/template')
        this.loading = true
        this.programProjectListInfoService.downloadReportAusstellungTpl(row.id).then((res) => {
          // 将二进制流文件写入excel表，以下为重要步骤
          this.$utils.downloadWord(res, '报告签发单')
          this.loading = false
        }).catch(function (err) {
          this.loading = false
          if (err.response) {
            console.log(err.response)
          }
        })
      },
      is () {
        userService.is().then((data) => {
          this.isAdmin = data
        })
      },
      // 下载文档
      exportFile () {
      	let options = {
			filename: '2022年项目登记列表信息',
			sheetName: 'sheet1'
		}
        this.loading = true
        this.programProjectListInfoService.exportFile({
          'itemType': '1',
          'tabType': '2022',
		  ...options,
          ...this.searchForm
        }).then((res) => {
          // 将二进制流文件写入excel表，以下为重要步骤
          this.$utils.downloadExcel(res, options.filename)
          this.loading = false
        }).catch(function (err) {
          this.loading = false
          if (err.response) {
            console.log(err.response)
          }
        })
      },
      saveReportNo (id) {
        this.$confirm(`确定生成项目报告号吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.programProjectListInfoService.saveReportNo(id).then((data) => {
            this.$message.success(data)
            this.refreshList()
            this.loading = false
          }).catch((e) => {
            this.loading = false
          })
        })
      },
      // 校对
      proofread (id) {
        this.$refs.proofreadForm.init(id)
      },
      // 浏览审核
      browse (id) {
        this.$refs.proofreadBrowseForm.init(id)
      },
      // 签发
      issued (row) {
        // 读取流程表单
        let title = `发起流程【评估-报告签发】`
        let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了[评估-报告签发]`
        let status = 'startAndHold'
        if (row.issuedStatus === '3' || row.issuedStatus === '4' || row.issuedStatus === '2') {
          status = 'startAndClose'
        }
        taskService.getTaskDef({ procDefId: this.processDefinitionId4,
          businessId: row.id,
          businessTable: 'proofread_issued'}).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskForm',
              query: {
                procDefId: this.processDefinitionId4,
                procDefKey: this.procDefKey4,
                title: title,
                formType: data.formType,
                formUrl: data.formUrl,
                formTitle: processTitle,
                businessTable: 'proofread_issued',
                businessId: row.id,
                isShow: 'false',
                status: status,
                routePath: '/program/registered/ProjectList'
              }
            })
          })
      },
      // 签发单详情
      issuedDetail (row) {
        if (row.issuedStatus !== undefined && row.issuedStatus !== '1') {
          // eslint-disable-next-line eqeqeq
          taskService.getTaskDef({
            procInsId: row.procInsId4,
            procDefId: this.processDefinitionId4
          }).then((data) => {
            this.$router.push({
              path: '/flowable/task/TaskFormDetail',
              query: {
                isShow: 'false',
                readOnly: true,
                title: '报告签发单' + '流程详情',
                formTitle: '报告签发单' + '流程详情',
                businessId: row.id,
                status: 'reback',
                ...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'title', 'businessId')
              }
            })
          })
        }
      },
      // 签发撤回
      issuedReback (row) {
        this.$confirm(`确定要撤回该申请吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          await this.proofreadIssuedService.findById(row.id).then((data) => {
            if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
              this.$message.error('数据已发生改变或不存在，请刷新数据')
              this.refreshList()
            } else {
              processService.revokeProcIns(row.procInsId4).then((data) => {
                let form = {status: '3', id: row.id}
                this.proofreadIssuedService.updateStatus(form)
                this.$message.success(data)
                this.refreshList()
              })
            }
          })
        })
      }
    }
  }
</script>
