<!-- 评审素材预览 -->
<template>
  <div>
    <up-down-layout :handleFlag.sync="handleFlag">
      <!-- 搜索 -->
      <search-form resetPerms="reset"
                  v-if="searchFormView"
                   searchPerms="search"
                   slot="query"
                   :formValue.sync="queryParas"
                   :componentList="componentList"
                   @handleFilter="handleFilter"
                   @clearParam="clearParam"></search-form>
        <!-- table列表 -->
        <template slot="table">
          <data-table ref="tableData"
                      v-bind="elHeightObj"
                      operateBtnLayout=""
                      :api="api"
                      :handleFlag.sync="handleFlag"
                      :headTitleFlag="headTitleFlag"
                      :queryParas="queryParas"
                      :sourceData.sync="sourceData"
                      :loadCount.sync="loadCount"
                      :columns="columns"
                      :spanMethod="objectSpanMethod"
                      :showSelection="true"
                      :IsRight="false"
                      :pageAll="true"
                      :menuFlag="true"
                      @selectRowChange="selectRowChange"
                      @onDelsRow="onDelsRow">
            <!-- 文字折叠 -->
            <template slot="fileName"
                      slot-scope="scope">
              <span-plus :index="scope.data.$index"
                         :text="getHgCommon(scope.data.row, 'fileName')"></span-plus>
            </template>
            <template slot="problemType"
                      slot-scope="scope">
              <span-plus :index="scope.data.$index"
                         :text="getHgCommon(scope.data.row, 'problemType')"></span-plus>
            </template>
            <template slot="problemPoint"
                      slot-scope="scope">
              <span-plus :index="scope.data.$index"
                         :text="getHgCommon(scope.data.row, 'problemPoint')"></span-plus>
            </template>
            <template slot="solution"
                      slot-scope="scope">
              <span-plus :index="scope.data.$index"
                         :text="getHgCommon(scope.data.row,'solution')"></span-plus>
            </template>
            <template slot="problemSummary"
                      slot-scope="scope">
              <span-plus :index="scope.data.$index"
                         :text="scope.data.row.problemSummary"></span-plus>
            </template>
            <template slot="problemDesc"
                      slot-scope="scope">
              <span-plus :index="scope.data.$index"
                         :text="scope.data.row.problemDesc"></span-plus>
            </template>
            <template slot="reviewConclusion"
                      slot-scope="scope">
              <span-plus :index="scope.data.$index"
                         :text="scope.data.row.reviewConclusion"></span-plus>
            </template>
            <template slot="remark"
                      slot-scope="scope">
              <span-plus :index="scope.data.$index"
                         :text="scope.data.row.remark"></span-plus>
            </template>
            <template slot="headButton">
              <div align="right">
                <!-- 新增 -->
                <auth-button type="primary"
                             icon="iconfont iconxinzeng"
                             :size="'medium'"
                             :label="$t('reviewMaterialIndex.addMaterial')"
                             @click="showCreate"></auth-button>
                <!-- 批量转交 -->
                <auth-button type="primary"
                             icon="iconfont iconzhuanjiao"
                             :size="'medium'"
                             :label="$t('reviewMaterialIndex.batchTransfer')"
                             @click="myBatchTransfer"></auth-button>
                <!-- 批量删除 -->
                <auth-button type="danger"
                             icon="iconfont iconshanchu"
                             :size="'medium'"
                             :label="$t('common.dels')"
                             @click="showDels"></auth-button>
              </div>
            </template>
            <!-- 相关文件 -->
            <el-table-column :label="$t('feedbackMaterialIndex.relatedAccessories')"
                             size="small"
                             align="center"
                             width="100px"
                             fixed="right">
              <template slot-scope="scope">
                <btn-batch-download :fileID="FileBatchDown(scope.row)"
                                    size="medium"
                                    v-if="scope.row.accessoryExtDtoList && scope.row.accessoryExtDtoList.length > 0"></btn-batch-download>
              </template>
            </el-table-column>
            <!-- 操作 -->
            <el-table-column :label="$t('common.operate')"
                             align="center"
                             width="300"
                             fixed="right">
              <template slot-scope="scope">
                <!-- 分析 -->
                <auth-button size="small"
                             class="iconCircle marginLeft"
                             icon="iconfont iconfenxi"
                             :title="$t('common.analysis')"
                             @click="showAnalysis(scope.$index, scope.row)"
                             v-if="analysisPermi(scope.row)"></auth-button>
                <!-- 复核 -->
                <auth-button size="small"
                             class="iconCircle marginLeft"
                             icon="iconfont iconfuhe"
                             :title="$t('common.review')"
                             @click="showReview(scope.$index, scope.row)"
                             v-if="showFhButton(scope.row)"></auth-button>
                <!-- 转交 -->
                <auth-button size="small"
                             class="iconCircle marginLeft"
                             icon="iconfont iconzhuanjiao1"
                             :title="$t('common.transpond')"
                             @click="transfer(scope.row)"
                             v-if="forwardingPermi(scope.row)"></auth-button>
                <!-- 编辑 -->
                <auth-button size="small"
                             class="iconCircle marginLeft"
                             icon="iconfont iconbianji"
                             :title="$t('common.edit')"
                             @click="showEdit(scope.$index, scope.row, 'E')"
                             v-if="editPermi(scope.row)"></auth-button>
                <!-- 删除 -->
                <auth-button class="pssc-css iconCircle marginLeft"
                             size="small"
                             type="danger"
                             icon="iconfont iconycjian"
                             :title="$t('common.delete')"
                             @click="del(scope.$index, scope.row)"
                             v-if="deletePermi(scope.row)"></auth-button>
                <!-- 查看 -->
                <auth-button size="small"
                             class="iconCircle marginLeft"
                             icon="iconfont iconchakan"
                             :title="$t('common.view')"
                             showBtn="false"
                             @click="showView(scope.$index, scope.row, 'V')" ></auth-button>
            </template>
          </el-table-column>
          </data-table>
        </template>
    </up-down-layout>
    <!-- 新增、编辑 -->
    <reviewMaterial-add v-if="showDetail"
                        :item="item"
                        :searchFormView.sync="searchFormView"
                        :payCodeOption="payCodeOption"
                        :tableData="tableData"
                        :editModel="editModel"
                        :showDetail.sync="showDetail"
                        @showAnalysisCg="showAnalysisCg"
                        @handleFilter="handleFilter"></reviewMaterial-add>
    <!-- 分析、复核 -->
    <reviewMaterial-analysis v-if="dialogVisible"
                             :visible.sync="dialogVisible"
                             :diablogTitle="diablogTitle"
                             :form="form"
                             :keyId.sync ="keyId"
                             :commitStatus="commitStatus"
                             :editModel="editModel"
                             @getTable="getTable"
                             @handleFilter="handleFilter"></reviewMaterial-analysis>
                             <!-- @operateBtnClick="operateBtnClick" -->

    <!-- 转交 -->
    <transfer-personSetup-pageIndex :visible.sync="transferVisible"
                                    :editModel="editModel"
                                    :useTemplate="useTemplate"
                                    :deliverType="deliverType"
                                    :form="transferData"
                                    v-if="transferVisible"
                                    :transferApi='zfApi'
                                    @forwardCall="forwardCall"></transfer-personSetup-pageIndex>
  </div>
