shish hai 2 meses
pai
achega
c319cf83b8

+ 36 - 2
ghsPad/src/pages/home/components/rightGoods.vue

@@ -5,12 +5,12 @@
             <view :class="[flower==1?'active':'']" @click="changeKind(1)">花束花篮</view>
         </view>
         <view class="num-area" v-if="flower==1">
-            <view v-for="info in flowerNumList" :class="[flowerNum===info.num?'selected':'']" @click="setNum(info)" :key="info.num">{{info.name}}</view>
+            <view v-for="info in flowerNumList" :class="[flowerNum===info.num?'selected':'']" :data-flower-num="info.num" @click="handleSetNum" :key="info.num">{{info.name}}</view>
         </view>
         <scroll-view class="shop-show_box" enable-flex="true" scroll-y="true" lower-threshold="20" @scrolltolower="reachBottom">
             <view class="goods-item-area">
             <view v-for="(item, goodsIdx) in list.data" :key="goodsItemRowKey(item, goodsIdx)" class="show-shop_box">
-                <view class="item-detail" @click="popAddModelFn(item)">
+                <view class="item-detail" :data-goods-index="goodsIdx" @click="handlePopAddGoodsClick">
                     <image class="img" :key="goodsItemRowKey(item, goodsIdx)" :src="item.smallCover" :lazy-load="false" mode="scaleToFill" ></image>
                     <!-- 半透明底:老安卓同上,蒙层(dim)+内层文案 -->
                     <view class="shop-info_price">
