<template>
  <div>
    <el-dialog
      :before-close="handleClose"
      :close-on-click-modal="false"
      :title="title + '资料分类'"
      :visible="visible"
      custom-class="bbsl-location-dialog"
      top="25vh"
      width="40%"
    >
      <div>
        <el-form
          ref="formInfo"
          :model="this.parameter"
          :rules="rules"
          label-position="top"
          label-width="150px"
        >
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="资料分类名称" prop="name">
                <el-input
                  v-model="parameter.name"
                  clearable
                  placeholder="请输入资料分类名称"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="资料分类编码" prop="code">
                <el-input
                  v-model="parameter.code"
                  clearable
                  placeholder="请输入资料分类编码"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- <el-row :gutter="24">
              <el-col :span="24">
                <el-form-item label="备注：" prop="">
                  <el-input
                    clearable
                    type="textarea"
                    :rows="2"
                    placeholder="请输入备注"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row> -->
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleSave">确认</el-button>
        <el-button @click="handleClose">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import zlflMenu from '@/api/examination/zlflMenu.js'

export default {
  name: 'equSysMenuDialog',
  data() {
    return {
      title: '新增',
      visible: false,
      parameter: {
        code: '',
        name: ''
      },
      rules: {
        code: [
          {
            required: true,
            message: '请输入资料分类编码',
            trigger: 'blur'
          }
        ],
        name: [
          {
            required: true,
            message: '请输入资料分类名称',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  created() {},
  mounted() {},
  methods: {
    add(id) {
      this.title = '新增'
      this.visible = true
      this.parameter.parentId = id
    },
    edit(val) {
      this.parameter = val
      this.title = '修改'
      this.visible = true
    },
    // 关闭新增人员窗口
    handleClose() {
      this.visible = false
      this.title = '新增'
      this.parameter = {
        children: [],
        code: '',
        name: '',
        parentId: ''
      }
    },
    // 保存产品类型
    handleSave() {
      this.$refs.formInfo.validate(valid => {
        if (valid) {
          let method
          if (this.title === '新增') {
            method = zlflMenu.addMaterial
          }
          if (this.title === '修改') {
            method = zlflMenu.editMaterial
          }
          method(this.parameter, response => {
            if (response.state) {
              this.$notify({
                type: 'success',
                message: this.title + '成功',
                duration: 2000
              })
              this.handleClose()
              this.$emit('reload')
            } else {
              this.$message.warning(response.message)
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
