Commit 5f7c3ace by 李伟康

refactor(OrderPopup): 重构订单弹窗组件

- 提取公共逻辑到 popupmixin 中,减少重复代码
- 优化组件结构,提高可维护性和可扩展性
- 添加无数据提示功能,提升用户体验
- 修复了一些小问题,如搜索功能和数据加载逻辑
1 parent e488f0f3
......@@ -58,22 +58,15 @@
</template>
<script type='text/ecmascript-6'>
import popupmixin from './popupmixin'
export default {
mixins: [popupmixin],
name: 'CarModelList',
inject: ['userInfo'],
data () {
return {
list: [],
currentId: '',
searchList: [],
letter: 'A',
searchStatus: false,
}
},
props: {
params: Object,
data: Object,
},
mounted () {
},
methods: {
......@@ -93,7 +86,7 @@ export default {
if (data && data.length) {
this.initCarList(data)
params.cacheData = data
this.$emit('update:params', params)
this.updateParams(params)
}
},
initCarList (carData) {
......
......@@ -48,22 +48,15 @@
</template>
<script type='text/ecmascript-6'>
import popupmixin from './popupmixin'
export default {
mixins: [popupmixin],
name: 'CouponList',
inject: ['userInfo'],
data () {
return {
list: [],
currentId: '',
searchList: [],
searchStatus: false,
customerCouponList: []
}
},
props: {
params: Object,
data: Object,
},
watch: {
'data.customer.customerPhone': {
handler (val) {
......@@ -94,7 +87,7 @@ export default {
if (data && data.length) {
this.initCouponList(data)
params.cacheData = data
this.$emit('update:params', params)
this.updateParams(params)
}
},
initCouponList (data) {
......
......@@ -14,19 +14,14 @@
</template>
<script type='text/ecmascript-6'>
import popupmixin from './popupmixin'
export default {
mixins: [popupmixin],
name: 'DiversionMerchant',
inject: ['userInfo'],
data () {
return {
list: [],
currentId: ''
}
},
props: {
params: Object,
data: Object,
},
mounted () {
},
methods: {
......@@ -46,7 +41,7 @@ export default {
this.$emit('onComplete')
this.list = data
params.cacheData = data
this.$emit('update:params', params)
this.updateParams(params)
}
},
choose (i) {
......
......@@ -14,19 +14,15 @@
</template>
<script type='text/ecmascript-6'>
import popupmixin from './popupmixin'
export default {
mixins: [popupmixin],
name: 'EmployeeList',
inject: ['userInfo'],
data () {
return {
list: [],
currentId: ''
}
},
props: {
params: Object,
data: Object
},
mounted () {
},
methods: {
......@@ -49,7 +45,7 @@ export default {
this.$emit('onComplete')
this.list = data
params.cacheData = data
this.$emit('update:params', params)
this.updateParams(params)
}
},
handleSearch (searchValue) {
......
......@@ -22,23 +22,14 @@
</template>
<script type='text/ecmascript-6'>
import popupmixin from './popupmixin'
export default {
mixins: [popupmixin],
name: 'GoodsList',
inject: ['userInfo', 'baseConfigData'],
data () {
return {
list: [],
currentIds: [],
chooseList: [],
searchStatus: false,
searchList: [],
}
},
props: {
params: Object,
data: [Object, Array],
dataKey: String
},
mounted () {
},
methods: {
......@@ -60,7 +51,7 @@ export default {
if (response && response.length) {
this.list = this.initGoodsList(response)
params.cacheData = response
this.$emit('update:params', params)
this.updateParams(params)
}
},
handleSearch (searchValue) {
......
<template>
<view class="goods-list">
<!-- <template v-if="list.length"> -->
<template v-for="(item, index) in (searchStatus ? searchList : list)">
<view
:key="index"
@click="choose(item)"
:class="['item',{active: checkActive(item)}]"
>
<view class="title flex">
<view class="icon">
<uni-icons
type="circle"
:size="16"
color="#8C8C8C"
class="uni-icons"
></uni-icons>
<view class="sprite-icon icon-notice-success"></view>
</view>
{{item.packageGoods.packageAlias||item.packageGoods.packageName}}
<text class="price">¥{{item.packageGoods.upgradePrice}}</text>
</view>
<view class="package-list">
<template v-for="(i,ind) in item.packageGoods.goodsList">
<view
class="package-item flex"
:key="ind"
>
<view class="name">{{i.goodsAlias||i.upgradeGoodsAlias||i.upgradeGoodsName}}</view>
<view class="price">¥{{i.sellPrice}}</view>
<template v-if="params.loadComplete">
<template v-if="listData.length">
<template v-for="(item, index) in listData">
<view
:key="index"
@click="choose(item)"
:class="['item',{active: checkActive(item)}]"
>
<view class="title flex">
<view class="icon">
<uni-icons
type="circle"
:size="16"
color="#8C8C8C"
class="uni-icons"
></uni-icons>
<view class="sprite-icon icon-notice-success"></view>
</view>
{{item.packageGoods.packageAlias||item.packageGoods.packageName}}
<text class="price">¥{{item.packageGoods.upgradePrice}}</text>
</view>
<view class="package-list">
<template v-for="(i,ind) in item.packageGoods.goodsList">
<view
class="package-item flex"
:key="ind"
>
<view class="name">{{i.goodsAlias||i.upgradeGoodsAlias||i.upgradeGoodsName}}</view>
<view class="price">¥{{i.sellPrice}}</view>
</view>
</template>
</view>
</template>
</view>
</view>
</view>
</template>
</template>
</template>
<!-- </template> -->
</view>
</template>
<script type='text/ecmascript-6'>
import NP from 'number-precision'
import popupmixin from './popupmixin'
export default {
mixins: [popupmixin],
name: 'PackageList',
inject: ['userInfo', 'baseConfigData'],
data () {
return {
list: [],
currentIds: [],
chooseList: [],
searchStatus: false,
searchList: [],
}
},
props: {
params: Object,
data: [Object, Array],
dataKey: String
},
mounted () {
},
methods: {
......@@ -77,7 +70,7 @@ export default {
if (response && response.length) {
this.list = this.initGoodsList(response)
params.cacheData = response
this.$emit('update:params', params)
this.updateParams(params)
}
},
handleSearch (searchValue) {
......
<template>
<view class="goods-list">
<template v-for="(i, index) in (searchStatus ? searchList : list)">
<view
:key="index"
@click.stop="choose(i ,index)"
:class="['item',{active: checkActive(i) || i.active},{single:i.goodsFlag == 1}]"
>
<template v-if="i.goodsFlag == 1">
<view class="flex">
<view class="icon">
<uni-icons
type="circle"
:size="16"
color="#8C8C8C"
class="uni-icons"
></uni-icons>
<view class="sprite-icon icon-notice-success"></view>
</view>
<text class="goods-name text-hide">
{{replaceItemText(i.goods,'goodsAlias') ||replaceItemText(i.goods,'upgradeGoodsName') || replaceItemText(i.goodsInfo,'goodsName')}}
</text>
<template v-if="i.goods.merchantGoodsPosition && (i.goods.goodsInfo.goodsType == 1 || i.goods.goodsInfo.goodsType == baseConfigData.selfBuildFilmType)">
<text>「{{ i.goods.positionStr}}」</text>
<template v-if="params.loadComplete">
<template v-if="listData.length">
<template v-for="(i, index) in listData">
<view
:key="index"
@click.stop="choose(i ,index)"
:class="['item',{active: checkActive(i) || i.active},{single:i.goodsFlag == 1}]"
>
<template v-if="i.goodsFlag == 1">
<view class="flex">
<view class="icon">
<uni-icons
type="circle"
:size="16"
color="#8C8C8C"
class="uni-icons"
></uni-icons>
<view class="sprite-icon icon-notice-success"></view>
</view>
<text class="goods-name text-hide">
{{replaceItemText(i.goods,'goodsAlias') ||replaceItemText(i.goods,'upgradeGoodsName') || replaceItemText(i.goodsInfo,'goodsName')}}
</text>
<template v-if="i.goods.merchantGoodsPosition && (i.goods.goodsInfo.goodsType == 1 || i.goods.goodsInfo.goodsType == baseConfigData.selfBuildFilmType)">
<text>「{{ i.goods.positionStr}}」</text>
</template>
<text class="price">¥{{i.goods.price}}</text>
</view>
</template>
<text class="price">¥{{i.goods.price}}</text>
</view>
</template>
<template v-if="i.goodsFlag == 2">
<view class="title flex">
<view class="icon">
<uni-icons
type="circle"
:size="16"
color="#8C8C8C"
class="uni-icons"
></uni-icons>
<view class="sprite-icon icon-notice-success"></view>
</view>
{{i.multipleSpecificationsGoods.baseGoodsName}}
<template v-if="i.multipleSpecificationsGoods.goods && i.multipleSpecificationsGoods.goods.sellPrice">
<text class="price">¥{{i.multipleSpecificationsGoods.goods.sellPrice}}</text>
</template>
</view>
<template v-if="i.multipleSpecificationsGoods.specificationList && i.multipleSpecificationsGoods.specificationList.length">
<view
class="package-list"
:key="i.key"
>
<template v-for="(specific, specificIndex) in i.multipleSpecificationsGoods.specificationList">
<template v-if="i.goodsFlag == 2">
<view class="title flex">
<view class="icon">
<uni-icons
type="circle"
:size="16"
color="#8C8C8C"
class="uni-icons"
></uni-icons>
<view class="sprite-icon icon-notice-success"></view>
</view>
{{i.multipleSpecificationsGoods.baseGoodsName}}
<template v-if="i.multipleSpecificationsGoods.goods && i.multipleSpecificationsGoods.goods.sellPrice">
<text class="price">¥{{i.multipleSpecificationsGoods.goods.sellPrice}}</text>
</template>
</view>
<template v-if="i.multipleSpecificationsGoods.specificationList && i.multipleSpecificationsGoods.specificationList.length">
<view
class="package-list"
:key="i.key"
>
<template v-for="(specific, specificIndex) in i.multipleSpecificationsGoods.specificationList">
<picker
@click.stop
@change="handlePickerChange($event, {
<picker
@click.stop
@change="handlePickerChange($event, {
item:specific,
list:specific.specificationSelectValueList,
parent: i,
index
} )"
:range="specific.specificationSelectValueList"
:key="`key_${index}_${specificIndex}`"
>
<view class="package-item flex">
<view class="label">
{{specific.specificationName}}
</view>
<view class="value">
<template v-if="specific.value">
{{specific.value}}
</template>
<text
class="placeholder"
v-else
>请选择</text>
</view>
</view>
</picker>
:range="specific.specificationSelectValueList"
:key="`key_${index}_${specificIndex}`"
>
<view class="package-item flex">
<view class="label">
{{specific.specificationName}}
</view>
<view class="value flex">
<template v-if="specific.value">
{{specific.value}}
</template>
<text
class="placeholder flex"
v-else
>
请选择
</text>
<uni-icons
type="right"
size="14"
class="arrow"
/>
</view>
</view>
</picker>
</template>
</view>
</template>
</view>
</template>
</template>
</view>
</template>
</view>
</template>
</template>
</view>
</template>
<script type='text/ecmascript-6'>
import popupmixin from './popupmixin'
export default {
mixins: [popupmixin],
name: 'SkuGoodsList',
inject: ['userInfo', 'baseConfigData'],
data () {
return {
list: [],
currentIds: [],
chooseList: [],
searchStatus: false,
searchList: [],
}
},
props: {
params: Object,
data: [Object, Array],
dataKey: String
},
mounted () {
},
methods: {
......@@ -124,7 +126,7 @@ export default {
if (response && response.length) {
this.list = this.initGoodsList(response)
params.cacheData = response
this.$emit('update:params', params)
this.updateParams(params)
}
},
handleSearch (searchValue) {
......@@ -135,7 +137,12 @@ export default {
arr = []
goodsList.map(c => {
let name = ''
if (c.goodsFlag == 3 && c.packageGoods) name = c.packageGoods.packageName || c.packageGoods.packageAlias
if (c.goodsFlag == 1 && c.goods) {
name = c.goods.goodsAlias || c.goods.upgradeGoodsName || c.goods.goodsName || ''
}
if (c.goodsFlag == 2 && c.multipleSpecificationsGoods) {
name = c.multipleSpecificationsGoods.baseGoodsName
}
if (name.indexOf(searchValue) != -1) {
arr.push(c)
}
......@@ -462,6 +469,9 @@ export default {
margin-left: auto;
max-width: 50%;
flex-shrink: 0;
.arrow {
margin-left: 4rpx;
}
}
&:last-of-type {
border: none;
......
export default {
inject: ['userInfo', 'baseConfigData'],
data () {
return {
list: [],
searchStatus: false,
searchList: [],
chooseList: [],
currentId: '',
currentIds: [],
}
},
props: {
params: Object,
data: [Object, Array],
dataKey: String
},
computed: {
listData () {
return this.searchStatus ? this.searchList : this.list
},
noData () {
return !this.listData.length
}
},
watch: {
noData: {
handler (val) {
let { params } = this
params.noData = val
this.updateParams(params)
},
deep: true
}
},
methods: {
updateParams (params) {
this.$emit('update:params', params)
}
}
}
\ No newline at end of file
......@@ -21,39 +21,61 @@ const componentConfig = {
name: 'EmployeeList',
title: '销售顾问/录单员',
placeholder: '请输入姓名',
idKey: 'userId'
idKey: 'userId',
cacheData: [],
loadComplete: false,
searchValue: '',
noData: false
},
1: {
name: 'EmployeeList',
title: '交付专员',
placeholder: '请输入姓名',
nullTips: '请选择交付专员',
idKey: 'deliveryUserId'
idKey: 'deliveryUserId',
cacheData: [],
loadComplete: false,
searchValue: '',
noData: false
},
2: {
name: 'DiversionMerchant',
title: '二级流量方',
hideSearch: true,
idKey: 'subShopMerchantId'
idKey: 'subShopMerchantId',
cacheData: [],
loadComplete: false
},
3: {
name: 'EmployeeList',
title: '转化人员',
placeholder: '请输入姓名',
idKey: 'sellerUserId',
cacheData: [],
loadComplete: false,
searchValue: '',
noData: false
},
4: {
name: 'CarModelList',
title: '选择车型',
placeholder: '查找',
idKey: 'carSeriesId'
idKey: 'carSeriesId',
cacheData: [],
loadComplete: false,
searchValue: '',
noData: false
},
5: {
name: 'CouponList',
title: '选择礼券',
placeholder: '查找',
idKey: 'customerCouponCode',
nullTips: '优惠券不能为空'
nullTips: '优惠券不能为空',
cacheData: [],
loadComplete: false,
searchValue: '',
noData: false
},
6: {
name: 'GoodsList',
......@@ -61,7 +83,11 @@ const componentConfig = {
placeholder: '请输入名称',
idKey: 'goodsId',
nullTips: '请勾选商品',
goodsType: [1]//前档
goodsType: [1],//前档
cacheData: [],
loadComplete: false,
searchValue: '',
noData: false
},
7: {
name: 'GoodsList',
......@@ -69,7 +95,11 @@ const componentConfig = {
placeholder: '请输入名称',
idKey: 'goodsId',
nullTips: '请勾选商品',
goodsType: [2] // 前侧窗玻璃
goodsType: [2], // 前侧窗玻璃
cacheData: [],
loadComplete: false,
searchValue: '',
noData: false
},
8: {
name: 'GoodsList',
......@@ -77,7 +107,11 @@ const componentConfig = {
placeholder: '请输入名称',
idKey: 'goodsId',
nullTips: '请勾选商品',
goodsType: [3] // 后侧窗玻璃
goodsType: [3], // 后侧窗玻璃
cacheData: [],
loadComplete: false,
searchValue: '',
noData: false
},
9: {
name: 'GoodsList',
......@@ -85,7 +119,11 @@ const componentConfig = {
placeholder: '请输入名称',
idKey: 'goodsId',
nullTips: '请勾选商品',
goodsType: [4] // 后档
goodsType: [4],// 后档
cacheData: [],
loadComplete: false,
searchValue: '',
noData: false
},
10: {
name: 'GoodsList',
......@@ -93,26 +131,38 @@ const componentConfig = {
placeholder: '请输入名称',
idKey: 'goodsId',
nullTips: '请勾选商品',
goodsType: [5, 6, 7] // 天窗
goodsType: [5, 6, 7],// 天窗
cacheData: [],
loadComplete: false,
searchValue: '',
noData: false
},
11: {
name: 'PackageList',
title: '选择套餐',
placeholder: '查找',
nullTips: '请勾选套餐',
idKey: 'packageCode'
idKey: 'packageCode',
cacheData: [],
loadComplete: false,
searchValue: '',
noData: false
},
12: {
name: 'SkuGoodsList',
title: '选择商品',
nullTips: '请勾选商品',
placeholder: '查找',
cacheData: [],
loadComplete: false,
searchValue: '',
noData: false
},
13: {
name: 'DateTime',
title: '选择时间',
hideSearch: true,
loadComplete: false
}
}
export default { componentConfig }
\ No newline at end of file
......@@ -19,14 +19,14 @@
></uni-icons>
</view>
</view>
<template v-if="!componentObject.hideSearch">
<template v-if="!componentObject[popupType].hideSearch">
<view class="popup-search">
<input
class="input"
type="text"
:placeholder="componentObject.placeholder || '请输入'"
:placeholder="componentObject[popupType].placeholder || '请输入'"
placeholder-class="placeholder"
v-model="componentObject.searchValue"
v-model="componentObject[popupType].searchValue"
confirm-type="search"
@confirm="handleSearch"
>
......@@ -37,29 +37,33 @@
<uni-icons
type="closeempty"
size="16"
v-if="componentObject.searchValue"
v-if="componentObject[popupType].searchValue"
></uni-icons>
</view>
</view>
</template>
<view :class="['popup-body',{ 'hide-search' :componentObject.hideSearch}]">
<view :class="['popup-body',{ 'hide-search' :componentObject[popupType].hideSearch}]">
<scroll-view
scroll-y
:class="['popup-scroll-view',{show:loadComplete}]"
:class="['popup-scroll-view',{show:componentObject[popupType].loadComplete}]"
>
<component
:is="componentObject.name"
:params.sync="componentObject"
:is="componentObject[popupType].name"
:params.sync="componentObject[popupType]"
:data="data"
:dataKey="dataKey"
ref="componentRef"
@choose="chooseContent = $event"
@openSkuPopup="openSkuPopup"
@onComplete="loadComplete = true"
@onComplete="componentObject[popupType].loadComplete = true"
@updateCacheData="updateCacheData"
></component>
<template v-if="componentObject[popupType].noData">
<view class="nothing flex">暂无数据</view>
</template>
</scroll-view>
<image
v-if="!loadComplete"
v-if="!componentObject[popupType].loadComplete"
class="loading"
src="../../assets/images/common/loadding.gif"
/>
......@@ -127,14 +131,12 @@ export default {
return {
position: 'bottom',
chooseContent: null,
componentObject: null,
loadComplete: false
componentObject: config.componentConfig,
}
},
watch: {
popupType: {
handler (val) {
this.componentObject = config.componentConfig[this.popupType]
if (val == 11 || val == 12) this.position = 'right'
else this.position = 'bottom'
},
......@@ -143,9 +145,15 @@ export default {
},
externalData: {
handler (val) {
if (val && this.componentObject) this.componentObject.cacheData = val
if (val) {
}
if (val && val.length && this.componentObject[this.popupType]) {
this.componentObject[this.popupType].cacheData = val
}
},
deep: true,
immediate: true
}
},
computed: {
......@@ -170,6 +178,7 @@ export default {
this.initPopupData()
},
cancel () {
console.log()
this.$refs.popup.close()
this.$emit('cancel')
},
......@@ -180,7 +189,7 @@ export default {
initPopupData () {
let componentRef = this.componentRef()
if (!componentRef) setTimeout(this.initPopupData, .1e3)
else componentRef.getList && componentRef.getList(this.componentObject.searchValue)
else componentRef.getList && componentRef.getList(this.componentObject[this.popupType].searchValue)
},
handleSearch () {
let componentRef = this.componentRef()
......@@ -188,7 +197,7 @@ export default {
title: '请稍后再试',
icon: 'none'
})
else componentRef.handleSearch(this.componentObject.searchValue)
else componentRef.handleSearch(this.componentObject[this.popupType].searchValue)
},
confirm () {
try {
......@@ -197,14 +206,14 @@ export default {
chooseContent = this.componentRef().getResult()
}
if (chooseContent) {
if(Array.isArray(chooseContent) && !chooseContent.length && componentObject.nullTips) throw componentObject.nullTips
if (Array.isArray(chooseContent) && !chooseContent.length && componentObject[popupType].nullTips) throw componentObject.nullTips
this.$emit('onConfirm', {
chooseContent,
popupType
})
this.$refs.popup.close()
} else {
if (componentObject.nullTips) throw componentObject.nullTips
if (componentObject[popupType].nullTips) throw componentObject[popupType].nullTips
}
} catch (error) {
uni.showToast({
......@@ -224,9 +233,9 @@ export default {
})
},
clear () {
this.componentObject.searchValue = ''
this.componentObject[this.popupType].searchValue = ''
this.handleSearch()
}
},
}
}
</script>
......@@ -335,6 +344,15 @@ export default {
background: linear-gradient(0deg, #2c66f7 0%, #48a6ff 100%);
}
}
.nothing{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2;
justify-content: center;
}
}
.right-box {
width: 46vw;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!