<!-- 确权文件反馈 -->
<template>
<div>
    <up-down-layout :handleFlag.sync="handleFlag">
      <!-- 搜索栏 -->
      <search-form ref="search" slot="query" :formValue.sync="queryParas" searchPerms="search" resetPerms="reset" :componentList="componentList" @handleFilter="search" @clearParam="clearParam" @selectChanged="selectChanged"></search-form>
      <!-- 表格列表 -->
      <template slot="table">
          <data-table ref="dataTable" v-bind="attrs" :queryParas="queryParas" :menuFlag="true" :columns="columns" :sourceData.sync="sourceData" @sizeChange="handleFilter" @currentChange="handleFilter">
            <!-- 操作工具栏 -->
          <template slot="headButton">
            <div align="right">
              <!-- 批量下载资料 -->
              <auth-button class="iconfont iconxiazai1" :size="'medium'" :label="$t('feedBackMain.batchDownload')" type="primary" @click="openDialog(0)"></auth-button>
              <!-- 批量导入反馈 -->
              <btn-upload fileType=".xlsx,.xls" :uploadApi="uploadApi" type="primary" icon="iconfont icondaoru" :btnSize="'medium'" :uploadName="$t('feedBackMain.batchImportFeedback')" @uploadSuccess="importAsset" style="margin-left:10px"></btn-upload>
              <!-- <auth-button :disabled="feedbackEndFlag == '2'" class="iconfont icondaoru" :size="'medium'" :label="$t('feedBackMain.batchImportFeedback')" type="primary" @click="handleImport"></auth-button> -->
              <!-- 批量反馈 -->
              <!-- <auth-button :disabled="feedbackEndFlag == '2'" class="iconfont iconziliaoshenhe" :size="'medium'" :label="$t('feedBackMain.batchFeedback')" type="primary" @click="openDialog(2)"></auth-button> -->
              <!-- 批量处理 -->
              <auth-button :disabled="feedbackEndFlag == '2'" class="iconfont iconchuli" :size="'medium'" :label="$t('feedBackMain.batchOperate')" type="primary" @click="openDialog(3)"></auth-button>
              <!-- 反馈结束/继续反馈 -->
              <auth-button :loading="loading" :class="{iconfont:true,iconstart:feedbackEndFlag === '2',iconjieshu:feedbackEndFlag !== '2',}" :size="'medium'" :label="feedbackEndFlag == '2' ? $t('feedBackMain.continueFeedback') : $t('feedBackMain.endFeedback')" type="primary" :disabled="feedbackEndFlag == '0' || !queryParas.projectId || !queryParas.periods" @click="handleFeedback"></auth-button>
            </div>
          </template>
          <!-- 产品名称 -->
          <template #projectName="scope">
             <span-plus :index="scope.data.$index"
                           :text="scope.data.row.projectName"></span-plus>
          </template>
          <!-- 付款确认书编号 -->
          <template #assetCode="scope">
             <span-plus :index="scope.data.$index"
                           :text="scope.data.row.assetCode"></span-plus>
          </template>
          <!-- 供应商名称 -->
          <template #creditor="scope">
             <span-plus :index="scope.data.$index"
                           :text="scope.data.row.creditor"></span-plus>
          </template>
          <!-- 项目公司名称 -->
          <template #debtor="scope">
             <span-plus :index="scope.data.$index"
                           :text="scope.data.row.debtor"></span-plus>
          </template>
          <!-- 保理进度 -->
          <template #assetStatus="scope">
            <!-- 保理进度为退单时，字体呈红色 -->
            <div :class="{redBtn:scope.data.row.backStatus == '1'}">
              {{scope.data.row.backStatus == '1' ? $t('feedBackMain.backOrder') : (!scope.data.row.assetStatus || formatDict(scope.data.row.assetStatus,'SCRS0110') === scope.data.row.assetStatus ? '/' : formatDict(scope.data.row.assetStatus,'SCRS0110'))}}
            </div>
          </template>
          <!-- 问题处理情况 -->
          <template #problemHandling="scope">
            <expand-collapse v-if="scope.data.row.preAssetFlag != '2'" :sourceData="sourceData"
                                 colProp="problemHandling"
                                 valueProp="name"
                                 :rowIndex="scope.data.$index"></expand-collapse>
          </template>
          <!-- 审核结果 -->
          <template #extOrgAuditResult="scope">
            <!-- 抽中状态不是斜杠且未退单的才显示 -->
            <el-radio-group :disabled="scope.data.row.feedbackEndFlag == '2'" v-if="scope.data.row.extOrgAuditResult && (scope.data.row.preAssetFlag != '2' && ((scope.data.row.pointSampleFlag === '1' || scope.data.row.pointSampleFlag === '2') && scope.data.row.backStatus !== '1'))" v-model="scope.data.row.extOrgAuditResult" @change="e => auditFeedback(e,scope.data.row)">
              <div>
                <el-radio :label="(scope.data.row.extOrgAuditResult !== '3' && scope.data.row.extOrgAuditResult !== '0') ? scope.data.row.extOrgAuditResult : '1'" :name="scope.$index">{{$t('feedBackMain.pass')}}</el-radio>
              </div>
              <div class="box-column-margin-top" v-if="scope.data.row.feedbackQuestionsCount > 0">
                <el-radio :disabled="scope.data.row.extOrgAuditResult == '1' || scope.data.row.extOrgAuditResult == '2'" label="3" :name="scope.$index">{{$t('feedBackMain.confirmAfterSupplement')}}</el-radio>
              </div>
            </el-radio-group>
          </template>
          <!-- 单行操作 -->
            <template #operate="scope">
              <div v-if="scope.data.row.preAssetFlag != '2'">
              <!-- 补充资料下载 -->
              <auth-button v-if="scope.data.row.backStatus !== '1' && (scope.data.row.pointSampleFlag == '1' || scope.data.row.pointSampleFlag == '2') && ((scope.data.row.extOrgOpinionStatus === '1' && scope.data.row.feedbackQuestionsCount > 0) || scope.data.row.extOrgOpinionStatus === '2' || scope.data.row.extOrgOpinionStatus === '3')" class="iconCircle" icon="iconfont iconbuchongziliaoxiazai" :title="$t('feedBackMain.supplementDonwload')" @click="handleDownload(0,scope.data.row)"></auth-button>
              <!-- 确权资料下载 -->
              <auth-button v-if="scope.data.row.backStatus !== '1' && (scope.data.row.pointSampleFlag == '1' || scope.data.row.pointSampleFlag == '2') && (scope.data.row.extOrgOpinionStatus === '0' || scope.data.row.extOrgOpinionStatus === '1' || scope.data.row.extOrgOpinionStatus === '2' || scope.data.row.extOrgOpinionStatus === '3')" class="iconCircle" icon="iconfont iconquequanziliao" :title="$t('feedBackMain.confirmFileDonwload')" @click="handleDownload(1,scope.data.row)"></auth-button>
              <!-- 反馈 -->
              <auth-button :disabled="scope.data.row.feedbackEndFlag == '2'" v-if="scope.data.row.backStatus !== '1' && (((scope.data.row.extOrgOpinionStatus == '0' && scope.data.row.preAssetFlag == '1') || (scope.data.row.extOrgOpinionStatus == '1' && (!scope.data.row.feedbackQuestionsCount ||scope.data.row.feedbackQuestionsCount < 1))) && (scope.data.row.pointSampleFlag == '1' || scope.data.row.pointSampleFlag == '2'))" class="iconCircle" icon="iconfont iconfankui" :title="$t('feedBackMain.feedback')" @click="openDialog(1,scope.data.row)"></auth-button>
              <!-- 待审核 -->
              <auth-button :disabled="scope.data.row.feedbackEndFlag == '2'" v-if="scope.data.row.backStatus !== '1' && (scope.data.row.pointSampleFlag == '1' || scope.data.row.pointSampleFlag == '2') && scope.data.row.extOrgOpinionStatus === '3'" class="iconCircle" icon="iconfont icondaishenhe" :title="$t('feedBackMain.waitingAudit')" @click="openDialog(4,scope.data.row)"></auth-button>
              <!-- 待保理商处理 -->
              <auth-button :disabled="scope.data.row.feedbackEndFlag == '2'" v-if="scope.data.row.backStatus !== '1' && (scope.data.row.pointSampleFlag == '1' || scope.data.row.pointSampleFlag == '2') && scope.data.row.extOrgOpinionStatus === '2'" class="iconCircle" icon="iconfont icondaichuli" :title="$t('feedBackMain.waitingYf') " @click="openDialog(5,scope.data.row)"></auth-button>
              <!-- 查看 -->
              <auth-button :disabled="scope.data.row.feedbackEndFlag == '2'" v-if="(scope.data.row.extOrgOpinionStatus !== '0' && scope.data.row.backStatus === '1') || (scope.data.row.backStatus !== '1' && (scope.data.row.pointSampleFlag == '1' || scope.data.row.pointSampleFlag == '2') && scope.data.row.extOrgOpinionStatus === '1' && scope.data.row.feedbackQuestionsCount > 0)" class="iconCircle" icon="iconfont iconview" :title="$t('common.view')" @click="openDialog(5,scope.data.row)"></auth-button>
            </div>
            </template>
          </data-table>
      </template>
    </up-down-layout>
    <!-- 导出结果 -->
    <dialog-form :attr="{width:'500px'}" :visible.sync="isExport" editModel="E" :form="exportResult" :autoSave="false" :isExport="true" :exportAttrs="{
      total: 'total', // 总数
      fail: 'errorMsgCount', // 失败数
      success: 'successMsgCount', // 成功数
      file: 'returnFileId', // 文件Id
      ignore: 'failMsgCount' // 文件Id
    }">
    </dialog-form>
    <component :is="componentName" :visible.sync="dialogVisible" :headerTitle="componentTitle" :editModel="editModel" :form="newForm" :autoSave="autoSave" :currentRow="currentRow" :feedbackType="feedbackType"></component>
