From a3dbafce020d06c81820697d901357e1d281a979 Mon Sep 17 00:00:00 2001
From: chenhaozhe <gaozhechen26@gmail.com>
Date: 星期六, 04 四月 2026 21:53:18 +0800
Subject: [PATCH] 添加 打印模板设计和 打印功能

---
 src/views/component/printList/index.vue |  480 ++++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 272 insertions(+), 208 deletions(-)

diff --git a/src/views/component/printList/index.vue b/src/views/component/printList/index.vue
index a8af829..6a69e3a 100644
--- a/src/views/component/printList/index.vue
+++ b/src/views/component/printList/index.vue
@@ -1,217 +1,281 @@
 <template>
-    <div style="margin-top: -40px;">
-        <el-form ref="formData" :model="formData" label-width="100px">
-            <div style="padding: 10px; ">
-                <el-button type="primary" size="small" @click="printClick">鎶ヨ〃鎵撳嵃</el-button>
-                <el-button type="primary" size="small" @click="printClickWeb">鎶ヨ〃鎵撳嵃(缃戦〉)</el-button>
-            </div>
-            <el-table v-loading="loading" :data="printdata" ref="printTable" max-height="540"
-                @selection-change="handleSelectionChange" :row-class-name="rowSysIndex" border>
-                <el-table-column type="selection" width="55" align="center" />
-                <el-table-column align="center" label="妯″潡浠g爜" prop="HNumber" v-if="hideFlag" />
-                <el-table-column align="center" label="妯℃澘鍚嶇О" prop="妯℃澘鍚嶇О" />
-            </el-table>
-        </el-form>
-        <el-dialog title="鎶ヨ〃鎵撳嵃" :visible.sync="openPrint" width="800px" append-to-body>
-            <div ref="print" id="printId">111</div>
-            <el-button type="primary" size="small" @click="printClick">鎵撳嵃</el-button>
-        </el-dialog>
-    </div>
+  <div style="margin-top: -40px;">
+    <el-form ref="formData" :model="formData" label-width="100px">
+      <div style="padding: 10px; ">
+        <el-button type="primary" size="small" @click="printClick">鎶ヨ〃鎵撳嵃</el-button>
+        <el-button type="primary" size="small" @click="printClickWeb">鎶ヨ〃鎵撳嵃(缃戦〉)</el-button>
+        <a-button type="primary" icon="eye" @click="preView">棰勮</a-button>
+      </div>
+      <el-table v-loading="loading" :data="printdata" ref="printTable" max-height="540"
+        @selection-change="handleSelectionChange" :row-class-name="rowSysIndex" border>
+        <el-table-column type="selection" width="55" align="center" />
+        <el-table-column align="center" label="妯″潡浠g爜" prop="HNumber" v-if="hideFlag" />
+        <el-table-column align="center" label="妯℃澘鍚嶇О" prop="妯℃澘鍚嶇О" />
+      </el-table>
+    </el-form>
+    <el-dialog title="鎶ヨ〃鎵撳嵃" :visible.sync="openPrint" width="800px" append-to-body>
+      <div ref="print" id="printId">111</div>
+      <el-button type="primary" size="small" @click="printClick">鎵撳嵃</el-button>
+    </el-dialog>
+    <print-preview ref="preView" />
+  </div>
 </template>
 
 <script>
 import axios from 'axios'
