From ccda9ec2fe70d8f51ef184eafc04b78d22dfbabd Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期三, 26 六月 2024 15:02:28 +0800 Subject: [PATCH] 小程序,教材,课程 --- pages/cart/paymentPage/index.js | 256 +++++++++++++++++++++++++++++++++------------------ 1 files changed, 165 insertions(+), 91 deletions(-) diff --git a/pages/cart/paymentPage/index.js b/pages/cart/paymentPage/index.js index fcad534..9e747a2 100644 --- a/pages/cart/paymentPage/index.js +++ b/pages/cart/paymentPage/index.js @@ -1,13 +1,20 @@ // pages/cart/paymentPage/index.js +import Toast from 'tdesign-miniprogram/toast/index'; + const app = getApp() -import { getPublicImage } from '../../../assets/js/middleGround/tool'; -import drawQrcode from './js/weapp.qrcode' +import { + getPublicImage +} from '../../../assets/js/middleGround/tool'; + Page({ /** * 椤甸潰鐨勫垵濮嬫暟鎹� */ data: { + loading: true, + hidden: true, + myOrderOrderNumber: [], orderNumber: null, navBarHeight: '', barHeight: '', @@ -15,20 +22,21 @@ purchasedIds: [], productList: [], payPrice: '', - drawQrcodeText: 'https://www.baidu.com/', orderGoods: '', - - - confirmBtn: { content: '纭畾', variant: 'base' }, - dialogKey: 'false', - + isPaySuccess: false, + isPayComplete: false, + type: '', + onNorderSaleMethod: '', + ImmediatelyReceive: '' }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad(options) { - + wx.setNavigationBarTitle({ + title: '鎻愪氦璁㈠崟' + }); const systInfo = wx.getSystemInfoSync(); const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅 const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴� @@ -36,47 +44,12 @@ orderNumber: options.orderNumber, navBarHeight: navBarHeight, barHeight: systInfo.statusBarHeight, - selectedIds: options.selectedIds + selectedIds: options.selectedIds, + onNorderSaleMethod: options.onNorderSaleMethod }) - console.log('鎺ユ敹鍒扮殑璁㈠崟鍙�:', this.data.orderNumber); - - - this.getOrderByOrderNum() - - - - - drawQrcode({ - - width: 200, // 蹇呴』锛屼簩缁寸爜瀹藉害锛屼笌canvas鐨剋idth淇濇寔涓�鑷� - - height: 200, // 蹇呴』锛屼簩缁寸爜楂樺害锛屼笌canvas鐨刪eight淇濇寔涓�鑷� - - canvasId: 'myQrcode', - - background: '#ffffff', // 闈炲繀椤伙紝浜岀淮鐮佽儗鏅鑹诧紝榛樿鍊肩櫧鑹� - - foreground: '#2bb15e', // 闈炲繀椤伙紝浜岀淮鐮佸墠鏅壊锛岄粯璁ゅ�奸粦鑹� '#000000' - - // ctx: wx.createCanvasContext('myQrcode'), // 闈炲繀椤伙紝缁樺浘涓婁笅鏂囷紝鍙�氳繃 wx.createCanvasContext('canvasId') 鑾峰彇锛寁1.0.0+鐗堟湰鏀寔 - - text: this.data.drawQrcodeText, // 蹇呴』锛屼簩缁寸爜鍐呭 - // v1.0.0+鐗堟湰鏀寔鍦ㄤ簩缁寸爜涓婄粯鍒跺浘鐗� - - image: { - // imageResource: '../../images/icon.png', // 鎸囧畾浜岀淮鐮佸皬鍥炬爣 - dx: 70, - dy: 70, - dWidth: 60, - dHeight: 60 - } - }) - - - - - - + console.log(this.data.onNorderSaleMethod, 'options'); + this.getOrderByOrderNumData() + this.getDataList() }, /** @@ -131,72 +104,173 @@ wx.navigateBack(); }, - - getOrderByOrderNum() { + // 閲戦鏄剧ず.00鏍煎紡 + numFormat(value) { + if (!value) return "0.00"; + value = Number(value).toFixed(2); + var intPart = Math.trunc(value); // 鑾峰彇鏁存暟閮ㄥ垎 + var intPartFormat = intPart + .toString() + .replace(/(\d)(?=(?:\d{3})+$)/g, "$1,"); // 灏嗘暣鏁伴儴鍒嗛�笁涓�鏂� + var floatPart = ".00"; // 棰勫畾涔夊皬鏁伴儴鍒� + var value2Array = value.split("."); + // =2琛ㄧず鏁版嵁鏈夊皬鏁颁綅 + if (value2Array.length === 2) { + floatPart = value2Array[1].toString(); // 鎷垮埌灏忔暟閮ㄥ垎 + if (floatPart.length === 1) { + return `${intPartFormat}.${floatPart}0`; + } + return `${intPartFormat}.${floatPart}`; + } + return intPartFormat + floatPart; + }, + getOrderByOrderNumData() { + console.log(this.data.orderNumber, 'this.data.orderNumber'); let query = { orderNum: this.data.orderNumber, fields: { content: [], subtitle: [], - - } } app.MG.store.getOrderByOrderNum(query).then(res => { - console.log(res, 'res'); this.setData({ orderGoods: res.orderNumber }) - console.log(this.data.orderGoods, 'res.orderNumber'); - - console.log(res.payPrice); this.setData({ - payPrice: res.payPrice.toFixed(2) + payPrice: res.payPrice.toFixed(2), + ImmediatelyReceive: res.payPrice }) + console.log(this.data.ImmediatelyReceive); res.saleMethodLinks.forEach(item => { - + const type = item.orderSaleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product'; + item.type = type; // 灏唗ype璁剧疆涓篿tem瀵硅薄鐨勫睘鎬э紝鑰屼笉鏄娇鐢╯etData item.paymentIcon = getPublicImage(item.orderSaleMethod.product.icon) - console.log(item.orderSaleMethod.type); + item.payPrice = this.numFormat(item.payPrice) + console.log(item, 'item'); + }) + this.setData({ + productList: res.saleMethodLinks, + loading: false, + hidden: false, + }) - this.setData({ - productList: res.saleMethodLinks, - type: item.orderSaleMethod.type == 'createProductItemSaleMethod' ? 'item' : 'product' - }) + }) + }, + getDataList() { + let data = { + start: 0, + size: 999, + filterList: [{ + field: 'State', + value: 'WaitPay' + }], + sort: { + type: 'Desc', + field: 'CreateDate' + } + } + app.MG.store.getUserOrderList(data).then((res) => { + res.datas.forEach((item) => { + this.data.myOrderOrderNumber.push(item.saleMethodLinks[0].orderSaleMethod.id) + console.log(this.data.myOrderOrderNumber); }) }) }, confirmOrderGet() { + if (this.data.myOrderOrderNumber.includes(parseInt(this.data.onNorderSaleMethod))) { + Toast({ + context: this, + selector: '#t-toast', + message: '宸茬粡鍦ㄨ鍗曚腑', + theme: 'warning', + direction: 'column', + }); + } else { + var that = this; + let query = { + orderNum: this.data.orderGoods + } + app.MG.store.confirmOrder(query).then(res => { + console.log(res.orderNumber, 'res'); + if (res.orderNumber) { + let resOrderNum = { + orderNum: res.orderNumber, + platform: "WeChatAppCustom" + }; + console.log(resOrderNum, 'resOrderNum'); + // 鐢ㄦ埛鏈粦瀹氬井淇� 鎶�500 + app.MG.store.makeWeChatPay(resOrderNum).then(payRes => { + console.log(payRes, 'payRes'); + if (payRes) { + const payVal = JSON.parse(payRes); + console.log(payVal); + wx.requestPayment({ + "appId": payVal.appId, + "timeStamp": payVal.timeStamp, + "nonceStr": payVal.nonceStr, + "package": payVal.package, + "signType": payVal.signType, + "paySign": payVal.paySign, + success: function (res) { + console.log('鏀粯鎴愬姛'); + if (res.errMsg == 'requestPayment:ok') { + that.setData({ + isPaySuccess: true + }) + } + }, + fail: function (res) { + console.log('鏀粯澶辫触'); + }, + // 鏃犺鏀粯鎴愬姛澶辫触閮戒細璋冪敤 + "complete": function (res) { + if (res.errMsg == 'requestPayment:ok') { + that.setData({ + isPayComplete: true + }) + } + if (that.data.isPaySuccess && that.data.isPayComplete) { + that.navToBack() + } + } + }); + } else { + Toast({ + context: this, + selector: '#t-toast', + message: '鏀粯澶辫触', + theme: 'warning', + direction: 'column', + }); + } + + }) + } + }) + } + + }, + // 椤甸潰杩斿洖 + navToBack() { + this.getOrderByOrderNumData() + // 杩斿洖 + wx.navigateBack() + }, + onReceive() { let query = { orderNum: this.data.orderGoods } app.MG.store.confirmOrder(query).then(res => { - this.makeWeChatQrPayGet() + Toast({ + context: this, + selector: '#t-toast', + message: '棰嗗彇鎴愬姛', + theme: 'success', + direction: 'column', + }); + wx.navigateBack() }) - // 璋冨彇寰俊浜岀淮鐮佹敮浠� - - }, - // 璋冨彇寰俊浜岀淮鐮佹敮浠� - makeWeChatQrPayGet() { - let query = { - orderNum: this.data.orderGoods - } - app.MG.store.makeWeChatQrPay(query).then((res) => { - - this.setData({ - drawQrcodeText: res - }) - this.data.dialogKey = true - console.log(this.data.drawQrcodeText, 'drawQrcodeText'); - }) - }, - showDialog(e) { - const { key } = e.currentTarget.dataset; - this.setData({ [key]: true, dialogKey: key }); - }, - closeDialog() { - const { dialogKey } = this.data; - this.setData({ [dialogKey]: false }); - }, - + } }) \ No newline at end of file -- Gitblit v1.9.1