<!--
 * @Author: guanxiaoyan guanxiaoyan@pb-station.com
 * @Deion:
 * @Date: 2023-12-06 18:22:03
 * @LastEditors: guanxiaoyan guanxiaoyan@pb-station.com
 * @LastEditTime: 2024-01-04 17:47:21
 * @FilePath: /followUp-admin/src/components/DWViewer/index.vue
-->
<template>
  <div v-loading="loading" element-loading-text="加载中..." style="width: 100%; height: 100%;">
    <iframe @load="loading = false" style="width: 100%; height: 100%" :src="url" frameborder="0"></iframe>
  </div>
</template>

<script>
export default {
  name: "DWViewer",
  components: {},
  props: ["url"],
  data() {
    return {
      loading: true,
    };
  },
  watch: {
    url(val) {
      if (val) {
        this.loading = true;
      }
    },
  },
  created() {
    const self = this;
    window.__DW__ = {
      // 拦截器（可以阻止）
      interceptor: {
        publish: this.publishSurvey, // 发布问卷
      },
      // 通知
      notification: {
        // 提交问卷成功通知
        submitSurveyScuccess: (answerId, sid) => {
          console.log("提交问卷成功通知======",answerId,sid)
          self.$emit("submitSurveyScuccess")
        },
      },
      // 脚本
      script: {
        commonjs: this.commonScript, // common.js
      },
    };
  },
  methods: {
    // 发布
    async publishSurvey(baseDwFormId) {
      this.$emit("publish", baseDwFormId);
    },
    commonScript($, doc, win) {
      const self = this;
      $(doc).ready(function () {
        // 设计页面-[返回]按钮
        $("#backSurvey").click(function () {
          self.$emit("goback");
          return false;
        });
        // 设计页面-弹框[退出]按钮
        $("#dwDialogDesignExit").remove();
        // 预览页面-[返回列表]按钮
        $("#surveyList").remove();
        // 预览页面-底部版权
        $(".dw-footer").remove();
        console.log("!self.isStorage",self.isStorage)
        if (!self.isStorage) {
          $('#tempSaveSurvey').remove();
        }
      });
    },
  },
};
</script>

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