<template>
  <ele-form-dialog
    v-bind="formConfig"
    v-model="formFieldsData"
    v-dialogDrag
    :title="title"
    :request-fn="handleFormSubmit"
    :visible.sync="DialogVisible"
    width="450px"
    custom-class="abow_dialog"
    label-width="100px"
    label-position="left"
    :dialogAttrs="{ 'close-on-click-modal': false,'top':'8vh'}"
  />
</template>

<script>
export default {
  props: ["formModelVisible", "title"],
  data() {
    return {
      formData: {},
      formFieldsData: {
        department_id: "",
        number: "",
        name: "",
        model: "",
        brand:"",
        supplier:"",
        out_date:"",
        remark: "",
        type:2
      },
      url: "hydraulic",
      formConfig: {
        formDesc: {
          department_id: {
            type: "cascader",
            label: "所属部门",
            isOptions: true,
            options: [],
            required: true,
            attrs: {
              props: {
                label: "department_name",
                value: "id",
                emitPath: false,
                checkStrictly: true
              }
            }
          },
          number: {
            type: "input",
            label: "编号",
            required:true,
          },
           name: {
            type: "input",
            label: "名称",
            required:true
          },
          model: {
            type: "input",
            label: "型号",
            required:true
          },
           brand: {
            type: "input",
            label: "品牌"
          },
           supplier: {
            type: "input",
            label: "供应商"
          },
            out_date: {
            type: "date",
            label: "出厂日期"
          },
          remark: {
            type: "textarea",
            label: "备注"
          }
        },
        order: ["department_id","number", "name", "model","brand","supplier","out_date","remark"]
      }
    };
  },
  created() {
    this.$http.get("departments").then(response => {
      this.formConfig.formDesc.department_id.options = response.data;
    });
  },
  methods: {
    handleFormSubmit(data) {
      this.$parent.handleSubmit();
    },
    handleRequest(data) {
      return Promise.resolve();
    },
    handleRequestSuccess() {
      this.$message.success("发送成功");
    }
  },
  computed: {
    DialogVisible: {
      set(val) {
        this.$emit("sendVal", val); // 表示将子组件改变的值传递给父组件
      },
      get() {
        return this.formModelVisible; // 表示获取父组件的值
      }
    }
  }
};
</script>