Commit 54d23b27 by 李伟康

refactor(OrderPopup): 重构弹窗组件数据处理逻辑

- 移除 apiData 属性,使用 cacheData 代替
- 优化 getList 方法,优先使用缓存数据
- 更新数据处理流程,确保缓存数据的正确性和实时性
- 修复一些潜在的 bug,提高组件的健壮性
1 parent 04a83106
...@@ -67,16 +67,16 @@ export default { ...@@ -67,16 +67,16 @@ export default {
props: { props: {
params: Object, params: Object,
data: Object, data: Object,
apiData: Array
}, },
mounted () { mounted () {
}, },
methods: { methods: {
async getList (searchValue) { async getList (searchValue) {
const { userInfo, apiData } = this const { userInfo, params } = this,
{ cacheData } = params
this.currentId = '' this.currentId = ''
if (apiData && apiData.length) { if (cacheData && cacheData.length) {
this.list = apiData this.initCarList(cacheData)
if (searchValue) this.handleSearch(searchValue) if (searchValue) this.handleSearch(searchValue)
return return
} }
...@@ -84,7 +84,11 @@ export default { ...@@ -84,7 +84,11 @@ export default {
data = await uni.$api.popupApi.getMerchantCarBrandList({ data = await uni.$api.popupApi.getMerchantCarBrandList({
merchantId: shopMerchantId merchantId: shopMerchantId
}) })
if (data && data.length) this.initCarList(data) if (data && data.length) {
this.initCarList(data)
params.cacheData = data
this.$emit('update:params', params)
}
}, },
initCarList (carData) { initCarList (carData) {
let { params: { idKey }, data: { customer } } = this, let { params: { idKey }, data: { customer } } = this,
...@@ -99,7 +103,7 @@ export default { ...@@ -99,7 +103,7 @@ export default {
c.childs.map((s) => { c.childs.map((s) => {
s.carChildsBrandId = c.id; s.carChildsBrandId = c.id;
s.carChildsBrandName = c.name; s.carChildsBrandName = c.name;
if (customer[idKey]) { if (customer && customer[idKey]) {
if (s.id == customer[idKey]) { if (s.id == customer[idKey]) {
s.active = true; s.active = true;
this.letter = i.letter; this.letter = i.letter;
...@@ -125,7 +129,7 @@ export default { ...@@ -125,7 +129,7 @@ export default {
} }
}) })
this.list = carModelList this.list = carModelList
this.$emit('update:apiData', carModelList)
}, },
handleSearch (searchValue) { handleSearch (searchValue) {
if (!searchValue) { if (!searchValue) {
......
...@@ -26,17 +26,16 @@ export default { ...@@ -26,17 +26,16 @@ export default {
props: { props: {
params: Object, params: Object,
data: Object, data: Object,
apiData: Array
}, },
mounted () { mounted () {
}, },
methods: { methods: {
async getList () { async getList () {
const { userInfo, apiData } = this, const { userInfo: { shopMerchantId }, params } = this,
{ shopMerchantId } = userInfo { cacheData } = params
this.currentId = '' this.currentId = ''
if (apiData && apiData.length) { if (cacheData && cacheData.length) {
this.list = apiData this.list = cacheData
return return
} }
const data = await uni.$api.popupApi.getDiversionMerchantRef({ const data = await uni.$api.popupApi.getDiversionMerchantRef({
...@@ -44,7 +43,8 @@ export default { ...@@ -44,7 +43,8 @@ export default {
}) })
if (data && data.length) { if (data && data.length) {
this.list = data this.list = data
this.$emit('update:apiData', data) params.cacheData = data
this.$emit('update:params', params)
} }
}, },
choose (i) { choose (i) {
......
...@@ -26,16 +26,17 @@ export default { ...@@ -26,16 +26,17 @@ export default {
props: { props: {
params: Object, params: Object,
data: Object, data: Object,
apiData: Array cacheData: Array
}, },
mounted () { mounted () {
}, },
methods: { methods: {
async getList (searchValue, search) { async getList (searchValue, search) {
const { userInfo, params, apiData } = this const { userInfo, params } = this,
{ cacheData } = params
this.currentId = '' this.currentId = ''
if (!search && apiData && apiData.length) { if (!search && cacheData && cacheData.length) {
this.list = apiData this.list = cacheData
return return
} }
const { shopMerchantId, sceneType, merchantId } = userInfo, const { shopMerchantId, sceneType, merchantId } = userInfo,
...@@ -46,7 +47,8 @@ export default { ...@@ -46,7 +47,8 @@ export default {
}) })
if (data && data.length) { if (data && data.length) {
this.list = data this.list = data
this.$emit('update:apiData', data) params.cacheData = data
this.$emit('update:params', params)
} }
}, },
handleSearch (searchValue) { handleSearch (searchValue) {
......
...@@ -48,11 +48,10 @@ ...@@ -48,11 +48,10 @@
> >
<component <component
:is="componentObject.name" :is="componentObject.name"
:params="componentObject" :params.sync="componentObject"
:data="data" :data="data"
ref="componentRef" ref="componentRef"
@choose="chooseContent = $event" @choose="chooseContent = $event"
:apiData.sync="componentObject.apiData"
></component> ></component>
</scroll-view> </scroll-view>
...@@ -101,6 +100,7 @@ export default { ...@@ -101,6 +100,7 @@ export default {
type: Object, type: Object,
default: () => ({}) default: () => ({})
}, },
externalData: null
}, },
provide () { provide () {
return { return {
...@@ -122,10 +122,19 @@ export default { ...@@ -122,10 +122,19 @@ export default {
deep: true, deep: true,
immediate: true immediate: true
}, },
externalData: {
handler (val) {
this.componentObject.cacheData = val
},
deep: true,
}
}, },
computed: { computed: {
componentObject () { componentObject () {
return this.componentConfig[this.popupType] return {
...this.componentConfig[this.popupType],
cacheData: []
}
}, },
title () { title () {
return this.componentConfig[this.popupType].title return this.componentConfig[this.popupType].title
...@@ -175,7 +184,7 @@ export default { ...@@ -175,7 +184,7 @@ export default {
this.$refs.popup.close() this.$refs.popup.close()
} }
}, },
clear(){ clear () {
this.searchValue = '' this.searchValue = ''
this.handleSearch() this.handleSearch()
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!