<template>
  <el-dialog v-if="visible" :visible.sync="visible" :title="title" width="600px" @close="close">
    <el-form v-loading="loading" ref="form" :rules="rules" :model="form" label-width="110px" style="width: 500px;">
      <el-form-item label="行业类型" prop="INDUSTRY_TYPE_ARR">
        <cascader-dict
          ref="refIndustryType"
          v-model = "form.INDUSTRY_TYPE_ARR"
          :form.sync="form"
          :dict-id = "dictId"
          @cascaderNames="cascaderNames"
        />
      </el-form-item>
      <el-form-item label="标准名称" prop="CHECK_STANDARD_NAME">
        <el-input id="CHECK_STANDARD_NAME" ref="CHECK_STANDARD_NAME" v-model="form.CHECK_STANDARD_NAME" maxlength="255" placeholder="这里输入标准名称..." title="标准名称"/>
      </el-form-item>
      <el-form-item label="状态" prop="COMMON_STATUS">
        <el-select v-model="form.COMMON_STATUS" placeholder="状态" style="width: 100px" class="filter-item">
          <el-option v-for="item in commonStatusList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="confirm">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves'
import CascaderDict from '../../../../components/CascaderDict'
export default {
  components: { CascaderDict },
  directives: { waves },
  props: {
    title: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      loading: false,
      dialogType: 'add',
      dictId: 'f2598ba72e864eadabf0ca4b664d26b9', // 行业类型
      commonStatusList: [
        { id: 1, name: '有效' },
        { id: 2, name: '停用' }
      ],
      form: {
        COMMON_ID: '',
        INDUSTRY_TYPE_ARR: [],
        INDUSTRY_TYPE_TREE: '',
        CHECK_STANDARD_NAME: '',
        COMMON_STATUS: ''
      },
      rules: {
        INDUSTRY_TYPE_ARR: [{ required: true, message: '行业类型不能为空', trigger: 'blur' }],
        CHECK_STANDARD_NAME: [{ required: true, message: '标准名称不能为空', trigger: 'blur' }],
        COMMON_STATUS: [{ required: true, message: '状态不能为空', trigger: 'blur' }]
      },
      listQuery: {
        page: 1,
        limit: 10
      },
      corp_info_list: [],
      risk_unit_list: [],
      visible: false,
      info: {}
    }
  },
  methods: {
    init(e) {
      this.visible = true
      if (e) {
        this.dialogType = 'edit'
        this.form = e
        this.$set(this.form, 'INDUSTRY_TYPE_ARR', this.form.INDUSTRY_TYPE_TREE ? this.form.INDUSTRY_TYPE_TREE.split(',') : [])
        console.log(this.form)
      }
    },
    cascaderNames(e) {
      this.form.INDUSTRY_TYPE_NAMES = e
    },
    confirm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.loading = true
          this.form.INDUSTRY_TYPE = this.form.INDUSTRY_TYPE_ARR[this.form.INDUSTRY_TYPE_ARR.length - 1]
          this.form.INDUSTRY_TYPE_TREE = this.form.INDUSTRY_TYPE_ARR.join(',')

          requestFN(
            '/hiddenDangerCheckStandardCommon/' + this.dialogType,
            this.form
          ).then((data) => {
            this.loading = false
            this.close()
            this.$emit('beforeClose', '')
            this.$message.success('操作成功')
          }).catch((e) => {
            this.loading = false
          })
        } else {
          return false
        }
      })
    },
    resetForm() {
      // this.$refs.refIndustryType.clearNodes()
      this.form = {
        COMMON_ID: '',
        INDUSTRY_TYPE_ARR: [],
        INDUSTRY_TYPE_TREE: '',
        CHECK_STANDARD_NAME: '',
        COMMON_STATUS: ''
      }
    },
    close() {
      this.resetForm()
      this.visible = false
    },
    getDicTree() {
    }
  }
}

</script>
