<template>
  <div class="page">
	  <el-form :inline="true" class="query-form m-b-10" v-if="searchVisible" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()" @submit.native.prevent>
		  <!-- 搜索框-->
		  <el-form-item v-if="showHideItem" label="报告文号" prop="reportNo">
			  <el-input v-model="searchForm.reportNo" placeholder="请输入报告文号" clearable></el-input>
		  </el-form-item>
		  <el-form-item label="项目编号" prop="projectNumber">
			  <el-input v-model="searchForm.projectNumber" placeholder="请输入项目编号" clearable></el-input>
		  </el-form-item>
		  <el-form-item label="项目名称" prop="projectName">
			  <el-input v-model="searchForm.projectName" 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"
				  size="default"
				  :accordion="true"
				  @getValue="(value) => {searchForm.createBy=value}"/>
		  </el-form-item>

		  <el-form-item v-if="showHideItem" label="项目类别" prop="projectCategory">
			  <el-select v-model="searchForm.projectCategory" placeholder="请选择" style="width:100%;">
				  <el-option
					  v-for="item in $dictUtils.getDictList('program_engineering_consultation_type')"
					  :key="item.value"
					  :label="item.label"
					  :value="item.value">
				  </el-option>
			  </el-select>
		  </el-form-item>
		  <el-form-item v-if="showHideItem" label="创建时间" prop="contractDates">
			  <el-date-picker
				  placement="bottom-start"
				  format="YYYY-MM-DD HH:mm:ss"
				  value-format="YYYY-MM-DD HH:mm:ss"
				  v-model="searchForm.contractDates"
				  type="datetimerange"
				  range-separator="至"
				  start-placeholder="开始日期"
				  end-placeholder="结束日期">
			  </el-date-picker>
		  </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 top" style="">
      <vxe-toolbar :refresh="{query: refreshList}" ref="toolbarRef" export custom>
        <template #buttons>
<!--          <el-button v-if="hasPermission('cw_work_client:info:add')" type="primary" icon="el-icon-plus" @click="start()">新建</el-button>-->
        </template>
		  <template #tools>
			  <vxe-button
				  text
				  type="primary"
				  :title="searchVisible ? '收起检索' : '展开检索'"
				  icon="vxe-icon-search"
				  class="tool-btn"
				  @click="searchVisible = !searchVisible"
			  ></vxe-button>
		  </template>
      </vxe-toolbar>
      <div style="height: calc(100% - 90px)">
        <vxe-table
          border="inner"
          auto-resize
          resizable
          height="auto"
          :loading="loading"
          ref="clientTable"
          show-header-overflow
          show-overflow
          highlight-hover-row
          :print-config="{}"
          :export-config="{
                    remote: true,
                    filename: `报告信息${moment(new Date()).format('YYYY-MM-DD')}`,
                    sheetName: '报告信息',
                    exportMethod: exportMethod,
                    types: ['xlsx'],
                    modes: ['current', 'selected', 'all']
                  }"
          :menu-config="{}"
          @sort-change="sortChangeHandle"
          :sort-config="{remote:true}"
          :data="dataList"
          :checkbox-config="{}">
          <vxe-column type="seq" width="60" title="序号"></vxe-column>