@@ -118,6 +118,37 @@ export default {
         addToClear(){
             this.$msg('请扫码打开')
         },
+        getEventDataset(e) {
+            const cur = e && e.currentTarget ? e.currentTarget : (e && e.target)
+            return (cur && cur.dataset) ? cur.dataset : {}
+        },
+        handleSetNum(e) {
+            const num = Number(this.getEventDataset(e).flowerNum)
+            const info = (this.flowerNumList || []).find(function (item) {
+                return Number(item.num) === num
+            })
+            if (info) {
+                this.setNum(info)
+            }
+        },
+        resolveGoodsItemFromEvent(e) {
+            const ds = this.getEventDataset(e)
+            const list = (this.list && this.list.data) ? this.list.data : []
+            if (ds.goodsIndex !== undefined && ds.goodsIndex !== '') {
+                const idx = Number(ds.goodsIndex)
+                if (!isNaN(idx) && list[idx]) {
+                    return list[idx]
+                }
+            }
+            return null
+        },
+        handlePopAddGoodsClick(e) {
+            const info = this.resolveGoodsItemFromEvent(e)
+            if (!info) {
+                return
+            }
+            this.popAddModelFn(info)
+        },
         setNum(info){
             this.$util.hitVoice()
             this.flowerNum = info.num
@@ -127,6 +158,9 @@ export default {
             this.getGoodsData()
         },
 		popAddModelFn(info) {
+            if (!info || info.id == null) {
+                return
+            }
             this.$util.hitVoice()
 			this.showAddModelFn({ ...info, currentNum: 1, unitPrice: info.price,unitType:0})
 		},

+ 40 - 5
ghsPad/src/pages/home/components/rightItem.vue

@@ -36,8 +36,9 @@
                 <text>{{ searchKeyword ? '未找到相关花材' : '暂无花材' }}</text>
             </view>
             <!-- key:id+property+下标,避免任意重复键;名称须用 text,避免 App 端 view 插值与 image 异步刷新不同步出现「名错图对」 -->
+            <!-- 小程序端 @click="fn(item)" 对 v-for 变量传递不稳定,改用 data-index + 列表取项 -->
             <view v-for="(item, flowerIdx) in filteredItemList" :key="flowerItemRowKey(item, flowerIdx)" class="show-shop_box">
-                <view class="item-detail" @click="popAddModelFn(item)">
+                <view class="item-detail" :data-flower-index="flowerIdx" @click="handlePopAddModelClick">
                     <!-- 收银格图片小,关闭懒加载可减少原生 image 与底部文案层的刷新不同步(偶发相邻标题串位) -->
                     <image class="img" :key="flowerItemRowKey(item, flowerIdx)" :src="item.cover" :lazy-load="false" mode="scaleToFill" ></image>
                     <!-- 多颜色类型标识 -->
@@ -47,8 +48,8 @@
                     <view class="shop-info_price">
                         <view class="shop-info_price_dim" />
                         <view class="shop-info_price_inner">
-                            <text class="flower-card-name" :key="'nm-' + flowerItemRowKey(item, flowerIdx)" @click.stop="quickAddItem(item)">{{ item.name }}</text>
-                            <view class="flower-card-meta" @click.stop="quickAddItem(item)">
+                            <text class="flower-card-name" :key="'nm-' + flowerItemRowKey(item, flowerIdx)" :data-flower-index="flowerIdx" @click.stop="handleQuickAddItemClick">{{ item.name }}</text>
+                            <view class="flower-card-meta" :data-flower-index="flowerIdx" @click.stop="handleQuickAddItemClick">
                                 <text>¥{{parseFloat(item.price)}}</text>
                                 <text v-if="Number(item.reachNumDiscount)>0 && Number(item.reachNum)>0" style="color:#FFEB3B;">{{ item.reachNum }}↓{{ item.reachNumDiscount?parseFloat(item.reachNumDiscount):0 }}</text>
                                 <text>剩{{parseFloat(item.stock)}}</text>
@@ -192,9 +193,37 @@ export default {
                 this.closeSearchBox()
             }
         },
-        handleCategoryClick(e){
+        getEventDataset(e) {
             const cur = e && e.currentTarget ? e.currentTarget : (e && e.target)
-            const ds = cur && cur.dataset ? cur.dataset : {}
+            return (cur && cur.dataset) ? cur.dataset : {}
+        },
+        resolveFlowerItemFromEvent(e) {
+            const ds = this.getEventDataset(e)
+            const list = this.filteredItemList || []
+            if (ds.flowerIndex !== undefined && ds.flowerIndex !== '') {
+                const idx = Number(ds.flowerIndex)
+                if (!isNaN(idx) && list[idx]) {
+                    return list[idx]
+                }
+            }
+            return null
+        },
+        handlePopAddModelClick(e) {
+            const info = this.resolveFlowerItemFromEvent(e)
+            if (!info) {
+                return
+            }
+            this.popAddModelFn(info)
+        },
+        handleQuickAddItemClick(e) {
+            const info = this.resolveFlowerItemFromEvent(e)
+            if (!info) {
+                return
+            }
+            this.quickAddItem(info)
+        },
+        handleCategoryClick(e){
+            const ds = this.getEventDataset(e)
             const list = this.globalRightItemClass || []
             let cat = null
             if (ds.cid !== undefined && ds.cid !== '') {
@@ -226,12 +255,18 @@ export default {
             this.searchKeyword = ''
         },
 		popAddModelFn(info) {
+            if (!info || info.id == null) {
+                return
+            }
             const property = info.property !== undefined ? info.property : 1
             this.notifyOperateItem({ ...info, property })
             this.$util.hitVoice()
 			this.showAddModelFn({ ...info, property, currentNum: 1, unitPrice: info.price,unitType:0})
 		},
         quickAddItem(info){
+            if (!info || info.id == null) {
+                return
+            }
             const property = info.property !== undefined ? info.property : 1
             this.notifyOperateItem({ ...info, property })
             const hasItem = this.selectList.find(item => Number(item.id) == Number(info.id) && Number(item.property) == Number(property))

+ 64 - 3
hdPad/src/pages/home/components/rightGoods.vue

@@ -1,10 +1,17 @@
 <template>
     <view class="shop-listType_box">
         <view class="cat-list-area">
-            <view v-for="item in classList" :key="item.id" :class="[item.id==selIndex ? 'active':'']" @click="changeMyClass(item)">{{item.categoryName}}</view>
+            <view
+                v-for="(item, classIdx) in classList"
+                :key="item.id"
+                :class="[item.id==selIndex ? 'active':'']"
+                :data-class-id="item.id"
+                :data-class-index="classIdx"
+                @click="handleClassClick"
+            >{{item.categoryName}}</view>
         </view>
         <view class="num-area" v-if="Number(selIndex) > 0">
-            <view v-for="info in flowerNumList" :class="[flowerNum===info.num?'selected':'']" @click="setNum(info)" :key="info.num">{{info.name}}</view>
+            <view v-for="info in flowerNumList" :class="[flowerNum===info.num?'selected':'']" :data-flower-num="info.num" @click="handleSetNum" :key="info.num">{{info.name}}</view>
         </view>
         <view class="shop-show_box">
             <scroll-view 
@@ -17,7 +24,7 @@
                     :key="goodsItemRowKey(item, gridIdx)"
                     class="show-shop_box"
                 >
-                    <view class="item-detail" @click="popAddModelFn(item)">
+                    <view class="item-detail" :data-goods-index="gridIdx" @click="handlePopAddGoodsClick">
                         <image
                             class="img"
                             :key="goodsItemRowKey(item, gridIdx)"
@@ -131,6 +138,54 @@ export default {
         addToClear(){
             this.$msg('请扫码打开')
         },
+        getEventDataset(e) {
+            const cur = e && e.currentTarget ? e.currentTarget : (e && e.target)
+            return (cur && cur.dataset) ? cur.dataset : {}
+        },
+        handleClassClick(e) {
+            const ds = this.getEventDataset(e)
+            const list = this.classList || []
+            let cat = null
+            if (ds.classId !== undefined && ds.classId !== '') {
+                cat = list.find(function (c) { return String(c.id) === String(ds.classId) })
+            }
+            if (!cat && ds.classIndex !== undefined && ds.classIndex !== '') {
+                const idx = Number(ds.classIndex)
+                if (!isNaN(idx)) {
+                    cat = list[idx]
+                }
+            }
+            if (cat) {
+                this.changeMyClass(cat)
+            }
+        },
+        handleSetNum(e) {
+            const num = Number(this.getEventDataset(e).flowerNum)
+            const info = (this.flowerNumList || []).find(function (item) {
+                return Number(item.num) === num
+            })
+            if (info) {
+                this.setNum(info)
+            }
+        },
+        resolveGoodsItemFromEvent(e) {
+            const ds = this.getEventDataset(e)
+            const list = (this.list && this.list.data) ? this.list.data : []
+            if (ds.goodsIndex !== undefined && ds.goodsIndex !== '') {
+                const idx = Number(ds.goodsIndex)
+                if (!isNaN(idx) && list[idx]) {
+                    return list[idx]
+                }
+            }
+            return null
+        },
+        handlePopAddGoodsClick(e) {
+            const info = this.resolveGoodsItemFromEvent(e)
+            if (!info) {
+                return
+            }
+            this.popAddModelFn(info)
+        },
         setNum(info){
             this.$util.hitVoice()
             this.flowerNum = info.num
@@ -140,6 +195,9 @@ export default {
             this.getShowData()
         },
 		popAddModelFn(info) {
+            if (!info || info.id == null) {
+                return
+            }
             this.$util.hitVoice()
 			this.showAddModelFn({ ...info, currentNum: 1, unitPrice: info.price,unitType:0})
 		},
@@ -167,6 +225,9 @@ export default {
             }
         },
         changeMyClass(item){
+            if (!item || item.id == null) {
+                return
+            }
             this.$util.hitVoice()
             this.selIndex = item.id
             this.list.data=[]

+ 72 - 8
hdPad/src/pages/home/components/rightItem.vue

@@ -19,7 +19,17 @@
         </view>
 
         <view class="cat-list-area">
-            <view v-for="item in globalRightItemClass" :key="item.id" :class="[globalRightItemCatId===item.id?'active':'']" @click="handleCategoryClick(item)" > {{item.name}} </view>
+            <!-- 小程序端 @click="fn(item)" 对 v-for 变量传递不稳定,改用 data-index + 列表取项 -->
+            <view
+                v-for="(catItem, catIdx) in globalRightItemClass"
+                :key="categoryTabKey(catItem, catIdx)"
+                :class="[globalRightItemCatId===catItem.id?'active':'']"
+                :data-cid="catItem.id"
+                :data-cat-index="catIdx"
+                @click.stop="handleCategoryClick"
+            >
+                <text class="cat-tab-name">{{ catItem.name }}</text>
+            </view>
         </view>
         <view class="shop-show_box">
             <view v-if="filteredItemList.length === 0" class="no-data-tip">
@@ -30,7 +40,7 @@
                 :key="flowerItemRowKey(item, gridIdx)"
                 class="show-shop_box"
             >
-                <view class="item-detail" @click="popAddModelFn(item)">
+                <view class="item-detail" :data-flower-index="gridIdx" @click="handlePopAddModelClick">
                     <image
                         class="img"
                         :key="flowerItemRowKey(item, gridIdx)"
@@ -45,11 +55,12 @@
                             <text
                                 class="flower-card-name"
                                 :key="'nm-' + flowerItemRowKey(item, gridIdx)"
-                                @click.stop="quickAddItem(item)"
+                                :data-flower-index="gridIdx"
+                                @click.stop="handleQuickAddItemClick"
                             >
                                 {{ item.name }}
                             </text>
-                            <view class="flower-card-meta" @click.stop="quickAddItem(item)">
+                            <view class="flower-card-meta" :data-flower-index="gridIdx" @click.stop="handleQuickAddItemClick">
                                 <text>¥{{ parseFloat(item.price) }}</text>
                                 <text>剩{{ parseFloat(item.stock) }}</text>
                             </view>
@@ -170,6 +181,11 @@ export default {
         }
     },
     methods:{
+        /** 顶部分类 tab:id + 下标,避免小程序/App 端点击项与展示不一致 */
+        categoryTabKey(catItem, index) {
+            const id = catItem && catItem.id != null ? catItem.id : 'noid'
+            return `cat-${id}-${index}`
+        },
         /** 与 ghsPad 一致:id + property + 行下标,避免 App 端 v-for 节点复用错位 */
         flowerItemRowKey(item, index) {
             const id = item && item.id != null ? item.id : 'noid'
@@ -185,11 +201,53 @@ export default {
                 this.closeSearchBox()
             }
         },
-        handleCategoryClick(item){
-            // 点击分类时清空搜索框
+        getEventDataset(e) {
+            const cur = e && e.currentTarget ? e.currentTarget : (e && e.target)
+            return (cur && cur.dataset) ? cur.dataset : {}
+        },
+        handleCategoryClick(e){
+            const ds = this.getEventDataset(e)
+            const list = this.globalRightItemClass || []
+            let cat = null
+            if (ds.cid !== undefined && ds.cid !== '') {
+                cat = list.find(function (c) { return String(c.id) === String(ds.cid) })
+            }
+            if (!cat && ds.catIndex !== undefined && ds.catIndex !== '') {
+                const idx = Number(ds.catIndex)
+                if (!isNaN(idx)) {
+                    cat = list[idx]
+                }
+            }
+            if (!cat || cat.id == null) {
+                return
+            }
             this.searchKeyword = ''
-            // 调用原来的分类切换方法
-            this.changeCategory(item)
+            this.changeCategory(cat)
+        },
+        resolveFlowerItemFromEvent(e) {
+            const ds = this.getEventDataset(e)
+            const list = this.filteredItemList || []
+            if (ds.flowerIndex !== undefined && ds.flowerIndex !== '') {
+                const idx = Number(ds.flowerIndex)
+                if (!isNaN(idx) && list[idx]) {
+                    return list[idx]
+                }
+            }
+            return null
+        },
+        handlePopAddModelClick(e) {
+            const info = this.resolveFlowerItemFromEvent(e)
+            if (!info) {
+                return
+            }
+            this.popAddModelFn(info)
+        },
+        handleQuickAddItemClick(e) {
+            const info = this.resolveFlowerItemFromEvent(e)
+            if (!info) {
+                return
+            }
+            this.quickAddItem(info)
         },
         toggleSearchBox(){
             this.showSearchBox = !this.showSearchBox
@@ -204,12 +262,18 @@ export default {
             this.searchKeyword = ''
         },
 		popAddModelFn(info) {
+            if (!info || info.id == null) {
+                return
+            }
             const property = info.property !== undefined ? info.property : 1
             this.notifyOperateItem({ ...info, property })
             this.$util.hitVoice()
 			this.showAddModelFn({ ...info, property, currentNum: 1, unitPrice: info.price,unitType:0})
 		},
         quickAddItem(info){
+            if (!info || info.id == null) {
+                return
+            }
             const property = info.property !== undefined ? info.property : 1
             this.notifyOperateItem({ ...info, property })
             const hasItem = this.selectList.find(item => Number(item.id) == Number(info.id) && Number(item.property) == Number(property))