|
@@ -42,6 +42,8 @@ Page({
|
|
|
rows: 10,
|
|
|
recordList: [],
|
|
|
maxPage: 1, // 总分页数
|
|
|
+ refoundStatus: false,
|
|
|
+ goodsInfo: {}, // 选中的数据
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -89,7 +91,7 @@ Page({
|
|
|
openId: app.globalData.userInfo?.liteOpenid,
|
|
|
page: currentPage,
|
|
|
rows: this.data.rows,
|
|
|
- wechatOrderStatus: tabIdx == 0 ? "" : tabIdx == 1 ? "WAIT_PAY" : tabIdx == 2 ? "WAIT_USE" : tabIdx == 3 ? "PAID" : tabIdx == 4 ? "CLOSED" : tabIdx == 5 ? 'REFUNDING' : "",
|
|
|
+ wechatOrderStatus: tabIdx == 0 ? "" : tabIdx == 1 ? "WAIT_PAY" : tabIdx == 2 ? "WAIT_USE" : tabIdx == 3 ? "PAID" : tabIdx == 4 ? "CLOSED" : tabIdx == 5 ? 'SALE_AFTER' : "",
|
|
|
})
|
|
|
if (data.code == 200) {
|
|
|
const { rows, total } = data.data;
|
|
@@ -183,33 +185,9 @@ Page({
|
|
|
onPay(e: any) {
|
|
|
const { dataset } = e.currentTarget
|
|
|
const item: any = this.data.recordList.find((item: any) => item.id === dataset.id)
|
|
|
- console.log(dataset, item, 'item')
|
|
|
if(item) {
|
|
|
- const studentPaymentOrderDetails = item.studentPaymentOrderDetails[0]
|
|
|
- const prices: any = this.formatPrice(item.paymentCashAmount)
|
|
|
- const params = {
|
|
|
- // buyNum: "0",
|
|
|
- decimalPart: prices.decimalPart,
|
|
|
- // id: "1856596669912584193",
|
|
|
- integerPart: prices.integerPart,
|
|
|
- userPaymentOrderDetailId: studentPaymentOrderDetails.userPaymentOrderDetailId,
|
|
|
- name: studentPaymentOrderDetails.goodsName,
|
|
|
- num: studentPaymentOrderDetails.goodsNum,
|
|
|
- originalPrice: studentPaymentOrderDetails.originalPrice,
|
|
|
- period: studentPaymentOrderDetails.activationCodeInfo.type,
|
|
|
- pic: studentPaymentOrderDetails.goodsUrl,
|
|
|
- salePrice: item.paymentCashAmount,
|
|
|
- // shopId: "1815717514476302337",
|
|
|
- orderNo: item.orderNo,
|
|
|
- wechatStatus: item.wechatStatus,
|
|
|
- // stockNum: "10",
|
|
|
- typeName: studentPaymentOrderDetails.typeName
|
|
|
- }
|
|
|
- let info = JSON.stringify(params);
|
|
|
- console.log(params, "params")
|
|
|
- info = encodeURIComponent(info);
|
|
|
- wx.navigateTo({
|
|
|
- url: `../orders/order-detail?orderInfo=${info}`,
|
|
|
+ this.onSubmit({
|
|
|
+ orderNo: item.orderNo
|
|
|
})
|
|
|
}
|
|
|
},
|
|
@@ -220,8 +198,167 @@ Page({
|
|
|
},
|
|
|
onDetail(e: any) {
|
|
|
const { dataset } = e.currentTarget
|
|
|
- wx.navigateTo({
|
|
|
- url: '../orders/order-result?orderNo=' + dataset.orderno
|
|
|
+ if(dataset.wechatstatus === "WAIT_PAY") {
|
|
|
+ console.log()
|
|
|
+ this.onSubmit({orderNo: dataset.orderno})
|
|
|
+ } else {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '../orders/order-result?orderNo=' + dataset.orderno
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 购买
|
|
|
+ async onSubmit(goodsInfo: any) {
|
|
|
+ wx.showLoading({
|
|
|
+ mask: true,
|
|
|
+ title: "订单提交中...",
|
|
|
+ });
|
|
|
+ try {
|
|
|
+ const { orderNo } = goodsInfo
|
|
|
+ const {data} = await api_userPaymentOrderUnpaid({
|
|
|
+ orderNo: orderNo,
|
|
|
+ paymentType: 'WECHAT_MINI'
|
|
|
+ })
|
|
|
+ if (data.code === 200) {
|
|
|
+ const { paymentConfig, paymentType, orderNo } = data.data.paymentConfig
|
|
|
+ this.onExecutePay(paymentConfig, paymentType, orderNo)
|
|
|
+ } else {
|
|
|
+ this.onPayError()
|
|
|
+ }
|
|
|
+ } catch {
|
|
|
+ wx.hideLoading()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 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',
|
|
|
+ paymentType,
|
|
|
+ userId: app.globalData.userInfo?.id,
|
|
|
+ code: wxres.code,
|
|
|
+ wxMiniAppId: app.globalData.appId
|
|
|
+ })
|
|
|
+ wx.hideLoading()
|
|
|
+ if(res.data.code === 200) {
|
|
|
+ this.onPaying(paymentType, res.data.data.reqParams, orderNo)
|
|
|
+ } else {
|
|
|
+ this.onPayError(res.data.message)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: () => {
|
|
|
+ this.onPayError()
|
|
|
+ }
|
|
|
})
|
|
|
},
|
|
|
+ onPaying(paymentType: string, paymentConfig: any, orderNo: string) {
|
|
|
+ const isYeePay = paymentType.indexOf('yeepay') !== -1
|
|
|
+ const prePayInfo = isYeePay ? JSON.parse(paymentConfig.prePayTn)
|
|
|
+ : paymentConfig?.expend
|
|
|
+ ? JSON.parse(paymentConfig?.expend?.pay_info)
|
|
|
+ : paymentConfig
|
|
|
+ const that = this
|
|
|
+ wx.requestPayment({
|
|
|
+ timeStamp: prePayInfo.timeStamp,
|
|
|
+ nonceStr: prePayInfo.nonceStr,
|
|
|
+ package: prePayInfo.package ? prePayInfo.package : prePayInfo.packageValue,
|
|
|
+ paySign: prePayInfo.paySign,
|
|
|
+ signType: prePayInfo.signType ? prePayInfo.signType : 'MD5',
|
|
|
+ success() {
|
|
|
+ wx.showToast({ title: '支付成功', icon: 'success' });
|
|
|
+ // that.onRefoundComfirm()
|
|
|
+ },
|
|
|
+ fail(ressonInfo) {
|
|
|
+ console.log('支付失败', ressonInfo)
|
|
|
+ that.onPayError()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 获取后台配置的支付方式
|
|
|
+ async queryPayType() {
|
|
|
+ try {
|
|
|
+ // wxlite_payment_service_provider
|
|
|
+ const { data } = await api_queryByParamName({
|
|
|
+ paramName: app.globalData.appId
|
|
|
+ });
|
|
|
+ if (data.code == 200) {
|
|
|
+ const paramValue = data.data.paramValue ? JSON.parse(data.data.paramValue) : {}
|
|
|
+ this.setData({
|
|
|
+ paymentType: paramValue.vendor,
|
|
|
+ paymentChannel: paramValue.channel
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error, "error");
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onPayError(message?: string) {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: message || '支付取消',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ },
|
|
|
+ async onRefounded(e: any) {
|
|
|
+ const { dataset } = e.currentTarget
|
|
|
+ const item: any = this.data.recordList.find((item: any) => item.id === dataset.id)
|
|
|
+ console.log(dataset, item, 'item')
|
|
|
+ if(!item) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if(item.wechatStatus === "REFUNDING") {
|
|
|
+ try {
|
|
|
+ const refundOrderId = item.refundOrderId
|
|
|
+ const {data} = await api_userPaymentCancelRefund(refundOrderId)
|
|
|
+ console.log(data, 'data')
|
|
|
+ if(data.code == 200) {
|
|
|
+ wx.showToast({ title: '取消退款成功', icon: 'none' })
|
|
|
+ this.onRefoundComfirm()
|
|
|
+ } else {
|
|
|
+ wx.showToast({ title: data.message, icon: 'none' })
|
|
|
+ }
|
|
|
+ } catch {}
|
|
|
+ } else {
|
|
|
+ const { orderNo, studentPaymentOrderDetails } = item
|
|
|
+ const goodsInfo: any = {
|
|
|
+ orderNo,
|
|
|
+ goods: []
|
|
|
+ }
|
|
|
+ if(Array.isArray(studentPaymentOrderDetails)) {
|
|
|
+ studentPaymentOrderDetails.forEach((item: any) => {
|
|
|
+ goodsInfo.goods.push({
|
|
|
+ ...item,
|
|
|
+ id: item.userPaymentOrderDetailId,
|
|
|
+ currentPrice: item.paymentCashAmount
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ goodsInfo,
|
|
|
+ refoundStatus: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ changeRefoundStatus(e: {detail: any}) {
|
|
|
+ this.setData({
|
|
|
+ refoundStatus: e.detail
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onRefoundComfirm() {
|
|
|
+ const that = this
|
|
|
+ this.setData({
|
|
|
+ refoundStatus: false
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ that.setData({
|
|
|
+ page: 1,
|
|
|
+ maxPage: 1,
|
|
|
+ recordList: [],
|
|
|
+ }, () => {
|
|
|
+ this.getList()
|
|
|
+ })
|
|
|
+ }, 1500);
|
|
|
+ },
|
|
|
})
|