|
|
@@ -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;
|