<!--导入结果-->
<template>
  <div>
    <dialog-edit :api="api" :visible.sync="dialogVisible" :editModel="'E'" :form="form" :width="width" :saveFlag="true" :saveLabel="'重新导入'"
                 :autoSave="false" @onSaved="onSaved" :openPerms="true" :menuCode="menuCode" savePerms="chongXinBtn"
                 :title="$t('ladingManageList.importResult')" :footerBtnShow="footerVisible" :appendToBody="appendToBody">
      <data-table :operateBtnLayout="operateBtnLayout" :columns="columns" ref="dataTable" :showSelection="true"
                  :menuFlag="false" :sourceData.sync="souceData" :selectedRows.sync="selectedRows" :showPage="false">
      </data-table>
      <div style="margin-top: 24px" v-if="localfrom.resultList || localfrom.newNameUnaccredited || localfrom.unDataDtos">
        <el-card class="box-card" v-if="localfrom.resultList">
          <div slot="header" class="clearfix">
            <span>{{$t('guideSheetManage.importException')}}</span>
          </div>
          <div v-for="(item, index)  in localfrom.resultList" :key="index" class="text item clearfix">
            {{$t('guideSheetManage.exceptionMsg') + item.msg }}
          </div>
        </el-card>
        <el-card class="box-card" v-if="localfrom.notListEnterprise">
          <div slot="header" class="clearfix">
            <span>{{$t('guideSheetManage.qingdanweizengjia')}}{{localfrom.notListEnterprise.length}}{{$t('guideSheetManage.home')}}</span>
          </div>
          <div v-for="(item, index) in localfrom.notListEnterprise" :key="index" class="text item clearfix">
            <div v-if="localfrom.notListEnterprise.length > 0">
              {{(index + 1) + '.' + item.notListEnterpriseName }}
            </div>
          </div>
        </el-card>
        <el-card class="box-card" v-if="localfrom.newNameUnaccredited">
          <div slot="header" class="clearfix">
            <span>{{$t('guideSheetManage.cengyongmin')}}{{localfrom.newNameUnaccredited.length}}{{$t('guideSheetManage.home')}}</span>
          </div>
          <div v-for="(item, index) in localfrom.newNameUnaccredited" :key="index" class="text item clearfix">
            <div v-if="localfrom.newNameUnaccredited.length > 0">
              <p>{{$t('guideSheetManage.newName')}}{{item.newName}}</p>
              <p>{{$t('guideSheetManage.oldName')}}{{item.oldName}}</p>
            </div>
          </div>
        </el-card>
        <el-card class="box-card" v-if="localfrom.unDataDtos">
          <div slot="header" class="clearfix">
            <span>{{$t('guideSheetManage.noRkData')}} </span>
          </div>
          <div v-for="(item, index) in localfrom.unDataDtos" :key="index" class="text item clearfix">
            <p v-if="item.repeatMsg.length > 0">{{item.factoringApplyTime}}{{item.factoringName}}{{item.unauthorizedCompanyNum + $t('guideSheetManage.homeProjectCom') + '(' + item.repeatMsg[0] + ')'}}</p>
            <p v-else>{{item.factoringApplyTime}}{{item.factoringName}}{{item.unauthorizedCompanyNum + $t('guideSheetManage.homeProjectCom')}}</p>
            <p>{{$t('guideSheetManage.seJiBook')}}{{item.involvePayConfirm + $t('guideSheetManage.pen')}}</p>
            <p>{{$t('guideSheetManage.hejiRmbEn')}}{{item.accountsReceivable}}</p>
          </div>
        </el-card>
        <el-card class="box-card" v-if="localfrom.accountsReceivableCount">
          <div class="text item">
            {{$t('guideSheetManage.hejiRmbCn') + localfrom.accountsReceivableCount }}
          </div>
        </el-card>
      </div>
    </dialog-edit>
  </div>
</template>

<script>
import { DialogEdit, btnDownload, authButton, DataTable } from 'newepoch-components'
import BaseEdit from '@/pages/baseEditPage.js'
import guideSheetManageApi from '@/api/guideSheetManageApi'
export default {
  extends: new BaseEdit(),
  name: 'formalImportResultModify',
  components: {
    DialogEdit,
    btnDownload,
    authButton,
    DataTable
  },
  props: {
    menuCode: {
      type: String,
      default: null
    }
  },
  data () {
    return {
      localfrom: {},
      width: '680px',
      classType: true,
      appendToBody: true,
      footerVisible: true,
      operateBtnLayout: '',
      selectedRows: [],
      souceData: [],
      columns: [
        // 业务主键
        {
          prop: 'bussId',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingPlanManageList.bussIdLabel,
          width: '250px'
        },
        // 业务类型
        // {
        //   prop: 'bussType',
        //   align: 'center',
        //   label: this.$i18n.messages[this.$i18n.locale].ladingPlanManageList.bussTypeLabel,
        //   width: '40px'
        // },
        // 处理方式
        {
          prop: 'bussType',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].ladingPlanManageList.bussTypeResult,
          width: '100px'
        },
        // 附加信息
        {
          prop: 'extra',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].ladingPlanManageList.extraLabel,
          width: '250px'
        }
      ]
    }
  },
  computed: {
    api () {
      return guideSheetManageApi.guideSheetManage
    }
  },
  methods: {
    onSaved (data) {
      if (this.selectedRows.length > 0) {
        let perSen = []
        this.selectedRows.forEach(it => {
          let a = this.form.data.filter(it1 => {
            return (it.bussId === it1.assetCode)
          })
          perSen.push(...a)
        })
        perSen.forEach(it => {
          it.processMode = '1'
        })
        this.getData(perSen)
      } else {
        this.warning('请先选择数据')
      }
    },
    getData (data) {
      this.$refs.dataTable.vLoading = true
      this.souceData = []
      this.api.getFormalPayconfirm(data).then(res => {
        if (res && res.data) {
          this.souceData = res.data.batchRecordDTOS
          this.localfrom = res.data
          this.$emit('close')
          // if (index === 1) {
          // }
        }
      }).finally(res => {
        this.$refs.dataTable.vLoading = false
      })
    }
  },
  watch: {
    dialogVisible (n, o) {
      if (n) {
        this.$nextTick(() => {
          this.getData(this.form.data)
        })
      }
    }
  }
}
</script>

<style scoped lang="scss" src="@/styles/shouji/ladingManage/importResultEdit.scss">
</style>
