zhangjie 2 vuotta sitten
vanhempi
commit
a7c305ad8c

+ 2 - 2
src/constants/printTemplateData.js

@@ -1,5 +1,5 @@
 export const SIGN_DATA = {
-  header: [
+  basic: [
     {
       code: "courseName",
       name: "课程",
@@ -37,7 +37,7 @@ export const SIGN_DATA = {
       enable: true
     }
   ],
-  body: [
+  table: [
     {
       code: "studentName",
       name: "姓名",

+ 5 - 2
src/modules/base/api.js

@@ -127,6 +127,9 @@ export const deleteCardRule = id => {
 export const templateListPage = datas => {
   return $postParam("/api/admin/basic/template/list", datas);
 };
+export const templateDetail = id => {
+  return $postParam("/api/admin/basic/template/get_one", { id });
+};
 export const updateTemplate = datas => {
   return $post("/api/admin/basic/template/save", datas);
 };
@@ -136,8 +139,8 @@ export const ableTemplate = ({ id, enable }) => {
 export const templateCategoryList = type => {
   return $postParam("/api/admin/basic/template/list", type);
 };
-export const templateContentView = attachmentId => {
-  return $postParam("/api/admin/basic/template/read_content", { attachmentId });
+export const templateContentView = id => {
+  return $postParam("/api/admin/basic/template/read_content", { id });
 };
 // card-manage
 export const cardListPage = datas => {

+ 37 - 13
src/modules/base/components/ModifyPrintTemplate.vue

@@ -65,7 +65,7 @@
         prop="fields"
       >
         <el-checkbox
-          v-for="field in signDatas.header"
+          v-for="field in signDatas.basic"
           :key="field.code"
           v-model="field.enable"
           :disabled="field.disabled"
@@ -73,7 +73,7 @@
         >
         <el-divider></el-divider>
         <el-checkbox
-          v-for="field in signDatas.body"
+          v-for="field in signDatas.table"
           :key="field.code"
           v-model="field.enable"
           :disabled="field.disabled"
@@ -115,7 +115,7 @@
 </template>
 
 <script>
-import { updateTemplate } from "../api";
+import { templateDetail, updateTemplate } from "../api";
 import { attachmentDetail } from "../../login/api";
 import UploadFileView from "@/components/UploadFileView";
 import { TEMPLATE_TYPE } from "@/constants/enumerate";
@@ -173,8 +173,8 @@ export default {
         return callback();
       } else {
         if (
-          !this.signDatas.header.some(item => item.enable) ||
-          !this.signDatas.body.some(item => item.enable)
+          !this.signDatas.basic.some(item => item.enable) ||
+          !this.signDatas.table.some(item => item.enable)
         ) {
           return callback(new Error("请选择显示字段"));
         }
@@ -235,17 +235,44 @@ export default {
     };
   },
   methods: {
-    initData(val) {
-      this.modalForm = this.$objAssign(initModalForm, val);
+    async initData(val) {
       if (val.id) {
-        this.getAttachment();
+        const data = await templateDetail(val.id);
+        this.modalForm = this.$objAssign(initModalForm, data);
+
+        const unAttachmentTemps = ["SIGN", "PACKAGE"];
+        if (unAttachmentTemps.includes(this.modalForm.classify)) {
+          this.initFieldData(data);
+        } else {
+          this.getAttachment();
+        }
       } else {
+        this.modalForm = this.$objAssign(initModalForm, val);
+        this.packageDatas = [...PACKAGE_DATA];
+        this.signDatas = { ...SIGN_DATA };
         this.$nextTick(() => {
           this.$refs.UploadFileView.setAttachmentName("");
         });
       }
     },
+    initFieldData(data) {
+      const displayRange = data.displayRange
+        ? JSON.parse(data.displayRange)
+        : null;
+      if (!displayRange) {
+        this.packageDatas = [...PACKAGE_DATA];
+        this.signDatas = { ...SIGN_DATA };
+        return;
+      }
+
+      if (data.classify === "PACKAGE") {
+        this.packageDatas = displayRange;
+      } else {
+        this.signDatas = displayRange;
+      }
+    },
     async getAttachment() {
+      if (!this.instance.attachmentId) return;
       const data = await attachmentDetail(this.instance.attachmentId);
       this.attachment = data;
 
@@ -280,11 +307,8 @@ export default {
       };
       if (this.modalForm.classify === "PACKAGE") {
         datas.displayRange = this.packageDatas;
-      } else {
-        datas.displayRange = {
-          basic: this.signDatas.header,
-          table: this.signDatas.body
-        };
+      } else if (this.modalForm.classify === "SIGN") {
+        datas.displayRange = this.signDatas;
       }
       const data = await updateTemplate(datas).catch(() => {});
       this.isSubmit = false;

+ 1 - 1
src/modules/base/router.js

@@ -105,7 +105,7 @@ export default [
   },
   {
     path: "/base/college-manage",
-    name: "CollegeManage",
+    name: "BasicCollegeManage",
     component: CollegeManage
   },
   {

+ 2 - 37
src/modules/base/views/PrintTemplateManage.vue

@@ -156,19 +156,6 @@
       :instance="curTemplate"
       @modified="getList"
     ></modify-print-template>
-    <!-- template-detail -->
-    <el-dialog
-      :visible.sync="templateDetailDialogIsShow"
-      title="印品模板"
-      width="1200px"
-      top="10px"
-      :close-on-click-modal="false"
-      :close-on-press-escape="false"
-      append-to-body
-    >
-      <div id="template-frame"></div>
-      <div slot="footer"></div>
-    </el-dialog>
   </div>
 </template>
 
@@ -240,32 +227,10 @@ export default {
       this.$refs.ModifyPrintTemplate.open();
     },
     async toDetail(row) {
-      const content = await templateContentView(row.attachmentId);
+      const content = await templateContentView(row.id);
       if (!content) return;
 
-      this.templateDetailDialogIsShow = true;
-      this.$nextTick(() => {
-        this.initFrame(content);
-      });
-    },
-    initFrame(htmlContent) {
-      // 移除framemark标签
-      // htmlContent = htmlContent
-      //   .replace(/\$\{.+?\}/g, "")
-      //   .replace(/<#.+?>/g, "")
-      //   .replace(/<\/#.+?>/g, "");
-      const frameContainerDom = document.getElementById("template-frame");
-      frameContainerDom.innerHTML = "";
-      const iframeDom = document.createElement("iframe");
-      frameContainerDom.appendChild(iframeDom);
-      console.dir(frameContainerDom);
-      const wwidth = frameContainerDom.parentNode.clientWidth - 50;
-      const wheight = window.innerHeight - 130;
-      iframeDom.style.cssText = `width: ${wwidth}px;height: ${wheight}px;border:none;outline:none;background-color: #fff;`;
-      const iframeDoc = iframeDom.contentDocument;
-      iframeDoc.open();
-      iframeDoc.write(htmlContent);
-      iframeDoc.close();
+      window.open(content);
     },
     toEnable(row) {
       const action = row.enable ? "禁用" : "启用";