<template>
  <div class="auditing-box">
    <el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" label-position="top" label-width="150px" class="rule-form-orange">
      <el-form-item label="企业性质" prop="enterpriseNature" class="one-form-item">
        <el-select v-model="ruleForm.enterpriseNature" placeholder="请选择企业性质" :disabled="disabled" @change="getProjectNatureDetailList">
          <el-option
            v-for="item in enterpriseNatureList"
            v-show="item.code !== 'enterpriseNature_9' && item.code!== 'enterpriseNature_10'"
            :key="item.code"
            :label="item.name"
            :value="item.code"
          />
        </el-select>
      </el-form-item>
      <el-form-item
        v-if="ruleForm.enterpriseNature==='enterpriseNature_9'"
        label="上市公司类型"
        prop="enterpriseNatureDetail"
        class="one-form-item"
        :rules="[{ required: ruleForm.enterpriseNature==='enterpriseNature_9', message: '请选择企业性质细分', trigger: 'change' }]"
      >
        <el-select v-model="ruleForm.enterpriseNatureDetail" placeholder="请选择上市公司类型" :disabled="disabled">
          <el-option
            v-for="item in enterpriseNatureDetailList"
            :key="item.code"
            :label="item.name"
            :value="item.code"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="股东信息" style="width: 100%">
        <cy-comm-table
          ref="commTable"
          :columns="columns"
          :data="ruleForm.regStocks"
        />
      </el-form-item>
      <el-form-item label="国有控股比例" prop="holdingRatio">
        <el-select v-model="ruleForm.holdingRatio" placeholder="请选择国有控股比例" :disabled="disabled">
          <el-option
            v-for="item in holdingRatioList"
            v-show="item.code !== 'holdingRatio_4' && item.code!== 'holdingRatio_5' && item.code!== 'holdingRatio_6'"
            :key="item.code"
            :label="item.name"
            :value="item.code"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="股权层级" prop="equityHierarchy">
        <el-select v-model="ruleForm.equityHierarchy" placeholder="请选择股权层级" :disabled="disabled" @change="getequityHierarchyDetailList">
          <el-option
            v-for="item in equityHierarchyList"
            :key="item.code"
            :label="item.name"
            :value="item.code"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="股权层级细分" prop="equityHierarchyDetail">
        <el-select v-model="ruleForm.equityHierarchyDetail" placeholder="请选择股权层级" :disabled="disabled">
          <el-option
            v-for="item in equityHierarchyDetailList"
            v-show="item.code !== 'equityHierarchyDetail_2_F'"
            :key="item.code"
            :label="item.name"
            :value="item.code"
          />
        </el-select>
      </el-form-item>
      <cy-info-title type="center">负面清单</cy-info-title>
      <el-form-item label="历史涉诉数量（近一年）" prop="involvingLitigationAccessCcount" class="one-form-item">
        <el-input v-model="ruleForm.involvingLitigationAccessCcount" placeholder="请输入历史涉诉数量（近一年）" disabled />
      </el-form-item>
      <el-form-item label="准入结论" prop="involvingLitigationAccess" class="one-form-item">
        <el-radio-group v-model="ruleForm.involvingLitigationAccess" :disabled="disabled">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="行政处罚数量（近一年）" prop="administrativePenaltyAccessCcount" class="one-form-item">
        <el-input v-model="ruleForm.administrativePenaltyAccessCcount" placeholder="请输入行政处罚数量（近一年）" disabled />
      </el-form-item>
      <el-form-item label="准入结论" prop="administrativePenaltyAccess" class="one-form-item">
        <el-radio-group v-model="ruleForm.administrativePenaltyAccess" :disabled="disabled">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="行政处罚金额（万元）" prop="administrativePenaltyAmount" class="one-form-item">
        <el-input v-model="ruleForm.administrativePenaltyAmount" placeholder="请输入行政处罚金额" disabled />
      </el-form-item>
      <el-form-item label="准入结论" prop="administrativePenaltyAmountAccess" class="one-form-item">
        <el-radio-group v-model="ruleForm.administrativePenaltyAmountAccess" :disabled="disabled">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="环保处罚金额（万元）" prop="environmentalPenaltyAmount" class="one-form-item">
        <el-input v-model="ruleForm.environmentalPenaltyAmount" placeholder="请输入环保处罚金额" disabled />
      </el-form-item>
      <el-form-item label="准入结论" prop="environmentalPenaltyAmountAccess" class="one-form-item">
        <el-radio-group v-model="ruleForm.environmentalPenaltyAmountAccess" :disabled="disabled">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="民间借贷" style="width: 100%">
        <private-lending ref="privateLending" :type="'projectOwner'" :details-data="ruleForm.privateLendings" />
      </el-form-item>
      <el-form-item label="股权冻结" style="width: 100%">
        <equity-freezed ref="equityFreeze" :type="'projectOwner'" :details-data="ruleForm.equityFreezeDataList" />
      </el-form-item>
      <el-form-item label="重大异常诉讼" style="width: 100%">
        <major-anomalie ref="majorAbnormalLitigation" :type="'projectOwner'" :details-data="ruleForm.majorAnomalies" />
      </el-form-item>
      <el-form-item label="严重违法" style="width: 100%">
        <serious-illegality ref="seriousIllegality" :type="'projectOwner'" :details-data="ruleForm.seriousIllegalData" />
      </el-form-item>
      <el-form-item label="欠税公告" style="width: 100%">
        <tax-arrears ref="taxOweNotice" :type="'projectOwner'" :details-data="ruleForm.taxOweNoticeData" />
      </el-form-item>
      <el-form-item label="税收违法" style="width: 100%">
        <tax-revenue ref="taxIllegal" :type="'projectOwner'" :details-data="ruleForm.taxIllegalData" />
      </el-form-item>
      <el-form-item label="黑名单信息" style="width: 100%">
        <black-list ref="blacklist" :type="'projectOwner'" :details-data="ruleForm.blacklists" />
      </el-form-item>
      <el-form-item label="其他经营异常" style="width: 100%">
        <other-operations ref="exception" :type="'projectOwner'" :details-data="ruleForm.exceptionData" />
      </el-form-item>
      <el-form-item label="重大负面新闻舆情" style="width: 100%">
        <big-news ref="News" :type="'projectOwner'" :details-data="ruleForm.news" />
      </el-form-item>
      <cy-info-title>评估意见</cy-info-title>
      <el-form-item label="项目评估意见" prop="evaluationOpinions" class="one-form-item" style="margin-bottom: 15px;">
        <el-input v-model="ruleForm.evaluationOpinions" placeholder="请输入项目评估意见" :disabled="disabled" />
      </el-form-item>
    </el-form>

  </div>
