shish 7 miesięcy temu
rodzic
commit
431ce7de27

+ 23 - 10
ghsPad/src/pages/home/components/rightItem.vue

@@ -28,7 +28,7 @@
 
         <!-- 花材网格选择弹框 -->
         <uni-popup ref="selectFlowerGridRef" background-color="#fff" type="center" :animation="false">
-            <selectFlowerGrid :flowerData="globalGridFlowerList" @confirm="confirmFlowerGrid" @cancel="cancelFlowerGrid" :customId.sync="customId" :customData.sync="customData"></selectFlowerGrid>
+            <selectFlowerGrid :flowerData="globalGridFlowerList" @clearAll="clearAll" @confirm="confirmFlowerGrid" @cancel="cancelFlowerGrid" :customId.sync="customId" :customData.sync="customData"></selectFlowerGrid>
         </uni-popup>
 
     </view>
@@ -94,6 +94,18 @@ export default {
         }
     },
     methods:{
+        clearAll(customData){
+            
+			//this.customData = this.xjDataInfo
+            // this.customData.bigCount = 0
+            // this.customData.smallCount = 0
+            // this.replaceItemFn(this.customData,1)
+
+            customData.bigCount = 0
+            customData.smallCount = 0
+            this.replaceItemFn(customData,1)
+
+        },
         addToClear(){
             this.$msg('请扫码打开')
         },
@@ -113,15 +125,16 @@ export default {
             this.listenScanItem()
         },
         // 确认花材网格选择
-        confirmFlowerGrid(selectedItems) {
-            // 处理选中的花材
-            selectedItems.forEach(item => {
-                // 这里可以根据需要处理已选择的花材
-                // 例如添加到购物车或其他操作
-                console.log(`已选择: ${item.name}, 数量: ${item.selectedQty}`)
-            })
-            this.$msg(`已选择 ${selectedItems.length} 种花材`)
-            this.$refs.selectFlowerGridRef.close()
+        confirmFlowerGrid(customData,xjData) {
+
+            customData.bigCount = xjData.stock
+            customData.smallCount = 0
+            customData.bigPrice = xjData.price
+            customData.price = xjData.price
+            customData.itemPrice = xjData.price
+            customData.userPrice = xjData.price
+            this.confirmAddItemModel(customData)
+
         },
         // 取消花材网格选择
         cancelFlowerGrid() {

+ 99 - 9
ghsPad/src/pages/home/components/selectFlowerGrid.vue

@@ -44,6 +44,9 @@
 
         <!-- 底部按钮栏 -->
         <view class="popup-footer">
+            <view class="footer-btn cancel-btn" @tap="clearAllFlowers">
+                <text>清除全部</text>
+            </view>
             <view class="footer-btn cancel-btn" @tap="handleCancel">
                 <text>取消</text>
             </view>
@@ -66,7 +69,9 @@ export default {
         return {
             flowerList: [],
             scrollHeight: '600upx',
-            unitPrice:0
+            unitPrice:0,
+            numList: [],
+            xjData: []
         }
     },
     watch: {
@@ -84,6 +89,7 @@ export default {
         customData:{
             handler(newData){
                 this.unitPrice = newData.unitPrice?parseFloat(newData.unitPrice):0
+                this.initXjData()
             },
             deep: true,
             immediate: true
@@ -91,8 +97,24 @@ export default {
     },
     mounted() {
         this.calculateScrollHeight()
+        
     },
     methods: {
+        // 初始化xj数据 - 对应 onLoad 逻辑
+        initXjData() {
+            let saveInfo = uni.getStorageSync("xj" + this.customId)
+            if (!this.$util.isEmpty(saveInfo)) {
+                saveInfo.forEach((item, index) => {
+                    let hasList = item.list ? item.list : []
+                    if (!this.$util.isEmpty(hasList)) {
+                        hasList.forEach((hasItem) => {
+                            this.numList[hasItem.id] = hasItem.num
+                        })
+                    }
+                })
+            }
+        },
+
         // 计算滚动区域高度
         calculateScrollHeight() {
             // 总高度 - 头部高度 - 底部按钮高度
@@ -124,18 +146,86 @@ export default {
             item.selectedQty = qty
         },
 
+        // 清除全部 - 对应 xj.vue 的 clearXj
+        clearAllFlowers() {
+            this.$util.confirmModal({content:'确认全部清除?'},() => {
+                this.confirmClearXj()
+            })
+        },
+
+        // 确认清除 - 对应 xj.vue 的 confirmClearXj
+        confirmClearXj() {
+            uni.removeStorageSync("xj" + this.customId)
+            if (!this.$util.isEmpty(this.numList)) {
+                this.numList.forEach((item, index, arr) => {
+                    arr[index] = ''
+                })
+                this.$forceUpdate()
+            }
+            this.$emit('clearAll', this.customData)
+        },
+
         // 处理取消
         handleCancel() {
             this.$emit('cancel')
         },
-        // 处理确认
+
+        // 处理确认 - 对应 xj.vue 的 confirmXj
         handleConfirm() {
-            const selectedItems = this.flowerList.filter(item => item.selectedQty > 0)
-            if (selectedItems.length === 0) {
-                this.$msg('请至少选择一种花材')
-                return
+            // 收集选中的花材
+            let arr = []
+            this.numList.forEach((num, id) => {
+                if (!this.$util.isEmpty(num) && Number(num) > 0) {
+                    arr.push({id: id, num: num})
+                }
+            })
+
+            // 验证单价
+            if (this.$util.isMoney(this.unitPrice) == false) {
+                this.$msg("请填写单价")
+                return false
+            }
+
+            // 计算总数量
+            let totalNum = 0
+            arr.forEach((item) => {
+                totalNum = (Number(item.num) + Number(totalNum)).toFixed(0)
+            })
+
+            if (totalNum <= 0) {
+                this.$msg("请填写数量哈")
+                return false
+            }
+
+            // 验证库存
+            if (totalNum > Number(this.customData.stock)) {
+                this.$msg("数量超过总库存")
+                return false
             }
-            this.$emit('confirm', selectedItems)
+
+            // 保存到本地存储
+            let saveInfo = uni.getStorageSync("xj" + this.customId)
+            const ptItemId = this.customData.id ? this.customData.id : 0
+            if (!this.$util.isEmpty(saveInfo)) {
+                let getIndex = -1
+                saveInfo.forEach((colorItem, colorIndex) => {
+                    if (colorItem.ptItemId == ptItemId) {
+                        getIndex = colorIndex
+                    }
+                })
+                if (getIndex > -1) {
+                    saveInfo[getIndex].list = arr
+                } else {
+                    saveInfo.push({ptItemId: ptItemId, list: arr})
+                }
+            } else {
+                saveInfo = [{ptItemId: ptItemId, list: arr}]
+            }
+            uni.setStorageSync("xj" + this.customId, saveInfo)
+
+            // 返回确认数据
+            this.xjData = {price: this.unitPrice, stock: totalNum, hasUpdate: 1, cancel: 0}
+            this.$emit('confirm', this.xjData)
         }
     }
 }
@@ -347,8 +437,8 @@ export default {
             justify-content: center;
             border-radius: 2.22upx;
             transition: all 0.3s;
-            min-width: 42upx;
-            max-width: 69upx;
+            min-width: 62upx;
+            max-width: 89upx;
 
             text {
                 font-size: 16upx;