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