</template>
<script>
import issueInputCustom from '@/components/element/assetaudit/issueInput-custom.vue'
import * as hgCommon from '@/pages/common/hgCommon'
import { mapGetters } from 'vuex'
import feedbackMaterialApi from '@/api/assetaudit/feedbackMaterial/feedbackMaterialApi'
import FeedInput from '@/components/element/assetaudit/FeedInput'
import transferPersonSetupPageIndex from '@/pages/assetaudit/cKnowledgeBase/transferPersonSetupPage/transferPersonSetupPageIndex.vue'
import { keyWordInput, upDownLayout, searchForm, DataTable, authButton, btnExport, SelectSupplier, btnDel, btnBatchDownload, SpanPlus } from 'newepoch-components'
import SelectReviewMaterialIndex from '@/components/element/assetaudit/SelectReviewMaterialIndex'
import SelectReviewMaterialIndexJlz from '@/components/element/assetaudit/SelectReviewMaterialIndexJlz'
import reviewmaterialApi from '@/api/assetaudit/reviewMaterialApi'
import reviewMaterialAdd from './reviewMaterial-add'
import ReviewMaterialAnalysis from '@/pages/assetaudit/reviewMaterial/reviewMaterial-analysis'
import * as format from '@/filters/index' // 格式函数集合
import SelectProduct from '@/components/element/assetaudit/SelectProduct'
import ReviewPersonSetup from '@/pages/assetaudit/reviewPersonSetup/reviewPersonSetupPop'
import BasePage from '@/pages/basePage'
import mixin from '@/pages/mixin'
export default {
  extends: new BasePage(),
  mixins: [mixin],
  name: 'reviewPersonSetupIndex',
  components: {
    SpanPlus,
    transferPersonSetupPageIndex,
    FeedInput,
    SelectReviewMaterialIndexJlz,
    SelectReviewMaterialIndex,
    reviewMaterialAdd,
    btnBatchDownload,
    btnDel,
    SelectSupplier,
    searchForm,
    upDownLayout,
    DataTable,
    btnExport,
    authButton,
    SelectProduct,
    ReviewPersonSetup,
    ReviewMaterialAnalysis
  },
  data () {
    return {
      searchFormView: true, // form是否重新渲染
      payCodeOption: [],
      deliverType: '', // 转发类型 1分析转发 2复核转发
      useTemplate: 'psscgl',
      plMode: '',
      transferData: {},
      selectedRows: [],
      transferVisible: false,
      zfDialogVisible: false,
      options: [],
      childrenAll: [],
      selected: [],
      handleFlag: true,
      headerVisible: true,
      headTitleFlag: true,
      keyId: '',
      editModel: 'V',
      currentRow: {},
      detail: {},
      commitStatus: '', // 01:分析，02：复核
      setUp: false, // 复核人员设置弹框
      isShowResetBtn: true,
      isShowFoldBtn: false,
      queryData: {},
      form: {},
      tableData: [],
      dialogVisible: false,
      componentList: [
        {
          // 付款确认书编号
          label: this.$t('common.payCode'),
          disabled: false,
          maxlength: 64,
          value: 'payCode',
          placeholder: this.$t('common.pleaseInput'),
          labelWidth: '160px',
          clearable: true,
          componentName: issueInputCustom
        },
        {
          // 供应商名称（使用id查）
          label: this.$t('reviewMaterialIndex.gysName'),
          disabled: false,
          value: 'gysId',
          placeholder: this.$t('common.pleaseSelect'),
          labelWidth: '160px',
          clearable: true,
          componentName: SelectReviewMaterialIndex,
          filterable: true
        },
        {
          // 记录者
          label: this.$t('reviewMaterialIndex.registrar'),
          disabled: false,
          value: 'registrarId',
          placeholder: this.$t('common.pleaseSelect'),
          labelWidth: '160px',
          clearable: true,
          componentName: SelectReviewMaterialIndexJlz,
          filterable: true
        },
        {
          // 评审状态
          label: this.$t('reviewMaterialIndex.psStatus'),
          disabled: false,
          value: 'status',
          placeholder: this.$t('common.pleaseSelect'),
          labelWidth: '160px',
          clearable: true,
          componentName: 'selectDictionary',
          dictTypeCode: 'APPRAISAL_STATUS'
        },
        {
          // 分析状态
          label: this.$t('reviewMaterialIndex.analysisStatus'),
          disabled: false,
          value: 'analysisStatus',
          placeholder: this.$t('common.pleaseSelect'),
          labelWidth: '160px',
          clearable: true,
          componentName: 'selectDictionary',
          dictTypeCode: 'ANALYSIS_STATE'
        },
        {
          // 关键词
          label: this.$t('reviewMaterialIndex.keyWord'),
          disabled: false,
          maxlength: 200,
          value: 'keyWord',
          placeholder: this.$t('common.pleaseInput'),
          labelWidth: '160px',
          clearable: true,
          componentName: keyWordInput,
          attrs: {
            toolTip: this.$t('reviewMaterialIndex.keyWordTop')
          }
        }
      ],
      columns: [
        {
          // 评审编号
          prop: 'reviewNo',
          align: 'left',
          width: '100px',
          label: this.$t('reviewMaterialIndex.reviewNo')
        },
        {
          // 评审时间
          prop: 'inspectionTime',
          align: 'center',
          width: '180px',
          label: this.$t('reviewMaterialIndex.inspectionTime'),
          format: (row) => {
            return format.formatCheckDatetime(row.inspectionTime)
          }
        },
        {
          // 发起负责人
          prop: 'reviewPromoterName',
          align: 'left',
          width: '100px',
          label: this.$t('reviewMaterialIndex.reviewPromoterName')
        },
        {
          // 评审委员会人员
          prop: 'committeeMemberNames',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.committeeMemberNames')
        },
        {
          // 付款确认书编号
          prop: 'payCode',
          align: 'center',
          width: '250px',
          label: this.$t('reviewMaterialIndex.payCode')
        },
        {
          // 供应商名称
          prop: 'gysName',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.gysName')
        },
        {
          // 项目公司名称
          prop: 'xmgsName',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.xmgsName')
        },
        {
          // 问题概要
          prop: 'problemSummary',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.problemSummary'),
          slot: true
        },
        {
          // 问题描述
          prop: 'problemDesc',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.problemDesc'),
          columnMenusFlag: false, // 隐藏
          slot: true
        },
        {
          // 评审结论
          prop: 'reviewConclusion',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.reviewConclusion'),
          columnMenusFlag: false,
          slot: true
        },
        {
          // 状态
          prop: 'status',
          align: 'left',
          width: '100px',
          // label: this.$t('reviewMaterialIndex.status'),
          label: this.$t('reviewMaterialIndex.psStatus'),
          format: (row) => {
            return format.formatDict(row.status, 'APPRAISAL_STATUS')
          }
        },
        {
          // 备注
          prop: 'remark',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.remark'),
          columnMenusFlag: false,
          slot: true
        },
        {
          // 产品类型
          prop: 'businessType',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.businessType'),
          columnMenusFlag: false,
          format: (row) => {
            // ZD0087是临时代码，恢复修改为“BUSINESS_TYPE”
            return format.formatDict(row.businessType, 'ZD0087')
          }
        },
        {
          // 文件类型
          prop: 'fileType',
          align: 'center',
          width: '200px',
          label: this.$t('reviewMaterialIndex.fileType'),
          columnMenusFlag: false,
          format: (row) => {
            return hgCommon.DtOdictionary(row, 'fileType', 'HG_FILE_TYPE')
          }
        },
        {
          // 文件名称
          prop: 'fileName',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.fileName'),
          columnMenusFlag: false,
          slot: true
        },
        {
          // 问题类型
          prop: 'problemType',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.problemType'),
          columnMenusFlag: false,
          slot: true
        },
        {
          // 问题点
          prop: 'problemPoint',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.problemPoint'),
          columnMenusFlag: false,
          slot: true
        },
        {
          // 解决方式
          prop: 'solution',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.solution'),
          slot: true
        },
        {
          // 记录者
          prop: 'registrar',
          align: 'left',
          width: '100px',
          label: this.$t('reviewMaterialIndex.registrar')
        },
        {
          // 分析状态
          prop: 'analysisStatus',
          align: 'center',
          width: '100px',
          label: this.$t('reviewMaterialIndex.analysisStatus'),
          format: (row) => {
            return format.formatDict(row.analysisStatus, 'ANALYSIS_STATE')
          }
        },
        {
          // 分析时间
          prop: 'analysisTime',
          align: 'center',
          width: '180px',
          label: this.$t('reviewMaterialIndex.analysisTime'),
          format: (row) => {
            return format.formatCheckDatetime(row.analysisTime)
          }
        },
        {
          // 分析人员
          prop: 'analysisPersonName',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.analysisPersonName')
        },
        {
          // 复核状态
          prop: 'reviewStatus',
          align: 'left',
          width: '100px',
          label: this.$t('reviewMaterialIndex.reviewStatus'),
          format: (row) => {
            return format.formatDict(row.reviewStatus, 'REVIEW_STATUS')
          }
        },
        {
          // 复核时间
          prop: 'reviewTime',
          align: 'center',
          width: '180px',
          label: this.$t('reviewMaterialIndex.reviewTime'),
          format: (row) => {
            return format.formatCheckDatetime(row.reviewTime)
          }
        },
        {
          // 复核人员
          prop: 'reviewPersonName',
          align: 'left',
          width: '200px',
          label: this.$t('reviewMaterialIndex.reviewPersonName')
        }
      ],
      sourceData: [] // 列表数据
    }
  },
  computed: {
    // 用户信息
    ...mapGetters(['user', 'userId']),
    // api接口
    api () {
      return reviewmaterialApi.reviewmaterial
    },
    // 转交使用的api
    zfApi () {
      return feedbackMaterialApi.transpond
    }
  },
  mounted () {
    // 触发，获取tableData数据
    this.handleFilter()
  },
  watch: {
    sourceData () {
      this.getRowSpan()
    },
    // 监听新增、修改窗口，重现渲染form表单，获取最新下拉数据
    showDetail (val) {
      if (val === false) {
        setTimeout(() => { // 延迟，留给dom渲染时间
          this.searchFormView = true
        }, 100)
      }
    }
  },
  methods: {
    // 绑定对应的value值（row，对应字段）（防止属性引入报错）
    getHgCommon (row, value) {
      return hgCommon.DtoValue(row, value)
    },
    // 行合并（当前行row、当前列column、当前行号rowIndex、当前列号columnIndex）
    objectSpanMethod ({ row, column, rowIndex, columnIndex }) {
      if (column.type === 'selection' || column.property === 'businessType' || column.property === 'reviewNo' || column.property === 'inspectionTime' || column.property === 'reviewPromoterName' || column.property === 'committeeMemberNames' || column.property === 'payCode' || column.property === 'gysName' || column.property === 'xmgsName' || column.property === 'problemSummary' || column.property === 'problemDesc' || column.property === 'reviewConclusion' || column.property === 'status' || column.property === 'remark' || column.property === 'registrar' || column.property === 'analysisStatus' || column.property === 'analysisTime' || column.property === 'analysisPersonName' || column.property === 'reviewStatus' || column.property === 'reviewTime' || column.property === 'reviewPersonName' || column.fixed === 'right') {
        let _row = this.rowSpanArr[rowIndex]
        return {
          rowspan: _row, // 行
          colspan: 1 // 列
        }
      }
    },
    // 付款确认书合并
    getRowSpan () {
      this.rowSpanArr = []
      let position = ''
      this.sourceData.forEach((item, index) => {
        if (index === 0) {
          this.rowSpanArr.push(1)
          position = 0
        } else {
          if (this.sourceData[index].keyId === this.sourceData[index - 1].keyId) {
            this.rowSpanArr[position] += 1 // 付款确认书相同，合并到同一个数组
            this.rowSpanArr.push(0)
            this.sourceData[index].keyId = this.sourceData[index - 1].keyId
          } else {
            this.rowSpanArr.push(1)
            position = index
          }
        }
      })
    },
    // 解决方法过滤
    solutionFormat (row) {
      if (row.knowledgeMgrDTO && row.knowledgeMgrDTO.solution) {
        return row.knowledgeMgrDTO.solution
      } else if (row.materialAnalyzeDTO && row.materialAnalyzeDTO.solution) {
        return row.materialAnalyzeDTO.solution
      } else {
        return ''
      }
    },
    // 转发回调
    forwardCall () {
      this.handleFilter()
    },
    // 分析按键权限
    analysisPermi (row) {
      let data = {}
      let dataHand = {}
      let dataEnd = {}
      if (row.status === '02' && row.analysisStatus === '0') {
        if (!row.materialRygxExtDtoList) {
          return false
        }
        data = row.materialRygxExtDtoList.filter(item => item.handlePersonId === this.userId)
        if (data.length > 0) {
          dataHand = data.filter(item => item.handleStatus === '1')
          if (dataHand.length > 0) {
            dataEnd = dataHand.find(item => item.personType === '03' || item.personType === '04' || item.personType === '05')
          }
        }
      }
      if (dataEnd && JSON.stringify(dataEnd) !== '{}') {
        return true
      } else {
        return false
      }
    },
    // 编辑权限
    editPermi (row) {
      let data = {}
      let dataHand = {}
      let dataEnd = {}
      if (row.analysisStatus === '1' && row.reviewStatus !== '0') { // 已分析、已复核/无需复核不显示编辑
        return false
      } else if (row.analysisStatus === '0' && (this.userId === row.reviewPromoterId || this.userId === row.registrarId)) { // 未分析，userId等于发起负责人或记录着
        return true
      } else if (!row.materialRygxExtDtoList) {
        return false
      } else if (row.addUserId === this.userId && row.analysisStatus === '0') { // 添加人是登陆者、且未分析
        return true
      } else if (row.analysisStatus === '0') { // 以下判断达到（未分析、转交人 = 登录者、是否办理复核为1、人员类别是345）
        data = row.materialRygxExtDtoList.filter(item => item.handlePersonId === this.userId)
        if (data.length > 0) {
          dataHand = data.filter(item => item.handleStatus === '1')
          if (dataHand.length > 0) {
            dataEnd = dataHand.find(item => (item.personType === '03' || item.personType === '04' || item.personType === '05'))
            if (dataEnd && JSON.stringify(dataEnd) !== '{}') {
              return true
            }
          }
        }
      } else {
        return false
      }
    },
    // 转发权限
    forwardingPermi (row) {
      let data
      let dataHand
      let dataType
      let fxzj
      let fhzj
      if (!row.materialRygxExtDtoList) return false
      if (row.status === '02' && row.analysisStatus === '0') {
        data = row.materialRygxExtDtoList.filter(item => item.handlePersonId === this.userId)
        if (data.length > 0) {
          dataHand = data.filter(item => item.handleStatus === '1')
          if (dataHand.length > 0) { // 01委员会 02评审复核转交人 03发起负责人 04记录着 05评审分析人 06项目负责人 07反馈复核转交人 08合规对接人 09反馈分析转交人
            dataType = dataHand.find(item => ((item.personType === '03' || item.personType === '04' || item.personType === '05')))
          }
        }
      }
      if (dataType && JSON.stringify(dataType) !== '{}') {
        fxzj = true
      } else {
        fxzj = false
      }
      if (row.analysisStatus === '1' && row.reviewStatus === '0') {
        data = row.materialRygxExtDtoList.filter(item => item.handlePersonId === this.userId)
        if (data.length > 0) {
          dataHand = data.filter(item => item.handleStatus === '1')
          if (dataHand.length > 0) {
            dataType = dataHand.find(item => (item.personType === '01' || item.personType === '02'))
          }
        }
      }
      if (dataType && JSON.stringify(dataType) !== '{}') {
        fhzj = true
      } else {
        fhzj = false
      }
      if (fxzj || fhzj) {
        return true
      } else {
        return false
      }
    },
    // 复核权限
    showFhButton (row) {
      let data = {}
      let dataHand = {}
      let dataEnd = {}
      if (!row.materialRygxExtDtoList) return false
      if (row.analysisStatus === '1' && row.reviewStatus === '0') {
        data = row.materialRygxExtDtoList.filter(item => item.handlePersonId === this.userId)
        if (data.length > 0) {
          dataHand = data.filter(item => item.handleStatus === '1')
          if (dataHand.length > 0) {
            dataEnd = dataHand.find(item => (item.personType === '01' || item.personType === '02'))
          }
        }
      }
      if (dataEnd && JSON.stringify(dataEnd) !== '{}') {
        return true
      } else {
        return false
      }
    },
    // 删除权限（未打上包）
    deletePermi (row) { // 素材未复核可删除（修改了规则）
      if (row.reviewStatus === '0' && (row.addUserId === this.userId || row.registrarId === this.userId || row.reviewPromoterId === this.userId)) { // 创建人、记录者、发起负责人 = 登陆者
        return true
      } else {
        if (row.materialRygxExtDtoList && row.materialRygxExtDtoList.find(res => ((res.personType === '03' || res.personType === '04' || res.personType === '05') && this.userId === res.handlePersonId && res.handleStatus === '1'))) {
          return true
        } else {
          return false
        }
        // return false
      }
    },
    // 编辑
    showEdit (index, row, editModel) {
      let putData
      this.editModel = editModel
      reviewmaterialApi.createReviewMaterialIndex.get(row.keyId).then(res => {
        putData = [res.data.payCode]
        feedbackMaterialApi.assetbycode.create(putData).then(item => {
          this.$store.commit('payCodeDropdownOption', item.data) // 存入vuex
          this.$nextTick(() => {
            res.data.keyId = row.keyId
            this.item = Object.assign({}, res.data)
            this.showDetail = true
          })
        })
      })
    },
    // 批量下载
    FileBatchDown (row) {
      let arr = []
      row.accessoryExtDtoList.forEach(res => {
        arr.push(res.fileId)
      })
      return arr
    },
    // 批量转交按钮数据确认
    batchTransferShow (data) {
      for (let i = 0; i < data.length - 1; i++) {
        for (let j = 0; j < data.length - i - 1; j++) {
          if ((data[j].analysisStatus === '0' || data[j].reviewStatus === '0') && (data[j + 1].analysisStatus === '0' || data[j + 1].reviewStatus === '0')) {
            if ((Number(data[j].analysisStatus) & Number(data[j].reviewStatus)) !== (Number(data[j + 1].analysisStatus) & Number(data[j + 1].reviewStatus))) {
              this.$message.warning(this.$t('feedbackMaterialIndex.differentFormat'))
              return false
            }
          } else {
            this.$message.warning(this.$t('feedbackMaterialIndex.otherData'))
            return false
          }
        }
      }
      return true
    },
    // 表格数据行选择
    selectRowChange (selectedRows) {
      this.selectedRows = selectedRows
    },
    // 是否存在不同类型的转交数据
    differentData () {
      let kxArr = []
      let exist
      kxArr = this.selectedRows.filter(res => this.forwardingPermi(res))
      for (let i = 0; i < kxArr.length; i++) {
        exist = kxArr.find(item => item.analysisStatus !== kxArr[i].analysisStatus)
        if (exist) {
          this.$message({
            type: 'warning',
            message: this.$t('feedbackMaterialIndex.differentFormat')
          })
          return true
        } else {
          return false
        }
      }
    },
    // 判断批量可选行
    cantNotSelectRow () {
      let kxArr = []
      if (this.plMode === 'zf') {
        kxArr = this.selectedRows.findIndex(res => !this.forwardingPermi(res))
        if (kxArr !== -1) {
          this.$message({
            type: 'warning',
            message: this.$t('feedbackMaterialIndex.otherData')
          })
          return true
        } else {
          return false
        }
      } else if (this.plMode === 'sc') {
        kxArr = this.selectedRows.findIndex(res => !this.deletePermi(res))
        if (kxArr !== -1) {
          this.$message({
            type: 'warning',
            message: this.$t('feedbackMaterialIndex.cantDeleteData')
          })
          return true
        } else {
          return false
        }
      }
    },
    // 批量删除
    showDels () {
      this.plMode = 'sc'
      if (this.cantNotSelectRow()) { return }
      this.$refs.tableData.showDels()
    },
    // 批量删除触发
    onDelsRow (data) {
      let arr = data.map(it => { return it.keyId })
      reviewmaterialApi.reviewmaterial.dels({ keyIds: arr }).then(res => {
        this.success(this.$t('feedbackMaterialIndex.deleteSucceed'))
        this.handleFilter()
      })
    },
    // 分析
    showAnalysis (index, row) {
      // this.diablogTitle = '评审素材分析'
      this.diablogTitle = '素材分析'
      this.editModel = 'FX'
      this.keyId = row.keyId
      this.commitStatus = '01'
      this.dialogVisible = true
    },
    // 重构分析
    showAnalysisCg (keyId) {
      // this.diablogTitle = '评审素材分析'
      this.diablogTitle = '素材分析'
      this.editModel = 'FX'
      this.keyId = keyId
      this.commitStatus = '01'
      this.dialogVisible = true
    },
    // 复核
    showReview (index, row) {
      this.editModel = 'FH'
      this.keyId = row.keyId
      // this.diablogTitle = '评审素材复核'
      this.diablogTitle = '素材复核'
      this.commitStatus = '02'
      this.dialogVisible = true
    },
    // 批量转交
    myBatchTransfer () {
      this.plMode = 'zf'
      if (this.cantNotSelectRow()) {
        return
      }
      if (this.differentData()) {
        return
      }
      this.transferData = {}
      if (this.selectedRows.length === 0) {
        this.warning(this.$t('feedbackMaterialIndex.selectDataAll'))
        return
      }
      if (this.batchTransferShow(this.selectedRows)) {
        this.batchTransfer(this.selectedRows)
      }
    },
    // 转交（行）
    transfer (row) {
      if (row.analysisStatus === '0') {
        this.deliverType = '1'
      } else {
        this.deliverType = '2'
      }
      this.transferData = {}
      let arr = []
      arr.push(row.keyId)
      this.transferData.keyIdList = arr
      this.transferVisible = true
    },
    // 批量转交
    batchTransfer () {
      if (this.selectedRows[0].analysisStatus === '0') {
        this.deliverType = '1'
      } else {
        this.deliverType = '2'
      }
      let arr = this.selectedRows.map(it => {
        return it.keyId
      })
      this.transferData = {}
      this.transferData.keyIdList = arr
      this.transferVisible = true
    },
    // 查看
    showView (index, data, editModel) {
      this.editModel = editModel
      reviewmaterialApi.createReviewMaterialIndex.get(data.keyId).then(res => {
        if (res.data.analysisStatus === '0') {
          this.$nextTick(() => {
            this.item = Object.assign({}, res.data)
          })
          this.showDetail = true
        } else {
          this.keyId = data.keyId
          this.diablogTitle = '评审素材查看'
          this.dialogVisible = true
        }
      })
    },
    // 列表获取（重构）
    getTable () {
      this.$refs.tableData.loadTableData()
    },
    // 删除
    del (index, row) {
      this.$confirm(this.$t('feedbackMaterialIndex.dataDelete'), this.$t('feedbackMaterialIndex.Hint'), {
        type: 'warning'
      }).then(() => {
        let data = { keyIds: row.keyId }
        reviewmaterialApi.reviewmaterial.dels(data).then(res => {
          this.success(this.$t('feedbackMaterialIndex.deleteSucceed'))
          this.handleFilter()
        })
      }).catch({})
    }
  }
}
</script>
