优惠券:重构是否领取检查方式

pull/3/head
owen 2023-09-30 22:05:02 +08:00
parent 78da791d4c
commit 1ff0b665b6
5 changed files with 32 additions and 23 deletions

View File

@ -1,5 +1,6 @@
import request from "@/utils/request.js"; import request from "@/utils/request.js";
// 领取优惠券
export function takeCoupon(templateId) { export function takeCoupon(templateId) {
return request.post("app-api/promotion/coupon/take", { return request.post("app-api/promotion/coupon/take", {
templateId templateId
@ -11,14 +12,21 @@ export function getMatchCouponList(data) {
return request.get("app-api/promotion/coupon/match-list", data); return request.get("app-api/promotion/coupon/match-list", data);
} }
// 获得用户优惠劵列表
export function getCouponPage(data) { export function getCouponPage(data) {
return request.get("app-api/promotion/coupon/page", data); return request.get("app-api/promotion/coupon/page", data);
} }
// 获得优惠劵模板分页
export function getCouponTemplatePage(data) { export function getCouponTemplatePage(data) {
return request.get("app-api/promotion/coupon-template/page", data); return request.get("app-api/promotion/coupon-template/page", data);
} }
// 获得优惠劵模板列表
export function getCouponTemplateList(data) {
return request.get("app-api/promotion/coupon-template/list", data);
}
// 获得未使用的优惠劵数量 // 获得未使用的优惠劵数量
export function getUnusedCouponCount() { export function getUnusedCouponCount() {
return request.get("app-api/promotion/coupon/get-unused-count"); return request.get("app-api/promotion/coupon/get-unused-count");

View File

@ -11,7 +11,7 @@
<view class='item acea-row row-center-wrapper' v-for="(item,index) in coupon.list" <view class='item acea-row row-center-wrapper' v-for="(item,index) in coupon.list"
@click="getCouponUser(index, item.id)" :key='index'> @click="getCouponUser(index, item.id)" :key='index'>
<!-- 金额 --> <!-- 金额 -->
<view class='money acea-row row-column row-center-wrapper' :class='item.takeStatus?"moneyGray":""'> <view class='money acea-row row-column row-center-wrapper' :class='item.canTake ? "" : "moneyGray"'>
<view> <view>
<text v-if="item.discountType === 1" class='num'>{{ fen2yuan(item.discountPrice) }}</text> <text v-if="item.discountType === 1" class='num'>{{ fen2yuan(item.discountPrice) }}</text>
<text v-else class='num'>{{ (item.discountPercent / 10.0).toFixed(1) }} </text> <text v-else class='num'>{{ (item.discountPercent / 10.0).toFixed(1) }} </text>
@ -33,8 +33,8 @@
<view v-else> <view v-else>
{{ formatDate(item.validStartTime) + " - " + formatDate(item.validEndTime) }} {{ formatDate(item.validStartTime) + " - " + formatDate(item.validEndTime) }}
</view> </view>
<view class='bnt gray' v-if="item.takeStatus">{{item.use_title || ''}}</view> <view class='bnt bg-color' v-if="item.canTake">{{coupon.statusTile || ''}}</view>
<view class='bnt bg-color' v-else>{{coupon.statusTile || ''}}</view> <view class='bnt gray' v-else>{{item.use_title || ''}}</view>
</view> </view>
</view> </view>
</view> </view>
@ -88,11 +88,11 @@
getCouponUser: function(index, id) { getCouponUser: function(index, id) {
// //
let list = this.coupon.list; let list = this.coupon.list;
if (list[index].takeStatus && this.openType === 0) {
return;
}
switch (this.openType) { switch (this.openType) {
case 0: // case 0: //
if (!list[index].canTake) {
return;
}
CouponApi.takeCoupon(id).then(res => { CouponApi.takeCoupon(id).then(res => {
this.$util.Tips({ this.$util.Tips({
title: "领取成功" title: "领取成功"

View File

@ -819,8 +819,8 @@
* 获取优惠券 * 获取优惠券
*/ */
getCouponList(useType) { getCouponList(useType) {
CouponApi.getCouponTemplatePage({spuId: this.id, productScope: useType}).then(res => { CouponApi.getCouponTemplateList({spuId: this.id, productScope: useType, count: 10}).then(res => {
this.$set(this.coupon, 'list', res.data.list); this.$set(this.coupon, 'list', res.data);
}) })
}, },
/** /**

View File

@ -97,16 +97,16 @@
</navigator> </navigator>
</view> </view>
<view class="listBox acea-row"> <view class="listBox acea-row">
<view class="list" :class='item.takeStatus ? "listHui" : "listActive" ' <view class="list" :class='item.canTake ? "listActive" : "listHui"'
v-for="(item, index) in couponList" :key="index"> v-for="(item, index) in couponList" :key="index">
<view class="tit line1" :class='item.takeStatus ? "pricehui" : "titActive" '>{{ item.name }}</view> <view class="tit line1" :class='item.canTake ? "titActive" : "pricehui"'>{{ item.name }}</view>
<view class="price" :class='item.takeStatus ? "pricehui" : "icon-color" '> <view class="price" :class='item.canTake ? "icon-color" : "pricehui"'>
<text v-if="item.discountType === 1">{{ fen2yuan(item.discountPrice) }} </text> <text v-if="item.discountType === 1">{{ fen2yuan(item.discountPrice) }} </text>
<text v-else>{{ (item.discountPercent / 10.0).toFixed(1) }} </text> <text v-else>{{ (item.discountPercent / 10.0).toFixed(1) }} </text>
</view> </view>
<view class="ling" v-if="!item.takeStatus" :class='item.takeStatus ? "pricehui" : "icon-color" ' <view class="ling icon-color" v-if="item.canTake"
@click="getCoupon(item.id,index)">领取</view> @click="getCoupon(item.id,index)">领取</view>
<view class="ling" v-else :class='item.takeStatus ? "pricehui fonthui" : "icon-color" '>已领</view> <view class="ling pricehui fonthui" v-else></view>
<view class="priceM">{{ fen2yuan(item.usePrice) }}元可用</view> <view class="priceM">{{ fen2yuan(item.usePrice) }}元可用</view>
</view> </view>
</view> </view>
@ -184,6 +184,7 @@
import * as DecorateApi from '@/api/promotion/decorate.js'; import * as DecorateApi from '@/api/promotion/decorate.js';
import * as ProductUtil from '@/utils/product.js'; import * as ProductUtil from '@/utils/product.js';
import * as Util from '@/utils/util.js'; import * as Util from '@/utils/util.js';
export default { export default {
computed: mapGetters(['isLogin', 'uid']), computed: mapGetters(['isLogin', 'uid']),
components: { components: {
@ -381,8 +382,8 @@
* 获得优惠劵列表 * 获得优惠劵列表
*/ */
getcouponList() { getcouponList() {
CouponApi.getCouponTemplatePage({pageSize: 2}).then(res => { CouponApi.getCouponTemplateList({ count: 2 }).then(res => {
this.$set(this, 'couponList', res.data.list); this.$set(this, 'couponList', res.data);
}).catch(err => { }).catch(err => {
return this.$util.Tips({ return this.$util.Tips({
title: err title: err
@ -395,7 +396,7 @@
getCoupon: function(id, index) { getCoupon: function(id, index) {
CouponApi.takeCoupon(id).then(res => { CouponApi.takeCoupon(id).then(res => {
// //
this.$set(this.couponList[index], 'takeStatus', res.data !== true); this.$set(this.couponList[index], 'canTake', res.data !== true);
this.$util.Tips({ this.$util.Tips({
title: '领取成功' title: '领取成功'
}); });

View File

@ -9,7 +9,7 @@
<view style="height: 106rpx;"></view> <view style="height: 106rpx;"></view>
<view class='coupon-list' v-if="couponsList.length"> <view class='coupon-list' v-if="couponsList.length">
<view class='item acea-row row-center-wrapper' v-for="(item,index) in couponsList" :key="index"> <view class='item acea-row row-center-wrapper' v-for="(item,index) in couponsList" :key="index">
<view class='money' :class='item.takeStatus ? "moneyGray" : "" '> <view class='money' :class='item.canTake ? "" : "moneyGray"'>
<view> <view>
<text v-if="item.discountType === 1" class='num'>{{ fen2yuan(item.discountPrice) }}</text> <text v-if="item.discountType === 1" class='num'>{{ fen2yuan(item.discountPrice) }}</text>
<text v-else class='num'>{{ (item.discountPercent / 10.0).toFixed(1) }} </text> <text v-else class='num'>{{ (item.discountPercent / 10.0).toFixed(1) }} </text>
@ -18,11 +18,11 @@
</view> </view>
<view class='text'> <view class='text'>
<view class='condition line2'> <view class='condition line2'>
<span class='line-title' :class='(item.takeStatus)?"gray":""' <span class='line-title' :class='item.canTake ? "" : "gray"'
v-if='type === 1'>通用</span> v-if='type === 1'>通用</span>
<span class='line-title' :class='(item.takeStatus)?"gray":""' <span class='line-title' :class='item.canTake ? "" : "gray"'
v-else-if='type === 3'>品类</span> v-else-if='type === 3'>品类</span>
<span class='line-title' :class='(item.takeStatus)?"gray":""' v-else></span> <span class='line-title' :class='item.canTake ? "" : "gray"' v-else></span>
<span>{{item.name}}</span> <span>{{item.name}}</span>
</view> </view>
<view class='data acea-row row-between-wrapper'> <view class='data acea-row row-between-wrapper'>
@ -30,8 +30,8 @@
<view v-else> <view v-else>
{{ formatDate(item.validStartTime) + " - " + formatDate(item.validEndTime) }} {{ formatDate(item.validStartTime) + " - " + formatDate(item.validEndTime) }}
</view> </view>
<view class='bnt gray' v-if="item.takeStatus"></view> <view class='bnt bg-color' v-if="item.canTake" @click='getCoupon(item.id, index)'>立即领</view>
<view class='bnt bg-color' v-else @click='getCoupon(item.id, index)'>立即领</view> <view class='bnt gray' v-else></view>
</view> </view>
</view> </view>
</view> </view>
@ -112,7 +112,7 @@
// //
CouponApi.takeCoupon(id).then(res => { CouponApi.takeCoupon(id).then(res => {
// //
this.couponsList[index].takeStatus = res.data !== true; this.couponsList[index].canTake = res.data;
this.$set(this, 'couponsList', this.couponsList); this.$set(this, 'couponsList', this.couponsList);
this.$util.Tips({ this.$util.Tips({
title: '领取成功' title: '领取成功'