<template>
  <div>
    <Editor v-model:value="purchaseNotice" className="h-[70vh]" />
    <div class="flex items-center justify-end mt-4">
      <el-button @click="clearPurchaseNotice">清空内容</el-button>
      <el-button type="primary" @click="savePurchaseNotice">保存</el-button>
    </div>
  </div>
</template>
<script setup>
import { ref } from "vue";
import { request } from "@/utils";
import Editor from "@/components/Editor.vue";
import { ElMessage, ElMessageBox} from 'element-plus';

import { useUserStoreHook } from "@/store/modules/user";
const mechanismId = useUserStoreHook()?.profile.id;
const purchaseNotice = ref("");
const getPurchaseNotice = async () => {
  const { data } = await request.get(
    `/articleService/open/serviceProvider/purchaseNotice`,
    {
      params: {
        mechanismId
      }
    }
  );
  purchaseNotice.value = data.notice || "";
};
getPurchaseNotice();

const savePurchaseNotice = async () => {
  await request.post(`/articleService/serviceProvider/purchaseNotice`, {
    mechanismId,
    notice:
      purchaseNotice.value == "<p><br></p>" ? "" : purchaseNotice.value
  });
  ElMessage.success("保存成功");
};
const clearPurchaseNotice = async () => {
  await ElMessageBox.confirm(`确定要清空内容吗？`, "提示", {
    type: "warning"
  });
  await request.post(`/articleService/serviceProvider/purchaseNotice`, {
    mechanismId,
    notice: ""
  });
  ElMessage.success("清空成功");
};
</script>

<style lang="scss" scoped></style>
