|
@@ -1,4 +1,5 @@
|
|
|
import { api_executePayment, api_queryByParamName, api_studentOrderPage, api_userPaymentCancelRefund, api_userPaymentOrderUnpaid } from "../../api/login";
|
|
|
+import { formatPrice } from "../../utils/util";
|
|
|
// 获取应用实例
|
|
|
const app = getApp<IAppOption>()
|
|
|
Page({
|
|
@@ -16,10 +17,10 @@ Page({
|
|
|
id: 1,
|
|
|
label: "待付款",
|
|
|
},
|
|
|
- {
|
|
|
- id: 2,
|
|
|
- label: "待使用",
|
|
|
- },
|
|
|
+ // {
|
|
|
+ // id: 2,
|
|
|
+ // label: "待使用",
|
|
|
+ // },
|
|
|
{
|
|
|
id: 3,
|
|
|
label: "已完成",
|
|
@@ -28,10 +29,10 @@ Page({
|
|
|
id: 4,
|
|
|
label: "已取消",
|
|
|
},
|
|
|
- {
|
|
|
- id: 5,
|
|
|
- label: "售后",
|
|
|
- },
|
|
|
+ // {
|
|
|
+ // id: 5,
|
|
|
+ // label: "售后",
|
|
|
+ // },
|
|
|
// {
|
|
|
// id: 6,
|
|
|
// label: "已退款",
|
|
@@ -44,6 +45,7 @@ Page({
|
|
|
maxPage: 1, // 总分页数
|
|
|
refoundStatus: false,
|
|
|
cancelRefoundStatus: false,
|
|
|
+ paymentChannel: '',
|
|
|
goodsInfo: {}, // 选中的数据
|
|
|
},
|
|
|
|
|
@@ -89,6 +91,7 @@ Page({
|
|
|
try {
|
|
|
// @ApiModelProperty("订单状态 WAIT_PAY:待付款,WAIT_USE:待使用,SUCCESS:已完成,CLOSE:已取消")
|
|
|
const { data } = await api_studentOrderPage({
|
|
|
+ version: 'V2',
|
|
|
openId: app.globalData.userInfo?.liteOpenid,
|
|
|
page: currentPage,
|
|
|
rows: this.data.rows,
|
|
@@ -96,17 +99,31 @@ Page({
|
|
|
})
|
|
|
if (data.code == 200) {
|
|
|
const { rows, total } = data.data;
|
|
|
+
|
|
|
rows.forEach((item: any) => {
|
|
|
- item.amount = this.formatPrice(item.paymentCashAmount, 'ALL')
|
|
|
+ item.amount = formatPrice(item.paymentCashAmount, 'ALL')
|
|
|
item.statusName = this.formatOrderStatus(item.wechatStatus)
|
|
|
+ let originalPrice = 0
|
|
|
const studentPaymentOrderDetails = item.studentPaymentOrderDetails || [];
|
|
|
studentPaymentOrderDetails.forEach((student: any) => {
|
|
|
- student.originalPrice = this.formatPrice(student.paymentCashAmount, 'ALL');
|
|
|
+ student.originalPrice = formatPrice(student.originalPrice, 'ALL');
|
|
|
student.typeName = this.formatPeriod(student.activationCodeInfo?.times || 1, student.activationCodeInfo?.type);
|
|
|
+
|
|
|
+ // 总的日常价
|
|
|
+ originalPrice += Number(student.originalPrice || 0)
|
|
|
})
|
|
|
+
|
|
|
+ item.originalPrice = originalPrice
|
|
|
+ item.discountPrice = formatPrice(
|
|
|
+ originalPrice - item.paymentCashAmount,
|
|
|
+ "ALL"
|
|
|
+ )
|
|
|
+ const prices: any = formatPrice(item.paymentCashAmount)
|
|
|
+ item.integerPart = prices.integerPart
|
|
|
+ item.decimalPart = prices.decimalPart
|
|
|
item.studentPaymentOrderDetails = studentPaymentOrderDetails
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
const newList = this.data.recordList.concat(rows);
|
|
|
this.setData(
|
|
|
{
|
|
@@ -118,7 +135,7 @@ Page({
|
|
|
} else {
|
|
|
wx.hideLoading();
|
|
|
}
|
|
|
- } catch(e) {
|
|
|
+ } catch (e) {
|
|
|
console.log(e, 'e')
|
|
|
wx.hideLoading()
|
|
|
}
|
|
@@ -136,30 +153,18 @@ Page({
|
|
|
}
|
|
|
return template[status]
|
|
|
},
|
|
|
- // 格式化价格
|
|
|
- formatPrice(price: number, type?: string) {
|
|
|
- const amountStr = price.toFixed(2)
|
|
|
- const [integerPart, decimalPart] = amountStr.split('.');
|
|
|
- if(type === 'ALL') {
|
|
|
- return amountStr
|
|
|
- }
|
|
|
- return {
|
|
|
- integerPart,
|
|
|
- decimalPart
|
|
|
- }
|
|
|
- },
|
|
|
// 格式化类型
|
|
|
formatPeriod(num: number, type: string) {
|
|
|
- if(!num || !type) {
|
|
|
+ if (!num || !type) {
|
|
|
return ''
|
|
|
}
|
|
|
const template: any = {
|
|
|
- DAY: "天卡",
|
|
|
- MONTH: "月卡",
|
|
|
- YEAR: "年卡"
|
|
|
+ DAY: "天",
|
|
|
+ MONTH: "个月",
|
|
|
+ YEAR: "年"
|
|
|
}
|
|
|
- if(type === "YEAR" && num >= 99) {
|
|
|
- return '永久卡'
|
|
|
+ if (type === "YEAR" && num >= 99) {
|
|
|
+ return '永久'
|
|
|
}
|
|
|
return num + template[type]
|
|
|
},
|
|
@@ -186,7 +191,7 @@ Page({
|
|
|
onPay(e: any) {
|
|
|
const { dataset } = e.currentTarget
|
|
|
const item: any = this.data.recordList.find((item: any) => item.id === dataset.id)
|
|
|
- if(item) {
|
|
|
+ if (item) {
|
|
|
this.onSubmit({
|
|
|
orderNo: item.orderNo
|
|
|
})
|
|
@@ -199,13 +204,13 @@ Page({
|
|
|
},
|
|
|
onDetail(e: any) {
|
|
|
const { dataset } = e.currentTarget
|
|
|
- if(dataset.wechatstatus === "WAIT_PAY") {
|
|
|
- this.onSubmit({orderNo: dataset.orderno})
|
|
|
- } else {
|
|
|
+ // if (dataset.wechatstatus === "WAIT_PAY") {
|
|
|
+ // this.onSubmit({ orderNo: dataset.orderno })
|
|
|
+ // } else {
|
|
|
wx.navigateTo({
|
|
|
url: `../orders/order-result?orderNo=${dataset.orderno}&tabIdx=${this.data.tabIdx}`
|
|
|
})
|
|
|
- }
|
|
|
+ // }
|
|
|
},
|
|
|
// 购买
|
|
|
async onSubmit(goodsInfo: any) {
|
|
@@ -215,7 +220,7 @@ Page({
|
|
|
});
|
|
|
try {
|
|
|
const { orderNo } = goodsInfo
|
|
|
- const {data} = await api_userPaymentOrderUnpaid({
|
|
|
+ const { data } = await api_userPaymentOrderUnpaid({
|
|
|
orderNo: orderNo,
|
|
|
paymentType: 'WECHAT_MINI'
|
|
|
})
|
|
@@ -229,21 +234,30 @@ Page({
|
|
|
wx.hideLoading()
|
|
|
}
|
|
|
},
|
|
|
- async onExecutePay( paymentConfig: any, paymentType: string, orderNo: string) {
|
|
|
+ async onExecutePay(paymentConfig: any, paymentType: string, orderNo: string) {
|
|
|
wx.login({
|
|
|
success: async (wxres: any) => {
|
|
|
const res = await api_executePayment({
|
|
|
merOrderNo: paymentConfig.merOrderNo,
|
|
|
- paymentChannel: this.data.paymentChannel || 'wx_lite',
|
|
|
+ paymentChannel: this.data.paymentChannel || 'wx_lite',
|
|
|
paymentType,
|
|
|
userId: app.globalData.userInfo?.id,
|
|
|
code: wxres.code,
|
|
|
wxMiniAppId: app.globalData.appId
|
|
|
})
|
|
|
wx.hideLoading()
|
|
|
- if(res.data.code === 200) {
|
|
|
+ if (res.data.code === 200) {
|
|
|
this.onPaying(paymentType, res.data.data.reqParams, orderNo)
|
|
|
- } else {
|
|
|
+ } else if ([5435, 5436, 5437, 5439, 5442, 5443, 5408, 5427, 5432].includes(res.data.code)) {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: res.data.message,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ this.getList()
|
|
|
+ }, 1000);
|
|
|
+ } else {
|
|
|
this.onPayError(res.data.message)
|
|
|
}
|
|
|
},
|
|
@@ -304,19 +318,19 @@ Page({
|
|
|
const { dataset } = e.currentTarget
|
|
|
const item: any = this.data.recordList.find((item: any) => item.id === dataset.id)
|
|
|
console.log(dataset, item, 'item')
|
|
|
- if(!item) {
|
|
|
+ if (!item) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if(item.wechatStatus === "REFUNDING") {
|
|
|
+ if (item.wechatStatus === "REFUNDING") {
|
|
|
this.setData({
|
|
|
cancelRefoundStatus: true
|
|
|
}, async () => {
|
|
|
try {
|
|
|
const refundOrderId = item.refundOrderId
|
|
|
- const {data} = await api_userPaymentCancelRefund(refundOrderId)
|
|
|
+ const { data } = await api_userPaymentCancelRefund(refundOrderId)
|
|
|
wx.hideLoading()
|
|
|
- if(data.code == 200) {
|
|
|
+ if (data.code == 200) {
|
|
|
wx.showToast({ title: '取消退款成功', icon: 'none' })
|
|
|
this.onRefoundComfirm()
|
|
|
} else {
|
|
@@ -325,14 +339,14 @@ Page({
|
|
|
} catch {
|
|
|
}
|
|
|
})
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
const { orderNo, studentPaymentOrderDetails } = item
|
|
|
const goodsInfo: any = {
|
|
|
orderNo,
|
|
|
goods: []
|
|
|
}
|
|
|
- if(Array.isArray(studentPaymentOrderDetails)) {
|
|
|
+ if (Array.isArray(studentPaymentOrderDetails)) {
|
|
|
studentPaymentOrderDetails.forEach((item: any) => {
|
|
|
goodsInfo.goods.push({
|
|
|
...item,
|
|
@@ -348,7 +362,7 @@ Page({
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
- changeRefoundStatus(e: {detail: any}) {
|
|
|
+ changeRefoundStatus(e: { detail: any }) {
|
|
|
this.setData({
|
|
|
refoundStatus: e.detail,
|
|
|
cancelRefoundStatus: false,
|