浏览代码

添加退款功能

lex-xin 4 月之前
父节点
当前提交
e9afd2772e

+ 17 - 0
miniprogram/api/login.ts

@@ -82,4 +82,21 @@ export const api_userPaymentOrderDetail = (orderNo: string) => {
     url: `/edu-app/userPaymentOrder/detail/${orderNo}`,
     method: "get"
   } as any);
+};
+
+/** 订单取消退款 */
+export const api_userPaymentCancelRefund = (userRefundOrderId: string) => {
+  return request({
+    url: `/edu-app/userPaymentOrder/cancelRefund/${userRefundOrderId}`,
+    method: "post"
+  } as any);
+};
+
+/** 订单申请退款 */
+export const api_userPaymentOrderRefundPayment = (data: any) => {
+  return request({
+    url: `/edu-app/userPaymentOrder/refundPayment`,
+    method: "post",
+    data
+  } as any);
 };

+ 1 - 1
miniprogram/components/service/service.less

@@ -5,7 +5,7 @@
   left: 0;
   right: 0;
   bottom: 0;
-  z-index: 99;
+  z-index: 999;
 
   .service-mask {
     position: absolute;

+ 1 - 1
miniprogram/pages/login/login.ts

@@ -83,7 +83,7 @@ Page({
       } else {
         app.globalData.isLogin = false;
         wx.hideLoading()
-        wx.showToast({ title: data.msg, icon: "none" })
+        wx.showToast({ title: data.message, icon: "none" })
       }
     } catch(e) {
       console.log('error', e)

二进制
miniprogram/pages/orders/images/icon-close.png


+ 75 - 0
miniprogram/pages/orders/order-result.less

@@ -226,4 +226,79 @@ page {
     color: #FFFFFF;
     line-height: 44rpx;
   }
+}
+
+.useRefound-pop {
+  position: fixed;
+  top: 0;
+  left: 0;
+  right: 0;
+  bottom: 0;
+
+  .useRefound-mask {
+    position: absolute;
+    top: 0;
+    left: 0;
+    right: 0;
+    bottom: 0;
+    background-color: rgba(0, 0, 0, 0.6);
+  }
+  .useRefound-container {
+    position: absolute;
+    left: 0;
+    right: 0;
+    bottom: 0;
+    width: 100%;
+    background: linear-gradient( 180deg, #FFDEE7 0%, #FFFFFF 12%, #FFFFFF 100%);
+    background-color: #fff;
+    border-radius: 32rpx 32rpx 0rpx 0rpx;
+    .icon-close {
+      position: absolute;
+      width: 38rpx;
+      height: 38rpx;
+      top: 40rpx;
+      right: 40rpx;
+    }
+    .use-title {
+      font-weight: 600;
+      font-size: 36rpx;
+      color: #131415;
+      line-height: 50rpx;
+      padding-top: 34rpx;
+      padding-bottom: 30rpx;
+      text-align: center;
+    }
+    .use-form {
+      margin: 0 40rpx;
+      background: #F7F8F9;
+      border-radius: 16rpx;
+      padding: 16rpx 16rpx 8rpx;
+      margin-bottom: 80rpx;
+      textarea {
+        height: 140rpx;
+        font-size: 30rpx;
+      }
+      .num {
+        text-align: right;
+        font-size: 26rpx;
+        color: #AAAAAA;
+        line-height: 42rpx;
+      }
+    }
+
+    .btnSection {
+      padding: 0 32rpx 58rpx;
+      button {
+        margin: 0;
+        width: 100%;
+        background: linear-gradient( 270deg, #FF204B 0%, #FE5B71 100%);
+        border-radius: 78rpx;
+        padding: 22rpx 84rpx;
+        font-weight: 500;
+        font-size: 32rpx;
+        color: #FFFFFF;
+        line-height: 44rpx;
+      }
+    }
+  }
 }

+ 79 - 3
miniprogram/pages/orders/order-result.ts

@@ -1,6 +1,6 @@
 // pages/orders/order-detail.ts
 import drawQrcode from "../../utils/weapp.qrcode.esm";
-import { api_userPaymentOrderDetail } from "../../api/login";
+import { api_userPaymentCancelRefund, api_userPaymentOrderDetail, api_userPaymentOrderRefundPayment } from "../../api/login";
 
 // 获取应用实例
 Page({
@@ -48,6 +48,8 @@ Page({
     showCanvas: false, // 是否显示二维码
     canvasImg: "" as string,
     showService: false,
+    refoundStatus: false,
+    refoundValue: "" // 退款内容
   },
 
   /**
@@ -88,6 +90,7 @@ Page({
           createTime: result.createTime,
           wechatStatus: result.wechatStatus,
           goods: tempGoods,
+          refundOrderId: result.refundOrderId,
           refundTime: result.refundTime,
           refundAmount: this.formatPrice(result.refundAmount || 0, 'ALL'),
           refundStyleStr
@@ -108,7 +111,6 @@ Page({
             })
           }
         }
-        
       }
     } catch (error) {
       console.log(error, "error");
@@ -185,7 +187,9 @@ Page({
   },
   onTimeout() {
     // 轮询10次查询订单状态
-    const { goodsInfo, timerCount, timer } = this.data
+    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 () => {
@@ -213,4 +217,76 @@ Page({
       showService: event.detail
     })
   },
+  /** 申请退款 */
+  async cancelRefound() {
+    try {
+      const {data} = await api_userPaymentCancelRefund(this.data.goodsInfo.refundOrderId)
+      console.log(data, 'data')
+      if(data.code == 200) {
+        wx.showToast({ title: '取消退款成功', icon: 'none' })
+        wx.navigateBack({
+          delta: 1
+        })
+      } else {
+        wx.showToast({ title: data.message, icon: 'none' })
+      }
+    } catch {}
+  },
+  /** 申请退款 */
+  useRefound() {
+    this.setData({
+      refoundStatus: true,
+      refoundValue: ""
+    })
+  },
+  textareaInput(e: { detail: any }) {
+    this.setData({
+      refoundValue: e.detail.value
+    })
+  },
+  onRefoundClose() {
+    this.setData({
+      refoundStatus: false,
+      refoundValue: ''
+    })
+  },
+  async onRefound() {
+    console.log(this.data.refoundValue, 'value')
+    const refoundValue = this.data.refoundValue
+    if(!refoundValue) {
+      wx.showToast({ title: '请输入退款原因', icon: 'none' })
+      return
+    }
+    try {
+      const { goods, orderNo } = this.data.goodsInfo
+      console.log(this.data.goodsInfo, 'goodsInfo')
+      const details: any = []
+      goods.forEach((item: any) => {
+        details.push({
+          num: item.goodsNum,
+          onlyRefund: false,
+          userPaymentOrderDetailId: item.id,
+          refundAmount: item.currentPrice
+        })
+      })
+      const params = {
+        merOrderNo: orderNo,
+        serviceCharge: false,
+        refundReason: refoundValue,
+        serviceChargeFee: 0,
+        userRefundOrderDetails: details
+      }
+      const {data} = await api_userPaymentOrderRefundPayment(params)
+      if(data.code == 200) {
+        wx.showToast({ title: '申请成功', icon: 'none' })
+        setTimeout(() => {
+          wx.navigateBack({
+            delta: 1
+          })
+        }, 2000);
+      } else {
+        wx.showToast({ title: data.message, icon: 'none' })
+      }
+    } catch {}
+  }
 })

+ 21 - 2
miniprogram/pages/orders/order-result.wxml

@@ -47,7 +47,7 @@
 
     <view class="order-time" wx:if="{{ goodsInfo.wechatStatus == 'REFUNDED' }}">
       <view class="order-item">
-        <view class="title">退款时间</view>
+        <view class="title">{{ goodsInfo.wechatStatus == 'REFUNDED' ? '退款时间' : '申请退款时间' }}</view>
         <view class="value">{{ goodsInfo.refundTime }}</view>
       </view>
       <view class="order-item">
@@ -66,8 +66,27 @@
       <image src="./images/icon-service.png" />
       <text>客服</text>
     </view>
-    <button type="primary" bind:tap="onSubmit">再来一单</button>
+    <button type="primary" bind:tap="useRefound" wx:if="{{ goodsInfo.wechatStatus == 'WAIT_USE' }}">申请退款</button>
+    <block wx:else>
+      <button type="primary" bind:tap="cancelRefound" wx:if="{{ goodsInfo.wechatStatus == 'REFUNDING' }}">取消退款</button>
+      <button type="primary" wx:else bind:tap="onSubmit">再来一单</button>
+    </block>
   </view>
 
   <service popShow="{{ showService }}" bind:changePop="changePop"></service>
+
+  <view class="useRefound-pop" wx:if="{{ refoundStatus }}">
+    <view class="useRefound-mask"></view>
+    <view class="useRefound-container">
+      <image bind:tap="onRefoundClose" class="icon-close" src="./images/icon-close.png"></image>
+      <view class="use-title">选择退款原因</view>
+      <view class="use-form">
+        <textarea placeholder="请输入您的退款原因" maxlength="50" bindinput="textareaInput" value="{{ refoundValue }}"></textarea>
+        <view class="num">{{ refoundValue.length }}/50</view>
+      </view>
+      <view class="btnSection">
+        <button type="primary" bind:tap="onRefound">申请退款</button>
+      </view>
+    </view>
+  </view>
 </view>

+ 10 - 3
miniprogram/pages/orders/orders.ts

@@ -48,7 +48,15 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad() {
-    this.getList()
+  },
+  onShow() {
+    this.setData({
+      page: 1,
+      maxPage: 1,
+      recordList: [],
+    }, () => {
+      this.getList()
+    })
   },
   /** 切换分类 */
   switchTab(e: { currentTarget: { dataset: { idx: any } } }) {
@@ -81,7 +89,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 ? 'REFUNDED' : "",
+        wechatOrderStatus: tabIdx == 0 ? "" : tabIdx == 1 ? "WAIT_PAY" : tabIdx == 2 ? "WAIT_USE" : tabIdx == 3 ? "PAID" : tabIdx == 4 ? "CLOSED" : tabIdx == 5 ? 'REFUNDING' : "",
       })
       if (data.code == 200) {
         const { rows, total } = data.data;
@@ -97,7 +105,6 @@ Page({
         });
         
         const newList = this.data.recordList.concat(rows);
-        console.log(newList, "newList");
         this.setData(
           {
             recordList: newList,

+ 1 - 1
miniprogram/pages/orders/orders.wxml

@@ -14,7 +14,7 @@
           <view class="list-item" wx:for="{{recordList}}" wx:key="index" data-orderno="{{item.orderNo}}" bind:tap="onDetail">
             <view class="item-top">
               <view class="item-mid">订单号:{{ item.orderNo }}</view>
-              <text class="{{ item.wechatStatus == 'WAIT_PAY' || item.wechatStatus == 'WAIT_USE' ? 'red' : '' }}">{{ item.statusName }}</text>
+              <text class="{{ item.wechatStatus == 'WAIT_PAY' || item.wechatStatus == 'WAIT_USE' || item.wechatStatus == 'REFUNDING' ? 'red' : '' }}">{{ item.statusName }}</text>
             </view>
             <view class="item-content" wx:for="{{item.studentPaymentOrderDetails}}" wx:key="studentIndex">
               <image class='goods-icon' src="{{item.goodsUrl}}" mode="" />