<!--          <vxe-column width="100" align="center" title="单据编号" field="documentNo">-->
<!--            <template #default="scope">-->
<!--              <el-link  type="primary" :underline="false" v-if="hasPermission('cwProjectReport:list')" @click="view(scope.row.id)">{{scope.row.documentNo}}</el-link>-->
<!--              <el-link  type="primary" :underline="false" v-else-if="hasPermission('cwProjectReport:list')"  @click="view(scope.row.id,)">{{scope.row.documentNo}}</el-link>-->
<!--              <span v-else>{{scope.row.documentNo}}</span>-->
<!--            </template>-->
<!--          </vxe-column>-->
          <vxe-column width="150" align="center" title="项目编号" field="projectNumber"></vxe-column>
          <vxe-column min-width="220" align="center" title="项目名称" field="projectName">
			  <template #default="scope">
				  <el-link  type="primary" :underline="false" @click="projectView(scope.row.projectId)">{{scope.row.projectName}}</el-link>
			  </template>
		  </vxe-column>
		  <vxe-column width="170" align="center" title="报告号" field="reportNo"></vxe-column>
		  <vxe-column width="170" align="center" title="合同名称" field="contractName">
			  <template #default="scope">
				  <el-link  type="primary" :underline="false" @click="contractView(scope.row.contractId)">{{scope.row.contractName}}</el-link>
			  </template>
		  </vxe-column>
		  <vxe-column width="170" align="center" title="委托方" field="clientName"></vxe-column>
			<vxe-column width="80" align="center" title="登记人" field="userName"></vxe-column>
			<vxe-column width="110" align="center" title="复核通过时间" field="checkCompleteTime"></vxe-column>
          <vxe-column width="110" align="center" title="创建时间" field="createTime"></vxe-column>
			<vxe-column min-width="130" title="项目等级" field="projectLevel" align="center">
				<template #default="scope">
					{{$dictUtils.getDictLabel('cw_project_level', scope.row.projectLevel, '')}}
				</template>
			</vxe-column>
			<vxe-column min-width="130" title="质量复核" fixed="right" align="center" field="reviewStatus">
				<template #default="scope">
					<el-button v-if="scope.row.projectLevel==='1'" @click="detail(scope.row)" :type="$dictUtils.getDictLabel('quality_status_info', scope.row.reviewStatus, '')" effect="dark" >{{$dictUtils.getDictLabel("quality_status", scope.row.reviewStatus, '未开始')}} </el-button>
				</template>
			</vxe-column>
			<vxe-column min-width="100" title="报告签发" fixed="right" align="center" field="signAndIssueStatus">
				<template #default="scope">
					<el-button @click="signAndIssueDetail(scope.row)" v-if="scope.row.projectLevel==='1'"
							   :type="$dictUtils.getDictLabel('status_info', scope.row.signAndIssueStatus, '')"
							   effect="dark">
						{{$dictUtils.getDictLabel("status", scope.row.signAndIssueStatus, '未开始')}}
					</el-button>
				</template>
			</vxe-column>
			<vxe-column min-width="130" title="电子/超期天数" fixed="right" align="center" field="onlineArchivingStatus">
				<template #default="scope">
					<el-button @click="pushOnlineDetail(scope.row)" :type="$dictUtils.getDictLabel('online_status_info', scope.row.onlineArchivingStatus, '')" effect="dark" >{{$dictUtils.getDictLabel("online_status", scope.row.onlineArchivingStatus, '未开始')}} </el-button>
					<span v-if="scope.row.onlineOverdueDates > 0">{{scope.row.onlineOverdueDates}}天</span>
				</template>
			</vxe-column>
			<vxe-column min-width="100" title="纸质/超期天数" fixed="right" align="center" field="paperArchivingStatus">
				<template #default="scope">
					<el-button @click="pushPaperDetail(scope.row)" :type="$dictUtils.getDictLabel('online_status_info', scope.row.paperArchivingStatus, '')" effect="dark" >{{$dictUtils.getDictLabel("online_status", scope.row.paperArchivingStatus, '未开始')}} </el-button>
					<span v-if="scope.row.paperOverdueDates > 0">{{scope.row.paperOverdueDates}}天</span>
				</template>
			</vxe-column>
          <vxe-column title="操作" width="200px" fixed="right" align="center">
            <template  #default="scope">
              <div v-if="isAdmin">
                <el-button text type="primary"  @click="edit(scope.row.id)">修改</el-button>
                <el-button text type="primary" @click="del(scope.row.id,scope.row.projectId)">删除</el-button>
              </div>
				<div v-else>
					<!--<el-button v-if="hasPermission('cwProjectReport:edit')&&
                              (scope.row.createById === $store.state.user.id||haveProjectIds.includes(scope.row.projectId))&&
                              scope.row.status === '5' && scope.row.reviewStatus === '5'"
							   text type="primary"  @click="edit(scope.row.id)">修改</el-button>

					<el-button v-else-if="hasPermission('cwProjectReport:del')&&
                              (scope.row.createById === $store.state.user.id||haveProjectIds.includes(scope.row.projectId))&&
                              scope.row.status === '5' && scope.row.reviewStatus === '5'"
							   text type="primary" @click="del(scope.row.id,scope.row.projectId)">删除</el-button>-->
					<el-button v-if="hasPermission('cw:workContract:filed') && (scope.row.createById === $store.state.user.id || haveProjectIds.includes(scope.row.projectId)) && scope.row.status === '5' && (scope.row.reviewStatus === '0' || scope.row.reviewStatus === '1' || scope.row.reviewStatus === '6' || scope.row.reviewStatus === '3' || scope.row.reviewStatus === undefined || scope.row.reviewStatus === '' || (scope.row.projectLevel==='2' && scope.row.reviewStatus === '5' && (scope.row.onlineArchivingStatus === undefined || scope.row.onlineArchivingStatus === '' )))" text type="primary" @click="pushF(scope.row)">复核</el-button>
					<el-button v-if="hasPermission('cw:workContract:filed') && (scope.row.createById === $store.state.user.id||haveProjectIds.includes(scope.row.projectId)) && scope.row.status === '5'&& scope.row.reviewStatus === '2'" text type="primary" @click="rebackF(scope.row)">撤回复核</el-button>
					<!--              审核-->
