Commit e2861af4 by 李伟康

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

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