瀏覽代碼

贺卡打印

Funny 2 年之前
父節點
當前提交
a549e72c17
共有 3 個文件被更改,包括 104 次插入35 次删除
  1. 10 0
      src/api/shop.js
  2. 34 11
      src/api/tool.js
  3. 60 24
      src/components/settingComponents/print/greetingCardPrinter.vue

+ 10 - 0
src/api/shop.js

@@ -235,4 +235,14 @@ export const getCloudDevice = (params) => {
 // 云盒打印
 export const cloudPrint = (params) => {
   return post('app/order/print/card', params)
+}
+
+// 云盒配置列表
+export const cloudConfigList = (params) => {
+  return get('app/shop/cloud/card/list', params)
+}
+
+// 新增、编辑云盒配置
+export const cloudConfigAdd = (params) => {
+  return postJson('app/shop/cloud/card/add', params)
 }

+ 34 - 11
src/api/tool.js

@@ -1,4 +1,35 @@
+/**
+ * 是否数组
+ */
+function isArray(value) {
+  if (typeof Array.isArray === 'function') {
+    return Array.isArray(value)
+  }
+  return Object.prototype.toString.call(value) === '[object Array]'
+}
+/**
+ * @description 深度克隆
+ * @param {object} obj 需要深度克隆的对象
+ * @returns {*} 克隆后的对象或者原值(不是对象)
+ */
+function deepClone(obj) {
+  // 对常见的“非”值,直接返回原来值
+  if ([null, undefined, NaN, false].includes(obj)) return obj
+  if (typeof obj !== 'object' && typeof obj !== 'function') {
+    // 原始类型直接返回
+    return obj
+  }
+  const o = isArray(obj) ? [] : {}
+  for (const i in obj) {
+    if (obj.hasOwnProperty(i)) {
+      o[i] = typeof obj[i] === 'object' ? deepClone(obj[i]) : obj[i]
+    }
+  }
+  return o
+}
 export default {
+  isArray,
+  deepClone,
   /**
    * fun 需要防抖的方法
    * delay 最小抖动间隔
@@ -96,15 +127,6 @@ export default {
   },
 
   eosFormatTime2(oldTimes1, disparityTime) {
-    // let time1 = oldTimes1.split(" ");
-    // let time2 = time1[1].split(":");
-    // let time3 = time1[0].split("-");
-    // if (disparityTime % 1 === 0) {
-    //   return `${time3[1]}-${time3[2]} ${time2[0] - disparityTime}:00`;
-    // } else {
-    //   return `${time3[1]}-${time3[2]} ${time2[0] -
-    //     Math.ceil(disparityTime)}:30`;
-    // }
     var date = new Date(oldTimes1)
     let newDate = date - disparityTime * 60 * 60 * 1000
     let showDate = this.getFormatDate(newDate, 'MM-dd hh:mm:ss')
@@ -134,5 +156,6 @@ export default {
     else if (_min >= 1) result = "" + parseInt(_min) + "分钟";
     else result = "1分钟";
     return result;
-  }
-};
+  },
+
+}

+ 60 - 24
src/components/settingComponents/print/greetingCardPrinter.vue

@@ -44,7 +44,7 @@
 
           </div>
           <div class="card-setting">
-            <div class="card-left" :style="`max-height: ${params.dmPaperLength}mm;max-width: ${params.dmPaperWidth}mm;`">
+            <div class="card-left" :style="`max-height: ${params.cardHeight}mm;max-width: ${params.cardWidth}mm;`">
               <i class="el-icon-arrow-down icon1" :style="`top:${params.paddingTop}mm;left:${params.paddingLeft}mm;`"></i>
               <i class="el-icon-arrow-down icon2" :style="`top:${params.paddingTop}mm;right:${params.paddingRight}mm;`"></i>
               <i class="el-icon-arrow-down icon3" :style="`bottom:${params.paddingBottom}mm;left:${params.paddingLeft}mm;`"></i>
@@ -57,7 +57,7 @@
               <div class="setting-params">
                 <div class="card-title">所属门店<div class="card-tip">&emsp;(设置门店专属贺卡样式)</div>
                 </div>
-                <el-select v-model="params.shopId" multiple @change="changeShop">
+                <el-select v-model="params.shopIdList" multiple @change="changeShop" clearable>
                   <el-option v-for="item in shopList" :key="item.id" :value="item.id" :label="item.name">
                     <div>{{ item.name }}</div>
                   </el-option>
@@ -73,7 +73,7 @@
               </div>
               <div class="setting-params">
                 <div class="card-title">打印方向</div>
-                <el-select v-model="params.dmOrientation">
+                <el-select v-model="params.direction">
                   <el-option v-for="item in directonList" :key="item.value" :value="item.value" :label="item.name">
                     <div>{{ item.name }}</div>
                   </el-option>
@@ -81,7 +81,7 @@
               </div>
               <div class="setting-params">
                 <div class="card-title">贺卡尺寸类型</div>
-                <el-select v-model="params.dmPaperSize" @change="changeDmPaperSize">
+                <el-select v-model="params.sizeType" @change="changeDmPaperSize">
                   <el-option v-for="item in paperSize" :key="item.value" :value="item.value" :label="item.name">
                     <div>{{ item.name }}</div>
                   </el-option>
@@ -89,11 +89,11 @@
               </div>
               <div class="setting-params">
                 <div class="card-title">贺卡尺寸</div>
-                <el-input :disabled="[9,11].includes(params.dmPaperSize)" v-model="params.dmPaperWidth">
+                <el-input :disabled="[9,11].includes(params.sizeType)" v-model="params.cardWidth">
                   <template slot="prepend">宽</template>
                   <template slot="append">毫米</template>
                 </el-input>
-                <el-input :disabled="[9,11].includes(params.dmPaperSize)" v-model="params.dmPaperLength">
+                <el-input :disabled="[9,11].includes(params.sizeType)" v-model="params.cardHeight">
                   <template slot="prepend">高</template>
                   <template slot="append">毫米</template>
                 </el-input>
@@ -118,7 +118,7 @@
                 </el-input>
               </div>
               <div class="btns">
-                <el-button size="small" type="warning">保存贺卡</el-button>
+                <el-button size="small" @click="saveCard" type="warning">保存贺卡</el-button>
                 <el-button size="small" @click="printTest">打印测试页</el-button>
               </div>
             </div>
@@ -170,6 +170,8 @@ import {
   cloudPrint,
   shopDeviceList,
   deviceDelete,
+  cloudConfigList,
+  cloudConfigAdd,
 } from "../../../api/shop";
 export default {
   name: "greetingCardPrinter",
@@ -194,17 +196,18 @@ export default {
         shopId: 0,
       },
       cloudList: [],
+      configList: [],
       params: {
-        dmPaperWidth: 210,
-        dmPaperLength: 297,
+        cardWidth: 210,
+        cardHeight: 297,
         paddingTop: 10,
         paddingBottom: 10,
         paddingLeft: 10,
         paddingRight: 10,
-        dmOrientation: 1, // 1:竖向 2:横向
+        direction: 1, // 1:竖向 2:横向
         fontFamily: "FangZhengKaiTi",
-        shopId: [0],
-        dmPaperSize: 9, // 纸张尺寸
+        shopIdList: [0],
+        sizeType: 9, // 纸张尺寸
       },
       printerList: [],
       shopList: [],
@@ -275,8 +278,22 @@ export default {
   watch: {},
   // 方法集合
   methods: {
+    saveCard() {
+      cloudConfigAdd(this.params).then((res) => {
+        console.log("添加贺卡配置信息", res);
+        if (res.code === 200) {
+          this.$message.success(`保存贺卡成功!`)
+          this.getCloudConfigList();
+        } else {
+          this.$message({
+            type: "error",
+            message: res.msg,
+          });
+        }
+      });
+    },
     printTest() {
-      cloudPrint().then(() => {
+      cloudPrint().then((res) => {
         console.log("添加云盒信息", res);
         if (!res.code) {
           this.cloudList = res.data;
@@ -298,7 +315,9 @@ export default {
       if (!this.form.deviceSecret) {
         return this.$message.warning(`请输入云盒秘钥!`);
       }
-      deviceAdd(this.form).then((res) => {
+      let form = this.$tool.deepClone(this.form);
+      form.shopIds = form.shopIdList.join();
+      deviceAdd(form).then((res) => {
         console.log("添加云盒信息", res);
         if (res.code === 200) {
           this.$message.success(`成功添加云盒!`);
@@ -341,11 +360,11 @@ export default {
     },
     changeShop(e) {
       if (e.at(-1)) {
-        this.params.shopId = e.filter((v) => {
+        this.params.shopIdList = e.filter((v) => {
           return v;
         });
       } else {
-        this.params.shopId = [0];
+        this.params.shopIdList = [0];
       }
     },
     changePrinterShop(e) {
@@ -359,16 +378,16 @@ export default {
     },
     changeDmPaperSize(e) {
       if (e === 9) {
-        this.params.dmPaperWidth = 210;
-        this.params.dmPaperLength = 297;
+        this.params.cardWidth = 210;
+        this.params.cardHeight = 297;
       }
       if (e === 11) {
-        this.params.dmPaperWidth = 148;
-        this.params.dmPaperLength = 210;
+        this.params.cardWidth = 148;
+        this.params.cardHeight = 210;
       }
       if (e === 0) {
-        this.params.dmPaperWidth = 195;
-        this.params.dmPaperLength = 145;
+        this.params.cardWidth = 195;
+        this.params.cardHeight = 145;
       }
     },
     deletePrinter(v) {
@@ -382,10 +401,10 @@ export default {
           deviceDelete({ id: v.id }).then((res) => {
             if (res.code === 200) {
               this.$message({
-                type: "error",
+                type: "success",
                 message: "删除成功!",
               });
-              this.refreshData();
+              this.getCloudPrinterList();
             } else {
               this.$message({
                 type: "error",
@@ -426,11 +445,28 @@ export default {
         }
       });
     },
+    getCloudConfigList() {
+      cloudConfigList({ deviceType: 28 }).then((res) => {
+        if (res.code === 200) {
+          this.configList = res.data;
+          let data = this.$tool.deepClone(res.data[0]);
+          data.shopIdList = [0]
+          this.params = data;
+          console.log("params:", this.params);
+        } else {
+          this.$message({
+            type: "error",
+            message: res.msg,
+          });
+        }
+      });
+    },
   },
   // 生命周期 - 创建完成(可以访问当前this实例)
   created() {
     this.getNewShopList();
     this.getCloudPrinterList();
+    this.getCloudConfigList();
   },
   // 生命周期 - 挂载完成(可以访问DOM元素)
   mounted() {},