<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: {
        is_used:"",
        department_id: "",
        number: "",
        name: "",
        model: "",
        outside:"",
        torque:"",
        stress:"",
        bolt_size:"",
        bolt_number:"",
        install_position:"",
        brand:"",
        supplier:"",
        out_date:"",
        remark: "",
      }, 
      url: "flange",
      formConfig: {
        formDesc: {
           is_used: {
            type: "select",
            label: "使用状态",
            isOptions: true,
            options: [
              {
                text: "使用",
                value: 1
              },
              {
                text: "未使用",
                value: -1
              },
              {
                text: "已废弃",
                value: -2
              }
            ]
          },
          
           department_id: {
            type: "cascader",
            label: "所属部门",
            isOptions: true,
            options: [],
            required: true,
            attrs: {
              props: {
                label: "department_name",
                value: "id",
                emitPath: false,
                checkStrictly: true

              }
            }
          },
          //风场id
          fan_id:{
              type: "cascader",
              label: "风机编号",
              isOptions: true,
              options: [],
              required: true,
              attrs: {
                //查询
                filterable:true,
                props: {
                  label: "text",
                  value: "value",
                  emitPath: false,
                  checkStrictly: false,
                  multiple:false
                }
            }

          },
          number: {
            type: "input",
            label: "编号",
           
          },
           name: {
            type: "input",
            label: "名称",
            required:true
          },
          model: {
            type: "select",
            label: "型号",
            required:true,
            isOptions: true,
            options:[]
          },
           outside:{
            type: "input",
            label: "外径"
          },
           torque:{
             type: "number",
             label: "扭矩",
             required:true,
             rules: [
              {
                type: "number",
                trigger: "blur",

              }
            ]
          },
          stress:{
             type: "number",
             label: "压力",
              rules: [
              {
                type: "number",
                trigger: "blur",
                message: "必须是数字"
              }
            ]
          },
          bolt_size: {
             type: "number",
             label: "螺栓尺寸",
             rules: [
              {
                type: "number",
                trigger: "blur",
                message: "必须是数字"
              }
            ]
          },
           bolt_number: {
             type: "number",
             label: "螺栓数量",
             rules: [
              {
                type: "number",
                trigger: "blur",
                message: "必须是数字"
              }
            ]
          },
          install_position:{
            type: "input",
            label: "安装位置"
          },
           brand: {
            type: "input",
            label: "品牌"
          },
           supplier: {
            type: "input",
            label: "供应商"
          },
            out_date: {
            type: "date",
            label: "出厂日期"
          },
          remark: {
            type: "textarea",
            label: "备注"
          }
        },
        order: ["is_used","department_id","fan_id","number", "name", "model","outside","torque","stress","bolt_size","bolt_number","install_position","brand","supplier","out_date","remark"]
      }
    };
  },
  created() {
    this.$http.get("departments").then(response => {
      this.formConfig.formDesc.department_id.options = response.data;
    });
  
     this.$http.get("getwindfan").then(response => {
      this.formConfig.formDesc.fan_id.options = response.data;
    });
    this.$http.get("devicetype").then(response => {
      this.formConfig.formDesc.model.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>
