<!--反馈素材预览-->
<template>
  <div>
    <up-down-layout :headerVisible="headerVisible"
                    :header="$t('feedbackMaterialIndex.head')"
                    :handleFlag.sync="handleFlag">
    <!--查询-->
    <search-form ref="searchForm"
                 v-if="searchFormView"
                 searchPerms="search"
                 slot="query"
                 resetPerms="reset"
                 :formValue.sync="queryParas"
                 :componentList="componentList"
                 @handleFilter="handleFilter"
                 @clearParam="clearParam"></search-form>
      <template slot="table">
        <!--数据表格-->
        <data-table ref="feedDataTable"
                    v-bind="elHeightObj"
                    :api="api"
                    :headTitle="$t('feedbackMaterialIndex.feedbackInformationList')"
                    :loadCount.sync="loadCount"
                    :headTitleFlag="headTitleFlag"
                    :queryParas="queryParas"
                    :sourceData.sync="feedbackData"
                    :showSelection="showSelection"
                    :operateBtnLayout="operateBtnLayout"
                    :columns="columns"
                    :menuFlag="menuFlag"
                    :spanMethod="objectSpanMethod"
                    @selectRowChange="selectRowChange"
                    @getTableData="getTableData">
            <!-- 文字折叠 -->
            <template slot="fileName"
                      slot-scope="scope">
              <span-plus :index="scope.data.$index"
                         :text="getHgCommon(scope.data.row,'fileName')"></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="problemPoint"
                      slot-scope="scope">
              <span-plus :index="scope.data.$index"
                         :text="getHgCommon(scope.data.row, 'problemPoint')"></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="institutionOpinions"
                      slot-scope="scope">
              <span-plus :index="scope.data.$index"
                         :text="scope.data.row.institutionOpinions"></span-plus>
            </template>
            <template slot="hgOpinions"
                      slot-scope="scope">
              <span-plus :index="scope.data.$index"
                         :text="scope.data.row.hgOpinions"></span-plus>
            </template>
            <template slot="headButton">
                <div align="right">
                  <!--导入素材-->
                  <btn-batch-upload :btnDisplay="true"
                                    :uploadApi="batchUploadApi"
                                    :batchUploadName="$t('feedbackMaterialIndex.importMaterial')"
                                    btnSize="medium"
                                    style="margin-left: 10px;margin-right: 10px"
                                    @uploadSuccess="uploadSuccess"></btn-batch-upload>
                  <!--新增素材-->
                  <auth-button type="primary"
                               icon="iconfont iconxinzeng"
                               :size="'medium'"
                               :label="$t('feedbackMaterialIndex.addMaterial')"
                               @click="showCreate"></auth-button>
                  <!--批量转交-->
                  <auth-button type="primary"
                               icon="iconfont iconzhuanjiao"
                               :size="'medium'"
                               :label="$t('feedbackMaterialIndex.batchTransfer')"
                               @click="myBatchTransfer"></auth-button>
                  <!--批量删除-->
                  <auth-button type="danger"
                               icon="iconfont iconshanchu1"
                               :size="'medium'"
                               :label="$t('common.dels')"
                               @click="mybatchDel"></auth-button>
                </div>
            </template>
         <!-- 操作 -->
          <el-table-column :label="$t('feedbackMaterialIndex.relatedAccessories')"
                           align="center"
                           width="100px"
                           fixed="right">
            <template slot-scope="scope">
              <!-- 附件 -->
              <btn-batch-download :fileID="FileBatchDown(scope.row)"
                                  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="260" fixed="right">
            <template slot-scope="scope">
              <!-- 分析 -->
              <auth-button size="small"
                           class="iconCircle marginLeft"
                           :title="$t('feedbackMaterialIndex.analystic')"
                           @click="analysisAndReviewEdit(scope.row, 'A', '01')"
                           icon="iconfont iconfenxi"
                           v-if="analysisShow(scope.row)"></auth-button>
                           <!-- analysisShow(scope.row) -->
              <!-- 复核 -->
              <auth-button size="small"
                           class="iconCircle marginLeft"
                           :title="$t('common.review')"
                           @click="analysisAndReviewEdit(scope.row, 'R', '02')"
                           icon="iconfont iconfuhe"
                           v-if="reviewShow(scope.row)"></auth-button>
                           <!-- reviewShow(scope.row)" -->
              <!-- 转交 -->
              <auth-button size="small"
                           class="iconCircle marginLeft"
                           :title="$t('feedbackMaterialIndex.transfer')"
                           @click="transfer(scope.row)"
                           icon="iconfont iconzhuanjiao1"
                           v-if="analysisShow(scope.row) || reviewShow(scope.row)"></auth-button>
                           <!-- reviewShow(scope.row) || analysisShow(scope.row) -->
              <!-- 编辑 -->
              <auth-button size="small"
                           class="iconCircle marginLeft"
                           icon="iconfont iconbianji"
                           :title="$t('common.edit')"
                           @click="showEdit(scope.$index, scope.row, 'E')"
                           v-if="editShow(scope.row)"></auth-button>
                           <!-- editShow(scope.row) -->
              <!-- 删除 -->
              <auth-button  size="small"
                            :title="$t('common.del')"
                            @click="del(scope.row)"
                            icon="iconfont iconycjian"
                            class="iconCircle marginLeft pssc-css"
                            v-if="delShow(scope.row)"></auth-button>
                            <!-- delShow(scope.row) -->
              <!-- 查看 -->
              <auth-button size="small"
                           class="iconCircle marginLeft"
                           :title="$t('common.view')"
                           @click="viewShowEdit(scope.$index, scope.row, 'V')" icon="iconfont iconchakan"></auth-button>
            </template>
          </el-table-column>
        </data-table>
      </template>
    </up-down-layout>
    <!--新增、编辑-->
    <select-transfer-personnel v-if="showDetail"
                               :searchFormView.sync="searchFormView"
                               :visible.sync="showDetail"
                               :editModel="editModel"
                               :form="item"
                               @onSave="onSave"></select-transfer-personnel>
    <!-- 转交 -->
    <transfer-person-setup-page-index v-if="transferVisible"
                                      :visible.sync="transferVisible"
                                      :editModel="editModel"
                                      :form="transferData"
                                      :transferApi='transApi'
                                      @forwardCall="forwardCall"></transfer-person-setup-page-index>
    <!--反馈素材分析与复核-->
    <analysis-and-review-dialog ref="analysisAndReview"
                                v-if="dialogVisible"
                                :commitStatus="commitStatus"
                                :visible.sync="dialogVisible"
                                :editModel="editModel"
                                :form="analysisAndReview"
                                @operateBtnClick="operateBtnClick"></analysis-and-review-dialog>
    <!--导入成功-->
    <import-success-dialog v-if="importVisible"
                           :visible.sync="importVisible"
                           :form="importForm"
                           @operateBtnClick="operateBtnClick"></import-success-dialog>
  </div>
