<template>
  <div class="app-container">
    <DWViewer :url="url" @goback="hanldeBack" @publish="hanldePublish" @save="handleSave" @back="handleBack" />
  </div>
</template>

<script>
import { publishSurvey, saveSurveyDraft } from "@/api/hospital";
import DWViewer from "@/components/DWViewer/index.vue";

export default {
  name: "DesignSurvey",
  components: {
    DWViewer,
  },
  data() {
    return {
      url: `${process.env.VUE_APP_SURVEY_PREFIX}/survey/design-survey.html?surveyId=${this.$route.query.surveyId}`,
    };
  },
  methods: {
    // 发布
    hanldePublish() {
      publishSurvey(this.$route.query.id).then(() => {
        this.$message.success("发布成功");
        this.hanldeBack();
      });
    },
    // 保存
    handleSave() {
      setTimeout(() => {
        saveSurveyDraft(this.$route.query.surveyId
        ).then(() => {
          this.hanldeBack();
        })
      }, 2000)
    },
    // 返回按钮
    handleBack() {
      saveSurveyDraft(this.$route.query.surveyId
      ).then(() => {
        this.hanldeBack();
      })
    },
    // 返回
    hanldeBack() {
      this.$tab.closePage(undefined, { name: "SurveyManage" });
    },
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  height: 100%;
}
</style>
