feat 添加订单相关功能对接

This commit is contained in:
AERWEN\26795 2023-10-25 00:43:30 +08:00
parent 5751ee0f04
commit 573f8800bb
10 changed files with 372 additions and 130 deletions

View File

@ -87,7 +87,7 @@ Page({
// name: m.refundMethodName,
// amount: m.refundMethodAmount,
// })), // 退款明细
refundRequestAmount: serviceRaw.refundRequestAmount, // 申请退款金额
refundRequestAmount: serviceRaw.refundMoney, // 申请退款金额
// payTraceNo: serviceRaw.rightsRefund.traceNo, // 交易流水号
createTime: serviceRaw.createTime, // 申请时间
logisticsNo: serviceRaw.trajectoryVos?.logisticsCompanyCode, // 退货物流单号

View File

@ -20,7 +20,7 @@
title="{{service.isRefunded ? '退款金额' : '预计退款金额'}}"
bordered="{{false}}"
>
<wr-price slot="note" price="{{service.refundRequestAmount}}" fill />
<wr-price priceUnit="yuan" slot="note" price="{{service.refundRequestAmount}}" fill />
</t-cell>
<t-cell
wx:for="{{service.refundMethodList}}"
@ -33,7 +33,7 @@
title="{{item.name}}"
bordered="{{service.refundMethodList.length - 1 === index ? true : false}}"
>
<wr-price slot="note" price="{{item.amount}}" fill />
<wr-price priceUnit="yuan" slot="note" price="{{item.amount}}" fill />
</t-cell>
<block wx:if="{{service.isRefunded}}">
<t-cell
@ -144,7 +144,7 @@
t-class-note="t-refund-note"
title="退款金额"
>
<wr-price slot="note" price="{{service.refundRequestAmount}}" fill />
<wr-price priceUnit="yuan" slot="note" price="{{service.refundRequestAmount}}" fill />
</t-cell>
<t-cell
bordered="{{false}}"

View File

@ -1,7 +1,13 @@
import Dialog from 'tdesign-miniprogram/dialog/index';
import Toast from 'tdesign-miniprogram/toast/index';
import { priceFormat } from '../../../utils/util';
import { OrderStatus, ServiceType, ServiceReceiptStatus } from '../config';
import {
priceFormat
} from '../../../utils/util';
import {
OrderStatus,
ServiceType,
ServiceReceiptStatus
} from '../config';
import reasonSheet from '../components/reason-sheet/reasonSheet';
import {
fetchRightsPreview,
@ -9,6 +15,15 @@ import {
fetchApplyReasonList,
dispatchApplyService,
} from '../../../services/order/applyService';
import {
getRefundReason
} from '~/services/order/getRefundReason';
import {
addOrderRefund
} from '~/services/order/addOrderRefund';
import {
ServerBasePath
} from '~/app'
Page({
query: {},
@ -16,18 +31,38 @@ Page({
uploading: false, // 凭证上传状态
canApplyReturn: true, // 是否可退货
goodsInfo: {},
receiptStatusList: [
{ desc: '未收到货', status: ServiceReceiptStatus.NOT_RECEIPTED },
{ desc: '已收到货', status: ServiceReceiptStatus.RECEIPTED },
goodsList: [],
sessionFrom:{
rightsImageUrls: ""
},
receiptStatusList: [{
desc: '未收到货',
status: ServiceReceiptStatus.NOT_RECEIPTED
},
{
desc: '已收到货',
status: ServiceReceiptStatus.RECEIPTED
},
],
applyReasons: [],
serviceType: null, // 20-仅退款10-退货退款
serviceFrom: {
returnNum: 1,
receiptStatus: { desc: '请选择', status: null },
applyReason: { desc: '请选择', type: null },
receiptStatus: {
desc: '请选择',
status: null
},
applyReason: {
desc: '请选择',
type: null
},
// max-填写上限(单位分)current-当前值(单位分)temp输入框中的值(单位元)
amount: { max: 0, current: 0, temp: 0, focus: false },
amount: {
max: 0,
current: 0,
temp: 0,
focus: false
},
remark: '',
rightsImageUrls: [],
},
@ -40,6 +75,9 @@ Page({
},
submitting: false,
inputDialogVisible: false,
imageProps: {
mode: 'aspectFit',
},
uploadGridConfig: {
column: 3,
width: 212,
@ -88,7 +126,12 @@ Page({
valid = false;
msg = '退款金额必须大于0';
}
this.setData({ validateRes: { valid, msg } });
this.setData({
validateRes: {
valid,
msg
}
});
},
onLoad(query) {
@ -112,12 +155,17 @@ Page({
},
checkQuery() {
const { orderNo, skuId } = this.query;
const {
orderNo,
skuId
} = this.query;
if (!orderNo) {
Dialog.alert({
content: '请先选择订单',
}).then(() => {
wx.redirectTo({ url: 'pages/order/order-list/index' });
wx.redirectTo({
url: 'pages/order/order-list/index'
});
});
return false;
}
@ -133,33 +181,40 @@ Page({
},
async refresh() {
wx.showLoading({ title: 'loading' });
try {
const res = await this.getRightsPreview();
wx.hideLoading();
const goodsInfo = {
id: res.data.skuId,
thumb: res.data.goodsInfo && res.data.goodsInfo.skuImage,
title: res.data.goodsInfo && res.data.goodsInfo.goodsName,
spuId: res.data.spuId,
skuId: res.data.skuId,
specs: ((res.data.goodsInfo && res.data.goodsInfo.specInfo) || []).map((s) => s.specValue),
paidAmountEach: res.data.paidAmountEach,
boughtQuantity: res.data.boughtQuantity,
};
this.setData({
goodsInfo,
'serviceFrom.amount': {
max: res.data.refundableAmount,
current: res.data.refundableAmount,
},
'serviceFrom.returnNum': res.data.numOfSku,
amountTip: `最多可申请退款¥ ${priceFormat(res.data.refundableAmount, 2)},含发货运费¥ ${priceFormat(
res.data.shippingFeeIncluded,
2,
)}`,
maxApplyNum: res.data.numOfSkuAvailable,
wx.showLoading({
title: 'loading'
});
try {
// const res = await this.getRightsPreview();
const {
orderNo,
orderAmt,
goodsList,
freightFee
} = this.query;
wx.hideLoading();
// const goodsInfo = {
// id: res.data.skuId,
// thumb: res.data.goodsInfo && res.data.goodsInfo.skuImage,
// title: res.data.goodsInfo && res.data.goodsInfo.goodsName,
// spuId: res.data.spuId,
// skuId: res.data.skuId,
// specs: ((res.data.goodsInfo && res.data.goodsInfo.specInfo) || []).map((s) => s.specValue),
// paidAmountEach: res.data.paidAmountEach,
// boughtQuantity: res.data.boughtQuantity,
// };
this.setData({
// goodsInfo,
goodsList: JSON.parse(goodsList),
'serviceFrom.amount': {
max: orderAmt,
current: orderAmt,
},
// 'serviceFrom.returnNum': res.data.numOfSku,
amountTip: `最多可申请退款¥ ${orderAmt},含发货运费¥ ${freightFee}`,
// maxApplyNum: res.data.numOfSkuAvailable,
});
console.log(this.data, 'asdasdasdasdasd');
} catch (err) {
wx.hideLoading();
throw err;
@ -167,7 +222,11 @@ Page({
},
async getRightsPreview() {
const { orderNo, skuId, spuId } = this.query;
const {
orderNo,
skuId,
spuId
} = this.query;
const params = {
orderNo,
skuId,
@ -179,14 +238,23 @@ Page({
},
onApplyOnlyRefund() {
wx.setNavigationBarTitle({ title: '申请退款' });
this.setData({ serviceRequireType: 'REFUND_MONEY' });
wx.setNavigationBarTitle({
title: '申请退款'
});
this.setData({
serviceRequireType: 'REFUND_MONEY',
serviceType: ServiceType.ONLY_REFUND
});
this.switchReceiptStatus(0);
},
onApplyReturnGoods() {
wx.setNavigationBarTitle({ title: '申请退货退款' });
this.setData({ serviceRequireType: 'REFUND_GOODS' });
wx.setNavigationBarTitle({
title: '申请退货退款'
});
this.setData({
serviceRequireType: 'REFUND_GOODS'
});
const orderStatus = parseInt(this.query.orderStatus);
Promise.resolve()
.then(() => {
@ -208,7 +276,9 @@ Page({
return;
})
.then(() => {
this.setData({ serviceType: ServiceType.RETURN_GOODS });
this.setData({
serviceType: ServiceType.RETURN_GOODS
});
this.switchReceiptStatus(1);
});
},
@ -231,7 +301,9 @@ Page({
},
onChangeReturnNum(e) {
const { value } = e.detail;
const {
value
} = e.detail;
this.setData({
'serviceFrom.returnNum': value,
});
@ -259,34 +331,48 @@ Page({
if (!statusItem) {
this.setData({
showReceiptStatusDialog: false,
'serviceFrom.receiptStatus': { desc: '请选择', status: null },
'serviceFrom.applyReason': { desc: '请选择', type: null }, // 收货状态改变时,初始化申请原因
'serviceFrom.receiptStatus': {
desc: '请选择',
status: null
},
'serviceFrom.applyReason': {
desc: '请选择',
type: null
}, // 收货状态改变时,初始化申请原因
applyReasons: [],
});
return;
}
// 仅选中项与当前项不一致时才切换申请原因列表applyReasons
if (!statusItem || statusItem.status === this.data.serviceFrom.receiptStatus.status) {
this.setData({ showReceiptStatusDialog: false });
this.setData({
showReceiptStatusDialog: false
});
return;
}
this.getApplyReasons(statusItem.status).then((reasons) => {
this.setData({
showReceiptStatusDialog: false,
'serviceFrom.receiptStatus': statusItem,
'serviceFrom.applyReason': { desc: '请选择', type: null }, // 收货状态改变时,重置申请原因
'serviceFrom.applyReason': {
desc: '请选择',
type: null
}, // 收货状态改变时,重置申请原因
applyReasons: reasons,
});
});
},
// 获取退款原因列表
getApplyReasons(receiptStatus) {
const params = { rightsReasonType: receiptStatus };
return fetchApplyReasonList(params)
const params = {
rightsReasonType: receiptStatus
};
return getRefundReason(params)
.then((res) => {
return res.data.rightsReasonList.map((reason) => ({
type: reason.id,
desc: reason.desc,
return res.data.map((reason) => ({
type: reason.dictValue,
desc: reason.dictLabel,
}));
})
.catch(() => {
@ -295,13 +381,15 @@ Page({
},
onReceiptStatusDialogConfirm(e) {
const { index } = e.currentTarget.dataset;
const {
index
} = e.currentTarget.dataset;
this.switchReceiptStatus(index);
},
onAmountTap() {
this.setData({
'serviceFrom.amount.temp': priceFormat(this.data.serviceFrom.amount.current),
'serviceFrom.amount.temp': this.data.serviceFrom.amount.current,
'serviceFrom.amount.focus': true,
inputDialogVisible: true,
});
@ -319,15 +407,21 @@ Page({
// 对输入的值进行过滤
onAmountInput(e) {
let { value } = e.detail;
let {
value
} = e.detail;
const regRes = value.match(/\d+(\.?\d*)?/); // 输入中,允许末尾为小数点
value = regRes ? regRes[0] : '';
this.setData({ 'serviceFrom.amount.temp': value });
this.setData({
'serviceFrom.amount.temp': value
});
},
// 失去焦点时更严格的过滤并转化为float
onAmountBlur(e) {
let { value } = e.detail;
let {
value
} = e.detail;
const regRes = value.match(/\d+(\.?\d+)?/); // 失去焦点时,不允许末尾为小数点
value = regRes ? regRes[0] : '0';
value = parseFloat(value) * 100;
@ -341,42 +435,45 @@ Page({
},
onAmountFocus() {
this.setData({ 'serviceFrom.amount.focus': true });
this.setData({
'serviceFrom.amount.focus': true
});
},
onRemarkChange(e) {
const { value } = e.detail;
const {
value
} = e.detail;
this.setData({
'serviceFrom.remark': value,
});
},
// 发起申请售后请求
// 发起申请售后请求 提交
onSubmit() {
this.submitCheck().then(() => {
const params = {
rights: {
orderNo: this.query.orderNo,
refundRequestAmount: this.data.serviceFrom.amount.current,
rightsImageUrls: this.data.serviceFrom.rightsImageUrls,
rightsReasonDesc: this.data.serviceFrom.applyReason.desc,
rightsReasonType: this.data.serviceFrom.receiptStatus.status,
rightsType: this.data.serviceType,
},
rightsItem: [
{
itemTotalAmount: this.data.goodsInfo.price * this.data.serviceFrom.returnNum,
rightsQuantity: this.data.serviceFrom.returnNum,
skuId: this.query.skuId,
spuId: this.query.spuId,
},
],
refundMemo: this.data.serviceFrom.remark.current,
orderGuid: this.query.orderGuid,
refundType: this.data.serviceType,
goodsReceiveStatus: this.data.serviceFrom.receiptStatus.status,
RefundReason: this.data.serviceFrom.applyReason.type,
CustomerRefundDesc: this.data.serviceFrom.remark,
RefundMoney: this.data.serviceFrom.amount.current,
CustomerRefundImg: "",
};
this.setData({ submitting: true });
if(this.data.sessionFrom.rightsImageUrls){
if(this.data.sessionFrom.rightsImageUrls.length != 0){
params.CustomerRefundImg = this.data.sessionFrom.rightsImageUrls.map(item => item.url).join(',')
}
}
console.log(params);
this.setData({
submitting: true
});
// 发起申请售后请求
dispatchApplyService(params)
addOrderRefund(params)
.then((res) => {
if(res.code === 200){
Toast({
context: this,
selector: '#t-toast',
@ -385,17 +482,25 @@ Page({
});
wx.redirectTo({
url: `/pages/order/after-service-detail/index?rightsNo=${res.data.rightsNo}`,
url: `/pages/order/after-service-list/index`,
});
}
})
.then(() => this.setData({ submitting: false }))
.catch(() => this.setData({ submitting: false }));
.then(() => this.setData({
submitting: false
}))
.catch(() => this.setData({
submitting: false
}));
});
},
submitCheck() {
return new Promise((resolve) => {
const { msg, valid } = this.data.validateRes;
const {
msg,
valid
} = this.data.validateRes;
if (!valid) {
Toast({
context: this,
@ -410,16 +515,22 @@ Page({
},
handleSuccess(e) {
const { files } = e.detail;
const {
files
} = e.detail;
this.setData({
'sessionFrom.rightsImageUrls': files,
});
},
handleRemove(e) {
const { index } = e.detail;
const {
sessionFrom: { rightsImageUrls },
index
} = e.detail;
const {
sessionFrom: {
rightsImageUrls
},
} = this.data;
rightsImageUrls.splice(index, 1);
this.setData({
@ -438,4 +549,73 @@ Page({
uploading: true,
});
},
// 上传图片
handleAddPic(e) {
const {
files
} = e.detail;
// 每次选择图片都上传,展示每次上传图片的进度
files.forEach(file => this.onUploadPic(file))
},
// 移除Pic
handleRemovePic(e) {
const {
index
} = e.detail;
const {
sessionFrom: {
rightsImageUrls
},
} = this.data;
rightsImageUrls.splice(index, 1);
this.setData({
'sessionFrom.rightsImageUrls': rightsImageUrls,
});
},
// 上传图片方法
onUploadPic(file) {
const {
sessionFrom: {
rightsImageUrls
},
} = this.data;
this.setData({
'sessionFrom.rightsImageUrls' : [...rightsImageUrls, {
...file,
status: 'loading'
}],
});
const {
length
} = rightsImageUrls;
const task = wx.uploadFile({
url: ServerBasePath + 'Common/UploadFile', // 仅为示例,非真实的接口地址
filePath: file.url,
name: 'file',
formData: {
fileDir: 'Shops'
},
success: (res) => {
this.setData({
[`sessionFrom.rightsImageUrls[${length}].url`]: JSON.parse(res.data).data.url,
[`sessionFrom.rightsImageUrls[${length}].status`]: 'done',
});
// this.triggerEventToParent()
},
});
task.onProgressUpdate((res) => {
this.setData({
[`sessionFrom.rightsImageUrls[${length}].percent`]: res.progress,
});
});
},
});

View File

@ -1,17 +1,24 @@
<view class="select-service">
<view class="order-goods-card" >
<wr-order-goods-card goods="{{goodsInfo}}" no-top-line thumb-class="order-goods-card-title-class">
<view wx:for="{{ goodsList }}"
wx:key="index"
wx:for-item="item">
<wr-order-goods-card goods="{{item}}" no-top-line thumb-class="order-goods-card-title-class">
<view slot="footer" class="order-goods-card-footer">
<wr-price
price="{{goodsInfo.paidAmountEach}}"
priceUnit="yuan"
price="{{item.price}}"
fill
wr-class="order-goods-card-footer-price-class"
symbol-class="order-goods-card-footer-price-symbol"
decimal-class="order-goods-card-footer-price-decimal"
/>
<view class="order-goods-card-footer-num">x {{goodsInfo.boughtQuantity}}</view>
<!-- <view class="order-goods-card-footer-num">x {{item.num}}</view> -->
</view>
</wr-order-goods-card>
</view>
</view>
<view wx:if="{{!serviceRequireType}}" class="service-choice">
<t-cell-group>
@ -89,20 +96,22 @@
title="退款金额"
t-class-description="refund-money__description"
description="{{amountTip}}"
bind:tap="onAmountTap"
>
<!-- bind:tap="onAmountTap" -->
<view class="service-from-group__wrapper" slot="note">
<wr-price
priceUnit="yuan"
price="{{serviceFrom.amount.current}}"
fill
wr-class="refund-money-price-class"
symbol-class="refund-money-price-symbol"
decimal-class="refund-money-price-decimal"
/>
<view class="service-from-group__price">
<!-- <view class="service-from-group__price">
修改
<t-icon color="#bbb" name="chevron-right" size="30rpx" slot="left-icon" />
</view>
</view> -->
</view>
</t-cell>
</t-cell-group>
@ -119,8 +128,18 @@
bind:change="onRemarkChange"
/>
</view>
<view class="service-from-group__grid">
<t-upload
<t-upload mediaType="{{['image','video']}}" max="{{5}}" files="{{sessionFrom.rightsImageUrls}}" bind:add="handleAddPic" bind:remove="handleRemovePic" gridConfig="{{uploadGridConfig}}" imageProps="{{imageProps}}">
<view slot="add-content" class="upload-addcontent-slot">
<t-icon name="add" size="60rpx" />
<view class="upload-desc">
<text>上传凭证</text>
<text>最多3张</text>
</view>
</view>
</t-upload>
<!-- <t-upload
media-type="{{['image','video']}}"
files="{{sessionFrom.rightsImageUrls}}"
bind:remove="handleRemove"
@ -137,7 +156,7 @@
<text>最多3张</text>
</view>
</view>
</t-upload>
</t-upload> -->
</view>
<view class="bottom-bar">
<t-button

View File

@ -88,7 +88,7 @@ Component({
const params = { orderRefundGuid: this.data.service.id };
return repeal(params).then((res) => {
if(res.code === 200){
bindrefresh()
this.triggerEvent('refresh')
Toast({
context: this,
selector: '#t-toast',

View File

@ -31,16 +31,16 @@ Component({
type: Object,
observer(order) {
// 判定有传goodsIndex 则认为是商品button bar, 仅显示申请售后按钮
if (this.properties?.goodsIndex !== null) {
const goods = order.goodsList[Number(this.properties.goodsIndex)];
this.setData({
buttons: {
left: [],
right: (goods.buttons || []).filter((b) => b.type == OrderButtonTypes.APPLY_REFUND),
},
});
return;
}
// if (this.properties?.goodsIndex !== null) {
// const goods = order.goodsList[Number(this.properties.goodsIndex)];
// this.setData({
// buttons: {
// left: [],
// right: (goods.buttons || []).filter((b) => b.type == OrderButtonTypes.APPLY_REFUND),
// },
// });
// return;
// }
// 订单的button bar 不显示申请售后按钮
const buttonsRight = (order.buttons || [])
// .filter((b) => b.type !== OrderButtonTypes.APPLY_REFUND)
@ -233,19 +233,15 @@ Component({
// 重新调起支付
onPay(order) {
Toast({
context: this,
selector: '#t-toast',
message: '你点击了去支付',
icon: 'check-circle',
});
let data = {
orderNo: order.orderNo,
openId: wx.getStorageSync('openId')
}
wxRepay(data).then((res) => {
console.log(res, '重新调起支付的参数');
this.handlePay(res.data,order).then((res) => {
console.log(res);
})
})
},
@ -265,14 +261,19 @@ Component({
const params = {
orderGuid: order.Guid,
orderNo: order.orderNo,
goodsList: JSON.stringify(order.goodsList),
skuId: goods?.skuId,
spuId: goods?.id,
thumb: goods?.thumb,
title: goods?.title,
spec: goods?.spec,
orderStatus: order.status,
logisticsNo: order.logisticsNo,
price: goods?.price,
num: goods?.num,
createTime: order.createTime,
orderAmt: order.totalAmount,
freightFee: order.freightFee,
payAmt: order.amount,
canApplyReturn: true,
};
@ -295,7 +296,6 @@ Component({
/** 添加订单评论 */
onAddComment(order) {
console.log(order?.goodsList?.[0],'asdasdsa');
const imgUrl = order?.goodsList?.[0]?.thumb;
const title = order?.goodsList?.[0]?.title;
const specs = order?.goodsList?.[0]?.specs;
@ -307,7 +307,7 @@ Component({
},
// 处理支付
handlePay(data) {
handlePay(data,order) {
const {
jsApiUiPackage,
outTradeNo,
@ -317,8 +317,8 @@ Component({
const payOrderInfo = {
payInfo: jsApiUiPackage,
orderId: outTradeNo,
orderAmt: totalAmount,
payAmt: totalPayAmount,
orderAmt: order.totalAmount,
payAmt: order.totalAmount,
interactId: interactId,
tradeNo: outTradeNo,
transactionId: transactionId,

View File

@ -9,7 +9,7 @@
<block wx:if="{{!selectedNum}}">你有{{couponsList.length}}张可用优惠券</block>
<block wx:else>
已选中{{selectedNum}}张推荐优惠券, 共抵扣
<wr-price fill="{{false}}" price="{{reduce || 0}}" />
<wr-price priceUnit="yuan" fill="{{false}}" price="{{reduce || 0}}" />
</block>
</view> -->
<scroll-view class="coupons-list" scroll-y="true">

View File

@ -0,0 +1,21 @@
import {
request
} from '../_utils/request';
/** 申请售后 */
export function addOrderRefund(data) {
return new Promise((resolve, reject) => {
request({
url: `OrderRefundApi/addOrderRefund`,
method: 'POST',
data: data,
success: function (res) {
resolve(res);
},
fail: function (error) {
reject(error);
}
});
});
}

View File

@ -0,0 +1,22 @@
import {
request
} from '../_utils/request';
/* 获取售后订单商品列表 */
export async function getRefundReason(data) {
return new Promise((resolve, reject) => {
request({
url: `OrderRefundApi/getRefundReason`,
method: 'Get',
data: data,
success: function (res) {
resolve(res);
},
fail: function (error) {
reject(error);
}
});
});
}