|
@@ -5,15 +5,9 @@
|
|
|
ref="PaperTemplateDesign"
|
|
|
:content="tempContent"
|
|
|
@on-preview="toPreview"
|
|
|
- @on-save="toSave"
|
|
|
@on-submit="toSubmit"
|
|
|
@on-exit="toExit"
|
|
|
></paper-template-design>
|
|
|
-
|
|
|
- <!-- paper-template-view-frame -->
|
|
|
- <div v-if="tempPreviewUrl" class="design-preview-frame">
|
|
|
- <iframe :src="tempPreviewUrl" frameborder="0"></iframe>
|
|
|
- </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -29,31 +23,26 @@ export default {
|
|
|
return {
|
|
|
tid: this.$route.params.tid,
|
|
|
tempContent: {},
|
|
|
- tempPreviewUrl: "",
|
|
|
dataReady: false,
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
isEdit() {
|
|
|
- return !!this.cardId;
|
|
|
+ return !!this.tid;
|
|
|
},
|
|
|
},
|
|
|
- beforeDestroy() {
|
|
|
- delete window.submitCardTemp;
|
|
|
- },
|
|
|
mounted() {
|
|
|
this.initData();
|
|
|
- // todo:不需要预览了获取html了
|
|
|
- this.registWindowSubmit();
|
|
|
},
|
|
|
methods: {
|
|
|
- initData() {
|
|
|
+ async initData() {
|
|
|
this.dataReady = false;
|
|
|
if (this.isEdit) {
|
|
|
- this.getPaperTemplate();
|
|
|
+ await this.getPaperTemplate();
|
|
|
} else {
|
|
|
this.initTempContent();
|
|
|
}
|
|
|
+ this.dataReady = true;
|
|
|
},
|
|
|
async getPaperTemplate() {
|
|
|
const detDataRes = await paperTemplateDetailApi(this.tid);
|
|
@@ -71,8 +60,11 @@ export default {
|
|
|
};
|
|
|
},
|
|
|
// 操作
|
|
|
- async toPreview(datas) {
|
|
|
- await this.toSave(datas);
|
|
|
+ async toPreview(paperTempData) {
|
|
|
+ const result = await this.toSave(paperTempData).catch(() => {});
|
|
|
+ if (!result) {
|
|
|
+ this.$message.error("保存失败");
|
|
|
+ }
|
|
|
|
|
|
const { href } = this.$router.resolve({
|
|
|
name: "PaperTemplatePreview",
|
|
@@ -84,63 +76,28 @@ export default {
|
|
|
window.open(href);
|
|
|
},
|
|
|
// save
|
|
|
- async toSave(infos) {
|
|
|
- let datas = { ...infos };
|
|
|
- datas.id = this.tid;
|
|
|
- datas.formal = false;
|
|
|
+ async toSave(paperTempData) {
|
|
|
+ this.$refs.PaperTemplateDesign.loading();
|
|
|
+
|
|
|
+ let datas = {
|
|
|
+ id: this.tid,
|
|
|
+ content: JSON.stringify(paperTempData),
|
|
|
+ formal: true,
|
|
|
+ };
|
|
|
let result = await savePaperTemplateApi(datas).catch(() => {});
|
|
|
this.$refs.PaperTemplateDesign.unloading();
|
|
|
- if (!result) return;
|
|
|
+ if (!result) return Promise.reject("保存失败");
|
|
|
this.tid = result.data;
|
|
|
- this.$message.success("保存成功!");
|
|
|
+ return Promise.resolve("保存成功!");
|
|
|
},
|
|
|
async toSubmit(paperTempData) {
|
|
|
- const res = await this.$confirm("确定要提交当前模板吗?", "提示", {
|
|
|
- type: "warning",
|
|
|
- }).catch(() => {});
|
|
|
- if (res !== "confirm") return;
|
|
|
-
|
|
|
- window.paperTempData = paperTempData;
|
|
|
- this.$refs.PaperTemplateDesign.loading();
|
|
|
- const { href } = this.$router.resolve({
|
|
|
- name: "PaperTemplatePreview",
|
|
|
- params: {
|
|
|
- tid: 1,
|
|
|
- viewType: "frame",
|
|
|
- },
|
|
|
- query: {
|
|
|
- t: Date.now(),
|
|
|
- },
|
|
|
- });
|
|
|
- this.tempPreviewUrl = href;
|
|
|
- },
|
|
|
- registWindowSubmit() {
|
|
|
- window.submitCardTemp = async (tempContent) => {
|
|
|
- if (!tempContent) {
|
|
|
- this.$refs.PaperTemplateDesign.unloading();
|
|
|
- window.paperTempData = null;
|
|
|
- this.tempPreviewUrl = "";
|
|
|
- this.$message.error("提交失败,请重新尝试!");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- let datas = {
|
|
|
- content: tempContent,
|
|
|
- };
|
|
|
- datas.id = this.tid;
|
|
|
- datas.formal = true;
|
|
|
- let result = await savePaperTemplateApi(datas).catch(() => {});
|
|
|
- this.tempPreviewUrl = "";
|
|
|
- window.paperTempData = null;
|
|
|
- this.$refs.PaperTemplateDesign.unloading();
|
|
|
- if (result) {
|
|
|
- this.tid = result.data;
|
|
|
- this.$message.success("提交成功!");
|
|
|
- this.goback();
|
|
|
- } else {
|
|
|
- this.$message.error("提交失败,请重新尝试!");
|
|
|
- }
|
|
|
- };
|
|
|
+ const result = await this.toSave(paperTempData).catch(() => {});
|
|
|
+ if (result) {
|
|
|
+ this.$message.success("提交成功!");
|
|
|
+ this.goback();
|
|
|
+ } else {
|
|
|
+ this.$message.error("提交失败,请重新尝试!");
|
|
|
+ }
|
|
|
},
|
|
|
toExit() {
|
|
|
this.$confirm(
|