重构项目文件夹目录
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
const orderApi = require('../../api/order')
|
||||
const afterSaleApi = require('../../api/after-sale')
|
||||
const auth = require('../../utils/auth')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const theme = require('../../utils/theme')
|
||||
const { formatPrice } = require('../../utils/format')
|
||||
const { runWithLoading } = require('../../utils/loading')
|
||||
|
||||
function safeList(value) {
|
||||
return Array.isArray(value) ? value : []
|
||||
}
|
||||
|
||||
Page({
|
||||
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
|
||||
orderId: '',
|
||||
loading: false,
|
||||
submitting: false,
|
||||
isLoggedIn: false,
|
||||
order: null,
|
||||
items: [],
|
||||
typeOptions: ['退款', '售后服务'],
|
||||
form: {
|
||||
orderItemId: '',
|
||||
type: 'REFUND',
|
||||
typeIndex: 0,
|
||||
reason: '',
|
||||
refundAmount: ''
|
||||
}
|
||||
}),
|
||||
|
||||
onLoad(options) {
|
||||
this.setData({
|
||||
orderId: (options && options.orderId) || '',
|
||||
'form.orderItemId': (options && options.orderItemId) || ''
|
||||
})
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadOrder()
|
||||
},
|
||||
|
||||
handleBack() {
|
||||
navigation.goBack('/pages/orders/index')
|
||||
},
|
||||
|
||||
async loadOrder() {
|
||||
const isLoggedIn = auth.isLoggedIn()
|
||||
this.setData({ isLoggedIn })
|
||||
if (!isLoggedIn) {
|
||||
navigation.openAuth(navigation.getCurrentPageUrl())
|
||||
return
|
||||
}
|
||||
if (!this.data.orderId) return
|
||||
|
||||
this.setData({ loading: true })
|
||||
try {
|
||||
const order = await orderApi.getOrderDetail(this.data.orderId)
|
||||
const items = safeList(order && order.items)
|
||||
const selectedItem = items.find(item => String(item.id) === String(this.data.form.orderItemId)) || items[0]
|
||||
this.setData({
|
||||
order,
|
||||
items,
|
||||
'form.orderItemId': selectedItem ? selectedItem.id : '',
|
||||
'form.refundAmount': String(order && (order.actualAmount || order.totalAmount || '')),
|
||||
amountText: `¥${formatPrice(order && (order.actualAmount || order.totalAmount))}`
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '订单信息加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
handleItemChange(event) {
|
||||
const index = Number(event.detail.value)
|
||||
const item = this.data.items[index]
|
||||
this.setData({
|
||||
'form.orderItemId': item ? item.id : ''
|
||||
})
|
||||
},
|
||||
|
||||
handleTypeChange(event) {
|
||||
const index = Number(event.detail.value)
|
||||
this.setData({
|
||||
'form.typeIndex': index,
|
||||
'form.type': index === 0 ? 'REFUND' : 'AFTER_SALE'
|
||||
})
|
||||
},
|
||||
|
||||
handleInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`form.${field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
async submit() {
|
||||
if (!this.data.orderId) {
|
||||
wx.showToast({ title: '缺少订单信息', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const reason = String(this.data.form.reason || '').trim()
|
||||
if (!reason) {
|
||||
wx.showToast({ title: '请填写售后原因', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.setData({ submitting: true })
|
||||
try {
|
||||
await runWithLoading(() => afterSaleApi.applyAfterSale({
|
||||
orderId: this.data.orderId,
|
||||
orderItemId: this.data.form.orderItemId || undefined,
|
||||
type: this.data.form.type,
|
||||
reason,
|
||||
refundAmount: this.data.form.refundAmount ? Number(this.data.form.refundAmount) : undefined
|
||||
}), { title: '提交售后' })
|
||||
wx.showToast({ title: '售后申请已提交', icon: 'none' })
|
||||
wx.redirectTo({
|
||||
url: `/pages/after-sales/index?orderId=${encodeURIComponent(this.data.orderId)}`
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '售后申请提交失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({ submitting: false })
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<navigation-bar title="申请售后" showBack="{{true}}" fallbackPath="/pages/orders/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
|
||||
|
||||
<view class="page-shell" style="{{themeVars}}">
|
||||
<view class="page-content">
|
||||
<view class="page-hero">
|
||||
<text class="hero-kicker">售后申请</text>
|
||||
<text class="hero-title">{{order && order.orderNo || '选择订单'}}</text>
|
||||
<text class="hero-desc">{{order ? '可申请金�?' + amountText : '从订单详情进入可自动带入订单信息'}}</text>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{!orderId}}" class="page-card empty-card">
|
||||
<text class="empty-title">缺少订单信息</text>
|
||||
<text class="empty-desc">请从订单详情或订单中心发起售后��?/text>
|
||||
<view class="ghost-btn" bindtap="handleBack">返回订单</view>
|
||||
</view>
|
||||
|
||||
<view wx:else class="page-card form-card">
|
||||
<view class="field-block">
|
||||
<text class="field-label">订单项目</text>
|
||||
<picker mode="selector" range="{{items}}" range-key="productTitle" bindchange="handleItemChange">
|
||||
<view class="field-picker">{{form.orderItemId ? '已��择项目' : '默认整单'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field-block">
|
||||
<text class="field-label">售后类型</text>
|
||||
<picker mode="selector" range="{{typeOptions}}" value="{{form.typeIndex}}" bindchange="handleTypeChange">
|
||||
<view class="field-picker">{{typeOptions[form.typeIndex]}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field-block">
|
||||
<text class="field-label">逢�款金�?/text>
|
||||
<input class="field-input" type="digit" value="{{form.refundAmount}}" data-field="refundAmount" bindinput="handleInput" placeholder="可��? placeholder-class="field-placeholder" />
|
||||
</view>
|
||||
<view class="field-block">
|
||||
<text class="field-label">原因说明</text>
|
||||
<textarea class="field-textarea" maxlength="300" value="{{form.reason}}" data-field="reason" bindinput="handleInput" placeholder="请说明���款或售后原因" placeholder-class="field-placeholder"></textarea>
|
||||
</view>
|
||||
<button class="primary-btn" loading="{{submitting}}" bindtap="submit">提交申请</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,12 @@
|
||||
.form-card {
|
||||
margin-top: 22rpx;
|
||||
padding: 28rpx;
|
||||
}
|
||||
|
||||
.field-block + .field-block {
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
margin-top: 28rpx;
|
||||
}
|
||||
Reference in New Issue
Block a user