<template>
  <div class="corporate-goodwill">
    <cy-info-title type="center">征信情况</cy-info-title>
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-position="top" label-width="200px" class="rule-form-orange">
      <el-form-item
        label="征信报告"
        prop="resource"
        style="width: 100%;"
      >
        <cy-upload
          ref="fileStorage"
          :upload-params="{}"
          :file-data="ruleForm.creditDetailFiles"
          :upload-from-orange-status="true"
          placeholder="请上征信报告"
          disabled
        />
      </el-form-item>
      <div class="row-three">
        <div>
          <cy-info-title type="left">被追偿余额、关注类余额、不良类余额（红否）</cy-info-title>
          <el-form-item label="是否存在被追偿余额、关注类余额、不良类余额" prop="recoveredBalance" style="width: 100%">
            <el-select v-model="ruleForm.recoveredBalance" :disabled="disabled" placeholder="请选择是否存在被追偿余额、关注类余额、不良类余额">
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="0"></el-option>
            </el-select>
          </el-form-item>
        </div>
        <div>
          <cy-info-title type="left">未结清信贷的关注类账户数（红否）</cy-info-title>
          <el-form-item label="是否存在未结清信贷的关注类账户" prop="concernedAccountsWithOutstandingCredit" style="width: 100%">
            <el-select v-model="ruleForm.concernedAccountsWithOutstandingCredit" :disabled="disabled" placeholder="请选择是否存在未结清信贷的关注类账户">
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="0"></el-option>
            </el-select>
          </el-form-item>
        </div>
        <div>
          <cy-info-title type="left">未结清信贷的不良类账户（红否）</cy-info-title>
          <el-form-item label="是否存在未结清信贷的不良类账户" prop="outstandingNonPerformingAccounts" style="width: 100%">
            <el-select v-model="ruleForm.outstandingNonPerformingAccounts" :disabled="disabled" placeholder="请选择是否存在未结清信贷的不良类账户">
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="0"></el-option>
            </el-select>
          </el-form-item>
        </div>
      </div>
      <cy-info-title type="left">未结清短期借款余额</cy-info-title>
      <el-form-item label="未结清短期借款余额" prop="outstandingBalance">
        <cy-amount-input v-model="ruleForm.outstandingBalance" :disabled="disabled" placeholder="请输入未结清短期借款余额(单位万元)" />
      </el-form-item>
      <cy-info-title type="center">负面信息</cy-info-title>
      <el-form-item label="民间借贷" style="width: 100%">
        <private-lending ref="privateLendings" type="supplier" :disabled="disabled" :details-data="detailsInfo.privateLendings" />
      </el-form-item>
      <el-form-item label="严重违法" style="width: 100%">
        <serious-illegality ref="seriousIllegalities" type="supplier" :disabled="disabled" :details-data="detailsInfo.seriousIllegalities" />
      </el-form-item>
      <el-form-item label="欠税公告" style="width: 100%">
        <tax-arrears ref="taxOweNotices" type="supplier" :disabled="disabled" :details-data="detailsInfo.taxOweNotices" />
      </el-form-item>
      <el-form-item label="税收违法" style="width: 100%">
        <tax-revenue ref="taxIllegalData" type="supplier" :disabled="disabled" :details-data="detailsInfo.taxIllegalData" />
      </el-form-item>
      <el-form-item label="黑名单信息" style="width: 100%">
        <black-list ref="blacklists" type="supplier" :disabled="disabled" :details-data="detailsInfo.blacklists" />
      </el-form-item>
      <el-form-item label="其他经营异常" style="width: 100%">
        <other-operations ref="exceptionData" type="supplier" :disabled="disabled" :details-data="detailsInfo.exceptionData" />
      </el-form-item>
      <el-form-item label="重大负面新闻舆情" style="width: 100%">
        <big-news ref="news" type="supplier" :disabled="disabled" :details-data="detailsInfo.news" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  components: {
    PrivateLending: () => import('../../../videoDue/components/CorporateGoodwill/PrivateLending'),
    SeriousIllegality: () => import('../../../videoDue/components/CorporateGoodwill/SeriousIllegality'),
    TaxArrears: () => import('../../../videoDue/components/CorporateGoodwill/TaxArrears'),
    TaxRevenue: () => import('../../../videoDue/components/CorporateGoodwill/TaxRevenue'),
    BlackList: () => import('../../../videoDue/components/CorporateGoodwill/BlackList'),
    OtherOperations: () => import('../../../videoDue/components/CorporateGoodwill/OtherOperations'),
    BigNews: () => import('../../../videoDue/components/CorporateGoodwill/BigNews')
  },
  props: {
    detailsInfo: {
      type: Object,
      default: () => {}
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      ruleForm: {
        recoveredBalance: '',
        concernedAccountsWithOutstandingCredit: '',
        outstandingNonPerformingAccounts: '',
        outstandingBalance: ''
      },
      rules: {
        recoveredBalance: [
          { required: true, message: '请选择是否存在被追偿余额、关注类余额、不良类余额', trigger: 'change' }
        ],
        concernedAccountsWithOutstandingCredit: [
          { required: true, message: '请选择是否存在未结清信贷的关注类账户', trigger: 'change' }
        ],
        outstandingNonPerformingAccounts: [
          { required: true, message: '请选择是否存在未结清信贷的不良类账户', trigger: 'change' }
        ],
        outstandingBalance: [
          { required: true, message: '请输入未结清短期借款余额', trigger: 'blur' }
        ]
      }
    }
  },
  watch: {
    detailsInfo: {
      handler(newV) {
        this.ruleForm = {
          ...newV.corporateGoodwill,
          creditDetailFiles: newV.corporateGoodwill.creditDetailFiles || []
        }
        this.$nextTick(() => {
          this.$refs.ruleForm.clearValidate()
        })
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    validate(type) {
      return new Promise((resolve, reject) => {
        const params = {
          corporateGoodwill: {
            ...this.ruleForm
          },
          privateLendings: this.$refs.privateLendings.tableData,
          seriousIllegalities: this.$refs.seriousIllegalities.tableData,
          taxOweNotices: this.$refs.taxOweNotices.tableData,
          taxIllegalData: this.$refs.taxIllegalData.tableData,
          blacklists: this.$refs.blacklists.tableData,
          exceptionData: this.$refs.exceptionData.tableData,
          news: this.$refs.news.tableData
        }
        if (type === 'temp') {
          resolve(params)
        } else {
          this.$refs.ruleForm.validate(valid => {
            if (valid) {
              const newsTable = this.$refs.news.tableData
              if (newsTable.length) {
                for (let i = 0; i < newsTable.length; i++) {
                  const { News } = newsTable[i]
                  if (News !== 1 && News !== 0) {
                    this.$message.warning('请选择重大负面新闻舆情')
                    return
                  }
                }
              }
              resolve(params)
            } else {
              reject()
              return false
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.corporate-goodwill {

}
</style>
