<template>
  <el-dialog :close-on-click-modal="false" v-dialogDrag rechargeTypeId="form" :title="title" :visible.sync="dialogFormVisible" :before-close="handleClose">
    <el-form :model="form" :rules="rules" ref="form" label-width="120px">
      <el-form-item label="等级编码：" prop="classNum">
        <el-input ref="classNum" class="form-width" v-model="form.classNum" autocomplete="on"></el-input>
      </el-form-item>
      <el-form-item label="等级名称：" prop="className">
        <el-input class="form-width" v-model="form.className" autocomplete="on"></el-input>
      </el-form-item>
      <el-form-item label="制度：" prop="statisticsQuarter">
        <el-radio-group v-model="form.statisticsQuarter">
          <el-radio :label="0">月度</el-radio>
          <el-radio :label="1">半年度</el-radio>
          <el-radio :label="2">一年度</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="等级编号：" prop="classRow">
        <el-input class="form-width" type="number" placeholder="请输入等级编号" pattern="[0-9]*\" v-model="form.classRow" autocomplete="on"></el-input>
      </el-form-item>
      <el-form-item label="充值标准：" prop="rechargeStandard">
        <el-input class="form-width" type="number" placeholder="请输入充值标准" pattern="[0-9]*\" v-model="form.rechargeStandard" autocomplete="on"></el-input>
      </el-form-item>
      <el-form-item label="疗程标准：" prop="courseStandard">
        <el-input class="form-width" type="number" placeholder="请输入疗程标准" pattern="[0-9]*\" v-model="form.courseStandard" autocomplete="on"></el-input>
      </el-form-item>
      <el-form-item label="收银标准：" prop="cashDecimal">
        <el-input class="form-width" type="number" placeholder="请输入收银标准" pattern="[0-9]*\" v-model="form.cashDecimal" autocomplete="on"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" type="primary" plain @click="handleClose">取 消</el-button>
      <el-button size="mini" type="primary" @click="confirm">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { addMemberClass, editMemberClass } from "@/api/storeManage.js";
export default {
  data() {
    return {
      rules: {
        classNum: {
          required: true,
          message: "请输入等级编码",
          trigger: ["blur", "change"],
        },
        className: {
          required: true,
          message: "请输入等级名称",
          trigger: ["blur", "change"],
        },
        statisticsQuarter: {
          required: true,
          message: "请选择等级制度",
          trigger: ["blur", "change"],
        },

        rechargeStandard: {
          required: true,
          message: "请输入充值标准",
          trigger: ["blur", "change"],
        },
        classRow: {
          required: true,
          message: "请输入等级编号",
          trigger: ["blur", "change"],
        },
        courseStandard: {
          required: true,
          message: "请输入疗程标准",
          trigger: ["blur", "change"],
        },

        cashDecimal: {
          required: true,
          message: "请输入收银标准",
          trigger: ["blur", "change"],
        },
      },
      form: {}, //主对象
      title: "", //弹窗标题
      dialogFormVisible: false, //弹窗开关
    };
  },
  methods: {
    //关闭弹窗前的回调方法
    handleClose() {
      this.form = {};
      this.dialogFormVisible = false;
      this.$refs.form.clearValidate();
    },
    //组件传值
    show(text, form) {
      this.title = text;
      this.form = {};
      if (text == "修改") {
        this.form = { ...form };
      }
      setTimeout(() => {
        this.$refs.classNum.focus();
        this.$refs.classNum.select();
      }, 300);
      this.dialogFormVisible = true;
    },
    //确定返回方法
    confirm() {
      if (this.title == "添加") {
        addMemberClass(this.form)
          .then((res) => {
            if (res.code == "000000") {
              this.$emit("editData");
              this.dialogFormVisible = false;
              this.$message.success({
                message: "数据添加成功!",
              });
            } else {
              this.$alert(res.message, "提示", {
                confirmButtonText: "确定",
                confirmButtonClass: "confirmbtnFalses",
                type: "warning",
                center: true,
                callback: (action) => {},
              });
            }
          })
          .catch((err) => {
            //console.log(err);
          });
      } else {
        editMemberClass(this.form).then((res) => {
          if (res.code == "000000") {
            this.$emit("editData");
            this.dialogFormVisible = false;
            this.$message.success({
              message: res.message,
            });
          } else {
            this.$alert(res.message, "提示", {
              confirmButtonText: "确定",
              confirmButtonClass: "confirmbtnFalses",
              type: "warning",
              center: true,
              callback: (action) => {},
            });
          }
        });
      }
    },
  },
};
</script>

<style>
</style>
