<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 v-if="form.DICTIONARY_LEVEL === 2" label="所属标准类别" prop="PARENT_NAME">
        <el-input id="PARENT_NAME" ref="PARENT_NAME" v-model="form.PARENT_NAME" disabled maxlength="255" placeholder="这里输入所属标准类别..." title="所属标准类别"/>
      </el-form-item>
      <el-form-item :label="label.DICTIONARY_NAME" prop="DICTIONARY_NAME">
        <el-input id="DICTIONARY_NAME" ref="DICTIONARY_NAME" v-model="form.DICTIONARY_NAME" :placeholder="'这里输入'+label.DICTIONARY_NAME+'...'" :title="label.DICTIONARY_NAME" maxlength="255"/>
      </el-form-item>
      <el-form-item label="排序" prop="DICTIONARY_SORT">
        <el-input-number :min="1" :precision="0" v-model="form.DICTIONARY_SORT" style="width: 100%;" controls-position="right" autocomplete="off" placeholder="这里输入排序..." />
      </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: '停用' }
      ],
      label: {
        DICTIONARY_NAME: ''
      },
      form: {
        DICTIONARY_ID: '',
        DICTIONARY_NAME: '',
        PARENT_ID: '',
        PARENT_IDS: '',
        PARENT_NAME: '',
        DICTIONARY_NAMES: '',
        DICTIONARY_LEVEL: '',
        DICTIONARY_SORT: '',
        DICTIONARY_SOURCE: ''
      },
      rules: {
        DICTIONARY_NAME: [{ required: true, message: '类目名称不能为空', trigger: 'blur' }],
        DICTIONARY_SORT: [{ required: true, message: '排序不能为空', trigger: 'blur' }]
      },
      listQuery: {
        page: 1,
        limit: 10
      },
      visible: false,
      info: {}
    }
  },
  methods: {
    init(e) {
      this.visible = true
      if (e) {
        this.dialogType = 'edit'
        this.form = e
        if (this.form.DICTIONARY_LEVEL === 2) {
          this.label.DICTIONARY_NAME = '标准项目'
          this.$set(this.form, 'PARENT_NAME', this.form.DICTIONARY_NAMES.substr(0, this.form.DICTIONARY_NAMES.lastIndexOf(',')))
          this.rules.DICTIONARY_NAME = [{ required: true, message: '标准项目不能为空', trigger: 'blur' }]
        } else {
          this.label.DICTIONARY_NAME = '标准类别'
          this.rules.DICTIONARY_NAME = [{ required: true, message: '标准类别不能为空', trigger: 'blur' }]
        }
        console.log(this.form)
      }
    },
    confirm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.loading = true

          requestFN(
            '/hiddenDangerCheckStandardDictionary/' + 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: '',
        DICTIONARY_NAME: '',
        COMMON_STATUS: ''
      }
    },
    close() {
      this.resetForm()
      this.visible = false
    },
    getDicTree() {
    }
  }
}

</script>
