<template>
  <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose :title="title" :width="800"
              @ok="handleSubmit">
    <a-card :bordered="false" :body-style="{padding:0}" style="width:100%;min-height:60vh">
      <div class="tip">
        <section class="top">
          <h1>SEO月报模板优化话术</h1>
        </section>
        <a-col>
          <h2 class="title mb">当月优化话术</h2>
          <div class="num-suffix">
            <a-textarea :maxlength="1000" showCount :rows="10" placeholder="请输入"
                        v-model:value="currentMonthPlanText"
            ></a-textarea>
          </div>
        </a-col>
        <a-col>
          <h2 class="title mb">下月优化话术</h2>
          <div class="num-suffix">
            <a-textarea :maxlength="1000" showCount :rows="10" placeholder="请输入"
                        v-model:value="nextMonthPlanText"
            ></a-textarea>
          </div>
        </a-col>
      </div>
      <!--    <div style="background-color: white;height:100vh;z-index: -1;"></div>-->
    </a-card>
  </BasicModal>
</template>

<script lang="ts" setup>
import { ref, computed, unref, onMounted } from "vue";
import { BasicModal, useModalInner } from "/@/components/Modal";
import { BasicForm, useForm } from "/@/components/Form/index";
import { formSchema } from "../SeoPdfExport.data";
import { saveOrUpdate } from "../SeoPdfExport.api";
import { getAction } from "@/api/manage/manage";
// Emits声明
const emit = defineEmits(["register", "success"]);
const isUpdate = ref(true);
const isDetail = ref(false);
//表单配置
const [registerForm, { setProps, resetFields, setFieldsValue, validate }] = useForm({
  //labelWidth: 150,
  schemas: formSchema,
  showActionButtonGroup: false,
  baseColProps: { span: 24 }
});
//表单赋值
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  //重置表单
  await resetFields();
  setModalProps({
    confirmLoading: false,
    showCancelBtn: !!data?.showFooter,
    showOkBtn: !!data?.showFooter
  });
  isUpdate.value = !!data?.isUpdate;
  isDetail.value = !!data?.showFooter;
  if (unref(isUpdate)) {
    //表单赋值
    await setFieldsValue({
      ...data.record
    });
  }
  // 隐藏底部时禁用整个表单
  setProps({ disabled: !data?.showFooter });
});
//设置标题
const title = computed(() => (!unref(isUpdate) ? "新增" : !unref(isDetail) ? "详情" : "编辑"));

//表单提交事件
async function handleSubmit(v) {
  try {
    let param = {
      itemText:'seo_current_month_report',
      itemValue:currentMonthPlanText.value,
    }
    setModalProps({ confirmLoading: true });
    //提交表单
    await saveOrUpdate(param);
    let param2 = {
      itemText:'seo_next_month_report',
      itemValue:nextMonthPlanText.value,
    }
    await saveOrUpdate(param2);
    //关闭弹窗
    closeModal();
    //刷新列表
    emit("success");
  } finally {
    setModalProps({ confirmLoading: false });
  }
}

const currentMonthPlanText = ref("");
const nextMonthPlanText = ref("");
const getSeoMonthPlanContent = () => {
  getAction("/seo/seoMonthPdf/getSeoMonthPlanContent", {}).then(function(res) {
    currentMonthPlanText.value = res.result.currentMonthPlan;
    nextMonthPlanText.value = res.result.nextMonthPlan;
  });
};
onMounted(() => {
  getSeoMonthPlanContent();
});
</script>

<style lang="less" scoped>
/** 时间和数字输入框样式 */
:deep(.ant-input-number) {
  width: 100%;
}

:deep(.ant-calendar-picker) {
  width: 100%;
}
</style>
<style scoped lang="less">
.title {
  border-left: 4px solid #018FFB;
  line-height: 1;
  padding-left: 5px;
  margin: 40px 0 0;

  &.mb {
    margin-bottom: 20px;
  }
}

.tips {
  position: absolute;
  bottom: 0;
  right: 5px;
  line-height: 1;
  color: #999;
}

.tip {
  padding: 24px;
}

a-textarea {
  min-height: 170px;
}

.num-suffix {
  position: relative;

  .suffix-self {
    position: absolute;
    right: 10px;
    bottom: 10px;
  }
}

.top {
  text-align: center;

  h1 {
    font-size: 27px;
    font-weight: 500;
    line-height: 1;
    margin: 0;
  }
}
</style>