-
+import printPreview from './preview'
 export default {
-    name: 'PrintList',
-    props: {
-        linterid: { type: Number, },
-        MyMsg: { type: Number, },
-        Type: { type: String, },
-        HModName: { type: String, }
-    },
-    data() {
-        return {
-            openPrint: false,
-            selRowData: [],
-            baseURL: process.env.VUE_APP_BASE_API,
-            user: 'admin',//鐧诲綍鐢ㄦ埛鍚�
-            // 琛ㄦ牸鏁版嵁
-            printdata: [],
-            // 閫変腑鏁扮粍index
-            selIndex: [],
-            // 闈炲崟涓鐢�
-            single: true,
-            // 闈炲涓鐢�
-            multiple: true,
-            // 閬僵灞�
-            loading: true,
-            formData: {
-                HFixCols: '',
-                HFontSize: '',
-                HColumnWidth: '',
-                HPageSize: '',
-                HSortFlag: '',
-                HSelTotal: ''
-            },
-            colTitleName: '',
-            tableIns: null,
-            option: {},
-            tableData: [],
-            hideFlag:false,                             //闅愯棌鏍囪銆傜敤浜庤缃煇浜涗笉甯屾湜鏄剧ず鐨勬爣绛�                                          // 褰撳墠閫変腑鐨勮
-        }
-    },
-    created() {
-        this.getDisplay()
-    },
-    methods: {
-        handlePrint() {
-            this.openPrint = true
-        },
-        printClickWeb() {
-          const routeUrl = this.$router.resolve({ path: '/hBarPlanPrintWeb',query:{linterid:this.linterid.toString(),Type:this.Type.toString(),OpenTmp: encodeURIComponent(this.rowForm.妯℃澘鍚嶇О)} });
-          window.open(routeUrl.href, '_blank');
-        },
-        printClick() {
-            const routeUrl = this.$router.resolve({ path: '/hBarPlanPrint',query:{linterid:this.linterid.toString(),Type:this.Type.toString(),OpenTmp: encodeURIComponent(this.rowForm.妯℃澘鍚嶇О)} });
-            window.open(routeUrl.href, '_blank');
-        },
-        getDisplay() {
-            this.loading = true
-            axios.get(this.$baseUrl + '/Open_PrintTem/GetOpenTmpList_Json', {
-                params: { "HNumber": this.Type },
-            }).then(response => {
-                 console.log(response)
-                var result = response.data
-                this.printdata = result.data
-                this.loading = false
-            }).catch(error => {
-                console.log(error)
-                this.$modal.msgError("鎺ュ彛璇锋眰澶辫触!");
-            });
-        },
-        //涓婁竴琛�
-        handleMoveRowUp(row) {
-            if (this.selRowData.length != 1) {
-                this.$modal.msgError("璇烽�夋嫨涓�琛屾暟鎹紒")
-            } else {
-                let num = row.index - 1
-                if (num == 0) {
-                    this.$modal.msgError("绗竴琛屾暟鎹棤娉曚笂绉�");
-                } else { // 纭繚涓嶆槸绗竴琛�
-                    const record = this.rowTitleData.splice(num, 1)[0];
-                    this.rowTitleData.splice(num - 1, 0, record);
-                }
-            }
-            console.log(this.rowTitleData)
-        },
-        //涓嬩竴琛�
-        handleMoveRowDown(row) {
-            if (this.selRowData.length != 1) {
-                this.$modal.msgError("璇烽�夋嫨涓�琛屾暟鎹�")
-            } else {
-                let num = row.index - 1
-                if (num == this.rowTitleData.length - 1) {
-                    this.$modal.msgError("鏈�鍚庝竴琛屾暟鎹棤娉曚笅绉�");
-                } else { // 纭繚涓嶆槸绗竴琛�
-                    const record = this.rowTitleData.splice(num, 1)[0];
-                    this.rowTitleData.splice(num + 1, 0, record);
-                }
-            }
-        },
-        // 澶氶�夋閫変腑鏁版嵁
-        handleSelectionChange(selection) {
-            //鍗曢��
-            if (selection.length > 1) {
-                const del_row = selection.shift()
-                this.$refs.printTable.toggleRowSelection(del_row, false) //璁剧疆杩欎竴琛屽彇娑堥�変腑
-            }
-            this.rowForm = {}
-            this.ids = selection.map(item => item.HItemID)
-            this.rowForm = selection[0]
-        },
-        //琛ㄦ牸琛岀储寮�
-        rowSysIndex({ row, rowIndex }) {
-            row.index = rowIndex + 1;
-        },
-        //鍏ㄩ��
-        handleCheckAll() {
-            for (var i = 0; i < this.rowTitleData.length; i++) {
-                this.rowTitleData[i].IsHide = true;
-            }
-        },
-        //鍏ㄦ竻
-        handleClearBill() {
-            for (var i = 0; i < this.rowTitleData.length; i++) {
-                this.rowTitleData[i].IsHide = false;
-            }
-        },
-        //鍏ㄥ眳涓�
-        handleCenter() {
-            for (var i = 0; i < this.rowTitleData.length; i++) {
-                this.rowTitleData[i].Alignment = 'M';
-            }
-        },
-        //淇濆瓨
-        handleSave() {
-            const cache = this.rowTitleData
-            const num = cache.filter(item => item !== "").map((item, i) => {
-                item.LAY_TABLE_INDEX = i
-                return item
-            })
-            // 楠岃瘉鍒嗛〉鍙傛暟
-            const HPageSize = this.formData.HPageSize
-            if (HPageSize && !/^[0-9]+$/.test(HPageSize)) {
-                this.$modal.msgError("榛樿鍒嗛〉涓嶄负姝f暣鏁�!")
-                return
-            }
-            const sMainStr = JSON.stringify(this.formData)
-            const sSubStr = JSON.stringify(num)
-            const OperationType = "1"
-            const sMainSub = `${sMainStr};${sSubStr};${this.HModName};${OperationType};${this.user}`
-            axios({
-                method: 'post',
-                url: this.$baseUrl + "/Xt_grdAlignment_WMES/AddgrdAlignmentWMES",
-                data: {
-                    'sMainSub': sMainSub
-                },
-            }).then(response => {
-                console.log(1, response)
-                if (response.data.count == 1) {
-                    this.$modal.msgSuccess("鎻愪氦鎴愬姛")
-                } else {
-                    this.$modal.msgError(response.data.Message);
-                }
-            }).catch(error => {
-                console.log(2, error)
-
-                this.$modal.msgError("鎺ュ彛璇锋眰澶辫触!");
-            });
-        },
-        //閫�鍑�
-        handleExit() {
-            this.$emit('rowEditClose', false)
-        },
-        // 鍒犻櫎
-        handleDel() {
-            this.$modal.confirm('纭瑕佸垹闄ゅ悧锛屽垹闄ゅ悗涓嶈兘鎭㈠').then(() => {
-                console.log(this.rowForm.hmainid.toString())
-                axios.get(this.$baseUrl + "/Xt_grdAlignment_WMES/DelgrdAlignmentWMES", {
-                    params: { "HModName": this.HModName, "user": this.user }
-                }).then(response => {
-                    let result = response.data
-                    if (response.data.count == 1) {
-                        this.getList()
-                        this.$modal.msgSuccess(result.Message)
-                    } else {
-                        this.$modal.msgError("閿欒:" + result.code + result.Message);
-                    }
-                }).catch(error => {
-                    console.log(error)
-                    this.$modal.msgError("鎺ュ彛璇锋眰澶辫触!");
-                });
-            }).catch(() => { })
-        },
+  name: 'PrintList',
+  props: {
+    linterid: { type: Number | String, },
+    MyMsg: { type: Number | String, default: '' },
+    Type: { type: String, },
+    HModName: { type: String, }
+  },
+  components: { printPreview },
+  data() {
+    return {
+      openPrint: false,
+      selRowData: [],
+      baseURL: process.env.VUE_APP_BASE_API,
+      user: 'admin',//鐧诲綍鐢ㄦ埛鍚�
+      // 琛ㄦ牸鏁版嵁
+      printdata: [],
+      // 閫変腑鏁扮粍index
+      selIndex: [],
+      // 闈炲崟涓鐢�
+      single: true,
+      // 闈炲涓鐢�
+      multiple: true,
+      // 閬僵灞�
+      loading: true,
+      formData: {
+        HFixCols: '',
+        HFontSize: '',
+        HColumnWidth: '',
+        HPageSize: '',
+        HSortFlag: '',
+        HSelTotal: ''
+      },
+      colTitleName: '',
+      tableIns: null,
+      option: {},
+      tableData: [],
+      hideFlag: false,                             //闅愯棌鏍囪銆傜敤浜庤缃煇浜涗笉甯屾湜鏄剧ず鐨勬爣绛�                                          // 褰撳墠閫変腑鐨勮
     }
+  },
+  created() {
+    this.getDisplay()
+  },
+  methods: {
+    async preView() {
+      console.log(this.rowForm)
+      let templateName = this.rowForm["妯℃澘鍚嶇О"]
+      if (templateName) {
+        let printTemplate = await axios.get(`/static/printTemplate/${templateName}.json`)
+        let printData = await this.getPrintData()
+
+        this.openPrint = false
+        this.$refs.preView.show(printTemplate.data, printData.data.data)
+      } else {
+        this.$modal.msgWarning("鏈�変腑妯℃澘锛岃閫変腑妯℃澘鍚庡啀棰勮");
+      }
+    },
+    handlePrint() {
+      this.openPrint = true
+    },
+    printClickWeb() {
+      const routeUrl = this.$router.resolve({ path: '/hBarPlanPrintWeb', query: { linterid: this.linterid.toString(), Type: this.Type.toString(), OpenTmp: encodeURIComponent(this.rowForm.妯℃澘鍚嶇О) } });
+      window.open(routeUrl.href, '_blank');
+    },
+    printClick() {
+      const routeUrl = this.$router.resolve({ path: '/hBarPlanPrint', query: { linterid: this.linterid.toString(), Type: this.Type.toString(), OpenTmp: encodeURIComponent(this.rowForm.妯℃澘鍚嶇О) } });
+      window.open(routeUrl.href, '_blank');
+    },
+    getDisplay() {
+      this.loading = true
+      axios.get(this.$baseUrl + '/Open_PrintTem/GetOpenTmpList_Json', {
+        params: { "HNumber": this.Type },
+      }).then(response => {
+        console.log(response)
+        var result = response.data
+        this.printdata = result.data
+        this.loading = false
+      }).catch(error => {
+        console.log(error)
+        this.$modal.msgError("鎺ュ彛璇锋眰澶辫触!");
+      });
+    },
+    //涓婁竴琛�
+    handleMoveRowUp(row) {
+      if (this.selRowData.length != 1) {
+        this.$modal.msgError("璇烽�夋嫨涓�琛屾暟鎹紒")
+      } else {
+        let num = row.index - 1
+        if (num == 0) {
+          this.$modal.msgError("绗竴琛屾暟鎹棤娉曚笂绉�");
+        } else { // 纭繚涓嶆槸绗竴琛�
+          const record = this.rowTitleData.splice(num, 1)[0];
+          this.rowTitleData.splice(num - 1, 0, record);
+        }
+      }
+      console.log(this.rowTitleData)
+    },
+    //涓嬩竴琛�
+    handleMoveRowDown(row) {
+      if (this.selRowData.length != 1) {
+        this.$modal.msgError("璇烽�夋嫨涓�琛屾暟鎹�")
+      } else {
+        let num = row.index - 1
+        if (num == this.rowTitleData.length - 1) {
+          this.$modal.msgError("鏈�鍚庝竴琛屾暟鎹棤娉曚笅绉�");
+        } else { // 纭繚涓嶆槸绗竴琛�
+          const record = this.rowTitleData.splice(num, 1)[0];
+          this.rowTitleData.splice(num + 1, 0, record);
+        }
+      }
+    },
+    // 澶氶�夋閫変腑鏁版嵁
+    handleSelectionChange(selection) {
+      //鍗曢��
+      if (selection.length > 1) {
+        const del_row = selection.shift()
+        this.$refs.printTable.toggleRowSelection(del_row, false) //璁剧疆杩欎竴琛屽彇娑堥�変腑
+      }
+      this.rowForm = {}
+      this.ids = selection.map(item => item.HItemID)
+      this.rowForm = selection[0]
+    },
+    //琛ㄦ牸琛岀储寮�
+    rowSysIndex({ row, rowIndex }) {
+      row.index = rowIndex + 1;
+    },
+    //鍏ㄩ��
+    handleCheckAll() {
+      for (var i = 0; i < this.rowTitleData.length; i++) {
+        this.rowTitleData[i].IsHide = true;
+      }
+    },
+    //鍏ㄦ竻
+    handleClearBill() {
+      for (var i = 0; i < this.rowTitleData.length; i++) {
+        this.rowTitleData[i].IsHide = false;
+      }
+    },
+    //鍏ㄥ眳涓�
+    handleCenter() {
+      for (var i = 0; i < this.rowTitleData.length; i++) {
+        this.rowTitleData[i].Alignment = 'M';
+      }
+    },
+    //淇濆瓨
+    handleSave() {
+      const cache = this.rowTitleData
+      const num = cache.filter(item => item !== "").map((item, i) => {
+        item.LAY_TABLE_INDEX = i
+        return item
+      })
+      // 楠岃瘉鍒嗛〉鍙傛暟
+      const HPageSize = this.formData.HPageSize
+      if (HPageSize && !/^[0-9]+$/.test(HPageSize)) {
+        this.$modal.msgError("榛樿鍒嗛〉涓嶄负姝f暣鏁�!")
+        return
+      }
+      const sMainStr = JSON.stringify(this.formData)
+      const sSubStr = JSON.stringify(num)
+      const OperationType = "1"
+      const sMainSub = `${sMainStr};${sSubStr};${this.HModName};${OperationType};${this.user}`
+      axios({
+        method: 'post',
+        url: this.$baseUrl + "/Xt_grdAlignment_WMES/AddgrdAlignmentWMES",
+        data: {
+          'sMainSub': sMainSub
+        },
+      }).then(response => {
+        console.log(1, response)
+        if (response.data.count == 1) {
+          this.$modal.msgSuccess("鎻愪氦鎴愬姛")
+        } else {
+          this.$modal.msgError(response.data.Message);
+        }
+      }).catch(error => {
+        console.log(2, error)
+
+        this.$modal.msgError("鎺ュ彛璇锋眰澶辫触!");
+      });
+    },
+    //閫�鍑�
+    handleExit() {
+      this.$emit('rowEditClose', false)
+    },
+    // 鍒犻櫎
+    handleDel() {
+      this.$modal.confirm('纭瑕佸垹闄ゅ悧锛屽垹闄ゅ悗涓嶈兘鎭㈠').then(() => {
+        console.log(this.rowForm.hmainid.toString())
+        axios.get(this.$baseUrl + "/Xt_grdAlignment_WMES/DelgrdAlignmentWMES", {
+          params: { "HModName": this.HModName, "user": this.user }
+        }).then(response => {
+          let result = response.data
+          if (response.data.count == 1) {
+            this.getList()
+            this.$modal.msgSuccess(result.Message)
+          } else {
+            this.$modal.msgError("閿欒:" + result.code + result.Message);
+          }
+        }).catch(error => {
+          console.log(error)
+          this.$modal.msgError("鎺ュ彛璇锋眰澶辫触!");
+        });
+      }).catch(() => { })
+    },
+    getPrintData() {
+      let sql = "";
+      if (this.Type == "Kf_SellOutBillList") {
+        sql =
+          "exec h_p_Kf_SellOutBillList_PrintSellOutBill " +
+          this.linterid;
+      } else if (this.Type == "HGy_BarCodeBill") {
+        sql =
+          "select * from h_v_IF_BarCodeBillList where hmainid in(" +
+          this.linterid +
+          ") order by hmainid desc";
+      } else if (this.Type == "HPOInStockBill") {
+        sql =
+          "select * from h_v_Sc_PrintMouldProdOutBillList where hmainid=" +
+          this.linterid +
+          " order by hmainid";
+      } else if (this.Type == "HGyStockPlaceBarCode") {
+        let condition = decodeURI(this.linterid);
+        sql = `SELECT
+                CEILING(CAST(t.row_num AS FLOAT) / 2) AS orderid,
+                MAX(CASE WHEN t.row_num % 2 = 1 THEN t.鏉$爜缂栧彿 END) AS 鏉$爜缂栧彿1,
+                MAX(CASE WHEN t.row_num % 2 = 1 THEN t.浠撲綅鍚嶇О END) AS 浠撲綅鍚嶇О1,
+                MAX(CASE WHEN t.row_num % 2 = 0 THEN t.鏉$爜缂栧彿 END) AS 鏉$爜缂栧彿2,
+                MAX(CASE WHEN t.row_num % 2 = 0 THEN t.浠撲綅鍚嶇О END) AS 浠撲綅鍚嶇О2
+              FROM (
+                SELECT
+                  鏉$爜缂栧彿, 浠撲綅鍚嶇О,
+                  ROW_NUMBER() OVER (ORDER BY t1.HItemID) AS row_num
+                FROM h_v_IF_StockPlaceList t1 where 鏉$爜缂栧彿 in (${condition})
+              ) AS t
+              GROUP BY CEILING(CAST(t.row_num AS FLOAT) / 2)
+              ORDER BY orderid;`;
+      } else if (this.Type == "WL_YayBill") {
+
+        sql = "select * from h_v_WL_YayBilllist where hmainid in(" +
+          this.linterid +
+          ") order by hmainid desc";
+      }
+
+      return axios.get(this.$baseUrl + "/CommonModel/searchMethod", {
+        params: {
+          sql: sql,
+          user: sessionStorage["HUserName"],
+          ModRightNameCheck: " ",
+          // , "HSubID": data[i].hsubid
+        },
+      })
+    }
+  }
 }
 </script>
\ No newline at end of file

--
Gitblit v1.9.1