From 5bda5f83d8a7d01d900ce0cbf619dda0e9802281 Mon Sep 17 00:00:00 2001
From: liushiwei <499672082@qq.com>
Date: Tue, 8 Aug 2023 04:14:08 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
 src/api/chromeApi.js         |   5 +-
 src/entry/background.js      |   2 +-
 src/view/NormalSendGoods.vue | 164 +++++++++++++++++++++--------------
 3 files changed, 105 insertions(+), 66 deletions(-)
diff --git a/src/api/chromeApi.js b/src/api/chromeApi.js
index d994a9c..e1bd711 100644
--- a/src/api/chromeApi.js
+++ b/src/api/chromeApi.js
@@ -8,7 +8,10 @@ export function sendChromeAPIMessage(message) {
     message.type = 'api'
     message.url = "https://kuajing.pinduoduo.com/" + message.url;
     if (message.needMallId) {
-        message.mallId = store.state.mallId;
+        // 如果参数中没有携带MallId,则从state中获取
+        if (!message.mallId) {
+            message.mallId = store.state.mallId;
+        }
     }
     return new Promise((resolve) => {
         // @ts-ignore
diff --git a/src/entry/background.js b/src/entry/background.js
index 086f45e..34a7167 100644
--- a/src/entry/background.js
+++ b/src/entry/background.js
@@ -32,7 +32,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
       "" + Math.random(), {
         type: "basic",
         title: "TEMU助手",
-        message: "您的商品【" + request.productName + "】成功加入发货台,请尽快处理",
+        message: "您店铺【" + request.mallName + "】的商品【" + request.productName + "】成功加入发货台,请尽快处理",
         iconUrl: "./icons/48.png"
       }, null
     )
diff --git a/src/view/NormalSendGoods.vue b/src/view/NormalSendGoods.vue
index 9f245b7..fffa77a 100644
--- a/src/view/NormalSendGoods.vue
+++ b/src/view/NormalSendGoods.vue
@@ -10,20 +10,18 @@
       
         
           
-            选择商品
-            {{ isBegin ? '结束抢仓': '开始抢仓' }}
+            添加备货单
+            {{isBegin ? `结束抢仓(${choosedList.length}/${robTotal})`: '开始抢仓'}}
           
           
-            
           
         
         center
           
             
@@ -39,7 +37,7 @@
               
             
           
-          
+          
             
               
                 已抢仓 
{{ scope.row.robTotal }}
 次
@@ -62,26 +60,35 @@
               
+                移除
+              
+            
+            
         
         
-          
+          
+          
             
+              :value="item.mallId">
               {{ item.mallName }}
             
           
@@ -124,6 +131,10 @@
               
             
           
+          
         
       
     
@@ -148,59 +159,69 @@
           { slot: 'robInfo'},
           { slot: 'status' }
         ],
+        robColConfigs: [
+          { prop: 'subPurchaseOrderSn', width: '180px', label: '备货单号', align: 'left' },
+          { slot: 'productName' },
+          { prop: 'mallName', label: '店铺来源', width: '120px', align: 'center' },
+          { slot: 'className'},
+          { slot: 'robInfo'},
+          { slot: 'status' }
+        ],
         mallId: '',
+        mallName: '',
         tableData: [],
         total: 0,
-        ids: [],
         isBegin: false,
         timer: null,
         choosedList: [],
-        arr: []
+        arr: [],
+        robTotal: 0
       }
     },
 
     computed: {
-      ...mapState(['mallName', 'mallList'])
+      ...mapState(['mallList'])
     },
 
     created () {
-      setTimeout(() => {
-        this.isShow = true
-      }, 600)
-      this.getList()
-    },
-
-    activated () {
+      this.mallId = this.mallList[0].mallId
+      this.mallName = this.mallList[0].mallName
       this.getList()
     },
 
     methods: {
       onChooseChange (e) {
-        // this.choosedList = this.removeDuplicate([...this.choosedList, ...e])
         this.arr = e
-        console.log(this.choosedList)
       },
-
+      mallChange() {
+        let mallInfo = this.mallList.filter(item => {
+          return item.mallId == this.mallId
+        })
+        this.mallName = mallInfo.mallName
+        this.getList()
+      },
       onConfirm () {
-        this.choosedList = this.arr
-        this.isShow = false
-      },
-
-      // 数组去重
-      removeDuplicate (arr) {
-        let map = {}
-        arr.forEach(item => {
-          if (!map[item.subPurchaseOrderSn]) {
-            map[item.subPurchaseOrderSn]=item
+        if (this.arr.length == 0) {
+          Message.error("请选择备货单")
+          return
+        }
+        this.arr.map(item => {
+          let temp = this.choosedList.filter(i => {
+            return i.subPurchaseOrderSn == item.subPurchaseOrderSn
+          })
+          if (temp.length == 0) {
+            this.choosedList.push(item)
           }
         })
-        return Object.values(map)
+        Message.success("添加成功,可继续添加")
       },
 
       getList () {
+        this.tableData = []
         sendChromeAPIMessage({
           url: 'oms/bg/venom/api/supplier/purchase/manager/querySubOrderList',
           needMallId: true,
+          mallId: this.mallId,
           data: {
             "pageNo": 1,
             "pageSize": 100,
@@ -224,7 +245,10 @@
                   productSkcId: item.productSkcId,
                   productSkcPicture: item.productSkcPicture,
                   status: item.status,
-                  detailList: item.skuQuantityDetailList
+                  detailList: item.skuQuantityDetailList,
+                  category: item.category,
+                  mallId: this.mallId,
+                  mallName: this.mallName
                 };
               })
             } else {
@@ -232,11 +256,14 @@
             }
         })
       },
-
-      handleSelectionChange(e) {
-        this.ids = e.map(v => v.subPurchaseOrderSn)
+      remove(sn) {
+        for (let i = 0; i < this.choosedList.length; i++) {
+          if (this.choosedList[i].subPurchaseOrderSn == sn) {
+            this.choosedList.splice(i, 1)
+            break
+          }
+        }
       },
-
       getStyle(url) {
         return "background-image: url(" + url + "); width: 72px; height: 72px; cursor: pointer; border-radius: 6px; border: 1px solid rgba(0, 0, 0, 0.14);";
       },
@@ -260,21 +287,25 @@
               Message.error('您当前登录的TEMU账号与会员绑定账号不一致')
               return;
             }
-            if (this.ids.length <= 0) {
-              Message.error('请选择抢仓商品');
+            if (this.choosedList.length <= 0) {
+              Message.error('请选择备货单');
               return;
             }
+
+            this.robTotal = this.choosedList.length
             this.isBegin = true;
             this.timer = [];
 
-            for (let i = 0;i < this.ids.length; i++) {
-              let t = setInterval(this.robFunc(this.ids[i]), 1000);
-              this.timer.push({id: this.ids[i], timer: t})
+            for (let i = 0;i < this.choosedList.length; i++) {
+              setTimeout(() => {
+                let t = setInterval(this.robFunc(this.choosedList[i].subPurchaseOrderSn, this.choosedList[i].mallId), 1000);
+                this.timer.push({id: this.choosedList[i].subPurchaseOrderSn, timer: t})
+              }, 100 * i)
             }
 
             let _this = this;
             let tt = setInterval(function() {
-              if (_this.ids.length == 0) {
+              if (_this.choosedList.length == 0) {
                 _this.isBegin = false;
                 clearInterval(tt);
               }
@@ -285,23 +316,24 @@
         });
 
       },
-      robFunc(sn) {
+      robFunc(sn, mallId) {
         let _this = this;
         return function() {
-          _this.rob(sn);
+          _this.rob(sn, mallId);
         }
       },
-      rob(sn) {
+      rob(sn, mallId) {
         sendChromeAPIMessage({
           url: 'oms/bg/venom/api/supplier/purchase/manager/joinDeliveryGoodsOrderPlatform',
           needMallId: true,
+          mallId: mallId,
           data: {
             "subPurchaseOrderSn": sn
           }}).then((res) => {
             if (res.errorCode == 1000000) {
-              for (let i = 0;i < this.ids.length; i++) {
-                if (this.ids[i] == sn) {
-                  this.ids.splice(i, 1)
+              for (let i = 0;i < this.choosedList.length; i++) {
+                if (this.choosedList[i].subPurchaseOrderSn == sn) {
+                  this.choosedList.splice(i, 1)
                   break;
                 }
               }
@@ -313,35 +345,39 @@
                 clearInterval(t[0].timer)
               }
 
-              for (let j = 0; j < this.tableData.length; j++) {
-                if (this.tableData[j].subPurchaseOrderSn == sn) {
-                  this.sendSms(this.tableData[j].productName);
-                  this.sendNotification(this.tableData[j].productName);
-                  this.tableData.splice(j, 1);
+              for (let j = 0; j < this.choosedList.length; j++) {
+                if (this.choosedList[j].subPurchaseOrderSn == sn) {
+                  this.addSuccessInfo(this.choosedList[j]);
+                  this.sendNotification(this.choosedList[j]);
+                  this.choosedList.splice(j, 1);
                   break;
                 }
               }
             } else {
-              for (let j = 0; j < this.tableData.length; j++) {
-                if (this.tableData[j].subPurchaseOrderSn == sn) {
-                  this.tableData[j].robTotal ++;
+              for (let j = 0; j < this.choosedList.length; j++) {
+                if (this.choosedList[j].subPurchaseOrderSn == sn) {
+                  this.choosedList[j].robTotal ++;
                   break;
                 }
               }
             }
         })
       },
-      sendSms(productName) {
-        this.$http.post(`/api/sms/sendSuccessSms`, null, {
+      addSuccessInfo(obj) {
+        this.$http.post(`/api/successInfo/add`, null, {
           params: {
-            productName: productName
+            productName: obj.productName,
+            subPurchaseOrderSn: obj.subPurchaseOrderSn,
+            mallId: obj.mallId,
+            mallName: obj.mallName,
+            categoryName: obj.category
           }
         }).then(res => {
           console.log(res)
         })
       },
-      sendNotification(productName) {
-        sendChromeNotification({productName: productName})
+      sendNotification(obj) {
+        sendChromeNotification({productName: obj.productName, mallName: obj.mallName})
       }
     }
   }