<!--					<el-button v-if="scope.row.reviewStatus==='2' && checkIsAuditReview(scope.row)" text type="primary" @click="examineReview(scope.row)">审核</el-button>-->
					<!--              被驳回后当前申请人重新调整-->
					<el-button v-if="hasPermission('cw:workContract:filed')&&scope.row.createById === $store.state.user.id&&scope.row.reviewStatus === '4'" text type="primary" @click="adjustReview(scope.row)">驳回调整</el-button>
					<el-button v-if="hasPermission('cw:workContract:filed') && (scope.row.createById === $store.state.user.id||haveProjectIds.includes(scope.row.projectId)) && scope.row.status === '5' && (scope.row.reviewStatus === '5' || scope.row.reviewStatus === '7')
					&& (scope.row.signAndIssueStatus === '0' || scope.row.signAndIssueStatus === '1' || scope.row.signAndIssueStatus === '3' || scope.row.signAndIssueStatus === undefined || scope.row.signAndIssueStatus === '') && scope.row.projectLevel !== '2'" text type="primary" @click="pushSignAndIssue(scope.row)">报告签发</el-button>
					<el-button v-if="hasPermission('cw:workContract:filed') && (scope.row.createById === $store.state.user.id||haveProjectIds.includes(scope.row.projectId)) && scope.row.status === '5'&& scope.row.reviewStatus === '5' && scope.row.signAndIssueStatus === '2'" text type="primary" @click="rebackSignAndIssue(scope.row)">撤回签发</el-button>
					<el-button v-if="hasPermission('signAndIssue:del') && (scope.row.createById === $store.state.user.id||haveProjectIds.includes(scope.row.projectId)) && scope.row.status === '5'&& scope.row.reviewStatus === '5' && (scope.row.signAndIssueStatus === '1' || scope.row.signAndIssueStatus === '3' || scope.row.signAndIssueStatus === '4')" text type="primary" @click="deleteSignAndIssue(scope.row)">删除签发</el-button>
					<el-button v-if="hasPermission('cw:workContract:filed')&&scope.row.createById === $store.state.user.id&&scope.row.reviewStatus === '5'&&scope.row.signAndIssueStatus === '4'" text type="primary" @click="adjustSignAndIssue(scope.row)">驳回调整</el-button>
					<el-button v-if="hasPermission('cw:workContract:filed') && (scope.row.createById === $store.state.user.id||haveProjectIds.includes(scope.row.projectId)) && scope.row.status === '5' && (scope.row.reviewStatus === '5' || scope.row.reviewStatus === '7') && (scope.row.signAndIssueStatus === '5' || scope.row.projectLevel === '2')
							   && (scope.row.onlineArchivingStatus === '0' || scope.row.onlineArchivingStatus === '1' || scope.row.onlineArchivingStatus === '3' || scope.row.onlineArchivingStatus === undefined || scope.row.onlineArchivingStatus === '' || scope.row.onlineArchivingStatus === '6')"
							   text type="primary" @click="pushOnlineArchiving(scope.row)">线上归档</el-button>
					<el-button v-if="hasPermission('cw:workContract:filed') && (scope.row.createById === $store.state.user.id||haveProjectIds.includes(scope.row.projectId)) && scope.row.status === '5'&& scope.row.reviewStatus === '5' && scope.row.onlineArchivingStatus === '2'" text type="primary" @click="rebackPushOnline(scope.row)">撤回线上归档</el-button>
					<el-button v-if="hasPermission('cw:workContract:filed') && (scope.row.createById === $store.state.user.id||haveProjectIds.includes(scope.row.projectId)) && scope.row.status === '5'&& scope.row.reviewStatus === '5' && scope.row.onlineArchivingStatus === '4'" text type="primary" @click="adjustPushOnline(scope.row)">驳回调整</el-button>
					<el-button v-if="hasPermission('cw:workContract:filed') && (scope.row.createById === $store.state.user.id||haveProjectIds.includes(scope.row.projectId)) && scope.row.status === '5' && scope.row.reviewStatus === '5' && (scope.row.onlineArchivingStatus === '5' || scope.row.onlineArchivingStatus === '7') && scope.row.projectLevel === '1'
					&& (scope.row.paperArchivingStatus === '0' || scope.row.paperArchivingStatus === '1' || scope.row.paperArchivingStatus === '3' || scope.row.paperArchivingStatus === undefined || scope.row.paperArchivingStatus === '' || scope.row.paperArchivingStatus === '6')" text type="primary" @click="pushPaperArchiving(scope.row)">纸质归档</el-button>
					<el-button v-if="hasPermission('cw:workContract:filed') && (scope.row.createById === $store.state.user.id||haveProjectIds.includes(scope.row.projectId)) && scope.row.status === '5'&& scope.row.reviewStatus === '5' && scope.row.onlineArchivingStatus === '5' && scope.row.paperArchivingStatus === '2' && scope.row.projectLevel === '1'" text type="primary" @click="rebackPushPaper(scope.row)">撤回纸质归档</el-button>
					<el-button v-if="hasPermission('cw:workContract:filed') && (scope.row.createById === $store.state.user.id||haveProjectIds.includes(scope.row.projectId)) && scope.row.status === '5'&& scope.row.reviewStatus === '5' && scope.row.onlineArchivingStatus === '5' && scope.row.paperArchivingStatus === '4' && scope.row.projectLevel === '1'" text type="primary" @click="adjustPushPaper(scope.row)">驳回调整</el-button>
				</div>
            </template>
          </vxe-column>
        </vxe-table>
        <vxe-pager
          background
          :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>
    <ReportManagementForm ref="reportManagementForm" @refreshList="refreshList"></ReportManagementForm>
    <ReportManagementAddForm ref="reportManagementAddForm" @refreshList="refreshList"></ReportManagementAddForm>
	  <ContractAddForm ref="contractAddForm" @refreshDataList="refreshList"></ContractAddForm>
	  <ProjectRecordsInfoForm ref="projectRecordsInfoForm" @refreshList="refreshList"></ProjectRecordsInfoForm>
  </div>
