<!--资产标志管理-->
<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible"
                 :autoSave="false"
                 :editModel="editModel"
                 :form="{}"
                 center
                 @onSaved="onSaved"
                 :appendToBody="appendToBody"
                 :title="$t('effectDealFeedBackMain.asseMarkMrg')">
                 <div class="assetFlagMgrPop">
        <el-form-item :label="$t('common.payCode')" class="item-bottom">
            <span>{{form.assetCode}}</span>
            <el-checkbox-group v-model="markList" class="asset-flag-checkbox">
              <el-checkbox label="1" name="chargebackRiskFlag">{{$t('effectDealFeedBackMain.riskOfCancellation')}}</el-checkbox>
              <el-checkbox label="2" name="supplementPumpStatus">{{$t('effectDealFeedBackMain.supChargeback')}}</el-checkbox>
              <el-checkbox label="3" name="ifsToLoan">{{$t('effectDealFeedBackMain.lendableMark')}}</el-checkbox>
            </el-checkbox-group>
        </el-form-item>
        <data-table :columns="columns"
                    :queryParas.sync="queryParas"
                    @sizeChange="pageChange"
                    @currentChange="pageChange"
                    v-bind="{maxHeight:400}"
                    ref="assetTable">
            <template slot="feedbackQuestionContent" slot-scope="scope">
              <span-plus :index="scope.data.$index" :text="scope.data.row.feedbackQuestionContent"></span-plus>
            </template>
            <template slot="difficultQustionFlag" slot-scope="scope">
                 <el-checkbox v-model="scope.data.row.difficultQustionFlag" true-label="2" false-label="1"></el-checkbox>
            </template>
            <template slot="overdueFlag" slot-scope="scope">
                 <el-checkbox v-model="scope.data.row.overdueFlag" true-label="2" false-label="1"></el-checkbox>
            </template>
        </data-table>
        </div>
    </dialog-edit>
  </div>
</template>
<script>
import { DialogEdit, authButton, DataTable, SpanPlus } from 'newepoch-components'
import coordManageApi from '@/api/assetoutfeedback/coordManage/coordManageApi'
import BasePage from '@/pages/baseEditPage'
export default {
  name: 'assetFlagMgrPop',
  extends: new BasePage(),
  components: {
    DialogEdit,
    authButton,
    DataTable,
    SpanPlus
  },
  computed: {
    api () {
      return coordManageApi.getReviewFlag
    }
  },
  props: {
    editModel: {
      type: [String],
      default () {
        return 'E'
      }
    },
    form: {
      type: [Object],
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      queryParas: {
        pageIndex: 1,
        pageSize: 10
      },
      assMgrForm: {},
      appendToBody: true,
      markList: [],
      columns: [
        {
          // 问题序号
          prop: 'qusetionNumber',
          align: 'center',
          width: '50px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.feedbackQustionNo
        },
        {
          // 外部机构意见
          prop: 'feedbackQuestionContent',
          align: 'left',
          slot: true,
          width: '200px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.extOrgOpinionContent
        },
        {
          // 疑难问题
          prop: 'difficultQustionFlag',
          align: 'center',
          slot: true,
          width: '55px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.difficultQustion
        },
        {
          // 逾期问题
          prop: 'overdueFlag',
          align: 'center',
          slot: true,
          width: '55px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.overdueProblems
        }
      ],
      changedData: []
    }
  },
  mounted () {
    this.queryParas.auditFileType = this.form.auditFileType
    this.queryParas.feedbackResource = this.form.feedbackResource
    this.queryParas.assetCode = this.form.assetCode
    this.$nextTick(() => {
      this.myhandleFilter()
    })
  },
  methods: {
    // 更新表数据
    myhandleFilter () {
      this.api.getDefaultInfo(this.queryParas).then(res => {
        if (res.code === '0' && res.data.assetFlagInfoDtoPage.datas) {
          this.$refs.assetTable.buildTableData(res.data.assetFlagInfoDtoPage.datas, res.data.assetFlagInfoDtoPage.totalRow)
          this.assMgrForm = res.data
          if (res.data.chargebackRiskFlag === '2') {
            this.markList.push('1')
          }
          if (res.data.supplementPumpStatus === '2') {
            this.markList.push('2')
          }
          if (res.data.ifsToLoan === '2') {
            this.markList.push('3')
          }
        }
      })
    },
    // 页面改变
    pageChange () {
      this.myhandleFilter()
    },
    // 保存
    onSaved () {
      if (!this.UtilJs.isEmpty(this.assMgrForm)) {
        let arr = this.assMgrForm.assetFlagInfoDtoPage.datas
        this.assMgrForm = Object.assign(this.assMgrForm, { 'assetFlagInfoPartDTOList': arr })
        this.assMgrForm = Object.assign(this.assMgrForm, { 'assetCode': this.form.assetCode })
        this.assMgrForm.chargebackRiskFlag = this.markList.includes('1') ? '2' : '1'
        this.assMgrForm.supplementPumpStatus = this.markList.includes('2') ? '2' : '1'
        this.assMgrForm.ifsToLoan = this.markList.includes('3') ? '2' : '1'
        this.assetpkgmgrFullScreenLoading()
        this.api.putDefaultUpdate(this.assMgrForm).then(res => {
          this.assetpkgmgrFullScreenLoading().close()
          if (res.data) {
            this.success('更新资产标志信息成功')
            this.dialogVisible = false
            this.$emit('close', true)
          } else {
            this.success('更新资产标志信息失败')
          }
        }).catch(res => this.assetpkgmgrFullScreenLoading().close())
      }
    }
  }
}
</script>
<style lang="scss" scoped>
@import '~@/styles/assetoutfeedback/common.scss';
</style>
<style lang="scss">
.item-bottom .el-form-item__label{
  line-height: 20px !important;
  padding-top: 10px;
}
.item-bottom .el-form-item__content{
  line-height: 14px !important;
  padding-top: 10px;
}
</style>
