Commit b4b08a55 by 李伟康

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

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