123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- // pages/orders/order-detail.ts
- import drawQrcode from "../../utils/weapp.qrcode.esm";
- import { api_userPaymentCancelRefund, api_userPaymentOrderDetail, api_userPaymentOrderRefundPayment } from "../../api/login";
- // 获取应用实例
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- status: 'WAIT_PAY',
- statusList: {
- WAIT_PAY: {
- logo: './images/ing.png',
- title: '等待付款',
- content: '请尽快完成支付,以便我们为您处理订单'
- },
- PAID: {
- logo: './images/success.png',
- title: '交易完成',
- content: '登录「音乐数字课堂」APP使用AI学练'
- },
- CLOSED: {
- logo: './images/error.png',
- title: '交易取消',
- content: '您的交易订单已关闭'
- },
- WAIT_USE: {
- logo: './images/wait.png',
- title: '等待使用',
- content: '请尽快扫描下方二维码进行激活'
- },
- REFUNDING: {
- logo: './images/refounding.png',
- title: '退款中',
- content: '您的退款申请正在处理,预计7个工作日内完成审核'
- },
- REFUNDED: {
- logo: './images/refounded.png',
- title: '退款成功',
- content: '您的退款已成功处理,感谢您的理解和支持'
- }
- },
- timerCount: 0,
- timer: null as any,
- goodsInfo: {} as any,
- orderNo: "" as string,
- showCanvas: false, // 是否显示二维码
- tabIdx: 0, // 当前是从哪个tab来的
- canvasImg: "" as string,
- showService: false,
- refoundStatus: false,
- cancelRefoundStatus: false,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options: any) {
- if (options.orderNo) {
- this.setData({
- orderNo: options.orderNo,
- tabIdx: options.tabIdx
- });
- }
- },
- onShow() {
- if(this.data.orderNo) {
- this.getDetail(this.onTimeout)
- }
- },
- async getDetail(callback?: any) {
- try {
- const { data } = await api_userPaymentOrderDetail(this.data.orderNo);
- if (data.code == 200) {
- const result = data.data || {}
- const goodsInfos = result.goodsInfos || []
- const tempGoods: any = []
- goodsInfos.forEach((item: any) => {
- tempGoods.push({
- ...item,
- shortUrl: item.activationCodeInfo.shortUrl,
- code: item.activationCodeInfo.activationCode,
- originalPrice: this.formatPrice(item.paymentCashAmount, 'ALL'),
- typeName: this.formatPeriod(item.activationCodeInfo?.times || 1, item.activationCodeInfo.type)
- })
- })
- let refundStyleStr = ''
- if(result.refundStyle === 'TURN_BACK') {
- refundStyleStr = '原路返回'
- } else if(result.refundStyle === 'OFFLINE') {
- refundStyleStr = '线下'
- }
- const firstGoods = tempGoods[0]
- const goodsInfo = {
- orderNo: result.orderNo,
- createTime: result.createTime,
- wechatStatus: result.wechatStatus,
- goods: tempGoods,
- code: firstGoods.code || '',
- refundOrderId: result.refundOrderId,
- refundTime: result.refundTime,
- refundAmount: this.formatPrice(result.refundAmount || 0, 'ALL'),
- refundStyleStr
- }
- this.setData({
- goodsInfo,
- status: result.wechatStatus
- }, () => {
- callback && typeof callback === 'function' && callback()
- })
- if(result.wechatStatus != 'CLOSED' || result.wechatStatus != 'WAIT_PAY') {
- const firstGoods = tempGoods[0]
- if(firstGoods?.shortUrl) {
- this.setData({
- showCanvas: true
- }, () => {
- this.createQrCode(firstGoods?.shortUrl, 'canvasCode')
- })
- }
- }
- }
- } catch (error) {
- console.log(error, "error");
- }
- },
- // 格式化价格
- 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) {
- const template: any = {
- DAY: "天卡",
- MONTH: "月卡",
- YEAR: "年卡"
- }
- if(type === "YEAR" && num >= 99) {
- return '永久卡'
- }
- return num + template[type]
- },
- onSubmit() {
- wx.redirectTo({
- url: '../index/index'
- })
- },
- setCanvasSize: function () {
- var size = {} as any;
- try {
- const res = wx.getWindowInfo()
- var scale = 750 / 262; //不同屏幕下canvas的适配比例;设计稿是750宽
- var width = res.windowWidth / scale;
- var height = width; //canvas画布为正方形
- size.w = width;
- size.h = height;
- } catch (e) {
- // Do something when catch error
- console.log("获取设备信息失败" + e);
- }
- return size;
- },
- createQrCode(content: any, canvasId: any) {
- const size = this.setCanvasSize();
- drawQrcode({
- width: size.w,
- height: size.h,
- canvasId: canvasId,
- text: content,
- callback: () => {
- // 安卓机上不准确,生成的二维码无法扫描,加延时解决
- setTimeout(() => {
- wx.canvasToTempFilePath(
- {
- canvasId: canvasId,
- success: (res) => {
- this.setData({
- canvasImg: res.tempFilePath,
- });
- },
- },
- this
- );
- }, 0);
- },
- });
- },
- onTimeout() {
- // 轮询10次查询订单状态
- const goodsInfo = this.data.goodsInfo
- const timerCount = this.data.timerCount
- const timer = this.data.timer
- if(goodsInfo.wechatStatus === 'WAIT_PAY' && timerCount <= 10) {
- let count = timerCount
- const tempT = setTimeout(async () => {
- count += 1
- await this.getDetail()
- this.setData({
- timer: tempT,
- timerCount: count
- }, () => {
- this.onTimeout()
- })
- }, 3000);
- } else {
- clearTimeout(timer)
- }
- },
- /** 客服 */
- onService() {
- this.setData({
- showService: true
- })
- },
- changePop(event: { detail: any }) {
- this.setData({
- showService: event.detail
- })
- },
- /** 申请退款 */
- async cancelRefound() {
- this.setData({
- cancelRefoundStatus: true
- }, async () => {
- try {
- const {data} = await api_userPaymentCancelRefund(this.data.goodsInfo.refundOrderId)
- // console.log(data, 'data')
- if(data.code == 200) {
- wx.showToast({ title: '取消退款成功', icon: 'none' })
- this.getDetail()
- } else {
- wx.showToast({ title: data.message, icon: 'none' })
- }
- setTimeout(() => {
- this.setData({
- cancelRefoundStatus: false
- })
- }, 500);
- } catch {}
- })
-
- },
- /** 申请退款 */
- useRefound() {
- this.setData({
- refoundStatus: true
- })
- },
- changeRefoundStatus(e: {detail: any}) {
- this.setData({
- refoundStatus: e.detail
- })
- },
- onRefoundComfirm() {
- this.setData({
- refoundStatus: false
- })
- // wx.navigateBack({
- // delta: 1
- // })
- this.getDetail()
- },
- onCopy(e: { currentTarget: any }) {
- wx.setClipboardData({
- data: e.currentTarget.dataset.orderno,
- success: () => {
- wx.showToast({title: '复制成功', icon: 'none'})
- },
- fail: () => {
- wx.showToast({title: '复制失败,请稍后再试', icon: 'none'})
- }
- })
- },
- onActivation(e: { currentTarget: any }) {
- const code = e.currentTarget.dataset.code || ''
- if(!code) {
- wx.showToast({
- title: '暂无法激活',
- icon: 'none'
- })
- return
- }
- wx.navigateTo({
- url: '../protocol/register?type=activation&code=' + code
- })
- },
- onDownload() {
- wx.saveImageToPhotosAlbum({
- filePath: this.data.canvasImg,
- success: () => {
- wx.showToast({
- title: '保存成功',
- icon: 'success',
- });
- },
- fail: () => {
- wx.showToast({
- title: '保存失败',
- icon: 'none',
- });
- }
- })
- },
- onShareAppMessage() {
- return {
- title: '器乐数字AI工具',
- path: '/pages/index/index',
- imageUrl: 'https://oss.dayaedu.com/ktyq/1733312164991.png'
- }
- }
- })
|