<!-- 抽样文件反馈 -->
<template>
  <div>
    <up-down-layout :handleFlag.sync="handleFlag">
      <!-- 搜索栏 -->
      <search-form 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>
              <!-- 批量反馈 -->
              <auth-button :disabled="feedbackEndFlag == '2'" class="iconfont iconfankui1" :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>
          <!-- 单行操作 -->
          <!-- <el-table-column align="center" min-width="250px" :label="$t('common.operate')" fixed="right"> -->
            <template #operate="scope">
              <div v-if="scope.data.row.preAssetFlag != '2'">
              <!-- 已退单，若意见状态存在时 -->
              <!-- <div v-if="scope.row.extOrgOpinionStatus !== '0' && scope.row.assetStatus === '7'">
                <auth-button class="iconCircle" icon="iconfont iconview" :title="$t('common.view')"></auth-button>
              </div>
              <div v-if="scope.row.assetStatus !== '7' && (scope.data.row.pointSampleFlag == '1' || scope.data.row.pointSampleFlag == '2')">
                <div v-if="scope.row.extOrgOpinionStatus === '1' && scope.row.feedbackQuestionsCount < 1">
                  <btn-batch-download :title="$t('feedBackMain.dataDownload')"></btn-batch-download>
                  <auth-button class="iconCircle" icon="iconfont iconfankui" :title="$t('feedBackMain.feedback')" @click="openDialog(1,scope.data.row)"></auth-button>
                </div>
                <div v-if="scope.row.extOrgOpinionStatus === '1' && scope.row.feedbackQuestionsCount > 0">
                  <btn-batch-download v-if="scope.row.extOrgOpinionStatus === '0'" :title="$t('feedBackMain.supplementDonwload')"></btn-batch-download>
                  <btn-batch-download :title="$t('feedBackMain.dataDownload')"></btn-batch-download>
                  <auth-button class="iconCircle" icon="iconfont iconview" :title="$t('common.view')"></auth-button>
                </div>
                <div v-if="scope.row.extOrgOpinionStatus === '2'">
                  <btn-batch-download v-if="scope.row.extOrgOpinionStatus === '0'" :title="$t('feedBackMain.supplementDonwload')"></btn-batch-download>
                  <btn-batch-download :title="$t('feedBackMain.dataDownload')"></btn-batch-download>
                  <auth-button class="iconCircle" icon="iconfont icondaichuli" :title="$t('feedBackMain.waitingYf')"></auth-button>
                </div>
                <div v-if="scope.row.extOrgOpinionStatus === '3'">
                  <btn-batch-download v-if="scope.row.extOrgOpinionStatus === '0'" :title="$t('feedBackMain.supplementDonwload')"></btn-batch-download>
                  <btn-batch-download :title="$t('feedBackMain.dataDownload')"></btn-batch-download>
                  <auth-button class="iconCircle" icon="iconfont iconfuhe" :title="$t('feedBackMain.waitingAudit')" @click="openDialog(4)"></auth-button>
                </div>
              </div> -->
              <!-- 补充资料下载 -->
              <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 iconguidang" :title="$t('feedBackMain.dataDownload')" @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>
          <!-- </el-table-column> -->
          </data-table>
      </template>
    </up-down-layout>
    <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,
  BaseSelect,
  DataTable,
  amountInput,
  btnBatchDownload,
  btnDownload,
  SpanPlus,
  ExpandCollapse,
  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 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'