</template>

<script>
import { getDictionaryInfo } from '@/api/creditManage/projectManage'
export default {
  components: {
    EquityFreezed: () => import('../CorporateGoodwill/EquityFreezed'),
    MajorAnomalie: () => import('../CorporateGoodwill/MajorAnomalie'),
    PrivateLending: () => import('../../../../supplierManage/videoDue/components/CorporateGoodwill/PrivateLending'),
    SeriousIllegality: () => import('../../../../supplierManage/videoDue/components/CorporateGoodwill/SeriousIllegality'),
    TaxArrears: () => import('../../../../supplierManage/videoDue/components/CorporateGoodwill/TaxArrears'),
    TaxRevenue: () => import('../../../../supplierManage/videoDue/components/CorporateGoodwill/TaxRevenue'),
    BlackList: () => import('../../../../supplierManage/videoDue/components/CorporateGoodwill/BlackList'),
    OtherOperations: () => import('../../../../supplierManage/videoDue/components/CorporateGoodwill/OtherOperations'),
    BigNews: () => import('../../../../supplierManage/videoDue/components/CorporateGoodwill/BigNews')
  },
  props: {
    details: {
      type: Object,
      default: () => {}
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      enterpriseNatureList: [],
      enterpriseNatureDetailList: [],
      holdingRatioList: [],
      equityHierarchyList: [],
      equityHierarchyDetailList: [],
      ruleForm: {
        enterpriseNature: '',
        enterpriseNatureDetail: '',
        involvingLitigationAccessCcount: '',
        administrativePenaltyAccessCcount: '',
        administrativePenaltyAmount: '',
        environmentalPenaltyAmount: '',
        administrativePenaltyAccess: '',
        administrativePenaltyAmountAccess: '',
        environmentalPenaltyAmountAccess: '',
        holdingRatio: '',
        equityHierarchy: '',
        equityHierarchyDetail: '',
        involvingLitigationAccess: '',
        regStocks: [],
        privateLendings: [],
        equityFreezeDataList: [],
        majorAnomalies: [],
        seriousIllegalData: [],
        taxOweNoticeData: [],
        taxIllegalData: [],
        blacklists: [],
        exceptionData: [],
        news: [],
        evaluationOpinions: ''
      },
      rules: {
        enterpriseNature: [
          { required: true, message: '请选择企业性质', trigger: 'change' }
        ],
        holdingRatio: [
          { required: true, message: '请选择国有国有控股比例', trigger: 'change' }
        ],
        equityHierarchy: [
          { required: true, message: '请选择股权层级', trigger: 'change' }
        ],
        equityHierarchyDetail: [
          { required: true, message: '请选择股权层级', trigger: 'change' }
        ],
        administrativePenaltyAccess: [
          { required: true, message: '请选择准入结论', trigger: 'change' }
        ],
        administrativePenaltyAmountAccess: [
          { required: true, message: '请选择准入结论', trigger: 'change' }
        ],
        environmentalPenaltyAmountAccess: [
          { required: true, message: '请选择准入结论', trigger: 'change' }
        ],
        involvingLitigationAccess: [
          { required: true, message: '请选择准入结论', trigger: 'change' }
        ],
        evaluationOpinions: [
          { required: true, message: '请输入项目评估意见', trigger: 'blur' }
        ]

      },
      tableData: [
        { userName: '1111', statusName: '2131231' },
        { userName: '1111', statusName: '2131231' }
      ],
      columns: [
        {
          label: '序号',
          index: true
        },
        {
          label: '股东名称',
          prop: 'stockName',
          showTooltip: true
        },
        {
          label: '股东类型',
          showTooltip: true,
          prop: 'stockType'
        },
        {
          label: '持股比例',
          prop: 'stockPercent'
        },
        {
          label: '认缴出资额(万元)',
          prop: 'shouldCapi'
        }
      ]
    }
  },
  watch: {
    details: {
      handler(newV) {
        if (newV && Object.keys(newV)) {
          const details = JSON.parse(JSON.stringify(newV))
          // this.ruleForm.corporateName = ownerInfo.corporateName
          // this.ruleForm.companyForProject = ownerInfo.companyForProject
          // this.ruleForm = { ...ownerInfo }
          for (const k in this.ruleForm) {
            if (details[k] !== undefined && details[k] !== '' && details[k] !== null) {
              this.ruleForm[k] = details[k]
            }
          }
          if (this.ruleForm.equityHierarchyDetail) {
            this.getequityHierarchyDetailList(this.ruleForm.equityHierarchy)
          }
        }
      },
      immediate: true,
      deep: true
    }
  },
  created() {
    this.getEnterpriseNatureList()
    this.getholdingRatioList()
    this.getequityHierarchyList()
  },
  methods: {
    // 提交参数
    passData(submitType) {
      return new Promise((resolve, reject) => {
        const {
          enterpriseNature,
          enterpriseNatureDetail,
          holdingRatio,
          equityHierarchy,
          equityHierarchyDetail,
          involvingLitigationAccessCcount,
          administrativePenaltyAccessCcount,
          administrativePenaltyAmount,
          environmentalPenaltyAmount,
          administrativePenaltyAccess,
          administrativePenaltyAmountAccess,
          environmentalPenaltyAmountAccess,
          involvingLitigationAccess,
          evaluationOpinions
        } = this.ruleForm
        const postData = {
          enterpriseNature,
          enterpriseNatureDetail,
          holdingRatio,
          equityHierarchy,
          equityHierarchyDetail,
          involvingLitigationAccessCcount,
          administrativePenaltyAccessCcount,
          administrativePenaltyAmount,
          environmentalPenaltyAmount,
          administrativePenaltyAccess,
          administrativePenaltyAmountAccess,
          environmentalPenaltyAmountAccess,
          involvingLitigationAccess,
          evaluationOpinions
        }
        // 民间借贷
        if (this.ruleForm.privateLendings.length) {
          const projectOwnerPrivateLendings = []
          const flag = this.$refs.privateLending.tableData.some(ele => {
            const obj = ele
            obj.cJudgmentDocumentsId = ele.id
            // delete obj.id
            projectOwnerPrivateLendings.push(obj)
            return ele.privateLending === null
          })
          postData.projectCoreEnterprisePrivateLendingList = projectOwnerPrivateLendings
          if (flag && submitType !== 'temp') {
            this.$message.warning({ message: '请选择是否有民间借贷', duration: 2000 })
            return false
          }
        }
        // 股权冻结
        if (this.ruleForm.equityFreezeDataList.length) {
          const projectOwnerEquityFreezes = []
          const flag = this.$refs.equityFreeze.tableData.some(ele => {
            const obj = ele
            obj.cEquityFreezeDataId = ele.id
            // delete obj.id
            projectOwnerEquityFreezes.push(obj)

            return ele.equityFreeze === null
          })
          postData.projectCoreEnterpriseEquityFreezeList = projectOwnerEquityFreezes
          if (flag && submitType !== 'temp') {
            this.$message.warning({ message: '请选择是否有股权冻结', duration: 2000 })
            return false
          }
        }
        // 重大异常诉讼
        if (this.ruleForm.majorAnomalies.length) {
          const projectOwnerMajorAbnormalLitigations = []
          const flag = this.$refs.majorAbnormalLitigation.tableData.some(ele => {
            const obj = ele
            obj.cJudgmentDocumentsId = ele.id
            // delete obj.id
            projectOwnerMajorAbnormalLitigations.push(obj)

            return ele.majorAbnormalLitigation === null
          })
          postData.projectCoreEnterpriseMajorAbnormalLitigationList = projectOwnerMajorAbnormalLitigations
          console.log(flag)
          if (flag && submitType !== 'temp') {
            this.$message.warning({ message: '请选择是否有重大异常诉讼', duration: 2000 })
            return false
          }
        }
        // 严重违法
        if (this.ruleForm.seriousIllegalData.length) {
          const projectOwnerSeriousIllegalities = []
          const flag = this.$refs.seriousIllegality.tableData.some(ele => {
            const obj = ele
            obj.cSeriousIllegalDataId = ele.id
            // delete obj.id
            projectOwnerSeriousIllegalities.push(obj)

            return ele.seriousIllegality === null
          })
          postData.projectCoreEnterpriseSeriousIllegalityList = projectOwnerSeriousIllegalities
          if (flag && submitType !== 'temp') {
            this.$message.warning({ message: '请选择是否有严重违法', duration: 2000 })
            return false
          }
        }
        // 欠税公告
        if (this.ruleForm.taxOweNoticeData.length) {
          const projectOwnerTaxOweNotices = []
          const flag = this.$refs.taxOweNotice.tableData.some(ele => {
            const obj = ele
            obj.cTaxOweNoticeDataId = ele.id
            // delete obj.id
            projectOwnerTaxOweNotices.push(obj)

            return ele.taxOweNotice === null
          })
          postData.projectCoreEnterpriseTaxOweNoticeList = projectOwnerTaxOweNotices
          if (flag && submitType !== 'temp') {
            this.$message.warning({ message: '请选择是否有欠税公告', duration: 2000 })
            return false
          }
        }
        // 税收违法
        if (this.ruleForm.taxIllegalData.length) {
          const projectOwnerTaxIllegalDataList = []
          const flag = this.$refs.taxIllegal.tableData.some(ele => {
            const obj = ele
            obj.cTaxIllegalDataId = ele.id
            // delete obj.id
            projectOwnerTaxIllegalDataList.push(obj)

            return ele.taxIllegal === null
          })
          postData.projectCoreEnterpriseTaxIllegalDataList = projectOwnerTaxIllegalDataList
          if (flag && submitType !== 'temp') {
            this.$message.warning({ message: '请选择是否有税收违法', duration: 2000 })
            return false
          }
        }
        // 黑名单信息
        if (this.ruleForm.blacklists.length) {
          const projectOwnerBlacklists = []
          const flag = this.$refs.blacklist.tableData.some(ele => {
            const obj = ele
            obj.cBlacklistId = ele.id
            // delete obj.id
            projectOwnerBlacklists.push(obj)

            return ele.blacklist === null
          })
          postData.projectCoreEnterpriseBlacklistList = projectOwnerBlacklists
          if (flag && submitType !== 'temp') {
            this.$message.warning({ message: '请选择是否有黑名单信息', duration: 2000 })
            return false
          }
        }
        // 其他经营异常
        if (this.ruleForm.exceptionData.length) {
          const projectOwnerExceptionDataList = []
          const flag = this.$refs.exception.tableData.some(ele => {
            const obj = ele
            obj.cExceptionDataId = ele.id
            // delete obj.id
            projectOwnerExceptionDataList.push(obj)

            return ele.exception === null
          })
          postData.projectCoreEnterpriseExceptionDataList = projectOwnerExceptionDataList
          if (flag && submitType !== 'temp') {
            this.$message.warning({ message: '请选择是否有其他经营异常', duration: 2000 })
            return false
          }
        }
        // 重大负面新闻舆情
        if (this.ruleForm.news.length) {
          const projectOwnerNewsList = []
          const flag = this.$refs.News.tableData.some(ele => {
            const obj = ele
            obj.cNewsId = ele.id
            // delete obj.id
            projectOwnerNewsList.push(obj)

            return ele.News === null
          })
          postData.projectCoreEnterpriseNewsList = projectOwnerNewsList
          if (flag && submitType !== 'temp') {
            this.$message.warning({ message: '请选择是否有重大负面新闻舆情', duration: 2000 })
            return false
          }
        }

        if (submitType === 'submit' || submitType === 'assess') {
          this.$refs.ruleFormRef.validate(valid => {
            if (valid) {
              return resolve(postData)
            } else {
              reject()
              return false
            }
          })
        } else {
          resolve(postData)
        }
      })
    },

    // 企业性质
    getEnterpriseNatureList() {
      getDictionaryInfo({ parentCode: 'enterpriseNature' }).then(res => {
        this.enterpriseNatureList = res.data
      })
    },
    // 企业性质细分
    getProjectNatureDetailList(v) {
      // this.ruleForm.enterpriseNatureDetail = ''
      this.enterpriseNatureDetailList = []
      getDictionaryInfo({ parentCode: v }).then(res => {
        this.enterpriseNatureDetailList = res.data
      })
    },
    // 国有国有控股比例
    getholdingRatioList() {
      // this.ruleForm.enterpriseNatureDetail = ''
      this.holdingRatioList = []
      getDictionaryInfo({ parentCode: 'holdingRatio' }).then(res => {
        this.holdingRatioList = res.data
      })
    },
    // 股权层级
    getequityHierarchyList() {
      this.equityHierarchyList = []
      getDictionaryInfo({ parentCode: 'equityHierarchy' }).then(res => {
        this.equityHierarchyList = res.data
      })
    },
    // 股权层级细分
    getequityHierarchyDetailList(v) {
      // this.ruleForm.enterpriseNatureDetail = ''
      this.equityHierarchyDetailList = []
      getDictionaryInfo({ parentCode: v }).then(res => {
        this.equityHierarchyDetailList = res.data
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.auditing-box {
padding: 10px 15px;
}
</style>
