<template>
  <div class="shareholder">
    <el-form
      ref="ruleForm"
      :rules="rules"
      :model="ruleForm"
      label-position="top"
      label-width="150px"
      class="rule-form-orange"
    >
      <el-form-item
        label="指标名称"
        style="width: 100%"
      >
        <el-input v-model="title" disabled placeholder="请输入指标名称" />
      </el-form-item>
      <div style="width: 100%">
        <cy-comm-table
          ref="commTable"
          :columns="columns"
          :data="defaultDatailsInfo.regStocks"
        />
      </div>
      <el-form-item
        label="法定代表人"
      >
        <el-input v-model="defaultDatailsInfo.legalRepresentative" disabled placeholder="请输入法定代表人" />
      </el-form-item>
      <el-form-item
        label="年龄"
      >
        <el-input v-model="defaultDatailsInfo.age" disabled placeholder="请输入年龄" />
      </el-form-item>
      <el-form-item
        label="标准分值"
      >
        <el-input v-model="defaultDatailsInfo.shareholderStandardScore" disabled placeholder="请输入标准分值" />
      </el-form-item>
      <el-form-item
        label="测算分值"
      >
        <el-input v-model="defaultDatailsInfo.shareholderMeasurementScore" disabled placeholder="请输入测算分值" />
      </el-form-item>
      <el-form-item
        label="问题"
        prop="shareholderQuestion"
        class="two-form-item"
      >
        <el-input v-model="ruleForm.shareholderQuestion" type="textarea" :disabled="disabled" placeholder="请输入问题" />
      </el-form-item>
      <el-form-item
        label=" 尽调反馈"
        prop="shareholderFeedback"
        style="width: 100%;"
      >
        <unified-editor :content.sync="ruleForm.shareholderFeedback" :disabled="disabled" />
        <cy-upload
          ref="fileStorage"
          :upload-params="{}"
          :file-data="shareholderFile"
          :upload-from-orange-status="true"
          placeholder="请上传附件"
          :disabled="disabled"
        />
      </el-form-item>
      <el-form-item
        label="准入结论"
        prop="shareholderConclusion"
        style="width: 100%"
      >
        <el-select v-model="ruleForm.shareholderConclusion" :disabled="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>
  </div>
</template>

<script>
import bus from '@/utils/eventBus'
export default {
  components: {
    UnifiedEditor: () => import('@/components/UnifiedEditor/index.vue')
  },
  inject: ['datailsInfo', 'disabled', 'submitType'],
  data() {
    return {
      title: '股东',
      ruleForm: {
        shareholderFeedback: '',
        shareholderConclusion: '',
        shareholderQuestion: ''
      },
      rules: {
        shareholderConclusion: [
          { required: true, message: '请选择准入结论', trigger: 'change' }
        ]
      },
      shareholderFile: [],
      tableData: [],
      columns: [
        {
          label: '序号',
          index: true,
          width: '200'
        },
        {
          label: '股东名称',
          prop: 'stockName',
          showTooltip: true
        },
        {
          label: '持股比例',
          showTooltip: true,
          prop: 'stockPercent'
        }]
    }
  },
  computed: {
    defaultDatailsInfo() {
      return this.datailsInfo.value
    }
  },
  watch: {
    datailsInfo: {
      handler(newV) {
        if (newV.value === undefined) return
        if (newV && Object.keys(newV).length) {
          const { shareholderQuestion, shareholderFile, shareholderConclusion, shareholderFeedback } = newV.value
          this.ruleForm.shareholderQuestion = shareholderQuestion
          this.ruleForm.shareholderConclusion = shareholderConclusion
          this.ruleForm.shareholderFeedback = shareholderFeedback
          this.shareholderFile = shareholderFile || []
        }
      },
      deep: true,
      immediate: true
    }
  },
  mounted() {
    bus.on('shareholderParmas', (cb, parmas) => {
      cb(this.getParams())
    })
  },
  methods: {
    getParams() {
      return new Promise((resolve, reject) => {
        const fileList = this.$refs.fileStorage.getFileLists
        const params = {
          ...this.ruleForm,
          shareholderFileIds: fileList.map(item => item.id)
        }
        if (this.submitType() === 'temp') {
          resolve(params)
        } else {
          this.$refs.ruleForm.validate(valid => {
            if (valid) {
              resolve(params)
            } else {
              reject()
              return false
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.shareholder {

}
</style>