</template>

<script>
	import ContractAddForm from '@/views/cw/workContract/contractRegisitionAddForm/ContractAddForm'
	import ProjectRecordsInfoForm from './ProjectRecordsInfoForm'
  import InputNumber from '@/views/cw/workContract/InputNumber.vue'
  import projectReportService from '@/api/cw/reportManagement/ProjectReportService'
  import ReportReviewService from '@/api/cw/reportManagement/ReportReviewService'
  import ReportSignAndIssueService from '@/api/cw/reportManagement/ReportSignAndIssueService'
  import reportOnlineArchivingService from '@/api/cw/reportManagement/ReportOnlineArchivingService'
  import reportPaperArchivingService from '@/api/cw/reportManagement/reportPaperArchivingService'
  import ReportNumberApplyService from '@/api/cw/reportManagement/ReportNumberApplyService'
  import taskService from '@/api/flowable/TaskService'
  import processService from '@/api/flowable/ProcessService'
  import ReportManagementForm from './ReportManagementFormNew'
  import ReportManagementAddForm from './ReportManagementAddForm'
  import pick from 'lodash.pick'
  import userService from '@/api/sys/UserService'
  import SelectUserTree from '@/views/utils/treeUserSelect'
  import projectRecordsService from '@/api/cw/projectRecords/ProjectRecordsService'
  import UserSelect from '@/views/cw/workClientInfo/clientUserSelect'
  export default {
    data () {
      return {
      	searchVisible : true,
        showHideItem: false,
        showHideIcon: 'el-icon-arrow-down',
        showHideName: '展示',
        num: 0,
		  searchForm: {
			  reportNo: '',
			  projectNumber: '',
			  projectName: '',
			  createBy: '',
			  contractDates: [],
			  projectCategory: ''
		  },
        dataList: [],
        tablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: []
        },
        tableKey: '',
        loading: false,
        processDefinitionAuditId: '',
        procDefAuditKey: '',
		  signAndIssueProcDefId: '',
		  signAndIssueProcDefKey: '',
		  paperArchivingProcDefId: '',
		  paperArchivingProcDefKey: '',
		  onlineArchivingProcDefIdA: '',
		  onlineArchivingProcDefKeyA: '',
		  onlineArchivingProcDefIdB: '',
		  onlineArchivingProcDefKeyB: '',
		processDefinitionAuditIdAndSId: '',
        procDefAuditKeyAndSId: '',
        isAdmin: false,
        create: '',
        processDefinitionSId: '',
        procDefSKey: '',
        processDefinitionSId2: '',
        procDefSKey2: '',
        processDefinitionSId3: '',
        procDefSKey3: '',
        haveProjectIds: '',
	    processDefinitionSigId: '',
	    procDefSigKey: '',
	    processDefinitionTakeNumberAuditId: '',
	    procDefTakeNumberAuditKey: '',
	    processDefinitionTakeNumberSId: '',
	    procDefSTakeNumberKey: '',
		  processDefinitionTakeNumberReviewAuditId: '',
		  procDefTakeNumberReviewAuditKey: '',
      }
    },
    reportReviewService: null,
	  reportSignAndIssueService: null,
	  reportNumberApplyService: null,
    created () {
      this.reportReviewService = new ReportReviewService()
      this.reportSignAndIssueService = new ReportSignAndIssueService()
      this.reportNumberApplyService = new ReportNumberApplyService()
    },
    components: {
		ContractAddForm,
		ProjectRecordsInfoForm,
      ReportManagementForm,
      ReportManagementAddForm,
      SelectUserTree,
      InputNumber,
      UserSelect,
    },
    computed: {
      userName () {
        return this.$store.state.user.name
      },
      user () {
        this.createName = this.$store.state.user.name
        return this.$store.state.user
      }
    },
    mounted () {
		this.$nextTick(() => {
			//将表格和工具栏进行关联
			const $table = this.$refs.clientTable;
			const $toolbar = this.$refs.toolbarRef;
			$table.connect($toolbar);
		})
      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.reportManagementForm.init('edit', id, '')
      },
      // 查看
      view (id) {
        this.$refs.reportManagementForm.init('view', id, '报告审核单下载')
      },
		// 查看合同信息
	  contractView (id) {
			this.$refs.contractAddForm.init('view', id)
      },
		// 查看项目信息
	  projectView (id) {
			this.$refs.projectRecordsInfoForm.init('view', id)
      },
      // 查询当前用户是否是管理员用户
      checkIsAdmin () {
        userService.is().then((data) => {
          this.isAdmin = data
        })
      },
      // 获取数据列表
      refreshList () {
        this.loading = true
        projectReportService.list({
          'current': this.tablePage.currentPage,
          'size': this.tablePage.pageSize,
          'orders': this.tablePage.orders,
          ...this.searchForm
        }).then((data) => {
          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()
        processService.getByName('会计-报告复核').then((data) => {
          if (!this.commonJS.isEmpty(data.id)) {
            this.processDefinitionAuditId = data.id
            this.procDefAuditKey = data.key
          }
        })
		  processService.getByName('报告签发').then((data) => {
          if (!this.commonJS.isEmpty(data.id)) {
            this.signAndIssueProcDefId = data.id
            this.signAndIssueProcDefKey = data.key
          }
        })
		  processService.getByName('报告-线上归档(A)').then((data) => {
			  if (!this.commonJS.isEmpty(data.id)) {
				  this.onlineArchivingProcDefIdA = data.id
				  this.onlineArchivingProcDefKeyA = data.key
			  }
		  })
		  processService.getByName('报告-线上归档(B)').then((data) => {
			  if (!this.commonJS.isEmpty(data.id)) {
				  this.onlineArchivingProcDefIdB = data.id
				  this.onlineArchivingProcDefKeyB = data.key
			  }
		  })
		  processService.getByName('报告-纸质归档').then((data) => {
			  if (!this.commonJS.isEmpty(data.id)) {
				  this.paperArchivingProcDefId = data.id
				  this.paperArchivingProcDefKey = 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,projectId) {
      	console.log('projectId', projectId)
        let ids = id || this.$refs.clientTable.getCheckboxRecords().map(item => {
          return item.id
        }).join(',')
        this.$confirm(`确定删除所选项吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          projectReportService.delete(ids,projectId).then((data) => {
            this.$message.success(data)
            this.refreshList()
            this.loading = false
          })
        })
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.refreshList()
      },
      start () {
        this.$refs.reportManagementAddForm.init('add')
      },
		pushF (row) {
			// 读取流程表单
			let title = ' '
			if (!row.documentNo) {
				title = ' ' + row.projectName
			} else {
				title = ' ' + row.documentNo + ' - ' + row.projectName
			}

			let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了` + title + '[会计-报告复核]'
			let status = 'startAndHold'
			if (row.reviewStatus === '3') {
				status = 'startAndClose'
			} else if (row.reviewStatus === '4') {
				status = 'reapplyFlag'
			}

			if (row.projectLevel === '1') {
				status = 'startAndHold'
			}

			taskService.getTaskDef({ procDefId: this.processDefinitionAuditId,
				businessId: row.id,
				businessTable: 'cw_project_report_review_new'}).then((data) => {
				this.$router.push({
					path: '/flowable/task/TaskForm',
					query: {
						...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
						procDefId: this.processDefinitionAuditId,
						procDefKey: this.procDefAuditKey,
						title: title,
						formType: data.formType,
						formUrl: data.formUrl,
						formTitle: processTitle,
						businessTable: 'cw_project_report_review_new',
						businessId: row.id,
						isShow: 'false',
						status: status,
						routePath: '/cw/reportManagement/ReportManagementList'
					}
				})
			})
		},
		// 审核或重新调整跳转
		todoReview (row) {
			let cUser = false
			taskService.getTaskDefInfo({
				taskId: row.revTaskId
			}).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/reportManagement/ReportManagementList'   // 数据处理后需要跳转的页面路径
					}
				})
			})
		},
		// 查询当前登录人是否是数据的审核人
		checkIsAuditReview (row) {
			let loginUserId = this.$store.state.user.id  // 获取当前登录用户id
			if (this.commonJS.isNotEmpty(row.auditUserIdsRev)) {
				for (const userId of row.auditUserIdsRev) {
					if (userId === loginUserId) {  // 当数据的审核人中包含当前登录人id时，返回true
						return true
					}
				}
			}
			return false
		},
		// 流程详情
		detail (row) {
			if (!this.commonJS.isEmpty(row.reviewStatus) && row.reviewStatus !== '0') {
				taskService.getTaskDef({
					procInsId: row.procInsId3,
					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'
						}
					})
				})
			}

		},
		// 撤回报告复核
		rebackF (row) {
			this.$confirm(`确定要撤回该申请吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(async () => { // 需要修改row.sid1
				await this.reportReviewService.queryByReportIdNew(row.id).then((data) => {
					if (data.reviewStatus !== '2') { // status的值不等于“审核中”，就弹出提示
						this.$message.error('数据已发生改变或不存在，请刷新数据')
						this.refreshList()
					} else {
						processService.revokeProcIns(row.procInsId3).then((data) => {
							let form = {reviewStatus: '3', id: row.reviewNewId}
							this.reportReviewService.updateReviewStatusByReportIdNew(form)
							this.$message.success(data)
							this.refreshList()
						})
					}
				})
			})
		},
		// 驳回后调整
		adjustReview (row) {
			this.reportReviewService.queryByReportIdNew(row.id).then((data) => {
				if (data.reviewStatus !== '4') { // status的值不等于“驳回”，就弹出提示
					this.$message.error('数据已发生改变或不存在，请刷新数据')
					this.refreshList()
				} else {
					this.todoReview(row)
				}
			})
		},

		pushSignAndIssue (row) {
			// 读取流程表单
			let title = ' '
			if (!row.documentNo) {
				title = ' ' + row.projectName
			} else {
				title = ' ' + row.documentNo + ' - ' + row.projectName
			}

			let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了` + title + '[会计-报告签发]'
			let status = 'startAndHold'
			if (row.reviewStatus === '3') {
				status = 'startAndClose'
			} else if (row.reviewStatus === '4') {
				status = 'reapplyFlag'
			}

			if (row.projectLevel === '1') {
				status = 'startAndClose'
			}

			taskService.getTaskDef({ procDefId: this.signAndIssueProcDefId,
				businessId: row.signAndIssueId,
				businessTable: 'cw_project_report_sign_and_issue'}).then((data) => {
				this.$router.push({
					path: '/flowable/task/TaskForm',
					query: {
						...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
						procDefId: this.signAndIssueProcDefId,
						procDefKey: this.signAndIssueProcDefKey,
						title: title,
						formType: data.formType,
						formUrl: data.formUrl,
						formTitle: processTitle,
						businessTable: 'cw_project_report_sign_and_issue',
						businessId: row.id,
						isShow: 'false',
						status: status,
						routePath: '/cw/reportManagement/ReportManagementList'
					}
				})
			})
		},
		// 报告签发流程详情
		signAndIssueDetail (row) {
			if (!this.commonJS.isEmpty(row.signAndIssueStatus) && row.signAndIssueStatus !== '0') {
				taskService.getTaskDef({
					procInsId: row.procInsId4,
					procDefId: this.signAndIssueProcDefId
				}).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'
						}
					})
				})
			}

		},
		// 撤回报告签发
		rebackSignAndIssue (row) {
			this.$confirm(`确定要撤回该申请吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(async () => { // 需要修改row.sid1
				await this.reportSignAndIssueService.queryByReportId(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.signAndIssueId}
							this.reportSignAndIssueService.updateStatusByReportId(form)
							this.$message.success(data)
							this.refreshList()
						})
					}
				})
			})
		},
		// 报告签发驳回调整
		adjustSignAndIssue (row) {
			this.reportSignAndIssueService.queryByReportId(row.id).then((data) => {
				if (data.status !== '4') { // status的值不等于“驳回”，就弹出提示
					this.$message.error('数据已发生改变或不存在，请刷新数据')
					this.refreshList()
				} else {
					this.todoSignAndIssue(row)
				}
			})
		},
		// 审核或重新调整跳转
		todoSignAndIssue (row) {
      	console.log('row', row)
			let cUser = false
			taskService.getTaskDefInfo({
				taskId: row.signAndIssueTaskId
			}).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/reportManagement/ReportManagementList'   // 数据处理后需要跳转的页面路径
					}
				})
			})
		},
		// 删除签发
		deleteSignAndIssue (row) {
			this.$confirm(`确定要删除该报告签发吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				this.loading = true
				this.reportSignAndIssueService.delete(row.signAndIssueId).then((data) => {
					this.$message.success(data)
					this.refreshList()
					this.loading = false
				})
			})
		},
		pushOnlineArchiving (row) {
			// 读取流程表单
			let title = ' '
			if (!row.documentNo) {
				title = ' ' + row.projectName
			} else {
				title = ' ' + row.documentNo + ' - ' + row.projectName
			}

			let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了` + title + '[报告-线上归档]'
			let status = 'startAndHold'
			if (row.reviewStatus === '3') {
				status = 'startAndClose'
			} else if (row.reviewStatus === '4') {
				status = 'reapplyFlag'
			}

			let procDefId = ''
			let procDefKey = ''
			if (row.projectLevel === '1') {
				status = 'startAndHold'
				procDefId = this.onlineArchivingProcDefIdA
				procDefKey = this.onlineArchivingProcDefKeyA
			} else if (row.projectLevel === '2'){
				status = 'startAndHold'
				procDefId = this.onlineArchivingProcDefIdB
				procDefKey = this.onlineArchivingProcDefKeyB
			}
			console.log('row', row)


			taskService.getTaskDef({ procDefId: procDefId,
				businessId: row.id,
				businessTable: 'cw_project_report_online_archiving'}).then((data) => {
				this.$router.push({
					path: '/flowable/task/TaskForm',
					query: {
						...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
						procDefId: procDefId,
						procDefKey: procDefKey,
						title: title,
						formType: data.formType,
						formUrl: data.formUrl,
						formTitle: processTitle,
						businessTable: 'cw_project_report_online_archiving',
						businessId: row.id,
						isShow: 'false',
						status: status,
						routePath: '/cw/reportManagement/ReportManagementList'
					}
				})
			})
		},
		// 线上归档流程详情
		pushOnlineDetail (row) {
			if (!this.commonJS.isEmpty(row.onlineArchivingStatus) && row.onlineArchivingStatus !== '0') {
				let procDefId = ''
				if (row.projectLevel === '1') {
					procDefId = this.onlineArchivingProcDefIdA
				} else if (row.projectLevel === '2'){
					procDefId = this.onlineArchivingProcDefIdB
				}
				taskService.getTaskDef({
					procInsId: row.onlineArchivingProcInsId,
					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'
						}
					})
				})
			}

		},
		// 撤回线上归档
		rebackPushOnline (row) {
			this.$confirm(`确定要撤回该申请吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(async () => { // 需要修改row.sid1
				await reportOnlineArchivingService.queryByReportId(row.id).then((data) => {
					if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
						this.$message.error('数据已发生改变或不存在，请刷新数据')
						this.refreshList()
					} else {
						processService.revokeProcIns(row.onlineArchivingProcInsId).then((data) => {
							let form = {status: '3', id: row.onlineArchivingId}
							reportOnlineArchivingService.updateStatusByReportId(form)
							this.$message.success(data)
							this.refreshList()
						})
					}
				})
			})
		},
		// 在线归档驳回调整
		adjustPushOnline (row) {
			reportOnlineArchivingService.queryByReportId(row.id).then((data) => {
				if (data.status !== '4') { // status的值不等于“驳回”，就弹出提示
					this.$message.error('数据已发生改变或不存在，请刷新数据')
					this.refreshList()
				} else {
					this.todoPushOnline(row)
				}
			})
		},
		todoPushOnline (row) {
			let cUser = false
			taskService.getTaskDefInfo({
				taskId: row.onlineArchivingTaskId
			}).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/reportManagement/ReportManagementList'   // 数据处理后需要跳转的页面路径
					}
				})
			})
		},
		pushPaperArchiving (row) {
			// 读取流程表单
			let title = ' '
			if (!row.documentNo) {
				title = ' ' + row.projectName
			} else {
				title = ' ' + row.documentNo + ' - ' + row.projectName
			}

			let processTitle = `${this.userName} 在 ${this.moment(new Date()).format('YYYY-MM-DD HH:mm')} 发起了` + title + '[报告-纸质归档]'
			let status = 'startAndHold'
			if (row.reviewStatus === '3') {
				status = 'startAndClose'
			} else if (row.reviewStatus === '4') {
				status = 'reapplyFlag'
			}

			let procDefId = this.paperArchivingProcDefId
			let procDefKey = this.paperArchivingProcDefKey
			status = 'startAndClose'


			taskService.getTaskDef({ procDefId: procDefId,
				businessId: row.id,
				businessTable: 'cw_project_report_paper_archiving'}).then((data) => {
				this.$router.push({
					path: '/flowable/task/TaskForm',
					query: {
						...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
						procDefId: procDefId,
						procDefKey: procDefKey,
						title: title,
						formType: data.formType,
						formUrl: data.formUrl,
						formTitle: processTitle,
						businessTable: 'cw_project_report_paper_archiving',
						businessId: row.id,
						isShow: 'false',
						status: status,
						routePath: '/cw/reportManagement/ReportManagementList'
					}
				})
			})
		},
		// 纸质归档流程详情
		pushPaperDetail (row) {
			if (!this.commonJS.isEmpty(row.paperArchivingStatus) && row.paperArchivingStatus !== '0') {
				let procDefId = this.paperArchivingProcDefId
				taskService.getTaskDef({
					procInsId: row.paperArchivingProcInsId,
					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'
						}
					})
				})
			}

		},
		// 撤回纸质归档
		rebackPushPaper (row) {
			this.$confirm(`确定要撤回该申请吗?`, '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(async () => { // 需要修改row.sid1
				await reportPaperArchivingService.queryByReportId(row.id).then((data) => {
					if (data.status !== '2') { // status的值不等于“审核中”，就弹出提示
						this.$message.error('数据已发生改变或不存在，请刷新数据')
						this.refreshList()
					} else {
						processService.revokeProcIns(row.paperArchivingProcInsId).then((data) => {
							let form = {status: '3', id: row.paperArchivingId}
							reportPaperArchivingService.updateStatusByReportId(form)
							this.$message.success(data)
							this.refreshList()
						})
					}
				})
			})
		},
		// 纸质归档驳回调整
		adjustPushPaper (row) {
			reportPaperArchivingService.queryByReportId(row.id).then((data) => {
				if (data.status !== '4') { // status的值不等于“驳回”，就弹出提示
					this.$message.error('数据已发生改变或不存在，请刷新数据')
					this.refreshList()
				} else {
					this.todoPushPaper(row)
				}
			})
		},
		todoPushPaper (row) {
			let cUser = false
			taskService.getTaskDefInfo({
				taskId: row.onlineArchivingTaskId
			}).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/reportManagement/ReportManagementList'   // 数据处理后需要跳转的页面路径
					}
				})
			})
		},
    }
  }
</script>
