feat: add resident miniapp MVP

This commit is contained in:
王鹏
2026-07-07 16:38:13 +08:00
parent bb325151d6
commit 576c54ec9d
52 changed files with 17865 additions and 66 deletions

View File

@@ -1 +1,56 @@
Page({})
const { getGoodsOrderDetail, cancelGoodsOrder } = require('../../api/orderApi')
const { getExpressOrderDetail, cancelExpressOrder, completeExpressOrder } = require('../../api/expressApi')
const { getGroupBuyOrderDetail, cancelGroupBuyOrder } = require('../../api/groupBuyApi')
const { statusText } = require('../../utils/request')
Page({
data: {
type: '',
order: null
},
onLoad(options) {
this.type = options.type
this.id = Number(options.id)
this.setData({ type: this.type })
this.load()
},
load() {
const loaders = {
goods: getGoodsOrderDetail,
express: getExpressOrderDetail,
group: getGroupBuyOrderDetail
}
loaders[this.type](this.id)
.then((order) => this.setData({ order }))
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
},
cancel() {
const actions = {
goods: () => cancelGoodsOrder(this.id),
express: () => cancelExpressOrder(this.id, '用户取消'),
group: () => cancelGroupBuyOrder(this.id)
}
actions[this.type]()
.then(() => {
wx.showToast({ title: '已取消' })
this.load()
})
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
},
completeExpress() {
completeExpressOrder(this.id)
.then(() => {
wx.showToast({ title: '已完成' })
this.load()
})
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
},
statusText(status) {
return statusText(status)
}
})

View File

@@ -1 +1,29 @@
<view class="page">订单详情</view>
<view class="page" wx:if="{{order}}">
<view class="card">
<view class="section-title">{{order.orderNo}}</view>
<view class="tag">{{order.status}}</view>
<view class="muted">类型:{{type}}</view>
</view>
<view class="card">
<view wx:if="{{type === 'goods'}}">
<view>商品金额:¥{{order.totalAmountCent / 100}}</view>
<view>配送费:¥{{order.deliveryFeeCent / 100}}</view>
<view class="price">应收:¥{{order.payableAmountCent / 100}}</view>
<view class="muted">{{order.deliveryMethod}}</view>
</view>
<view wx:if="{{type === 'express'}}">
<view>{{order.expressCompany}} / {{order.pickupCode}}</view>
<view class="muted">{{order.pickupAddress}}</view>
<view class="price">服务费:¥{{order.feeCent / 100}}</view>
</view>
<view wx:if="{{type === 'group'}}">
<view>{{order.groupBuyTitle}}</view>
<view>数量:{{order.quantity}}</view>
<view class="price">金额:¥{{order.amountCent / 100}}</view>
</view>
</view>
<view class="button-row">
<button class="ghost" bindtap="cancel">取消订单</button>
<button wx:if="{{type === 'express'}}" class="primary" bindtap="completeExpress">确认完成</button>
</view>
</view>

View File

@@ -1,3 +1,3 @@
.page {
min-height: 100vh;
.button-row button {
flex: 1;
}

View File

@@ -1 +1,70 @@
Page({})
const { listGoodsOrders } = require('../../api/orderApi')
const { listExpressOrders } = require('../../api/expressApi')
const { listGroupBuyOrders } = require('../../api/groupBuyApi')
const { statusText } = require('../../utils/request')
Page({
data: {
loading: false,
orders: []
},
onLoad() {
this.load()
},
onShow() {
this.load()
},
load() {
this.setData({ loading: true })
Promise.all([
listGoodsOrders().catch(() => []),
listExpressOrders().catch(() => []),
listGroupBuyOrders().catch(() => [])
])
.then(([goodsOrders, expressOrders, groupBuyOrders]) => {
const orders = []
;(goodsOrders || []).forEach((item) => orders.push({
id: item.id,
type: 'goods',
typeText: '商品订单',
orderNo: item.orderNo,
title: item.orderNo,
amountCent: item.payableAmountCent,
status: item.status
}))
;(expressOrders || []).forEach((item) => orders.push({
id: item.id,
type: 'express',
typeText: '快递代取',
orderNo: item.orderNo,
title: item.expressCompany + ' ' + item.pickupCode,
amountCent: item.feeCent,
status: item.status
}))
;(groupBuyOrders || []).forEach((item) => orders.push({
id: item.id,
type: 'group',
typeText: '团购订单',
orderNo: item.orderNo,
title: item.groupBuyTitle,
amountCent: item.amountCent,
status: item.status
}))
this.setData({ orders })
})
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
.finally(() => this.setData({ loading: false }))
},
goDetail(event) {
const { type, id } = event.currentTarget.dataset
wx.navigateTo({ url: '/pages/orders/detail?type=' + type + '&id=' + id })
},
statusText(status) {
return statusText(status)
}
})

View File

@@ -1 +1,17 @@
<view class="page">我的订单</view>
<view class="page">
<view class="section-title">我的订单</view>
<view wx:for="{{orders}}" wx:key="id" class="card" bindtap="goDetail" data-type="{{item.type}}" data-id="{{item.id}}">
<view class="row between">
<view>
<view>{{item.title}}</view>
<view class="muted">{{item.typeText}} {{item.orderNo}}</view>
</view>
<view class="tag">{{item.status}}</view>
</view>
<view class="row between">
<view class="muted">状态:{{item.status}}</view>
<view class="price">¥{{item.amountCent / 100}}</view>
</view>
</view>
<view wx:if="{{!orders.length && !loading}}" class="card muted">暂无订单</view>
</view>

View File

@@ -1,3 +1,4 @@
.page {
min-height: 100vh;
.tag {
min-width: 120rpx;
text-align: center;
}