<template>
  <el-dialog title="激活码" width="500px" v-model="show" @close="reset">
    <el-form :model="form" ref="refForm" :rules="rules">
      <el-form-item label="激活码" prop="activateCode">
        <el-input v-model="form.activateCode" placeholder="请输入激活码"></el-input>
        <div class="tips">注：输入有效激活码表示添加的同时直接激活该店铺。</div>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="submit">确定</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import ShopApi from "@/api/account/shop";

const show = ref(false);
const form = reactive({
  activateCode: "",
  id: "",
});
const rules = {
  activateCode: [{ required: true, message: "请输入激活码", trigger: "blur" }],
};

function reset() {
  form.activateCode = "";
  form.id = "";
}
const emit = defineEmits(["submit"]);
const refForm = ref();
function submit() {
  refForm.value.validate((valid) => {
    if (valid) {
      ShopApi.edit(form).then(() => {
        ElNotification({
          title: "成功",
          message: "操作成功",
          type: "success",
        });
        emit("success");
        close();
      });
    }
  });
}
function close() {
  show.value = false;
}
function open(obj) {
  form.id = obj.id;
  show.value = true;
}
defineExpose({
  open,
  close,
});
</script>