|
|
@@ -28,8 +28,8 @@
|
|
|
</view>
|
|
|
<view class="qty-display">
|
|
|
<input
|
|
|
- v-model.number="item.selectedQty"
|
|
|
- type="number"
|
|
|
+ v-model="numList[item.id]"
|
|
|
+ type="digit"
|
|
|
class="qty-input"
|
|
|
@blur="validateQty(item)">
|
|
|
</view>
|
|
|
@@ -44,7 +44,7 @@
|
|
|
|
|
|
<!-- 底部按钮栏 -->
|
|
|
<view class="popup-footer">
|
|
|
- <view class="footer-btn cancel-btn" @tap="clearAllFlowers">
|
|
|
+ <view class="footer-btn cancel-btn" @tap="confirmClearXj">
|
|
|
<text>清除全部</text>
|
|
|
</view>
|
|
|
<view class="footer-btn cancel-btn" @tap="handleCancel">
|
|
|
@@ -62,8 +62,7 @@ export default {
|
|
|
name: 'selectFlowerGrid',
|
|
|
props: {
|
|
|
flowerData: { type: Array, default: () => [] },
|
|
|
- customData:{ type:Object, default:()=>{} },
|
|
|
- customId: { type: Number, default: 0 }
|
|
|
+ customData:{ type:Object, default:()=>{} }
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
@@ -78,10 +77,13 @@ export default {
|
|
|
flowerData: {
|
|
|
handler(newData) {
|
|
|
const dataToUse = (newData && newData.length > 0) ? newData : []
|
|
|
- this.flowerList = dataToUse.map(item => ({
|
|
|
- ...item,
|
|
|
- selectedQty: item.selectedQty || 0
|
|
|
- }))
|
|
|
+ this.flowerList = dataToUse
|
|
|
+ // 初始化 numList,保持已有的数量
|
|
|
+ dataToUse.forEach(item => {
|
|
|
+ if (!this.numList[item.id]) {
|
|
|
+ this.numList[item.id] = 0
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
deep: true,
|
|
|
immediate: true
|
|
|
@@ -97,12 +99,10 @@ export default {
|
|
|
},
|
|
|
mounted() {
|
|
|
this.calculateScrollHeight()
|
|
|
-
|
|
|
},
|
|
|
methods: {
|
|
|
- // 初始化xj数据 - 对应 onLoad 逻辑
|
|
|
initXjData() {
|
|
|
- let saveInfo = uni.getStorageSync("xj" + this.customId)
|
|
|
+ let saveInfo = uni.getStorageSync("xj")
|
|
|
if (!this.$util.isEmpty(saveInfo)) {
|
|
|
saveInfo.forEach((item, index) => {
|
|
|
let hasList = item.list ? item.list : []
|
|
|
@@ -114,63 +114,47 @@ export default {
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
// 计算滚动区域高度
|
|
|
calculateScrollHeight() {
|
|
|
// 总高度 - 头部高度 - 底部按钮高度
|
|
|
this.scrollHeight = 'calc(100vh - 100upx - 90upx)'
|
|
|
},
|
|
|
-
|
|
|
// 增加数量
|
|
|
increaseQty(item) {
|
|
|
this.$util.hitVoice()
|
|
|
- item.selectedQty = parseInt(item.selectedQty) || 0
|
|
|
- item.selectedQty++
|
|
|
+ let currentNum = parseInt(this.numList[item.id]) || 0
|
|
|
+ this.$set(this.numList, item.id, currentNum + 1)
|
|
|
},
|
|
|
-
|
|
|
// 减少数量
|
|
|
decreaseQty(item) {
|
|
|
this.$util.hitVoice()
|
|
|
- item.selectedQty = parseInt(item.selectedQty) || 0
|
|
|
- if (item.selectedQty > 0) {
|
|
|
- item.selectedQty--
|
|
|
+ let currentNum = parseInt(this.numList[item.id]) || 0
|
|
|
+ if (currentNum > 0) {
|
|
|
+ this.$set(this.numList, item.id, currentNum - 1)
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
// 验证数量输入
|
|
|
validateQty(item) {
|
|
|
- let qty = parseInt(item.selectedQty) || 0
|
|
|
+ let qty = parseInt(this.numList[item.id]) || 0
|
|
|
if (qty < 0) {
|
|
|
- item.selectedQty = 0
|
|
|
+ this.$set(this.numList, item.id, 0)
|
|
|
+ } else {
|
|
|
+ this.$set(this.numList, item.id, qty)
|
|
|
}
|
|
|
- item.selectedQty = qty
|
|
|
},
|
|
|
-
|
|
|
- // 清除全部 - 对应 xj.vue 的 clearXj
|
|
|
- clearAllFlowers() {
|
|
|
- this.$util.confirmModal({content:'确认全部清除?'},() => {
|
|
|
- this.confirmClearXj()
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
- // 确认清除 - 对应 xj.vue 的 confirmClearXj
|
|
|
confirmClearXj() {
|
|
|
- uni.removeStorageSync("xj" + this.customId)
|
|
|
+ uni.removeStorageSync("xj")
|
|
|
if (!this.$util.isEmpty(this.numList)) {
|
|
|
this.numList.forEach((item, index, arr) => {
|
|
|
- arr[index] = ''
|
|
|
+ arr[index] = 0
|
|
|
})
|
|
|
this.$forceUpdate()
|
|
|
}
|
|
|
- this.$emit('clearAll', this.customData)
|
|
|
+ this.$emit('globalClearXj', this.customData)
|
|
|
},
|
|
|
-
|
|
|
- // 处理取消
|
|
|
handleCancel() {
|
|
|
- this.$emit('cancel')
|
|
|
+ this.$emit('globalCloseXjPop')
|
|
|
},
|
|
|
-
|
|
|
- // 处理确认 - 对应 xj.vue 的 confirmXj
|
|
|
handleConfirm() {
|
|
|
// 收集选中的花材
|
|
|
let arr = []
|
|
|
@@ -196,7 +180,6 @@ export default {
|
|
|
this.$msg("请填写数量哈")
|
|
|
return false
|
|
|
}
|
|
|
-
|
|
|
// 验证库存
|
|
|
if (totalNum > Number(this.customData.stock)) {
|
|
|
this.$msg("数量超过总库存")
|
|
|
@@ -204,7 +187,7 @@ export default {
|
|
|
}
|
|
|
|
|
|
// 保存到本地存储
|
|
|
- let saveInfo = uni.getStorageSync("xj" + this.customId)
|
|
|
+ let saveInfo = uni.getStorageSync("xj")
|
|
|
const ptItemId = this.customData.id ? this.customData.id : 0
|
|
|
if (!this.$util.isEmpty(saveInfo)) {
|
|
|
let getIndex = -1
|
|
|
@@ -221,11 +204,11 @@ export default {
|
|
|
} else {
|
|
|
saveInfo = [{ptItemId: ptItemId, list: arr}]
|
|
|
}
|
|
|
- uni.setStorageSync("xj" + this.customId, saveInfo)
|
|
|
+ uni.setStorageSync("xj", saveInfo)
|
|
|
|
|
|
// 返回确认数据
|
|
|
this.xjData = {price: this.unitPrice, stock: totalNum, hasUpdate: 1, cancel: 0}
|
|
|
- this.$emit('confirm', this.xjData)
|
|
|
+ this.$emit('globalConfirmChangeXj',this.customData, this.xjData)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -257,7 +240,7 @@ export default {
|
|
|
align-items: center;
|
|
|
|
|
|
text {
|
|
|
- font-size: 18upx;
|
|
|
+ font-size: 19upx;
|
|
|
color: #333333;
|
|
|
font-weight: 500;
|
|
|
margin-right: 10upx;
|