export default {
  extends: new BasePage(),
  name: 'sampleFeedBackMain',
  mixins: [mixin],
  components: {
    searchForm,
    upDownLayout,
    authButton,
    DataTable,
    btnBatchDownload,
    btnDownload,
    SpanPlus,
    ExpandCollapse,
    collapseTitle
  },
  data () {
    let $this = this
    return {
      dialogVisible: false, // 组件显隐控件
      componentType: 0, // 组件类型
      autoSave: false, // 是否自动保存
      feedbackType: '1', // 反馈类型
      feedbackEndFlag: '0', // 反馈状态
      loading: false, // 表格加载控件
      currentRow: {}, // 选中行
      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: 'ifsUrgent',
          width: '100px',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.ifsUrgent,
          format (row) {
            return row.ifsUrgent === '1'
              ? $this.$t('common.yes')
              : $this.$t('common.no')
          }
        },
        {
          // 产品名称
          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,
          width: '300px',
          headerAlign: 'center',
          maxlength: '50',
          label: this.$i18n.messages[this.$i18n.locale].feedBackMain.assetCode
        },
        {
          // 供应商名称
          prop: 'creditor',
          width: '300px',
          slot: true,
          // showOverflowTooltip: 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.feedbackFrequency,
          disabled: false,
          value: 'feedbackFrequency',
          prop: 'feedbackFrequency',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: '115px',
          clearable: true,
          queryName: ['projectId', 'periods'],
          queryValue: ['projectId', 'periods'],
          attrs: { auditFileType: '1001' },
          componentName: feedBackFreqSelectList
        },
        {
          // 付款确认书编号
          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,
          maxlength: 50,
          minlength: 0,
          componentName: 'el-input'
        },
        {
          // 抽中状态
          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.ifsUrgent,
          disabled: false,
          value: 'ifsUrgent',
          prop: 'ifsUrgent',
          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.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 () {
    setTimeout(() => {
      this.handleFilter()
    }, 500)
  },
  watch: {
    'queryParas.projectId' (val) {
      this.feedbackEndFlag = '0'
      this.$set(this.queryParas, 'feedbackFrequency', '')
    },
    'queryParas.periods' (val) {
      this.feedbackEndFlag = '0'
      this.$set(this.queryParas, 'feedbackFrequency', '')
    }
  },
  computed: {
    newForm () {
      return {
        projectId: this.queryParas.projectId,
        projectName: this.projectName,
        periods: this.queryParas.periods,
        auditFileType: '1001'
      }
    },
    attrs () {
      return Object.assign(this.elHeightObj, { 'row-style': this.tableRowClassName })
    },
    // api接口
    api () {
      return feedBackMain.sampleList
    },
    // 组件文件名
    componentName () {
      // 组件类型
      let type = this.componentType
      // 组件列表
      let name = [
        'sampleFileDownBatchPop',
        'sampleFeedBackSinglePop',
        'sampleFeedBackBatchPop',
        'sampleFileAuditBatchPop',
        'sampleFileAuditSinglePop',
        'sampleFileAuditSinglePop'
      ]
      // 引入组件
      return resolve => require([`@/pages/assetoutfeedback/feedBackMain/${name[type]}`], resolve)
    },
    // 组件标题
    componentTitle () {
      // 组件类型
      let type = this.componentType
      // 组件标题
      let name = [
        this.$t('feedBackMain.batchDownload'),
        this.$t('feedBackMain.feedbackOne'),
        this.$t('feedBackMain.batchFeedback'),
        this.$t('feedBackMain.batchOperate'),
        this.$t('feedBackMain.sampleFileAuditSinglePop'),
        this.$t('feedBackMain.sampleQustDetailPop')
      ]
      return name[type]
    }
  },
  methods: {
    ...format,
    // 下拉框回调
    selectChanged (a) {
      if (a.productNameInfo) {
        this.projectName = a.productNameInfo.projectName
      }
    },
    // 资料下载:type:0 补充资料;1 归档资料
    handleDownload (type, row) {
      let api = ['rpyfileList', 'danganFile'][type] // 请求api
      let func = ['getList', 'getDefault'][type] // 请求api方法
      let fileName = [this.$t('feedBackMain.supplementFiles'), this.$t('feedBackMain.danganFiles')][type] // 文件名
      let args = [
        {
          assetCode: row.assetCode,
          feedbackFrequency: row.feedbackFrequency,
          auditFileType: '1001'
        },
        {
          assetInfoIds: [row.assetInfoId],
          fileTypes: ['0']
        }
      ][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, `${fileName}(${row.assetCode}).zip`)
            }).catch(res => {
              this.error(res.message)
            })
          } else {
            this.warning(this.$t('feedBackMain.noFiles'))
          }
        })
      }).catch((e) => {})
    },
    // 反馈结束/继续反馈
    handleFeedback () {
      let $this = this
      // console.log(this.modifyTime)
      // 配置参数：产品，期数，更新时间,反馈类型
      let args = {
        projectId: $this.queryParas.projectId,
        periods: $this.queryParas.periods,
        modifyTime: format.formatDatetime($this.modifyTime),
        auditFileType: '1001',
        operType: $this.feedbackEndFlag
      }
      $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 (row, callback) {
      let projectId = row ? row.projectId : this.queryParas.projectId
      let periods = row ? row.periods : this.queryParas.periods
      if (!projectId) {
        this.warning(this.$t('feedBackMain.checkProject'))
        return false
      }
      if (!periods) {
        this.warning(this.$t('feedBackMain.checkPeriods'))
        return false
      }
      callback && callback()
    },
    search () {
      this.queryParas.pageIndex = 1
      this.handleFilter()
    },
    // 列表回调
    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(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
          }
          row.auditFileType = this.newForm.auditFileType
          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>
