Commit b4b08a55 by 李伟康

refactor(OrderPopup): 优化数据处理逻辑

- 在多个组件中替换数据处理逻辑,避免空数组判断
- 使用 data || [] 替代 if 语句,简化代码结构
- 统一处理空数据的情况,提高代码健壮性
1 parent 9561ab32
......@@ -85,7 +85,7 @@ export default {
data = await uni.$api.popupApi.getMerchantCarBrandList({
merchantId: shopMerchantId
})
if (data && data.length) this.updateParams(params, data)
this.updateParams(params, data || [])
},
initData (carData) {
let { params: { idKey }, data: { customer } } = this,
......
......@@ -88,7 +88,7 @@ export default {
yqMerchantId: merchantId,
orderByType: 9
})
if (data && data.length) this.updateParams(params, data)
this.updateParams(params, data || [])
},
initData (data) {
let couponTypeList = Array.from(new Set([...data.map((e) => e.couponInfo.couponType)])),
......
......@@ -36,7 +36,7 @@ export default {
const data = await uni.$api.popupApi.getDiversionMerchantRef({
merchantId: shopMerchantId
})
if (data && data.length) this.updateParams(params, data)
this.updateParams(params, data || [])
},
initData (data) {
this.list = data
......
......@@ -40,9 +40,9 @@ export default {
sceneList: params.idKey == 'sellerUserId' ? '' : [sceneType],
name: searchValue
})
if (data && data.length) this.updateParams(params, data)
this.updateParams(params, data || [])
},
initData(data){
initData (data) {
this.list = data
this.$emit('onComplete')
},
......
......@@ -4,11 +4,18 @@
<template v-if="listData.length">
<template v-for="(i, index) in listData">
<template v-if="isDefeatOrder">
<view class="item-box" :key="index">
<view
class="item-box"
:key="index"
>
<view class="goods-title flex">{{ i.goodsTypeName }}|建议价</view>
<view class="defeat-goods-list">
<template v-for="(item, ind) in i.upgradeGoodsList">
<view :class="['item flex', { active: checkActive(item) }]" :key="`${index}_${ind}`" @click="choose(item)">
<view
:class="['item flex', { active: checkActive(item) }]"
:key="`${index}_${ind}`"
@click="choose(item)"
>
<view class="sprite-icon icon-tag-checked"></view>
<text class="goods-name text-hide">
{{ replaceItemText(item, 'upgradeGoodsAlias') || replaceItemText(item, 'upgradeGoodsName') || replaceItemText(item.goodsInfo, 'goodsName') }}
......@@ -26,7 +33,11 @@
</view>
</template>
<template v-else>
<view :key="index" @click="choose(i)" :class="['item flex', { active: checkActive(i) }]">
<view
:key="index"
@click="choose(i)"
:class="['item flex', { active: checkActive(i) }]"
>
<view class="sprite-icon icon-tag-checked"></view>
<text class="goods-name text-hide">
{{ replaceItemText(i.goods, 'goodsAlias') || replaceItemText(i.goods, 'upgradeGoodsName') || replaceItemText(i.goodsInfo, 'goodsName') }}
......@@ -76,7 +87,7 @@ export default {
}
isDefeatOrder ? apiParams.upradeFlag = 'N' : apiParams.sceneType = sceneType
const data = await uni.$api.popupApi[apiName](apiParams)
if (data && data.length) this.updateParams(params, data)
this.updateParams(params, data || [])
},
handleSearch (searchValue) {
let { isDefeatOrder } = this
......
......@@ -67,7 +67,7 @@ export default {
merchantId: shopMerchantId,
sceneType
})
if (data && data.length) this.updateParams(params, data)
this.updateParams(params, data || [])
},
handleSearch (searchValue) {
if (!searchValue) this.searchStatus = false
......
......@@ -123,7 +123,7 @@ export default {
merchantId: shopMerchantId,
sceneType
})
if (data && data.length) this.updateParams(params, data)
this.updateParams(params, data || [])
},
handleSearch (searchValue) {
if (!searchValue) this.searchStatus = false
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!