<template>
  <div class="industry">
    <el-form
      ref="ruleForm"
      :rules="rules"
      :model="ruleForm"
      label-position="top"
      class="rule-form-orange"
    >
      <el-form-item
        label="指标名称"
        style="width: 100%"
      >
        <el-input v-model="title" disabled placeholder="请输入指标名称" />
      </el-form-item>
      <el-form-item
        label="所属行业"
        style="width: 100%"
      >
        <el-input v-model="defaultDatailsInfo.industry" disabled placeholder="请输入所属行业" />
      </el-form-item>
      <el-form-item
        label="问题"
        style="width: 100%;"
      >
        <el-input v-model="ruleForm.industryQuestion" type="textarea" placeholder="请输入问题" :disabled="disabled" />
      </el-form-item>
      <el-form-item
        label=" 尽调反馈"
        style="width: 100%;"
      >
        <unified-editor :content.sync="ruleForm.industryFeedback" :disabled="disabled" />
        <cy-upload
          ref="fileStorage"
          :upload-params="{}"
          :file-data="industryFile"
          :upload-from-orange-status="true"
          placeholder="请上传附件"
          :disabled="disabled"
        />
      </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: {
        industryQuestion: '',
        industryFeedback: ''
      },
      industryFile: [],
      rules: {
        capitalConclusion: [
          { required: true, message: '请选择准入结论', trigger: 'change' }
        ]
      }
    }
  },
  computed: {
    defaultDatailsInfo() {
      return this.datailsInfo.value
    }
  },
  watch: {
    datailsInfo: {
      handler(newV) {
        const { industryQuestion, industryFeedback, industryFile } = newV.value
        this.ruleForm = {
          industryQuestion,
          industryFeedback
        }
        this.industryFile = industryFile || []
      },
      deep: true,
      immediate: true
    }
  },
  mounted() {
    bus.on('industryParams', (cb) => {
      cb(this.getParams())
    })
  },
  methods: {
    getParams() {
      return new Promise((resolve, reject) => {
        const fileList = this.$refs.fileStorage.getFileLists
        const params = {
          ...this.ruleForm,
          industryFileIds: 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>
.industry {

}
</style>
