<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
          :upload-params="{}"
          :file-data="ruleForm.fileStorageList"
          :upload-from-orange-status="true"
          placeholder="请上征信报告"
          disabled
        />
      </el-form-item>
      <el-form-item
        style="width: 100%;"
      >
        <div class="auditing-box">
          <div>
            <cy-info-title type="center">审核内容</cy-info-title>
          </div>
          <div>
            <cy-info-title type="center">调整内容</cy-info-title>
          </div>
        </div>
      </el-form-item>
      <el-form-item label="是否存在被追偿余额、关注类余额、不良类余额" class="one-form-item">
        <el-select v-model="defaultDatailsInfo.recoveredBalance" disabled placeholder="请选择是否存在被追偿余额、关注类余额、不良类余额">
          <el-option
            v-for="item in [{ value: 1, label: '是'}, { value: 0, label: '否' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否存在被追偿余额、关注类余额、不良类余额" prop="recoveredBalance" class="one-form-item">
        <el-select v-model="ruleForm.recoveredBalance" placeholder="请选择是否存在被追偿余额、关注类余额、不良类余额" :disabled="disabled">
          <el-option
            v-for="item in [{ value: 1, label: '是'}, { value: 0, label: '否' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否存在未结清信贷的关注类账户" prop="name" class="one-form-item">
        <el-select v-model="defaultDatailsInfo.concernedAccountsWithOutstandingCredit" disabled placeholder="请选择是否存在未结清信贷的关注类账户">
          <el-option
            v-for="item in [{ value: 1, label: '是'}, { value: 0, label: '否' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否存在未结清信贷的关注类账户" prop="unclearFollowUpAccounts" class="one-form-item">
        <el-select v-model="ruleForm.unclearFollowUpAccounts" placeholder="请选择是否存在未结清信贷的关注类账户" :disabled="disabled">
          <el-option
            v-for="item in [{ value: 1, label: '是'}, { value: 0, label: '否' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否存在未结清信贷的不良类账户" prop="name" class="one-form-item">
        <el-select v-model="defaultDatailsInfo.outstandingNonPerformingAccounts" disabled placeholder="请选择是否存在未结清信贷的不良类账户">
          <el-option
            v-for="item in [{ value: 1, label: '是'}, { value: 0, label: '否' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否存在未结清信贷的不良类账户" prop="outstandingNonPerformingAccounts" class="one-form-item">
        <el-select v-model="ruleForm.outstandingNonPerformingAccounts" placeholder="请选择是否存在未结清信贷的不良类账户" :disabled="disabled">
          <el-option
            v-for="item in [{ value: 1, label: '是'}, { value: 0, label: '否' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="未结清短期借款余额" prop="name" class="one-form-item">
        <el-input v-model="defaultDatailsInfo.outstandingBalance" disabled placeholder="请输入未结清短期借款余额" />
      </el-form-item>
      <el-form-item label="未结清短期借款余额" prop="outstandingShortTermLoanBalance" class="one-form-item">
        <el-input v-model="ruleForm.outstandingShortTermLoanBalance" placeholder="请输入未结清短期借款余额" :disabled="disabled" />
      </el-form-item>
      <el-form-item
        label="问题"
        prop="resource"
        style="width: 100%;"
      >
        <el-input v-model="ruleForm.question" type="textarea" placeholder="请输入问题" :disabled="disabled" />
      </el-form-item>
      <el-form-item
        label=" 尽调反馈"
        prop="resource"
        style="width: 100%;"
      >
        <unified-editor :content.sync="ruleForm.feedback" :disabled="disabled" />
        <cy-upload
          ref="fileStorage"
          :upload-params="{}"
          :file-data="goodwillFileList"
          :upload-from-orange-status="true"
          placeholder="请上传附件"
          :disabled="disabled"
        />
      </el-form-item>

      <cy-info-title type="center">负面清单</cy-info-title>
      <el-form-item label="失信被执行信息" prop="name" class="one-form-item">
        <el-select v-model="defaultDatailsInfo.shiXin" disabled placeholder="请选择失信被执行信息">
          <el-option
            v-for="item in [{ value: 1, label: '存在'}, { value: 0, label: '不存在' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="历史失信被执行信息" prop="name" class="one-form-item">
        <el-select v-model="defaultDatailsInfo.historyShiXin" disabled placeholder="请选择历史失信被执行信息">
          <el-option
            v-for="item in [{ value: 1, label: '存在'}, { value: 0, label: '不存在' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="被执行人信息" prop="name" class="one-form-item">
        <el-select v-model="defaultDatailsInfo.zhiXing" disabled placeholder="请选择被执行人信息">
          <el-option
            v-for="item in [{ value: 1, label: '存在'}, { value: 0, label: '不存在' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="历史被执行人信息" prop="name" class="one-form-item">
        <el-select v-model="defaultDatailsInfo.historyZhiXing" disabled placeholder="请选择历史被执行人信息">
          <el-option
            v-for="item in [{ value: 1, label: '存在'}, { value: 0, label: '不存在' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="限制高消费信息" prop="name" class="one-form-item">
        <el-select v-model="defaultDatailsInfo.gaoXiao" disabled placeholder="请选择限制高消费信息">
          <el-option
            v-for="item in [{ value: 1, label: '存在'}, { value: 0, label: '不存在' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="历史限制高消费信息" prop="name" class="one-form-item">
        <el-select v-model="defaultDatailsInfo.historyGaoXiao" disabled placeholder="请选择历史限制高消费信息">
          <el-option
            v-for="item in [{ value: 1, label: '存在'}, { value: 0, label: '不存在' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="近两年行政处罚数量" prop="name" class="one-form-item">
        <el-input v-model="defaultDatailsInfo.punish" disabled placeholder="请输入近两年行政处罚数量" />
      </el-form-item>
      <el-form-item label="近两年行政处罚金额" prop="name" class="one-form-item">
        <el-input v-model="defaultDatailsInfo.punishAmount" disabled placeholder="请输入近两年行政处罚金额" />
      </el-form-item>
      <el-form-item label="涉诉（原告）" prop="name" class="one-form-item">
        <el-select v-model="defaultDatailsInfo.documnetYuanGao" disabled placeholder="请选择涉诉（原告）">
          <el-option
            v-for="item in [{ value: 1, label: '存在'}, { value: 0, label: '不存在' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="涉诉（被告）" prop="name" class="one-form-item">
        <el-select v-model="defaultDatailsInfo.documnetBeiGao" disabled placeholder="请选择涉诉（原告）">
          <el-option
            v-for="item in [{ value: 1, label: '存在'}, { value: 0, label: '不存在' }]"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="民间借贷" prop="name" style="width: 100%">
        <private-lending ref="privateLendings" type="videoDue" :details-data="defaultDatailsInfo.privateLendings" />
      </el-form-item>
      <el-form-item label="严重违法" prop="name" style="width: 100%">
        <serious-illegality ref="seriousIllegalities" type="videoDue" :details-data="defaultDatailsInfo.seriousIllegalities" />
      </el-form-item>
      <el-form-item label="欠税公告" prop="name" style="width: 100%">
        <tax-arrears ref="taxOweNotices" type="videoDue" :details-data="defaultDatailsInfo.taxOweNotices" />
      </el-form-item>
      <el-form-item label="税收违法" prop="name" style="width: 100%">
        <tax-revenue ref="taxIllegalData" type="videoDue" :details-data="defaultDatailsInfo.taxIllegalData" />
      </el-form-item>
      <el-form-item label="黑名单信息" prop="name" style="width: 100%">
        <black-list ref="blacklists" type="videoDue" :details-data="defaultDatailsInfo.blacklists" />
      </el-form-item>
      <el-form-item label="其他经营异常" prop="name" style="width: 100%">
        <other-operations ref="exceptionData" type="videoDue" :details-data="defaultDatailsInfo.exceptionData" />
      </el-form-item>
      <el-form-item label="重大负面新闻舆情" prop="name" style="width: 100%">
        <big-news ref="news" type="videoDue" :details-data="defaultDatailsInfo.news" />
      </el-form-item>

      <el-form-item
        label="问题"
        prop="resource"
        style="width: 100%"
      >
        <el-input v-model="ruleForm.negativeInformationQuestion" placeholder="请输入问题" :disabled="disabled" />
      </el-form-item>
      <el-form-item
        label=" 尽调反馈"
        prop="resource"
        style="width: 100%;"
      >
        <unified-editor :content.sync="ruleForm.negativeInformationFeedback" :disabled="disabled" />
        <cy-upload
          ref="negativeInformationFileStorage"
          :upload-params="{}"
          :file-data="negativeInformationFile"
          :upload-from-orange-status="true"
          placeholder="请上传附件"
          :disabled="disabled"
        />
      </el-form-item>
      <el-form-item
        label="动产融资登记"
        prop="resource"
      >
        <cy-upload
          :upload-params="{}"
          disabled
          :file-data="chattelFile"
          :upload-from-orange-status="true"
          placeholder="请上传附件"
        />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  components: {
    UnifiedEditor: () => import('@/components/UnifiedEditor/index.vue'),
    PrivateLending: () => import('./PrivateLending'),
    SeriousIllegality: () => import('./SeriousIllegality'),
    TaxArrears: () => import('./TaxArrears'),
    TaxRevenue: () => import('./TaxRevenue'),
    BlackList: () => import('./BlackList'),
    OtherOperations: () => import('./OtherOperations'),
    BigNews: () => import('./BigNews')
  },
  inject: ['datailsInfo', 'disabled'],
  data() {
    return {
      ruleForm: {
        recoveredBalance: '',
        unclearFollowUpAccounts: '',
        outstandingNonPerformingAccounts: '',
        outstandingShortTermLoanBalance: '',
        question: '',
        feedback: '',
        fileStorageList: [],
        negativeInformationQuestion: ''
      },
      rules: {
        recoveredBalance: [
          { required: true, message: '请选择是否存在被追偿余额、关注类余额、不良类余额', trigger: 'change' }
        ],
        unclearFollowUpAccounts: [
          { required: true, message: '请选择是否存在未结清信贷的关注类账户', trigger: 'change' }
        ],
        outstandingNonPerformingAccounts: [
          { required: true, message: '请选择是否存在未结清信贷的不良类账户', trigger: 'change' }
        ],
        outstandingShortTermLoanBalance: [
          { required: true, message: '请输入未结清短期借款余额', trigger: 'blur' }
        ]
      },
      goodwillFileList: [],
      negativeInformationFile: []
    }
  },
  computed: {
    defaultDatailsInfo() {
      return this.datailsInfo.value?.corporateGoodwill
    },
    chattelFile() {
      return this.datailsInfo.value?.files || []
    }
  },
  watch: {
    datailsInfo: {
      handler(newV) {
        if (newV.value === undefined) return
        if (newV && Object.keys(newV).length) {
          const {
            // corporateGoodwill: { question },
            negativeInformationQuestion,
            negativeInformationFeedback,
            negativeInformationFile,
            videoDueDiligenceCorporateGoodwill
          } = newV.value
          this.ruleForm = {
            ...videoDueDiligenceCorporateGoodwill,
            fileStorageList: videoDueDiligenceCorporateGoodwill.creditDetailFiles || [],
            negativeInformationQuestion,
            negativeInformationFeedback
          }
          this.goodwillFileList = videoDueDiligenceCorporateGoodwill.files || []
          this.negativeInformationFile = negativeInformationFile || []
        }
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    getParams(type) {
      return new Promise((resolve, reject) => {
        const fileList = this.$refs.fileStorage.getFileLists
        const negativeInformationFile = this.$refs.negativeInformationFileStorage.getFileLists
        const params = {
          videoDueDiligenceCorporateGoodwill: {
            ...this.ruleForm,
            fileIds: fileList.map(item => item.id)
          },
          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,
          negativeInformationQuestion: this.ruleForm.negativeInformationQuestion,
          negativeInformationFeedback: this.ruleForm.negativeInformationFeedback,
          negativeInformationFileIds: negativeInformationFile.map(item => item.id)
        }
        delete params.videoDueDiligenceCorporateGoodwill.negativeInformationQuestion
        delete params.videoDueDiligenceCorporateGoodwill.negativeInformationFeedback
        if (type === 'temp') {
          resolve(params)
        } else {
          this.$refs.ruleForm.validate(valid => {
            if (valid) {
              resolve(params)
            } else {
              reject()
              return false
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.corporate-goodwill {
  .auditing-box {
    display: flex;
    justify-content: space-around;
  }
}
</style>