</div>
</template>
<script>
import {
  upDownLayout,
  searchForm,
  DataTable,
  amountInput,
  btnBatchDownload,
  btnDownload,
  SpanPlus,
  btnUpload,
  ExpandCollapse,
  BaseSelect,
  SelectDictionary,
  keyWordInput,
  authButton
} from 'newepoch-components'
import * as format from '@/filters/index.js'
import fileApi from '@/api/fileApi.js'
import {
  downFile
} from '@/utils/devUtils'
import outProjectSelectList from '@/components/element/assetoutfeedback/outProjectSelectList' // 产品名称
import feedBackFreqSelectList from '@/components/element/assetoutfeedback/feedBackFreqSelectList' // 反馈批次
import fileSelectList from '@/components/element/assetoutfeedback/fileSelectList' // 文件类型
import dialogForm from '@/components/element/assetoutfeedback/dialogForm'
import collapseTitle from '@/components/element/assetoutfeedback/collapseTitle'
import feedBackMain from '@/api/assetoutfeedback/feedBackMain/feedBackMain.js'
import components from '@/api/assetoutfeedback/componentsApi.js'
import BasePage from '@/pages/basePage'
import mixin from '@/pages/mixin'
import { UPLOAD_API } from '@/constant.js'

export default {
  extends: new BasePage(),
  name: 'confirmFeedBackMain',
  mixins: [mixin],
  components: {
    searchForm,
    upDownLayout,
    authButton,
    dialogForm,
    DataTable,
    btnBatchDownload,
    SpanPlus,
    ExpandCollapse,
    SelectDictionary,
    btnUpload,
    btnDownload,
    collapseTitle
  },
  data () {
    let $this = this
    return {
      uploadApi: UPLOAD_API,
      dialogVisible: false, // 组件显隐控件
      componentType: 0, // 组件类型
      autoSave: false, // 是否自动保存
      feedbackType: '2', // 反馈类型
      feedbackEndFlag: '0', // 反馈状态
      loading: false, // 表格加载控件
      currentRow: {}, // 选中行
      isExport: false, // 导出控件
      exportResult: {}, // 导出结果
      modifyTime: '',
      // 表格列表
      sourceData: [],
      // 表格头部
      columns: [

        {
          // 抽中状态
          prop: 'pointSampleFlag',
          align: 'center',
          width: '100px',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.pointSampleFlag,
          format: row => {
            let pointSampleFlag = ['0', this.$t('feedBackMain.SampleFlagNo'), this.$t('feedBackMain.SampleFlag')][row.pointSampleFlag]
            return row.pointSampleFlag === pointSampleFlag ? '/' : pointSampleFlag
          }
        },
        {
          // 意见状态
          prop: 'extOrgOpinionStatus',
          width: '100px',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.extOrgOpinionStatus,
          format: row => {
            let extOrgOpinionStatus = format.formatDict(row.extOrgOpinionStatus, 'AUDIT_OUT_OPINION_STATUS')
            return row.extOrgOpinionStatus === extOrgOpinionStatus ? '/' : extOrgOpinionStatus
          }
        },
        {
          // 文件类型
          prop: 'auditFileType',
          width: '230px',
          headerAlign: 'center',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.auditFileType,
          format (row) {
            let auditFileType = $this.$refs.search.$refs.auditFileType.options.filter(item => {
              return row.auditFileType === item.fileType
            })
            // })
            return auditFileType.length > 0 ? auditFileType[0].fileName : ''
          }
        },
        {
          // 产品名称
          prop: 'projectName',
          width: '300px',
          slot: true,
          headerAlign: 'center',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.projectName
        },
        {
          // 期数
          prop: 'periods',
          headerAlign: 'center',
          width: '100px',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.periods
        },
        {
          // 反馈批次
          prop: 'feedbackFrequency',
          headerAlign: 'center',
          columnMenusFlag: false,
          width: '100px',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.feedbackFrequency,
          format: row => {
            return row.feedbackFrequency === '0' ? '' : row.feedbackFrequency
          }
        },
        {
          // 付款确认书编号
          prop: 'assetCode',
          slot: true,
          // showOverflowTooltip: true,
          width: '300px',
          headerAlign: 'center',
          maxlength: '50',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.assetCode
        },
        {
          // 供应商名称
          prop: 'creditor',
          width: '300px',
          slot: true,
          headerAlign: 'center',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.creditor
        },
        {
          // 项目公司名称
          prop: 'debtor',
          width: '300px',
          slot: true,
          headerAlign: 'center',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.debtor
        },
        {
          // 保理金额
          prop: 'factoringMoney',
          columnMenusFlag: false,
          width: '180px',
          headerAlign: 'center',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.accountsReceivable,
          format: row => {
            return format.thousandFilter(row.factoringMoney)
          }
        },
        {
          // 应收账款到期日
          prop: 'dueDate',
          columnMenusFlag: false,
          align: 'center',
          width: '171px',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.accountsReceivableEndTime
        },
        {
          // 是否关联企业
          prop: 'ifsConnectCompany',
          width: '120px',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.ifsConnectCompany,
          format (row) {
            return row.ifsConnectCompany === '1'
              ? $this.$t('common.yes')
              : $this.$t('common.no')
          }
        },
        {
          // 正确合同类型
          prop: 'contractType',
          columnMenusFlag: false,
          width: '150px',
          headerAlign: 'center',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.contractType,
          format: (row) => {
            return format.formatDict(row.contractType, 'ZD0107')
          }
        },
        {
          // 拟入池清单合同类型
          prop: 'nrcContractType',
          columnMenusFlag: false,
          width: '150px',
          headerAlign: 'center',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.nrcContractType,
          format: (row) => {
            return format.formatDict(row.nrcContractType, 'ZD0107')
          }
        },
        {
          // 大区域
          prop: 'bigAreaName',
          columnMenusFlag: false,
          width: '150px',
          headerAlign: 'center',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.fourArea
        },
        {
          // 小区域
          prop: 'coreAreaAttacheName',
          columnMenusFlag: false,
          width: '150px',
          headerAlign: 'center',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.area
        },
        {
          // 保理进度
          prop: 'assetStatus',
          width: '200px',
          align: 'center',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.absState
        },
        // {
        //   // 保理商审核记录
        //   prop: 'reviewRecord',
        //   columnMenusFlag: false,
        //   width: '180px',
        //   headerAlign: 'center',
        //   slot: true,
        //   label: this.$i18n.messages[this.$i18n.locale].feedBackMain.reviewRecord
        // },
        {
          // 反馈问题总数
          prop: 'feedbackQuestionsCount',
          headerAlign: 'center',
          width: '120px',
          align: 'right',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.feedbackQuestionsCount
        },
        {
          // 问题处理情况
          prop: 'problemHandling',
          slot: true,
          width: '150px',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.problemHandling
        },
        {
          // 外部机构审核结果
          prop: 'extOrgAuditResult',
          headerAlign: 'center',
          slot: true,
          width: '150px',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.extOrgQustionResult
        },
        {
          // 操作
          prop: 'operate',
          align: 'center',
          slot: true,
          fixed: 'right',
          width: '250px',
          label: this.$i18n.messages[this.$i18n.locale].common.operate
        }
      ],
      // 表单
      queryParas: Object.assign({
        pageIndex: 1,
        pageSize: 10
      }, this.form),
      // 表单列表
      componentList: [
        {
          // 产品名称
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.projectName,
          disabled: false,
          value: 'projectId',
          prop: 'projectId',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: '115px',
          clearable: true,
          componentName: outProjectSelectList
        },
        {
          // 期数
          label: this.$i18n.messages[this.$i18n.locale].common.periodsNum,
          disabled: false,
          value: 'periods',
          prop: 'periods',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          labelWidth: '115px',
          maxlength: 3,
          clearable: true,
          componentName: amountInput
        },
        {
          // 文件类型
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.auditFileType,
          disabled: false,
          value: 'auditFileType',
          prop: 'auditFileType',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: '115px',
          filterable: true,
          clearable: true,
          attrs: {
            fileQueryType: 2,
            stampWay: 3,
            ref: 'auditFileType'
          },
          componentName: fileSelectList
        },
        {
          // 反馈批次
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.feedbackFrequency,
          disabled: false,
          value: 'feedbackFrequency',
          prop: 'feedbackFrequency',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: '115px',
          clearable: true,
          queryName: ['projectId', 'periods', 'auditFileType'],
          queryValue: ['projectId', 'periods', 'auditFileType'],
          componentName: feedBackFreqSelectList
        },
        {
          // 抽中状态
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.pointSampleFlag,
          disabled: false,
          value: 'pointSampleFlag',
          prop: 'pointSampleFlag',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: '115px',
          clearable: true,
          options: [
            {
              id: '1',
              name: this.$t('feedBackMain.SampleFlagNo')
            },
            {
              id: '2',
              name: this.$t('feedBackMain.SampleFlag')
            }
          ],
          componentName: BaseSelect
        },
        {
          // 意见状态
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.extOrgOpinionStatus,
          disabled: false,
          value: 'extOrgOpinionStatus',
          prop: 'extOrgOpinionStatus',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: '115px',
          clearable: true,
          dictTypeCode: 'AUDIT_OUT_OPINION_STATUS',
          componentName: SelectDictionary
        },
        {
          // 付款确认书编号
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.assetCode,
          disabled: false,
          value: 'assetCode',
          prop: 'assetCode',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          labelWidth: '115px',
          clearable: true,
          componentName: 'el-input'
        },
        {
          // 关键词搜索
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.keyWord,
          disabled: false,
          value: 'keyWord',
          prop: 'keyWord',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          labelWidth: '115px',
          clearable: true,
          attrs: {
            toolTip: this.$i18n.messages[this.$i18n.locale].feedBackMain.searchToolTip
          },
          componentName: keyWordInput
        },
        {
          // 是否关联企业
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.ifsConnectCompany,
          disabled: false,
          value: 'ifsConnectCompany',
          prop: 'ifsConnectCompany',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: '115px',
          clearable: true,
          options: [
            {
              id: '0',
              name: this.$t('common.no')
            },
            {
              id: '1',
              name: this.$t('common.yes')
            }
          ],
          componentName: BaseSelect
        },
        {
          // 保理进度
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.absState,
          disabled: false,
          value: 'assetStatus',
          prop: 'assetStatus',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: '115px',
          clearable: true,
          dictTypeCode: 'SCRS0110',
          componentName: SelectDictionary
        }
      ],
      // 当前产品名称
      projectName: ''
    }
  },
  props: {
    // 外传搜索表单
    form: {
      type: Object,
      default () {
        return null
      }
    }
  },
  mounted () {
    this.handleFilter()
  },
  computed: {
    newForm () {
      return {
        projectId: this.queryParas.projectId,
        projectName: this.projectName,
        periods: this.queryParas.periods,
        auditFileType: this.queryParas.auditFileType
      }
    },
    attrs () {
      return Object.assign(this.elHeightObj, { 'row-style': this.tableRowClassName })
    },
    // api接口
    api () {
      return feedBackMain.confirmList
    },
    // 组件文件名
    componentName () {
      let type = this.componentType // 组件类型
      let name = [
        'confirmFileDownBatchPop',
        'sampleFeedBackSinglePop',
        'sampleFeedBackBatchPop',
        'sampleFileAuditBatchPop',
        'sampleFileAuditSinglePop',
        'sampleFileAuditSinglePop'
      ] // 组件列表
      // 引入组件
      return resolve => require([`@/pages/assetoutfeedback/feedBackMain/${name[type]}`], resolve)
    },
    // 组件标题
    componentTitle () {
      let type = this.componentType // 组件类型
      let name = [
        this.$t('feedBackMain.fileDownloadOne'),
        this.$t('feedBackMain.feedbackTwo'),
        this.$t('feedBackMain.batchFeedback'),
        this.$t('feedBackMain.confirmFileAuditBatchPop'),
        this.$t('feedBackMain.confirmFileAuditSinglePop'),
        this.$t('feedBackMain.confirmQustDetailPop')
      ] // 组件标题
      return name[type]
    }
  },
  watch: {
    'queryParas.projectId' (val) {
      this.feedbackEndFlag = '0'
      this.$set(this.queryParas, 'feedbackFrequency', '')
    },
    'queryParas.periods' (val) {
      this.feedbackEndFlag = '0'
      this.$set(this.queryParas, 'feedbackFrequency', '')
    }
  },
  methods: {
    ...format,
    // 批量导入反馈
    importAsset (e) {
      // console.log(e)
      feedBackMain.importBatch.postQuery({ fileId: e.fileID }).then(res => {
        if (res.success && res.data) {
          this.exportResult = res.data
          this.isExport = true
        }
      })
    },
    // 搜索
    search () {
      this.queryParas.pageIndex = 1
      this.handleFilter()
    },
    // 下拉框选择回调
    selectChanged (a) {
      if (a.productNameInfo) {
        this.projectName = a.productNameInfo.projectName
      }
    },
    // 资料下载:type:0 补充资料;1 确权文件资料
    handleDownload (type, row) {
      let api = ['rpyfileList', 'danganFile'][type]
      let func = ['getList', 'getDefault'][type]
      let name = [this.$t('feedBackMain.supplementFilesTwo  '), this.$t('feedBackMain.danganFilesTwo')][type] // 文件名
      let args = [
        {
          assetCode: row.assetCode,
          feedbackFrequency: row.feedbackFrequency,
          auditFileType: row.auditFileType
        },
        {
          assetInfoIds: [row.assetInfoId],
          fileTypes: {
            '2001': ['1', '2'],
            '2002': ['1'],
            '2003': ['2']
          }[row.auditFileType]
        }
      ][type]
      this.$confirm(this.$t('common.confirm') + this.$t('common.downLoad'), this.$t('common.tip'), {
        type: 'warning'
      }).then(() => {
        components[api][func](args).then(res => {
          if (res.success && res.data.length > 0) {
            let files = null
            if (type === 0) {
              files = { keyIds: res.data.map(item => { return item.fileId }) }
            } else {
              files = { keyIds: res.data[0].fileInfos.map(item => { return item.ossId }) }
            }
            fileApi.file.batchDownload(files).then(res => {
              downFile(res, `${name}(${row.assetCode}).zip`)
            }).catch(res => {
              this.error(res.message)
            })
          } else {
            this.warning(this.$t('feedBackMain.noFiles'))
          }
        })
      }).catch((e) => {})
    },
    // 反馈结束/继续反馈
    handleFeedback () {
      let $this = this
      // 配置参数：产品，期数，更新时间,反馈类型
      let args = {
        projectId: $this.queryParas.projectId,
        periods: $this.queryParas.periods,
        modifyTime: format.formatDatetime($this.modifyTime),
        auditFileType: $this.queryParas.auditFileType,
        operType: $this.feedbackEndFlag
      }
      if (!args.auditFileType) {
        this.warning(this.$t('feedBackMain.checkAuditFileType'))
        return false
      }
      $this.loading = true
      feedBackMain.over.putData(args).then(res => {
        $this.loading = false
        if (res.success && res.data) {
          $this.success($this.$t('feedBackMain.handleSuccess'))
          // 重置列表
          $this.handleFilter()
        } else {
          $this.error($this.$t('feedBackMain.handleError'))
        }
      }).catch(res => {
        $this.loading = false
      })
    },
    // 审核结果切换
    auditFeedback (e, row) {
      // console.log(row.examineAudit)
      // 若为合格
      if (e === '1' || e === '2') {
        let num = 0
        for (let index in row.problemHandling) {
          let item = row.problemHandling[index].id
          if (item !== '2' && item !== '1') {
            num++
          }
        }
        if (num > 0) {
          this.warning(this.$t('feedBackMain.passPropmtTwo'))
          row.extOrgAuditResult = row.examineAudit
          return false
        }
        if (row.feedbackQuestionsCount > 0) {
          this.updateResult(e, row)
        } else {
          this.$confirm(this.$t('feedBackMain.passPropmt'), this.$t('common.tip'), {
            type: 'warning'
          }).then(() => {
            this.updateResult(e, row)
          }).catch((e) => {
            row.extOrgAuditResult = row.examineAudit
          })
        }
      // 若为确认后补
      } else {
        this.updateResult(e, row)
      }
    },
    // 合格/确认后补
    updateResult (e, row) {
      let args = {
        extOrgAuditResult: e === '3' ? '2' : '1',
        keyId: row.keyId,
        modifyTime: format.formatDatetime(row.modifyTime)
      }
      this.assetpkgmgrFullScreenLoading()
      feedBackMain.later.putData(args).then(res => {
        this.assetpkgmgrFullScreenLoading().close()
        if (res.success && res.data) {
          this.success(this.$t('feedBackMain.handleSuccess'))
          this.handleFilter()
        } else {
          row.extOrgAuditResult = row.examineAudit
          this.error(this.$t('feedBackMain.handleError'))
        }
      }).catch(res => {
        // 请求失败恢复单选框初始状态
        this.assetpkgmgrFullScreenLoading().close()
        row.extOrgAuditResult = row.examineAudit
        // console.log(res, row.extOrgAuditResult)
      })
    },
    // 校验产品和期数
    checkForm (type, row, callback) {
      let projectId = row ? row.projectId : this.queryParas.projectId
      let periods = row ? row.periods : this.queryParas.periods
      // let auditFileType = row ? row.auditFileType : this.queryParas.auditFileType
      if (!projectId) {
        this.warning(this.$t('feedBackMain.checkProject'))
        return false
      }
      if (!periods) {
        this.warning(this.$t('feedBackMain.checkPeriods'))
        return false
      }
      // if (!auditFileType) {
      //   this.warning(this.$t('feedBackMain.checkAuditFileType'))
      //   return false
      // }
      callback && callback()
    },
    // 列表回调
    handleFilter () {
      let $this = this
      $this.$refs.dataTable.vLoading = true
      // 过滤无效参数
      for (let index in this.queryParas) {
        let item = this.queryParas[index]
        if (this.UtilJs.isEmpty(item)) {
          delete this.queryParas[index]
        }
      }
      $this.api.getPage(this.queryParas).then(res => {
        $this.$refs.dataTable.vLoading = false
        if (res.success) {
          if (res.data && res.data.fileInformationPage) {
            let fileInformationPage = res.data.fileInformationPage
            let datas = res.data.fileInformationPage.datas
            // 重构问题处理情况数据
            for (let index in datas) {
              let item = datas[index]
              let list = []
              for (let index2 in item.problemHandling) {
                let item2 = format.formatDict(index2, 'AUDIT_OUT_LAW_DEAL_STATUS')
                list.push(
                  { name: `[${item2}]${item.problemHandling[index2]}`, id: index2 }
                )
              }
              item.problemHandling = list
              item.examineAudit = item.extOrgAuditResult
              // console.log(item.examineAudit, item.extOrgAuditResult)
            }
            // 映射列表
            $this.$refs.dataTable.buildTableData(datas, fileInformationPage.totalRow)
            // 映射反馈状态
            $this.feedbackEndFlag = res.data.feedbackEndFlag || '0'
            // 映射更新时间
            $this.modifyTime = res.data.modifyTime
          } else {
            $this.error(res.errmsg || $this.$t('feedBackMain.errorMsg'))
          }
        }
      }).catch(res => {
        $this.$refs.dataTable.vLoading = false
      })
    },
    // 打开弹窗 type：0 批量下载资料;1 意见反馈,2 批量处理
    openDialog (type, row) {
      this.checkForm(type, row, () => {
        // 更改组件类型
        this.componentType = type
        // 打开组件
        let name = ['D', 'S', 'D', 'O', 'A', 'A'] // 组件操作类型
        this.editModel = name[type]
        if (type === 1 || type === 4 || type === 5) {
          if (type === 4) {
            row.isAudit = true
          }
          this.currentRow = row
        }
        setTimeout(() => {
          this.dialogVisible = true
        }, 150)
      })
    },
    // 动态加载行背景色
    tableRowClassName ({ row, rowIndex }) {
      if (row.ifsUrgent === '1') {
        return 'background-color:#ffe5e5 !important;background:#ffe5e5 !important'
      }
      return ''
    }
  }
}
</script>
<style lang="scss" scoped>
@import "~@/styles/assetoutfeedback/common.scss";
</style>
