<template>
  <el-dialog :close-on-click-modal="false" v-dialogDrag rechargeTypeId="form" :title="title" :visible.sync="dialogFormVisible">
    <el-form :model="form" :rules="rules" ref="form" label-width="120px">
      <el-form-item label="编码：" prop="rechargeTypeNum">
        <div>
          {{form.courseProjectNum}}{{form.rechargeTypeNum}}
        </div>
      </el-form-item>
      <el-form-item label="名称：" prop="rechargeTypeName">
        <div>
          {{form.courseProjectName}}{{form.rechargeTypeName}}
        </div>
      </el-form-item>
      <el-form-item label="到期日期：" prop="discount">
        <el-date-picker v-model="form.endTime" type="date" value-format="yyyy-MM-dd" placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" type="primary" plain @click="dialogFormVisible = false">取 消</el-button>
      <el-button size="mini" type="primary" @click="confirm">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { editCouAccount, editRecAccount } from "@/api/eashier.js";
export default {
  data() {
    return {
      rules: {
        rechargeTypeName: {
          required: true,
          message: "请输入充值名称",
          trigger: ["blur", "change"],
        },
        rechargeTypeNum: {
          required: true,
          message: "请输入充值编码",
          trigger: ["blur", "change"],
        },
        rechargeMoney: {
          required: true,
          message: "请输入充值金额",
          trigger: ["blur", "change"],
        },
      },
      form: {}, //主对象
      title: "", //弹窗标题
      dialogFormVisible: false, //弹窗开关
    };
  },
  methods: {
    //组件传值
    show(form) {
      this.title = "帐户延期";
      this.form = { ...form };
      this.dialogFormVisible = true;
    },
    //确定返回方法
    confirm() {
      var form = {
        id: this.form.id,
        endTime: this.form.endTime,
      };
      if (this.form.rechargeTypeName) {
        editRecAccount(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 {
        editCouAccount(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>
