Commit cc2f11f8 by 李伟康

refactor(OrderPopup): 重构弹窗组件的初始化和数据更新逻辑

- 将 initCarList、initCouponList 等方法统一改为 initData
- 优化了缓存数据的处理逻辑,减少重复代码
- 调整了数据更新和参数更新的流程,提高了组件的可维护性
- 重构了部分方法,提高了代码的可读性和执行效率
1 parent 5f7c3ace
...@@ -75,7 +75,7 @@ export default { ...@@ -75,7 +75,7 @@ export default {
{ cacheData } = params { cacheData } = params
this.currentId = '' this.currentId = ''
if (cacheData && cacheData.length) { if (cacheData && cacheData.length) {
this.initCarList(cacheData) this.initData(cacheData)
if (searchValue) this.handleSearch(searchValue) if (searchValue) this.handleSearch(searchValue)
return return
} }
...@@ -83,13 +83,9 @@ export default { ...@@ -83,13 +83,9 @@ export default {
data = await uni.$api.popupApi.getMerchantCarBrandList({ data = await uni.$api.popupApi.getMerchantCarBrandList({
merchantId: shopMerchantId merchantId: shopMerchantId
}) })
if (data && data.length) { if (data && data.length) this.updateParams(params, data)
this.initCarList(data)
params.cacheData = data
this.updateParams(params)
}
}, },
initCarList (carData) { initData (carData) {
let { params: { idKey }, data: { customer } } = this, let { params: { idKey }, data: { customer } } = this,
letterList = Array.from(new Set([...carData.map((e) => e.letter)])), letterList = Array.from(new Set([...carData.map((e) => e.letter)])),
carModelList = letterList.map(e => { carModelList = letterList.map(e => {
......
...@@ -74,7 +74,7 @@ export default { ...@@ -74,7 +74,7 @@ export default {
{ cacheData } = params { cacheData } = params
this.currentId = '' this.currentId = ''
if (cacheData && cacheData.length) { if (cacheData && cacheData.length) {
this.initCouponList(cacheData) this.initData(cacheData)
if (searchValue) this.handleSearch(searchValue) if (searchValue) this.handleSearch(searchValue)
return return
} }
...@@ -84,13 +84,9 @@ export default { ...@@ -84,13 +84,9 @@ export default {
yqMerchantId: merchantId, yqMerchantId: merchantId,
orderByType: 9 orderByType: 9
}) })
if (data && data.length) { if (data && data.length) this.updateParams(params, data)
this.initCouponList(data)
params.cacheData = data
this.updateParams(params)
}
}, },
initCouponList (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)])),
couponList = couponTypeList.map((e, index) => { couponList = couponTypeList.map((e, index) => {
let list = []; let list = [];
......
...@@ -30,19 +30,17 @@ export default { ...@@ -30,19 +30,17 @@ export default {
{ cacheData } = params { cacheData } = params
this.currentId = '' this.currentId = ''
if (cacheData && cacheData.length) { if (cacheData && cacheData.length) {
this.$emit('onComplete') this.initData(cacheData)
this.list = cacheData
return return
} }
const data = await uni.$api.popupApi.getDiversionMerchantRef({ const data = await uni.$api.popupApi.getDiversionMerchantRef({
merchantId: shopMerchantId merchantId: shopMerchantId
}) })
if (data && data.length) { if (data && data.length) this.updateParams(params, data)
this.$emit('onComplete') },
initData (data) {
this.list = data this.list = data
params.cacheData = data this.$emit('onComplete')
this.updateParams(params)
}
}, },
choose (i) { choose (i) {
this.currentId = i.subMerchantId this.currentId = i.subMerchantId
......
...@@ -31,8 +31,7 @@ export default { ...@@ -31,8 +31,7 @@ export default {
{ cacheData } = params { cacheData } = params
this.currentId = '' this.currentId = ''
if (!search && cacheData && cacheData.length) { if (!search && cacheData && cacheData.length) {
this.$emit('onComplete') this.initData(cacheData)
this.list = cacheData
return return
} }
const { shopMerchantId, sceneType, merchantId } = userInfo, const { shopMerchantId, sceneType, merchantId } = userInfo,
...@@ -41,12 +40,11 @@ export default { ...@@ -41,12 +40,11 @@ export default {
sceneList: params.idKey == 'sellerUserId' ? '' : [sceneType], sceneList: params.idKey == 'sellerUserId' ? '' : [sceneType],
name: searchValue name: searchValue
}) })
if (data && data.length) { if (data && data.length) this.updateParams(params, data)
this.$emit('onComplete') },
initData(data){
this.list = data this.list = data
params.cacheData = data this.$emit('onComplete')
this.updateParams(params)
}
}, },
handleSearch (searchValue) { handleSearch (searchValue) {
this.list = [] this.list = []
......
...@@ -39,20 +39,16 @@ export default { ...@@ -39,20 +39,16 @@ export default {
this.currentIds = [] this.currentIds = []
this.chooseList = [] this.chooseList = []
if (cacheData && cacheData.length) { if (cacheData && cacheData.length) {
this.list = this.initGoodsList(cacheData) this.initData(cacheData)
if (searchValue) this.handleSearch(searchValue) if (searchValue) this.handleSearch(searchValue)
return return
} }
const { shopMerchantId, sceneType } = userInfo, const { shopMerchantId, sceneType } = userInfo,
response = await uni.$api.popupApi.getGoodsList({ data = await uni.$api.popupApi.getGoodsList({
merchantId: shopMerchantId, merchantId: shopMerchantId,
sceneType sceneType
}) })
if (response && response.length) { if (data && data.length) this.updateParams(params, data)
this.list = this.initGoodsList(response)
params.cacheData = response
this.updateParams(params)
}
}, },
handleSearch (searchValue) { handleSearch (searchValue) {
if (!searchValue) this.searchStatus = false if (!searchValue) this.searchStatus = false
...@@ -71,9 +67,9 @@ export default { ...@@ -71,9 +67,9 @@ export default {
this.searchStatus = true this.searchStatus = true
} }
}, },
initGoodsList (goodsData) { initData (goodsData) {
let { goodsType } = this.params, let { goodsType } = this.params,
{ data ,dataKey } = this, { data, dataKey } = this,
arr = [] arr = []
goodsData.map(val => { goodsData.map(val => {
if (val.goodsFlag == 1) { if (val.goodsFlag == 1) {
...@@ -91,7 +87,7 @@ export default { ...@@ -91,7 +87,7 @@ export default {
this.chooseList.push(e) this.chooseList.push(e)
}) })
this.$emit('onComplete') this.$emit('onComplete')
return arr this.list = arr
}, },
choose (i) { choose (i) {
let { goodsId } = i.goods, let { goodsId } = i.goods,
......
...@@ -58,20 +58,16 @@ export default { ...@@ -58,20 +58,16 @@ export default {
this.currentIds = [] this.currentIds = []
this.chooseList = [] this.chooseList = []
if (cacheData && cacheData.length) { if (cacheData && cacheData.length) {
this.list = this.initGoodsList(cacheData) this.initData(cacheData)
if (searchValue) this.handleSearch(searchValue) if (searchValue) this.handleSearch(searchValue)
return return
} }
const { shopMerchantId, sceneType } = userInfo, const { shopMerchantId, sceneType } = userInfo,
response = await uni.$api.popupApi.getGoodsList({ data = await uni.$api.popupApi.getGoodsList({
merchantId: shopMerchantId, merchantId: shopMerchantId,
sceneType sceneType
}) })
if (response && response.length) { if (data && data.length) this.updateParams(params, data)
this.list = this.initGoodsList(response)
params.cacheData = response
this.updateParams(params)
}
}, },
handleSearch (searchValue) { handleSearch (searchValue) {
if (!searchValue) this.searchStatus = false if (!searchValue) this.searchStatus = false
...@@ -90,7 +86,7 @@ export default { ...@@ -90,7 +86,7 @@ export default {
this.searchStatus = true this.searchStatus = true
} }
}, },
initGoodsList (goodsData) { initData (goodsData) {
let { data, dataKey } = this, let { data, dataKey } = this,
arr = [] arr = []
goodsData.map(val => { goodsData.map(val => {
...@@ -108,7 +104,7 @@ export default { ...@@ -108,7 +104,7 @@ export default {
this.chooseList.push(e) this.chooseList.push(e)
}) })
this.$emit('onComplete') this.$emit('onComplete')
return arr this.list = arr
}, },
choose (i) { choose (i) {
let { packageCode } = i.packageGoods, let { packageCode } = i.packageGoods,
......
...@@ -114,20 +114,16 @@ export default { ...@@ -114,20 +114,16 @@ export default {
this.currentIds = [] this.currentIds = []
this.chooseList = [] this.chooseList = []
if (cacheData && cacheData.length) { if (cacheData && cacheData.length) {
this.list = this.initGoodsList(cacheData) this.initData(cacheData)
if (searchValue) this.handleSearch(searchValue) if (searchValue) this.handleSearch(searchValue)
return return
} }
const { shopMerchantId, sceneType } = userInfo, const { shopMerchantId, sceneType } = userInfo,
response = await uni.$api.popupApi.getGoodsList({ data = await uni.$api.popupApi.getGoodsList({
merchantId: shopMerchantId, merchantId: shopMerchantId,
sceneType sceneType
}) })
if (response && response.length) { if (data && data.length) this.updateParams(params, data)
this.list = this.initGoodsList(response)
params.cacheData = response
this.updateParams(params)
}
}, },
handleSearch (searchValue) { handleSearch (searchValue) {
if (!searchValue) this.searchStatus = false if (!searchValue) this.searchStatus = false
...@@ -151,7 +147,7 @@ export default { ...@@ -151,7 +147,7 @@ export default {
this.searchStatus = true this.searchStatus = true
} }
}, },
initGoodsList (goodsData) { initData (goodsData) {
let { data, dataKey } = this, let { data, dataKey } = this,
arr = [] arr = []
goodsData.map((val) => { goodsData.map((val) => {
...@@ -190,8 +186,8 @@ export default { ...@@ -190,8 +186,8 @@ export default {
this.chooseList.push(e) this.chooseList.push(e)
} }
}) })
this.list = arr
this.$emit('onComplete') this.$emit('onComplete')
return arr
}, },
async choose (i, index) { async choose (i, index) {
if (i.goodsFlag == 2) { if (i.goodsFlag == 2) {
......
...@@ -34,8 +34,13 @@ export default { ...@@ -34,8 +34,13 @@ export default {
} }
}, },
methods: { methods: {
updateParams (params) { updateParams (params, data) {
if (data) {
this.initData && this.initData(data)
params.cacheData = data
}
this.$emit('update:params', params) this.$emit('update:params', params)
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!