From 9bc3cb5584fc9480d4e91a904dfebb2b4458c09b Mon Sep 17 00:00:00 2001 From: qiaomu <3520484422@qq.com> Date: Fri, 6 Dec 2024 17:41:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BC=98=E6=83=A0=E5=88=B8?= =?UTF-8?q?=EF=BC=8C=E7=A7=AF=E5=88=86=E4=BF=AE=E6=94=B9=EF=BC=88=E9=A2=86?= =?UTF-8?q?=E5=88=B8=E9=83=A8=E5=88=86=E6=B2=A1=E5=81=9A=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.json | 1 - components/discountCoupon/index.js | 25 ++++++++++- components/discountCoupon/index.wxml | 17 ++++--- pages/discountCoupon/index.js | 36 ++++++++++++++- pages/discountCoupon/index.json | 4 +- pages/discountCoupon/index.wxml | 16 ++++++- pages/integral/index.js | 30 ++++++++++++- pages/integral/index.json | 3 +- pages/integral/index.wxml | 7 ++- pages/integralRecord/index.js | 30 +++++++++++-- pages/integralRecord/index.json | 6 ++- pages/integralRecord/index.wxml | 22 ++++++++++ pages/my/index.js | 2 +- pages/my/index.wxml | 6 +-- pages/ticket/index.js | 66 ---------------------------- pages/ticket/index.json | 7 --- pages/ticket/index.wxml | 3 -- pages/ticket/index.wxss | 1 - service/system.js | 17 ++++++- utils/request.js | 4 +- 20 files changed, 198 insertions(+), 105 deletions(-) delete mode 100644 pages/ticket/index.js delete mode 100644 pages/ticket/index.json delete mode 100644 pages/ticket/index.wxml delete mode 100644 pages/ticket/index.wxss diff --git a/app.json b/app.json index 50f3120..28d92db 100644 --- a/app.json +++ b/app.json @@ -28,7 +28,6 @@ "pages/aid/law/index", "pages/aid/detail/index", "pages/aid/consult/index", - "pages/ticket/index", "pages/integral/index", "pages/discountCoupon/index", "pages/integralRecord/index" diff --git a/components/discountCoupon/index.js b/components/discountCoupon/index.js index 1100b62..6ff50f7 100644 --- a/components/discountCoupon/index.js +++ b/components/discountCoupon/index.js @@ -1,3 +1,8 @@ +import { alertInfo, alertSuccess, loadingFunc } from "../../utils/index" +import { redeemCoupons } from "../../service/system"; +import request from "../../utils/request" +const { OK } = request; + // components/discountCoupon/index.js Component({ @@ -5,7 +10,8 @@ Component({ * 组件的属性列表 */ properties: { - + type: Number, + data: Object }, /** @@ -20,7 +26,22 @@ Component({ */ methods: { handleUse() { - + alertInfo("敬请期待") + }, + handleChange() { + const { data } = this.data; + const that = this; + loadingFunc(async () => { + console.log("--------------========", data) + const { code, message } = await redeemCoupons({ id: data.id, type: 2 }) + console.log("code", code, 'message', message) + if (code !== OK) { + alertInfo(message) + return + } + alertSuccess("兑换成功") + this.triggerEvent("change", { id, type: 2 }) + }) } } }) \ No newline at end of file diff --git a/components/discountCoupon/index.wxml b/components/discountCoupon/index.wxml index bbee968..c1b1018 100644 --- a/components/discountCoupon/index.wxml +++ b/components/discountCoupon/index.wxml @@ -5,28 +5,33 @@ - 通用优惠券 + 通用优惠券 + 无门槛优惠券 + 满减券 - 有效期至2024.12.01 + 有效期至 {{ data.endTime }} - 30 + {{ data.discount }} 折 + {{ data.discountMoney }} 元 + - - 满30可用 + 满 {{ data.useMin }} 可用 - 仅限商城使用 + - 去使用 + 去领取 + 去兑换 \ No newline at end of file diff --git a/pages/discountCoupon/index.js b/pages/discountCoupon/index.js index d474e1a..e74c84c 100644 --- a/pages/discountCoupon/index.js +++ b/pages/discountCoupon/index.js @@ -1,11 +1,18 @@ // pages/discountCoupon/index.js + +import request from "../../utils/request" +import { getCurrentCoupons, getCurrentIntegral, getRedeemableCoupons } from "../../service/system"; +import { alertInfo, loadingFunc } from "../../utils/index"; +const { OK } = request; + Page({ /** * 页面的初始数据 */ data: { - + currentList: [], + canGetList: [], }, /** @@ -28,7 +35,32 @@ Page({ onShow() { }, - + async getCurrent() { + const that = this; + loadingFunc(async() => { + const { code, message, data = [], } = await getCurrentCoupons(); + if (code !== OK) { + alertInfo(message) + return + } + that.setData({ + currentList: data + }) + }) + }, + getCanGet() { + const that = this; + loadingFunc(async() => { + const { code, message, data = [], } = await getRedeemableCoupons({ type: 1 }); + if (code !== OK) { + alertInfo(message) + return + } + that.setData({ + currentList: data + }) + }) + }, /** * 生命周期函数--监听页面隐藏 */ diff --git a/pages/discountCoupon/index.json b/pages/discountCoupon/index.json index a6d770b..06c8be8 100644 --- a/pages/discountCoupon/index.json +++ b/pages/discountCoupon/index.json @@ -1,6 +1,8 @@ { "usingComponents": { - "navigator": "/components/navigator/index" + "navigator": "/components/navigator/index", + "van-tab": "@vant/weapp/tab/index", + "van-tabs": "@vant/weapp/tabs/index" }, "navigationStyle": "custom" } \ No newline at end of file diff --git a/pages/discountCoupon/index.wxml b/pages/discountCoupon/index.wxml index 3d23205..db106bb 100644 --- a/pages/discountCoupon/index.wxml +++ b/pages/discountCoupon/index.wxml @@ -1,2 +1,16 @@ - \ No newline at end of file + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pages/integral/index.js b/pages/integral/index.js index cd63725..f4445f6 100644 --- a/pages/integral/index.js +++ b/pages/integral/index.js @@ -1,6 +1,7 @@ // pages/integral/index.js import request from "../../utils/request" -import { getCurrentIntegral } from "../../service/system"; +import { getCurrentIntegral, getRedeemableCoupons } from "../../service/system"; +import { alertInfo, loadingFunc } from "../../utils/index"; const { OK } = request; Page({ @@ -10,6 +11,10 @@ Page({ */ data: { integral: 0, + page: 1, + size: 20, + list: [], + totalPage: 0, }, /** @@ -31,6 +36,28 @@ Page({ */ onShow() { this.getIntegral(); + this.getCoupons(); + }, + async getCoupons() { + const { page, size } = this.data + const { code, message, data, total } = await getRedeemableCoupons({ page, size, type: 2 }) + if (code !== OK) { + alertInfo(message) + return; + } + this.setData({ + list: data, + totalPage: Math.ceil(total / size), + }) + }, + refresh() { + const that = this; + that.setData({ + page: 1, + size: 20 + }, () => { + that.getCoupons() + }) }, jumpToRecord() { wx.navigateTo({ @@ -47,6 +74,7 @@ Page({ integral: data?.balance || 0 }) }, + /** * 生命周期函数--监听页面隐藏 */ diff --git a/pages/integral/index.json b/pages/integral/index.json index 9e5a1a4..b96ac58 100644 --- a/pages/integral/index.json +++ b/pages/integral/index.json @@ -1,7 +1,8 @@ { "usingComponents": { "navigator": "/components/navigator/index", - "discount-coupon": "/components/discountCoupon/index" + "discount-coupon": "/components/discountCoupon/index", + "empty": "/components/empty/index" }, "navigationStyle": "custom" } \ No newline at end of file diff --git a/pages/integral/index.wxml b/pages/integral/index.wxml index 3fa518b..2a9207e 100644 --- a/pages/integral/index.wxml +++ b/pages/integral/index.wxml @@ -5,7 +5,10 @@ 当前积分: {{ integral }} 查看积分明细 - - + + + + + \ No newline at end of file diff --git a/pages/integralRecord/index.js b/pages/integralRecord/index.js index 33703ae..88a5747 100644 --- a/pages/integralRecord/index.js +++ b/pages/integralRecord/index.js @@ -1,7 +1,7 @@ // pages/integralRecord/index.js import request from "../../utils/request" import { getIntegralRecord } from "../../service/system"; -import { alertInfo, loadingFunc } from "../../utils"; +import { alertInfo, loadingFunc } from "../../utils/index"; const { OK } = request; Page({ @@ -30,11 +30,27 @@ Page({ return; } this.setData({ - list: data || [], + list: data?.map(item => { + item.type = ['充值增加', '系统增加', '系统减少', '冲正减少', '退费减少', '兑换优惠券', '积分清零'][item.type] + item.nowBalance = Number(item.nowBalance || 0) + item.lastBalance = Number(item.lastBalance || 0) + item.value = item.nowBalance - item.lastBalance; + item.value = item.value > 0 ? `+${item.value}` : item.value + return item + }) || [], total, totalPage: Math.ceil(total / size), }) }, + refresh() { + const that = this; + this.setData({ + page: 1, + size: 20, + }, () => { + that.init(); + }) + }, /** * 生命周期函数--监听页面初次渲染完成 */ @@ -51,7 +67,15 @@ Page({ await that.init(); }) }, - + async onChangePage(e) { + const page = e.detail.currentIndex; + const that = this; + this.setData({ + page + }, () => { + that.init(); + }) + }, /** * 生命周期函数--监听页面隐藏 */ diff --git a/pages/integralRecord/index.json b/pages/integralRecord/index.json index a6d770b..58991b7 100644 --- a/pages/integralRecord/index.json +++ b/pages/integralRecord/index.json @@ -1,6 +1,10 @@ { "usingComponents": { - "navigator": "/components/navigator/index" + "navigator": "/components/navigator/index", + "van-cell": "@vant/weapp/cell/index", + "van-cell-group": "@vant/weapp/cell-group/index", + "empty": "/components/empty/index", + "pagination": "/components/pagination/index" }, "navigationStyle": "custom" } \ No newline at end of file diff --git a/pages/integralRecord/index.wxml b/pages/integralRecord/index.wxml index 5b0a52c..1ef3cb6 100644 --- a/pages/integralRecord/index.wxml +++ b/pages/integralRecord/index.wxml @@ -1,2 +1,24 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/pages/my/index.js b/pages/my/index.js index 6a28faa..1f3f353 100644 --- a/pages/my/index.js +++ b/pages/my/index.js @@ -66,7 +66,7 @@ Page({ } this.init() this.getUnReadNumber() - // this.getIntegral() + this.getIntegral() const tenement = wx.getStorageSync('tenement') this.setData({ tenement }) }, diff --git a/pages/my/index.wxml b/pages/my/index.wxml index 29fc796..a77c1d7 100644 --- a/pages/my/index.wxml +++ b/pages/my/index.wxml @@ -8,7 +8,7 @@ {{ user.nickName }} {{ tenement.name }} - 积分: - + 积分: {{ integral }} @@ -51,7 +51,7 @@ - + diff --git a/pages/ticket/index.js b/pages/ticket/index.js deleted file mode 100644 index 4775f6c..0000000 --- a/pages/ticket/index.js +++ /dev/null @@ -1,66 +0,0 @@ -// pages/ticket/index.js -Page({ - - /** - * 页面的初始数据 - */ - data: { - - }, - - /** - * 生命周期函数--监听页面加载 - */ - onLoad(options) { - - }, - - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady() { - - }, - - /** - * 生命周期函数--监听页面显示 - */ - onShow() { - - }, - - /** - * 生命周期函数--监听页面隐藏 - */ - onHide() { - - }, - - /** - * 生命周期函数--监听页面卸载 - */ - onUnload() { - - }, - - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh() { - - }, - - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom() { - - }, - - /** - * 用户点击右上角分享 - */ - onShareAppMessage() { - - } -}) \ No newline at end of file diff --git a/pages/ticket/index.json b/pages/ticket/index.json deleted file mode 100644 index 9e5a1a4..0000000 --- a/pages/ticket/index.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "usingComponents": { - "navigator": "/components/navigator/index", - "discount-coupon": "/components/discountCoupon/index" - }, - "navigationStyle": "custom" -} \ No newline at end of file diff --git a/pages/ticket/index.wxml b/pages/ticket/index.wxml deleted file mode 100644 index ef43b1f..0000000 --- a/pages/ticket/index.wxml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/pages/ticket/index.wxss b/pages/ticket/index.wxss deleted file mode 100644 index 2d42574..0000000 --- a/pages/ticket/index.wxss +++ /dev/null @@ -1 +0,0 @@ -/* pages/ticket/index.wxss */ \ No newline at end of file diff --git a/service/system.js b/service/system.js index 6206f57..fbf4cf9 100644 --- a/service/system.js +++ b/service/system.js @@ -79,4 +79,19 @@ export const getCurrentIntegral = async function() { // 获取积分明细 export const getIntegralRecord = async function({ page, size }) { return await GET(`/integral/getWxIntegralList/detail?page=${page}&size=${size}`); -} \ No newline at end of file +} + +// 获取优惠券列表 +export const getRedeemableCoupons = async function({ page, size, type }) { + return await GET(`/wx/getRedeemableCoupons?page=${page}&size=${size}&type=${type}`); +} + +// 获取优惠券列表 +export const redeemCoupons = async function({ id, type }) { + return await POST(`/wx/redeemCoupons`, { id, type }); +} + +// 获取当前拥有的优惠券列表 +export const getCurrentCoupons = async function() { + return await GET(`/wx/getCurrentCoupons`); +} diff --git a/utils/request.js b/utils/request.js index 921723b..a6434d0 100644 --- a/utils/request.js +++ b/utils/request.js @@ -87,7 +87,7 @@ const parseResponse = function (response, url) { alertError("服务异常") return } - console.log('url', url,'statusCode', statusCode, 'response.data', response) + console.log('url', url,'statusCode', statusCode, 'response.data', response?.data) if (code === 401) { const currentUrl = getPageUrl() @@ -107,7 +107,7 @@ const parseResponse = function (response, url) { url: '/pages/login/index', }) wx.clearStorageSync() - return { code: 404, message: "服务故障" } + return { code: 404, message: "服务不存在" } } if (500 <= code && code < 600) { return { code: 500, message: "服务错误" }