<template>
  <el-dialog title="激活" width="550px" v-model="show" @close="reset">
    <el-form :model="form" ref="refForm" :rules="rules">
      <el-form-item label="激活时长" prop="activateDuration">
        <activeDate v-model="form.activateDuration" v-model:activeCost="form.activateAmount" />
        <!-- <el-input v-model="form.activateDuration" 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";
import activeDate from "./activeDate.vue";

const show = ref(false);
const form = reactive({
  activateDuration: "",
  activateAmount: '',
  id: "",
});
const rules = {
  activateDuration: [{ required: true, message: "请选择激活时长", trigger: "blur" }],
};

function reset() {
  form.activateDuration = "";
  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>