</template>

<script>
import * as hgCommon from '@/pages/common/hgCommon'
import issueInputZzs from '@/components/element/assetaudit/issueInput-zzs.vue'
import issueInputCustom from '@/components/element/assetaudit/issueInput-custom.vue'
import { mapGetters } from 'vuex'
import selectTransferPersonnel from './feedbackMaterial-add'
import SelectAnalysisPerson from '@/components/element/assetaudit/SelectAnalysisPerson'
import SelectReviewPerson from '@/components/element/assetaudit/SelectReviewPerson'
import issueInput from '@/components/element/assetaudit/issueInput'
import feedbackMaterialApi from '@/api/assetaudit/feedbackMaterial/feedbackMaterialApi'
import transferPersonSetupPageIndex from '@/pages/assetaudit/cKnowledgeBase/transferPersonSetupPage/transferPersonSetupPageIndex'
import analysisAndReviewDialog from '@/pages/assetaudit/feedbackMaterial/feedbackMaterial-analysis'
import importSuccessDialog from '@/pages/assetaudit/feedbackMaterial/importSuccessDialog'
import * as format from '@/filters/index'
import { BATCH_UPLOAD_API } from '@/constant'
import { keyWordInput, searchForm, DataTable, upDownLayout, SelectProductName, SelectDictionary, authButton, btnImport, btnBatchDownload, btnBatchUpload, SpanPlus } from 'newepoch-components'
import BasePage from '@/pages/basePage'
import mixin from '@/pages/mixin'
export default {
  extends: new BasePage(),
  mixins: [mixin],
  components: {
    issueInputCustom,
    importSuccessDialog,
    DataTable,
    searchForm,
    selectTransferPersonnel,
    upDownLayout,
    SelectProductName,
    SelectDictionary,
    authButton,
    btnImport,
    SelectAnalysisPerson,
    SelectReviewPerson,
    btnBatchDownload,
    btnBatchUpload,
    transferPersonSetupPageIndex,
    analysisAndReviewDialog,
    issueInput,
    issueInputZzs,
    SpanPlus
  },
  name: 'feedbackMaterialIndex',
  data () {
    return {
      searchFormView: true, // form是否重新渲染
      batchUploadApi: BATCH_UPLOAD_API,
      selectedRows: [],
      feedbackData: [],
      rowSpanArr: [],
      transferData: {},
      importForm: {},
      analysisAndReview: {},
      operateBtnLayout: '',
      importVisible: false,
      transferVisible: false,
      headerVisible: false,
      dialogVisible: false,
      headTitleFlag: false,
      handleFlag: true,
      menuFlag: true,
      editVisible: false,
      showSelection: true,
      formItem: {},
      componentList: [
        {
          // 产品名称
          label: this.$t('common.productName'),
          disabled: false,
          value: 'productNameId',
          placeholder: this.$t('common.pleaseSelect'),
          labelWidth: '160px',
          clearable: true,
          componentName: SelectProductName
        },
        {
          // 期数
          label: this.$t('common.periodsNum'),
          disabled: false,
          value: 'issue',
          placeholder: this.$t('common.pleaseInputNum'),
          labelWidth: '160px',
          clearable: true,
          componentName: issueInputZzs
        },
        {
          // 付款确认书编号
          label: this.$t('common.payCode'),
          disabled: false,
          value: 'payCode',
          maxlength: 64,
          minlength: 0,
          placeholder: this.$t('common.pleaseInput'),
          labelWidth: '160px',
          clearable: true,
          componentName: issueInputCustom
        },
        {
          // 分析人员
          label: this.$t('feedbackMaterialIndex.analyst'),
          disabled: false,
          value: 'analysisPersonId',
          placeholder: this.$t('common.pleaseSelect'),
          labelWidth: '160px',
          clearable: true,
          componentName: SelectAnalysisPerson
        },
        {
          // 分析状态
          label: this.$t('feedbackMaterialIndex.analysisState'),
          disabled: false,
          value: 'analysisStatus',
          placeholder: this.$t('common.pleaseSelect'),
          labelWidth: '160px',
          clearable: true,
          store: this.$store,
          componentName: 'SelectDictionary',
          dictTypeCode: 'ANALYSIS_STATE'
        },
        {
          // 关键词
          label: this.$t('feedbackMaterialIndex.keyword'),
          disabled: false,
          value: 'keyWord',
          placeholder: this.$t('common.pleaseInput'),
          labelWidth: '160px',
          clearable: true,
          maxlength: 255,
          minlength: 0,
          componentName: keyWordInput,
          attrs: {
            toolTip: this.$t('feedbackMaterialIndex.keywordTop')
          }
        },
        {
          // 复核人员（有重复数据）
          label: this.$t('feedbackMaterialIndex.reviewer'),
          disabled: false,
          value: 'reviewPersonId',
          placeholder: this.$t('common.pleaseSelect'),
          labelWidth: '160px',
          clearable: true,
          componentName: SelectReviewPerson
        },
        {
          // 复核状态
          label: this.$t('feedbackMaterialIndex.reviewStatus'),
          disabled: false,
          value: 'reviewStatus',
          placeholder: this.$t('common.pleaseSelect'),
          labelWidth: '160px',
          clearable: true,
          store: this.$store,
          componentName: 'SelectDictionary',
          dictTypeCode: 'REVIEW_STATUS'
        }
      ],
      columns: [
        {
          // 素材编号
          prop: 'materialNo',
          align: 'left',
          width: '80px',
          label: this.$t('feedbackMaterialIndex.materialNo')
        },
        {
          // 产品类型
          prop: 'businessType',
          align: 'left',
          width: '100px',
          label: this.$t('feedbackMaterialIndex.businessType'),
          format: (row) => {
            // return format.formatDict(row.businessType, 'BUSINESS_TYPE') // 原代码
            return format.formatDict(row.businessType, 'ZD0087')
          }
        },
        {
          // 素材来源
          prop: 'materialSourceType',
          align: 'left',
          width: '100px',
          label: this.$t('feedbackMaterialIndex.materialSourceType'),
          format: (row) => {
            return format.formatDict(row.materialSourceType, 'FEEDBACK_SOURCE')
          }
        },
        {
          // 付款确认书编号
          prop: 'payCode',
          align: 'center',
          width: '250px',
          label: this.$t('feedbackMaterialIndex.payCode')
        },
        {
          // 产品名称
          prop: 'productName',
          align: 'left',
          width: '200px',
          label: this.$t('feedbackMaterialIndex.productName')
        },
        {
          // 期数
          prop: 'issue',
          align: 'right',
          width: '50px',
          label: this.$t('feedbackMaterialIndex.issue'),
          format (row) {
            if (row.issue === 0) {
              return ''
            } else {
              return row.issue
            }
          }
        },
        {
          // 第三方机构反馈意见
          prop: 'institutionOpinions',
          align: 'left',
          width: '250px',
          label: this.$t('feedbackMaterialIndex.institutionOpinions'),
          slot: true
        },
        {
          // 合规反馈
          prop: 'hgOpinions',
          align: 'left',
          width: '250px',
          label: this.$t('feedbackMaterialIndex.hgOpinions'),
          columnMenusFlag: false,
          slot: true
        },
        {
          // 解决方式编号
          prop: 'solutionCode',
          align: 'center',
          width: '160px',
          label: this.$t('feedbackMaterialIndex.solutionNo'),
          // columnMenusFlag: false,
          format (row) {
            return hgCommon.DtoValue(row, 'solutionCode')
          }
        },
        {
          // 文件类别
          prop: 'fileType',
          align: 'center',
          width: '130px',
          label: this.$t('feedbackMaterialIndex.fileType'),
          columnMenusFlag: false,
          format: (row) => {
            return hgCommon.DtOdictionary(row, 'fileType', 'HG_FILE_TYPE')
          }
        },
        {
          // 文件名称
          prop: 'fileName',
          align: 'left',
          width: '200px',
          label: this.$t('feedbackMaterialIndex.fileName'),
          columnMenusFlag: false,
          slot: true
        },
        {
          // 问题类型
          prop: 'problemType',
          align: 'left',
          width: '130px',
          label: this.$t('feedbackMaterialIndex.problemType'),
          columnMenusFlag: false,
          slot: true
        },
        {
          // 问题点
          prop: 'problemPoint',
          align: 'left',
          width: '200px',
          label: this.$t('feedbackMaterialIndex.problemPoint'),
          columnMenusFlag: false,
          slot: true
        },
        {
          // 解决方式
          prop: 'solution',
          align: 'left',
          width: '200px',
          label: this.$t('feedbackMaterialIndex.solution'),
          columnMenusFlag: false,
          slot: true
        },
        {
          // 适用产品
          prop: 'applicableProject',
          align: 'left',
          width: '200px',
          label: this.$t('feedbackMaterialIndex.applicableProject'),
          columnMenusFlag: false,
          format (row) {
            return hgCommon.DtoValue(row, 'applicableProject')
          }
        },
        {
          // 分析状态
          prop: 'analysisStatus',
          align: 'center',
          width: '130px',
          label: this.$t('feedbackMaterialIndex.analysisStatus'),
          format: (row) => {
            return format.formatDict(row.analysisStatus, 'ANALYSIS_STATE')
          }
        },
        {
          // 分析时间
          prop: 'analysisTime',
          align: 'center',
          width: '180px',
          label: this.$t('feedbackMaterialIndex.analysisTime'),
          format: (row) => {
            return format.formatCheckDatetime(row.analysisTime)
          }
        },
        {
          // 分析人员
          prop: 'analysisPersonName',
          align: 'left',
          width: '130px',
          label: this.$t('feedbackMaterialIndex.analysisPersonName')
        },
        {
          // 复核状态
          prop: 'reviewStatus',
          align: 'center',
          width: '130px',
          label: this.$t('feedbackMaterialIndex.reviewStatus'),
          format: (row) => {
            return format.formatDict(row.reviewStatus, 'REVIEW_STATUS')
          }
        },
        {
          // 复核时间
          prop: 'reviewTime',
          align: 'center',
          width: '180px',
          label: this.$t('feedbackMaterialIndex.reviewTime'),
          format: (row) => {
            return format.formatCheckDatetime(row.reviewTime)
          }
        },
        {
          // 复核人员
          prop: 'reviewPersonName',
          align: 'left',
          width: '130px',
          label: this.$t('feedbackMaterialIndex.reviewPersonName')
        },
        {
          // 维护方式
          prop: 'maintenanceWayType',
          align: 'center',
          width: '130px',
          label: this.$t('feedbackMaterialIndex.maintenanceWayType'),
          format: (row) => {
            return format.formatDict(row.maintenanceWayType, 'MAINTAIN_TYPE')
          }
        }
      ]
    }
  },
  mounted () {
    this.handleFilter()
  },
  computed: {
    ...mapGetters(['nikeName', 'userId']),
    api () {
      return feedbackMaterialApi.feedbackmaterial
    },
    transApi () {
      return feedbackMaterialApi.changeBatch
    },
    feedbackmateriaiImportApi () {
      return feedbackMaterialApi.feedbackmateriaiImport
    }
  },
  watch: {
    // 监听新增、修改窗口，重现渲染form表单，获取最新下拉数据
    showDetail (val) {
      if (val === false) {
        setTimeout(() => { // 延迟，留给dom渲染时间
          this.searchFormView = true
        }, 100)
      }
    },
    // 导入成功
    importVisible (val) {
      if (val === false) {
        this.handleFilter()
      }
    }
  },
  methods: {
    // 绑定对应的value值（row，对应字段）（防止属性引入报错）
    getHgCommon (row, value) {
      return hgCommon.DtoValue(row, value)
    },
    // 解决方式过滤
    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()
    },
    // 保存成功后，回到一览界面查询
    onSave (val) {
      if (val === 'success') {
        this.handleFilter()
      }
    },
    // 分析权限
    analysisShow (row) {
      // 未分析
      if (row.analysisStatus === '0') {
        // 未转交 materialRygxExtDtoList
        if (!row.materialRygxExtDtoList || row.materialRygxExtDtoList.length <= 0) {
          return this.userId === row.dockPersonId
        } else {
          // let canAnalysis = false
          // 获取分析转交人
          let fxzjrs = row.materialRygxExtDtoList.filter(res => res.personType === '09')
          // 如果分析转交人存在
          if (fxzjrs && fxzjrs.length > 0) {
            // 获取未办理的人
            let wblrys = fxzjrs.filter(res => res.handlePersonId === this.userId)
            if (wblrys && wblrys.length > 0) {
              let wblry = wblrys.filter(res => res.handleStatus === '1')
              if (wblry && wblry.length > 0) {
                return true
              } else {
                return false
              }
            } else {
              return false
            }
          } else {
            return false
          }
        }
      } else {
        return false
      }
      // if (row.analysisStatus === '0' && row.reviewStatus === '0') {
      //   if (this.userId === row.dockPersonId) {
      //     return true
      //   }
      //   if (!row.materialRygxExtDTOList) {
      //     return false
      //   }
      //   let isType = row.materialRygxExtDTOList.filter(res => res.personType === '09')
      //   if (isType.length > 0) {
      //     let isPersonId = isType.filter(res => res.handlePersonId === this.userId)
      //     if (isPersonId.length > 0) {
      //       let isStatus = isPersonId.find(res => res.handleStatus === '1')
      //       if (isStatus) {
      //         return true
      //       } else {
      //         return false
      //       }
      //     } else {
      //       return false
      //     }
      //   } else {
      //     return false
      //   }
      // } else {
      //   return false
      // }
    },
    // 复核权限
    reviewShow (row) {
      if (row.analysisStatus === '1' && row.reviewStatus === '0') {
        if (row.materialRygxExtDtoList && row.materialRygxExtDtoList.length > 0) {
          // 被转交人不为空
          let fzrzj = row.materialRygxExtDtoList.filter(res => res.personType === '07')
          if (fzrzj && fzrzj.length > 0) {
            // 获取未办理的人
            let wblrys = fzrzj.filter(res => res.handlePersonId === this.userId)
            if (wblrys && wblrys.length > 0) {
              let wblry = wblrys.filter(res => res.handleStatus === '1')
              if (wblry && wblry.length > 0) {
                return true
              } else {
                return false
              }
            } else {
              return false
            }
          } else {
            // 未被转交
            if (row.leader === '1') {
              return true
            } else {
              return false
            }
          }
        } else {
          // 未被转交
          if (row.leader === '1') {
            return true
          } else {
            return false
          }
        }
      }
    },
    // 编辑权限
    editShow (row) {
      if (row.analysisStatus === '0' && row.reviewStatus === '0') {
        let cond1 = () => { // userId = 添加人 或 合规对接人id
          if (this.userId === row.addUserId || this.userId === row.dockPersonId) {
            return true
          }
        }
        let cond2 = () => {
          let scry = row.materialRygxExtDtoList
          if (scry && scry.length > 0) { // 素材人员扩展表.person_type = 09 && userId = handlePersonId && handle_status = 1
            if (scry.find(res => (res.personType === '09' && this.userId === res.handlePersonId && res.handleStatus === '1'))) {
              return true
            }
          }
        }
        if (cond1() || cond2()) {
          return true
        } else {
          return false
        }
      } else {
        return false
      }
    },
    // 删除权限
    delShow (row) {
      // if (row.analysisStatus === '0' && row.reviewStatus === '0') { // 素材未分析、未复核
      if (row.reviewStatus === '0') { // 素材未复核可以删除（修改规则）
        // if (row.addUserId === this.userId) {
        //   return true
        // }
        // if (this.userId === row.addUserId || this.userId === row.dockPersonId) {
        //   return true
        // }
        // if (!row.materialRygxExtDTOList) {
        //   return false
        // }
        // let ExtDTOList = row.materialRygxExtDTOList
        // let isType = ExtDTOList.filter(res => (res.personType === '09' || res.personType === '07'))
        // if (isType.length > 0) {
        //   let isPersonId = isType.filter(res => res.handlePersonId === this.userId)
        //   if (isPersonId.length > 0) {
        //     let isStatus = isPersonId.find(res => res.handleStatus === '1')
        //     if (isStatus) {
        //       return true
        //     } else {
        //       return false
        //     }
        //   } else {
        //     return false
        //   }
        // }
        // if (row.analysisSubmitterPersonId && row.analysisSubmitterPersonId === this.userId) {
        //   return true
        // } else {
        //   return false
        // }
        let cond1 = () => { // userId = 添加人 或 合规对接人id
          if (this.userId === row.addUserId || this.userId === row.dockPersonId) {
            return true
          } else {
            return false
          }
        }
        let cond2 = () => { // 素材人员扩展表.person_type = 09 或 07 && userId = handlePersonId  && handle_status =1
          if (row.materialRygxExtDtoList && row.materialRygxExtDtoList.find(res => ((res.personType === '09' || res.personType === '07') && this.userId === res.handlePersonId && res.handleStatus === '1'))) {
            return true
          } else {
            return false
          }
        }
        let cond3 = () => { // 分析转交人员id != null && userId = 分析转交人员id
          if (row.analysisSubmitterPersonId && this.userId === row.analysisSubmitterPersonId) {
            return true
          } else {
            return false
          }
        }
        if (cond1() || cond2() || cond3()) {
          return true
        } else {
          return false
        }
      } else {
        return false
      }
    },
    // 批量转交按钮数据确认
    batchTransferShow (data) {
      // if (data.length === 0) {
      //   this.$message.warning('请先勾选要转交的数据')
      //   return false
      // }
      let listData = data.filter(res => (this.reviewShow(res) || this.analysisShow(res)))
      if (data.length !== listData.length) {
        this.$message.warning(this.$t('feedbackMaterialIndex.otherData'))
        return false
      }
      let diff = listData.find(res => {
        return listData.some(item => res.analysisStatus !== item.analysisStatus)
      })
      if (diff) {
        this.$message.warning(this.$t('feedbackMaterialIndex.differentFormat'))
        return false
      } else {
        return true
      }
    },
    // 查看
    viewShowEdit (index, row, editModel) {
      if (row.analysisStatus === '0') { // 未分析跳转到反馈素材查看界面
        this.showEdit(index, row, editModel)
      } else {
        this.analysisAndReviewEdit(row, editModel) // 已分析跳转到反馈素材分析与复核界面
      }
    },
    // 操作事件
    operateBtnClick (returnData) {
      if (returnData) {
        this.$refs.feedDataTable.loadTableData() // 查询table数据
      }
    },
    // 数据初始化完成事件
    getTableData () {
      this.getRowSpanKeyId()
      this.getRowSpan()
    },
    // 判断文件类型
    fileType (type) {
      return ['png', 'xt'].indexOf(type.toLowerCase())
    },
    // 数据导入
    uploadSuccess (returnData) {
      let index
      let ext
      let temp
      let fileJudge = returnData.fileList.every(res => {
        if (res.relativelyPath.indexOf('附件') === -1) {
          index = res.relativelyPath.lastIndexOf('.')
          ext = res.relativelyPath.substr(index + 1)
          if (ext !== 'xlsx') {
            temp = false
          } else {
            temp = true
          }
        } else {
          index = res.relativelyPath.lastIndexOf('.')
          ext = res.relativelyPath.substr(index + 1)
          let banFileTypes = ['exe', 'bat', 'cmd', 'sh', 'py', 'vbs', 'js']
          if (banFileTypes.indexOf(ext) !== -1) {
            temp = false
          } else {
            temp = true
          }
        }
        return temp
      })
      if (!fileJudge) { // 导入文件格式不对提示
        this.warning(this.$t('feedbackMaterialIndex.fileFormatWrong'))
        return
      }
      let param = []
      returnData.fileList.forEach(res => {
        param.push({
          fileName: res.fileName,
          keyId: res.keyId,
          relativelyPath: res.relativelyPath
        })
      })
      // 导入
      this.feedbackmateriaiImportApi.create(param).then(res => {
        if (res.data) {
          this.importForm = res.data
          this.importForm.failNumber = res.data.importNumber - res.data.successfulNumber
          this.importVisible = true
        } else {
          this.error('导入失败')
        }
      })
    },
    // 表格数据行选择
    selectRowChange (selectedRows) {
      this.selectedRows = selectedRows
    },
    // 删除
    del (row) {
      this.selectedRows = []
      this.selectedRows.push(row)
      this.batchDel()
    },
    // 分析、复核按钮
    analysisAndReviewEdit (row, editModel, state) {
      this.commitStatus = state
      this.editModel = editModel
      this.analysisAndReview = row
      this.dialogVisible = true
    },
    handleClick () {
      this.editVisible = true
    },
    // 导入素材按钮按下，批量文件上传
    FileBatchDown (row) {
      let arr = []
      row.accessoryExtDtoList.forEach(res => {
        arr.push(res.fileId)
      })
      return arr
    },
    // 批量删除
    mybatchDel () {
      if (this.selectedRows.length > 0) {
        if (this.selectedRows.find(res => (!this.delShow(res)))) { // 判断选中数据中是否存在不能删除的数据
          this.warning(this.$t('feedbackMaterialIndex.cantDeleteData'))
          return
        }
        this.selectedRows.every(res => {
          if (!this.delShow(res)) {
            this.warning(this.$t('feedbackMaterialIndex.cantDeleteData'))
            return false
          }
          this.batchDel()
        })
      } else {
        this.batchDel()
      }
    },
    // 批量转交
    myBatchTransfer () {
      this.transferData = {}
      if (this.selectedRows.length === 0) {
        this.warning(this.$t('feedbackMaterialIndex.selectDataAll'))
        return
      }
      if (this.batchTransferShow(this.selectedRows)) {
        this.batchTransfer(this.selectedRows)
      }
    },
    // 批量转交操作
    batchTransfer () {
      let arr = this.selectedRows.map(it => {
        return it.keyId
      })
      let str = this.selectedRows[0].analysisStatus === '0' ? '01' : '02' // 判断是否分析
      this.transferData.projectLeaderId = this.userId
      this.transferData.projectLeaderName = this.nikeName
      this.transferData.status = str
      this.transferData.keyIdList = arr
      this.transferVisible = true
    },
    // 单条转交数据操作
    transfer (row) {
      this.transferData = {}
      let arr = []
      arr.push(row.keyId)
      // let str = '0' + ((Number(row.analysisStatus) & Number(row.reviewStatus)) + 1)
      let status = row.analysisStatus === '0' ? '01' : '02' // 判断是否分析
      this.transferData.projectLeaderId = this.userId
      this.transferData.projectLeaderName = this.nikeName
      this.transferData.status = status
      this.transferData.keyIdList = arr
      this.transferVisible = true
    },
    // 素材keyId 相同合并
    getRowSpanKeyId () {
      let rowSpanArrSc = []
      let position = ''
      this.feedbackData.forEach((item, index) => {
        if (index === 0) {
          rowSpanArrSc.push(1)
          position = 0
        } else {
          if (this.feedbackData[index].keyId === this.feedbackData[index - 1].keyId) {
            rowSpanArrSc[position] += 1
            rowSpanArrSc.push(0)
            this.feedbackData[index].keyId = this.feedbackData[index - 1].keyId
          } else {
            rowSpanArrSc.push(1)
            position = index
          }
        }
      })
      return rowSpanArrSc
    },
    // 素材来源和付款确认书相同合并
    getRowSpan () {
      let rowSpanArr = []
      this.feedbackData.forEach((item, index) => {
        if (index === 0) {
          rowSpanArr.push(1)
          this.position = 0
        } else {
          if (this.feedbackData[index].payCode === this.feedbackData[index - 1].payCode && this.feedbackData[index].materialSourceType === this.feedbackData[index - 1].materialSourceType) {
            rowSpanArr[this.position] += 1
            rowSpanArr.push(0)
            this.feedbackData[index].payCode = this.feedbackData[index - 1].payCode
            this.feedbackData[index].materialSourceType = this.feedbackData[index - 1].materialSourceType
          } else {
            rowSpanArr.push(1)
            this.position = index
          }
        }
      })
      return rowSpanArr
    },
    // 产品类型状态不一致时不合并
    businessTypeRow () {
      let rowSpanArr = []
      this.feedbackData.forEach((item, index) => {
        if (index === 0) {
          rowSpanArr.push(1)
          this.position = 0
        } else {
          let reviewJu = false // 判断复核状态是否相同（无需复核和已复核是一类）
          if (this.feedbackData[index].reviewStatus === '0' && this.feedbackData[index - 1].reviewStatus === '0') {
            reviewJu = true
          } else if (this.feedbackData[index].reviewStatus !== '0' && this.feedbackData[index - 1].reviewStatus !== '0') {
            reviewJu = true
          }
          if (this.feedbackData[index].payCode === this.feedbackData[index - 1].payCode && this.feedbackData[index].materialSourceType === this.feedbackData[index - 1].materialSourceType && this.feedbackData[index].analysisStatus === this.feedbackData[index - 1].analysisStatus && reviewJu) {
            rowSpanArr[this.position] += 1
            rowSpanArr.push(0)
            this.feedbackData[index].payCode = this.feedbackData[index - 1].payCode
            this.feedbackData[index].materialSourceType = this.feedbackData[index - 1].materialSourceType
          } else {
            rowSpanArr.push(1)
            this.position = index
          }
        }
      })
      return rowSpanArr
    },
    // 行合并（当前行row、当前列column、当前行号rowIndex、当前列号columnIndex）
    objectSpanMethod ({ row, column, rowIndex, columnIndex }) {
      /**
       * 1.keyid相同合并：
       * 素材编号、产品类型、素材来源、付款确认书编号、产品名称、期数、第三方机构意见、合规意见、分析状态、分析时间、分析人员、复核状态、复核时间、复核人员、维护方式、相关文件、操作
       * 2.素材来源、付款确认书编号相同：
       * 素材编号、产品类型、素材来源、付款确认书编号、产品名称、期数
      */
      let _row
      if (column.type === 'selection' || column.property === 'materialNo' || column.property === 'institutionOpinions' || column.property === 'hgOpinions' || column.property === 'analysisStatus' || column.property === 'analysisTime' || column.property === 'analysisPersonName' || column.property === 'reviewStatus' || column.property === 'reviewTime' || column.property === 'reviewPersonName' || column.property === 'maintenanceWayType' || column.fixed === 'right') {
        _row = this.getRowSpanKeyId()[rowIndex]
        return {
          rowspan: _row, // 行
          colspan: 1 // 列
        }
      } else if (column.property === 'businessType' || column.property === 'materialSourceType' || column.property === 'payCode' || column.property === 'productName' || column.property === 'issue') { // 状态不一致时不合并
        _row = this.businessTypeRow()[rowIndex]
        return {
          rowspan: _row, // 行
          colspan: 1 // 列
        }
      }
      // else if (column.property === 'businessType') { // 产品类型状态不一致时不合并
      //   _row = this.businessTypeRow()[rowIndex]
      //   return {
      //     rowspan: _row, // 行
      //     colspan: 1 // 列
      //   }
      // }
    }
  }
}
</script>
