Commit e2861af4 by 李伟康

feat(OrderPopup): 选择优惠券功能

- 新增 CouponList 组件,实现优惠券列表展示和选择功能
- 重构 CarModelList 组件,增加选中状态和搜索功能
- 修改 OrderPopup 组件,支持切换不同类型的弹窗内容
- 优化搜索逻辑,支持对优惠券名称和品牌名称的搜索
1 parent 7ce5ceeb
...@@ -28,7 +28,10 @@ ...@@ -28,7 +28,10 @@
{active: currentId ? j.id == currentId : j.id == data.customer[params.idKey]} {active: currentId ? j.id == currentId : j.id == data.customer[params.idKey]}
]" ]"
@click="choose(j,c)" @click="choose(j,c)"
>{{j.name}}</view> >
<view class="sprite-icon icon-tag-checked" v-if="!j.isTitle"></view>
{{j.name}}
</view>
</template> </template>
</view> </view>
</view> </view>
......
<template> <template>
<view class="car-model-box"> <view class="coupon-box">
<scroll-view <template v-if="customerCouponList.length">
class="scroll-view" <view class="item-box">
scroll-y <view class="coupon-title flex">客户拥有的券</view>
:scroll-into-view="letter" <view class="coupon-list">
> <template v-for="(c,cindex) in customerCouponList">
<template v-for="(i, index) in (searchStatus ? searchList : list)"> <view
<view :key="cindex"
class="item-box" :class="[
:key="index"
>
<view class="letter-title flex">{{i.title}}</view>
<view class="brand-list">
<template v-for="(c,cindex) in i.list">
<view
:key="cindex"
:class="[
'item flex', 'item flex',
{active: currentId ? c.id == currentId : c.id == data[params.idKey]}, {active: currentId ? c.customerCouponCode == currentId : c.customerCouponCode == data[params.idKey]},
{disabled: c.disabled}
]" ]"
@click="choose(c)" @click="choose(c,true)"
>{{c.couponName}}{{c.merchantCouponCode}}</view> >
</template> <view class="sprite-icon icon-tag-checked"></view>
</view> {{c.couponName}}{{c.customerCouponCode}}
</view>
</template>
</view> </view>
</template> </view>
</scroll-view> </template>
<view class="letter-list"> <template v-for="(i, index) in (searchStatus ? searchList : list)">
<template v-for="(i, index) in list"> <view
<view class="item-box"
class="letter-item" :key="index"
:key="index" >
@click="letter = i.letter" <view class="coupon-title flex">{{i.title}}</view>
> <view class="coupon-list">
{{i.letter}} <template v-for="(c,cindex) in i.list">
<view
:key="cindex"
:class="[
'item flex',
{active: currentId ? c.merchantCouponCode == currentId : c.merchantCouponCode == data[params.idKey]},
{disabled:checkDisabled(c) }
]"
@click="choose(c)"
>
<view class="sprite-icon icon-tag-checked"></view>
{{c.couponName}}{{c.merchantCouponCode}}
</view>
</template>
</view> </view>
</template> </view>
</view> </template>
</view> </view>
</template> </template>
<script type='text/ecmascript-6'> <script type='text/ecmascript-6'>
export default { export default {
name: 'CarModelList', name: 'CouponList',
inject: ['userInfo'], inject: ['userInfo'],
data () { data () {
return { return {
...@@ -51,12 +57,22 @@ export default { ...@@ -51,12 +57,22 @@ export default {
currentId: '', currentId: '',
searchList: [], searchList: [],
searchStatus: false, searchStatus: false,
customerCouponList: []
} }
}, },
props: { props: {
params: Object, params: Object,
data: Object, data: Object,
}, },
watch: {
'data.customer.customerPhone': {
handler (val) {
if (val) this.getCustomerCouponList(val)
},
deep: true,
immediate: true
}
},
mounted () { mounted () {
}, },
methods: { methods: {
...@@ -98,92 +114,86 @@ export default { ...@@ -98,92 +114,86 @@ export default {
list, list,
}; };
}) })
console.log(couponList)
this.list = couponList this.list = couponList
}, },
async getCustomerCouponList (customerPhone) {
const phoneRex = /^[1]([3-9])[0-9]{9}$/,
{ userInfo, params: formParams, data: orderObj } = this,
params = {
customerPhone,
statusList: [0, 1],
usedFlag: "N",
}
if (phoneRex.test(customerPhone)) {
const data = await uni.$api.popupApi.getCustomerCouponList(params)
this.customerCouponList = data.filter((item) => {
return (
item.status != 1 ||
(item.status == 1 && item.customerCouponCode == orderObj[formParams.idKey])
);
})
}
},
handleSearch (searchValue) { handleSearch (searchValue) {
if (!searchValue) { if (!searchValue) {
this.searchStatus = false this.searchStatus = false
this.letter = 'A'
} else { } else {
searchValue = searchValue.toUpperCase() searchValue = searchValue.toUpperCase()
let { list } = this, let { list } = this,
carBrand = JSON.parse(JSON.stringify(list)) couponList = JSON.parse(JSON.stringify(list))
let arr = []; let arr = [];
carBrand.map(c => { couponList.map((i) => {
c.list.map(i => { let list = [];
let childs_list = [], i.list.map((s) => {
i_name = i.name.toUpperCase() let name = s.couponName.toUpperCase()
i.childs_list.map((k) => { if (name.indexOf(searchValue) != -1) {
let k_name = k.name.toUpperCase() list.push(s);
if (k_name.indexOf(searchValue) != -1) {
childs_list.push(k);
}
});
if (i_name.indexOf(searchValue) != -1 || childs_list.length > 0) {
i.childs_list = childs_list.length > 0 ? childs_list : i.childs_list;
arr.push(i);
}
})
})
let letterList = Array.from(new Set([...arr.map((e) => e.letter)]));
let searchList = letterList.map((l) => {
let _list = [];
arr.map((i) => {
if (l === i.letter) {
_list.push(i);
} }
}) });
return { let title = i.title.toUpperCase()
letter: l, if (title.indexOf(searchValue) != -1 || list.length > 0) {
list: _list, i.list = list.length > 0 ? list : i.list;
arr.push(i);
} }
}) })
this.searchList = searchList this.searchList = arr
this.searchStatus = true this.searchStatus = true
} }
}, },
choose (that, item) { choose (item, isCustomer = false) {
if (that.isTitle) return if (item.disabled) return
let chooseItem = { let customerCouponCode = isCustomer ? item.customerCouponCode : item.merchantCouponCode,
carBrandId: item.id, key = isCustomer ? 'customerCouponId' : 'merchantCouponId',
carBrand: item.name, chooseItem = {
carChildsBrandId: that.carChildsBrandId, couponName: item.couponName,
carChildsBrandName: that.carChildsBrandName, merchantId: item.merchantId,
carSeriesId: that.id, customerCouponCode,
carSeriesName: that.name, [key]: item.id
} }
this.currentId = that.id this.currentId = customerCouponCode
this.$emit('choose', chooseItem) this.$emit('choose', chooseItem)
},
checkDisabled (item) {
let disabled = false,
{ customerCouponList } = this
if (customerCouponList.length) {
disabled = customerCouponList.some(i => i.merchantCoupon.id == item.id)
}
item.disabled = disabled
return disabled
} }
} }
} }
</script> </script>
<style scoped lang='scss'> <style scoped lang='scss'>
.car-model-box { .coupon-box {
position: relative; position: relative;
height: 100%; height: 100%;
width: 100%; width: 100%;
.scroll-view {
height: 100%;
}
.letter-list {
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 0;
color: #888888;
font-size: 28rpx;
line-height: 40rpx;
padding: 0 18rpx;
text-align: center;
}
.item-box { .item-box {
margin-bottom: 32rpx; margin-bottom: 32rpx;
.letter-title { .coupon-title {
color: #888888; color: #888888;
font-size: 28rpx; font-size: 28rpx;
height: 40rpx; height: 40rpx;
...@@ -192,7 +202,7 @@ export default { ...@@ -192,7 +202,7 @@ export default {
margin-bottom: 16rpx; margin-bottom: 16rpx;
} }
} }
.brand-list { .coupon-list {
// display: grid; // display: grid;
// grid-template-columns: repeat(4, 1fr); // grid-template-columns: repeat(4, 1fr);
gap: 32rpx; gap: 32rpx;
...@@ -211,7 +221,7 @@ export default { ...@@ -211,7 +221,7 @@ export default {
color: #333333; color: #333333;
font-size: 32rpx; font-size: 32rpx;
padding: 14rpx 16rpx; padding: 14rpx 16rpx;
word-break:break-all; word-break: break-all;
text-align: center; text-align: center;
.sprite-icon { .sprite-icon {
display: none; display: none;
...@@ -220,6 +230,9 @@ export default { ...@@ -220,6 +230,9 @@ export default {
right: 0; right: 0;
} }
} }
.disabled {
opacity: 0.5;
}
.active { .active {
border-color: #2c66f7; border-color: #2c66f7;
background: #ecf1ff; background: #ecf1ff;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
type="text" type="text"
:placeholder="componentObject.placeholder || '请输入'" :placeholder="componentObject.placeholder || '请输入'"
placeholder-class="placeholder" placeholder-class="placeholder"
v-model="searchValue" v-model="componentObject.searchValue"
confirm-type="search" confirm-type="search"
@confirm="handleSearch" @confirm="handleSearch"
> >
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
<uni-icons <uni-icons
type="closeempty" type="closeempty"
size="16" size="16"
v-if="searchValue" v-if="componentObject.searchValue"
></uni-icons> ></uni-icons>
</view> </view>
</view> </view>
...@@ -110,7 +110,6 @@ export default { ...@@ -110,7 +110,6 @@ export default {
data () { data () {
return { return {
position: 'bottom', position: 'bottom',
searchValue: '',
chooseContent: null, chooseContent: null,
componentObject: null, componentObject: null,
} }
...@@ -118,7 +117,6 @@ export default { ...@@ -118,7 +117,6 @@ export default {
watch: { watch: {
popupType: { popupType: {
handler (val) { handler (val) {
this.searchValue = ''
this.componentObject = this.componentConfig[this.popupType] this.componentObject = this.componentConfig[this.popupType]
}, },
deep: true, deep: true,
...@@ -160,7 +158,7 @@ export default { ...@@ -160,7 +158,7 @@ export default {
initPopupData () { initPopupData () {
let componentRef = this.componentRef() let componentRef = this.componentRef()
if (!componentRef) setTimeout(this.initPopupData, .1e3) if (!componentRef) setTimeout(this.initPopupData, .1e3)
else componentRef.getList && componentRef.getList(this.searchValue) else componentRef.getList && componentRef.getList(this.componentObject.searchValue)
}, },
handleSearch () { handleSearch () {
let componentRef = this.componentRef() let componentRef = this.componentRef()
...@@ -168,7 +166,7 @@ export default { ...@@ -168,7 +166,7 @@ export default {
title: '请稍后再试', title: '请稍后再试',
icon: 'none' icon: 'none'
}) })
else componentRef.handleSearch(this.searchValue) else componentRef.handleSearch(this.componentObject.searchValue)
}, },
confirm () { confirm () {
let { chooseContent, popupType } = this let { chooseContent, popupType } = this
...@@ -181,10 +179,9 @@ export default { ...@@ -181,10 +179,9 @@ export default {
} }
}, },
clear () { clear () {
this.searchValue = '' this.componentObject.searchValue = ''
this.handleSearch() this.handleSearch()
} }
} }
} }
</script> </script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!