<template>
  <el-dialog title="生产激活码" v-model="dialogVisible" width="500px" @close="reset">
    <el-form :model="form" :rules="rules" label-width="100px" label-position="left">
      <el-form-item label="激活时长" prop="periodMonth">
        <el-input-number
          v-model="form.periodMonth"
          controls-position="right"
          :min="1"
          :step="1"
          step-strictly
        ></el-input-number>
      </el-form-item>
      <el-form-item label="生产数量" prop="num">
        <el-input-number
          v-model="form.num"
          controls-position="right"
          :min="1"
          :step="1"
          step-strictly
        ></el-input-number>
      </el-form-item>
      <!-- <el-form-item label="所属代理" prop="agent">
                <el-input v-model="form.agent" placeholder="请输入完整的代理账号查找"></el-input>
            </el-form-item> -->
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" v-loading="loading" @click="tbMerchantRegisterPost">
          生产激活码
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import RegisterApi from "@/api/account/register";

export default {
  data() {
    return {
      dialogVisible: false,
      loading: false,
      form: {
        periodMonth: 1,
        num: 1,
        agent: "",
      },
      rules: {
        periodMonth: [
          {
            required: true,
            message: " ",
            trigger: "blur",
          },
        ],
        num: [
          {
            required: true,
            message: " ",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    async tbMerchantRegisterPost() {
      try {
        this.loading = true;
        const res = await RegisterApi.add(this.form);
        this.$emit("success", res);
        this.close();
        this.$notify({
          title: "成功",
          message: `添加成功`,
          type: "success",
        });
        this.loading = false;
      } catch (error) {
        this.loading = false;
        console.log(error);
      }
    },
    show() {
      this.dialogVisible = true;
    },
    close() {
      this.dialogVisible = false;
    },
    reset() {
      this.form.periodMonth = 1;
      this.form.num = 1;
      this.form.agent = "";
    },
  },
};
</script>