<template>
  <!-- 添加或修改部门对话框 -->
  <el-dialog
    :title="title"
    :visible.sync="open"
    width="500px"
    append-to-body
    :close-on-click-modal="false"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="性别" prop="gender">
            <el-radio-group v-model="form.gender">
              <el-radio :label="1">男</el-radio>
              <el-radio :label="2">女</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="身高" prop="height">
            <el-input v-model="form.height" placeholder="请输入身高">
              <template slot="suffix">cm</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="体重" prop="weight">
            <el-input v-model="form.weight" placeholder="请输入体重">
              <template slot="suffix">kg</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="年龄" prop="age">
            <el-input v-model="form.age" placeholder="请输入年龄" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>
  
<script>
import { isNum, isNumber, isInteger } from "@/utils/validate.js";
export default {
  data() {
    const checkIsNum = (rule, value, callback) => {
      if (!isNum(value) || value < 50) {
        callback(new Error("请输入正确的数字"));
      } else {
        callback();
      }
    };
    const checkIsNumber = (rule, value, callback) => {
      if (!isNumber(value) || value < 5) {
        callback(new Error("请输入正确的数字"));
      } else {
        callback();
      }
    };
    const checkIsInteger = (rule, value, callback) => {
      if (!isInteger(value)) {
        callback(new Error("请输入正确的数字"));
      } else {
        callback();
      }
    };
    return {
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
      },
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        gender: [{ required: true, message: "请选择性别", trigger: "change" }],
        height: [
          {
            required: true,
            message: "身高不能为空",
            trigger: ["blur", "change"],
          },
          { validator: checkIsNum, trigger: ["blur", "change"] },
        ],
        weight: [
          {
            required: true,
            message: "体重不能为空",
            trigger: ["blur", "change"],
          },
          { validator: checkIsNumber, trigger: ["blur", "change"] },
        ],
        age: [
          { required: true, message: "年龄不能为空", trigger: "change" },
          { validator: checkIsInteger, trigger: ["blur", "change"] },
        ]
      },
    };
  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        deviceid: undefined,
        gender: undefined,
        height: undefined,
        weight: undefined,
        age: undefined,
      };
      this.resetForm("form");
    },
    /** 修改按钮操作 */
    handleSet(deviceId) {
      this.reset();
      this.form.deviceid = deviceId;
      this.open = true;
      this.title = "下发用户";
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.deviceid != undefined) {
            // updateDept(this.form).then(response => {
            //   this.msgSuccess("修改成功");
            //   this.open = false;
            //   this.getList();
            // });
          }
        }
      });
    },
  },
};
</script>
  
<style lang="sass" scoped>
</style>