Commit 70060cee by 胡悦

feat(订单): 实现订单创建、分页查询及商品选择功能

新增订单创建页面及相关API接口,支持商品分页查询和选择
重构订单列表组件,支持分页加载和状态筛选
优化商品展示组件,计算总价逻辑改为前端计算
1 parent a684c344
...@@ -441,5 +441,18 @@ module.exports = { ...@@ -441,5 +441,18 @@ module.exports = {
projectName: 'pad', projectName: 'pad',
...data ...data
}) })
} },
// 获取订单分页列表
getOrderPage(data) {
console.log(data)
return http.shukeRequest('linkwe-gateway/open/weSubstitute/customer/order', data, 'GET', true)
},
// 新增订单
addOrder(data) {
return http.shukeRequest('linkwe-gateway/open/weSubstitute/customer/order', data, 'POST', true)
},
// 商品列表
getProductList(data) {
return http.shukeRequest('linkwe-gateway/open/product/page/list', data, 'GET', true)
},
} }
...@@ -10,29 +10,36 @@ ...@@ -10,29 +10,36 @@
</view> </view>
</view> </view>
<template v-if="list.length > 0"> <template v-if="list.length > 0">
<view class="card-list"> <scroll-view scroll-y class="content-scroll" @scrolltolower="loadMore" lower-threshold="60">
<view v-for="(i, index) in list" :key="index" class="card">
<view class="card-left"> <view class="card-list">
<view class="title">{{ maskName(i.purchaser) }}</view> <view v-for="(i, index) in list" :key="index" class="card">
<view class="model">{{ i.productName }}</view> <view class="card-left">
<view class="row"> <view class="title">{{ maskName(i.purchaser) }}</view>
<view class="label">商品数量</view> <view class="model">{{ i.productName }}</view>
<view class="value">{{ i.amount || '--' }}</view> <view class="row">
<view class="label">商品数量</view>
<view class="value">{{ i.amount || '--' }}</view>
</view>
<view class="row">
<view class="label">下单时间</view>
<view class="value">{{ i.orderTime || '--' }}</view>
</view>
<view class="row total">
<view class="label">订单价格</view>
<view class="value amount">¥{{ formatPrice(i.totalPrice) }}</view>
</view>
</view> </view>
<view class="row"> <view class="card-right">
<view class="label">下单时间</view> <image class="preview-img" :src="i.productUrl" />
<view class="value">{{ i.orderTime || '--' }}</view>
</view> </view>
<view class="row total">
<view class="label">订单价格</view>
<view class="value amount">¥{{ formatPrice(i.totalPrice) }}</view>
</view>
</view>
<view class="card-right">
<image class="preview-img" :src="i.productUrl" />
</view> </view>
</view> </view>
</view> <view class="list-footer">
<view v-if="loading" class="loading">加载中...</view>
<view v-else-if="!hasMore">没有更多了</view>
</view>
</scroll-view>
</template> </template>
<template v-else> <template v-else>
<view class="nothing flex"> <view class="nothing flex">
...@@ -45,6 +52,8 @@ ...@@ -45,6 +52,8 @@
</view> </view>
</template> </template>
<script> <script>
import tag from 'uview-ui/libs/config/props/tag';
export default { export default {
components: { components: {
}, },
...@@ -58,65 +67,76 @@ export default { ...@@ -58,65 +67,76 @@ export default {
{ tabName: '已支付', num: () => '' }, { tabName: '已支付', num: () => '' },
{ tabName: '待支付', num: () => '' } { tabName: '待支付', num: () => '' }
], ],
page: {
pageNum: 1,
pageSize: 12
},
list: [],
loading: false,
hasMore: true
} }
}, },
computed: { mounted() {
list() { this.getOrderPage()
switch (this.firstIndex) { uni.$on('ORDER_LIST_REFRESH', this.reload)
case 1: },
return [] beforeDestroy() {
case 2: uni.$off('ORDER_LIST_REFRESH', this.reload)
return []
default:
return [
{
"id": "1991757770310443008",
"productName": "智能手afdsfadsf adsf环",
"productUrl": "https://wx.glsx.com.cn/upload/biz/80316c9f-ee40-486f-a8c8-faf34c39d9f1.jpeg",
"orderStatus": "已支付",
"totalPrice": 3941548,
"purchaser": "张三",
"orderTime": "2025-11-20",
"amount": 2
},
{
"id": "1991746058219839488",
"productName": "智能手环",
"productUrl": "https://wx.glsx.com.cn/upload/biz/80316c9f-ee40-486f-a8c8-faf34c39d9f1.jpeg",
"orderStatus": "已支付",
"totalPrice": 398,
"purchaser": "张三",
"orderTime": "2025-11-20",
"amount": 2
},
{
"id": "1991360412418482176",
"productName": "智能手环",
"productUrl": "https://wx.glsx.com.cn/upload/biz/80316c9f-ee40-486f-a8c8-faf34c39d9f1.jpeg",
"orderStatus": "已支付",
"totalPrice": 398,
"purchaser": "张三",
"orderTime": "2025-11-20",
"amount": 2
}
]
}
}
}, },
methods: { methods: {
changeType(index, tagIndex) { reload() {
this.page.pageNum = 1
this.hasMore = true
this.list = []
this.getOrderPage()
},
async getOrderPage(orderStatus) {
if (this.loading) return
const { pageNum, pageSize } = this.page
const params = { pageNum, pageSize }
if (orderStatus) params.orderStatus = orderStatus
this.loading = true
try {
const res = await uni.$api.commonApi.getOrderPage(params)
if (res.code == 200) {
const rows = Array.isArray(res.rows) ? res.rows : []
if (this.page.pageNum === 1) {
this.list = rows
} else {
this.list = this.list.concat(rows)
}
this.hasMore = rows.length === pageSize
}
} finally {
this.loading = false
}
},
changeType(index) {
this.firstIndex = index this.firstIndex = index
this.page.pageNum = 1
this.hasMore = true
this.list = []
const statusMap = { 1: '已支付', 2: '待支付' }
this.getOrderPage(statusMap[index])
}, },
// 脱敏显示姓名,如“张*”
maskName(name) { maskName(name) {
if (!name) return '--' if (!name) return '--'
const first = name[0] const first = name[0]
return `${first}*` return `${first}*`
}, },
// 金额格式化为两位小数
formatPrice(val) { formatPrice(val) {
const num = Number(val) const num = Number(val)
if (isNaN(num)) return '--' if (isNaN(num)) return '--'
return num.toFixed(2) return num.toFixed(2)
}, },
loadMore() {
if (!this.hasMore || this.loading) return
this.page.pageNum += 1
const statusMap = { 1: '已支付', 2: '待支付' }
this.getOrderPage(statusMap[this.firstIndex])
}
} }
} }
</script> </script>
...@@ -141,6 +161,8 @@ export default { ...@@ -141,6 +161,8 @@ export default {
position: relative; position: relative;
overflow: hidden; overflow: hidden;
padding: toRpx(40) toRpx(48); padding: toRpx(40) toRpx(48);
display: flex;
flex-direction: column;
.type-box { .type-box {
position: relative; position: relative;
...@@ -190,6 +212,24 @@ export default { ...@@ -190,6 +212,24 @@ export default {
} }
} }
.content-scroll {
flex: 1;
height: calc(100% - #{toRpx(136)});
margin-top: toRpx(48);
}
.list-footer {
margin-top: toRpx(24);
padding: toRpx(16) 0;
text-align: center;
color: #8B97A3;
font-size: toRpx(26);
}
.list-footer .loading {
color: #3773F8;
}
.nothing { .nothing {
width: 100%; width: 100%;
flex-direction: column; flex-direction: column;
...@@ -203,13 +243,15 @@ export default { ...@@ -203,13 +243,15 @@ export default {
margin-bottom: toRpx(24); margin-bottom: toRpx(24);
} }
} }
.card-list { .card-list {
margin-top: toRpx(48); // margin-top: toRpx(48);
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
gap: toRpx(24); gap: toRpx(24);
width: 100%; width: 100%;
} }
.card { .card {
width: calc((100% - #{toRpx(52)}) / 3); width: calc((100% - #{toRpx(52)}) / 3);
display: flex; display: flex;
...@@ -221,44 +263,53 @@ export default { ...@@ -221,44 +263,53 @@ export default {
box-shadow: 0 toRpx(8) toRpx(24) rgba(59, 115, 255, 0.08); box-shadow: 0 toRpx(8) toRpx(24) rgba(59, 115, 255, 0.08);
margin-bottom: 0; margin-bottom: 0;
} }
.card-left { .card-left {
flex: 1; flex: 1;
padding: toRpx(32); padding: toRpx(32);
} }
.title { .title {
font-size: toRpx(28); font-size: toRpx(28);
font-weight: 600; font-weight: 600;
color: #596170; color: #596170;
} }
.model { .model {
margin-top: toRpx(8); margin-top: toRpx(8);
font-size: toRpx(28); font-size: toRpx(28);
color: #3773F8; color: #3773F8;
} }
.row { .row {
display: flex; display: flex;
align-items: center; align-items: center;
margin-top: toRpx(10); margin-top: toRpx(10);
font-size: toRpx(26); font-size: toRpx(26);
} }
.row .label { .row .label {
width: toRpx(140); width: toRpx(140);
color: #8B97A3; color: #8B97A3;
} }
.row .value { .row .value {
flex: 1; flex: 1;
color: #596170; color: #596170;
} }
.row.total .amount { .row.total .amount {
color: #21C060; color: #21C060;
font-weight: 600; font-weight: 600;
} }
.card-right { .card-right {
width: toRpx(252); width: toRpx(252);
height: 100%; height: 100%;
border-radius: 0 toRpx(24) toRpx(24) 0; border-radius: 0 toRpx(24) toRpx(24) 0;
overflow: hidden; overflow: hidden;
} }
.preview-img { .preview-img {
width: 100%; width: 100%;
height: 100%; height: 100%;
......
...@@ -23,6 +23,13 @@ ...@@ -23,6 +23,13 @@
} }
}, },
{ {
"path": "pages/equity/createOrder",
"style": {
"navigationStyle": "custom",
"disableSwipeBack": true
}
},
{
"path": "pages/common/nothing", "path": "pages/common/nothing",
"style": { "style": {
"navigationBarTitleText": "提示" "navigationBarTitleText": "提示"
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
</view> </view>
<view class="info"> <view class="info">
<view class="name">商品名称:{{ item.describe }}</view> <view class="name">商品名称:{{ item.describe }}</view>
<view class="price">¥{{ formatPrice(item.price) }} * {{ item.orderNum }}</view> <view class="price">¥{{ formatPrice(item.price) }} * {{number}}</view>
</view> </view>
<view class="total-price">总价:¥{{ formatPrice(item.orderTotalAmount) }}</view> <view class="total-price">总价:¥{{ formatPrice(item.price * number) }}</view>
</view> </view>
</view> </view>
</template> </template>
...@@ -24,6 +24,11 @@ ...@@ -24,6 +24,11 @@
default: () => [] default: () => []
} }
}, },
data() {
return {
number: 1
}
},
methods: { methods: {
formatPrice(val) { formatPrice(val) {
const num = Number(val) const num = Number(val)
......
...@@ -16,14 +16,14 @@ ...@@ -16,14 +16,14 @@
</view> </view>
</template> </template>
<view :class="['popup-body', { 'hide-search': hideSearch }]"> <view :class="['popup-body', { 'hide-search': hideSearch }]">
<scroll-view scroll-y :class="['popup-scroll-view', { show: loadComplete }]"> <scroll-view scroll-y :class="['popup-scroll-view', { show: loadComplete }]" @scrolltolower="loadMore" lower-threshold="60">
<template> <template>
<view class="shop-list"> <view class="shop-list">
<view class="shop-item" v-for="(shop, idx) in shopList" :key="shop.id || idx" @click="selectShop(shop)"> <view class="shop-item" v-for="(shop, idx) in renderList" :key="shop.id || idx" @click="selectShop(shop)">
<view class="sprite-icon icon-tag-checked" v-if="isSelected(shop)"></view> <view class="sprite-icon icon-tag-checked" v-if="isSelected(shop)"></view>
<view class="info-box"> <view class="info-box">
<view class="name">{{ shop.describe }}</view> <view class="name">{{ shop.describe }}</view>
<view class="price">¥{{ shop.orderTotalAmount }}</view> <view class="price">¥{{ shop.price }}</view>
</view> </view>
</view> </view>
</view> </view>
...@@ -60,10 +60,6 @@ ...@@ -60,10 +60,6 @@
type: Boolean, type: Boolean,
default: true default: true
}, },
noData: {
type: Boolean,
default: false
},
loadComplete: { loadComplete: {
type: Boolean, type: Boolean,
default: true default: true
...@@ -71,46 +67,63 @@ ...@@ -71,46 +67,63 @@
shopList: { shopList: {
type: Array, type: Array,
default: () => [ default: () => [
{ // {
"id": 1, // "id": 1,
"picture": "https://example.com/phone1.jpg", // "picture": "https://example.com/phone1.jpg",
"describe": "智能手机A", // "describe": "智能手机A",
"productSn": "PHONE001", // "productSn": "PHONE001",
"price": "29.99", // "price": "29.99",
"orderNum": 100, // "orderNum": 100,
"orderTotalAmount": "2999.00", // "orderTotalAmount": "2999.00",
"createBy": "admin", // "createBy": "admin",
"updateTime": "2023-10-15 14:30:00" // "updateTime": "2023-10-15 14:30:00"
}, // },
{ // {
"id": 2, // "id": 2,
"picture": "https://example.com/phone2.jpg", // "picture": "https://example.com/phone2.jpg",
"describe": "智能手机B", // "describe": "智能手机B",
"productSn": "PHONE002", // "productSn": "PHONE002",
"price": "19.99", // "price": "19.99",
"orderNum": 50, // "orderNum": 50,
"orderTotalAmount": "999.50", // "orderTotalAmount": "999.50",
"createBy": "admin", // "createBy": "admin",
"updateTime": "2023-10-14 10:20:00" // "updateTime": "2023-10-14 10:20:00"
} // }
] ]
}, },
selectList: { selectList: {
type: Array, type: Array,
default: () => [] default: () => []
},
api: {
type: String,
default: ''
},
hasPage: {
type: Boolean,
default: false
} }
}, },
data() { data() {
return { return {
searchValue: '', searchValue: '',
tempSelect: [] tempSelect: [],
renderList: [],
loading: false,
finished: false,
page: {
current: 1,
size: 10,
total: 0
},
noData: false
} }
}, },
methods: { methods: {
// 搜索 // 搜索
handleSearch() { handleSearch() {
console.log(this.searchValue)
this.$emit('handleSearch', this.searchValue) this.$emit('handleSearch', this.searchValue)
this.getList(true, 'name')
}, },
clear() { clear() {
this.searchValue = '' this.searchValue = ''
...@@ -134,31 +147,81 @@ ...@@ -134,31 +147,81 @@
// 弹窗取消 // 弹窗取消
cancel() { cancel() {
console.log('quxiao') console.log('quxiao')
this.searchValue = ''
// this.$emit('cancel') // this.$emit('cancel')
this.close() this.close()
}, },
// 弹窗打开 // 弹窗打开
open () { open () {
this.tempSelect = Array.isArray(this.selectList) ? [...this.selectList] : [] this.tempSelect = Array.isArray(this.selectList) ? [...this.selectList] : []
if (this.tempSelect.length > 1) this.tempSelect = [this.tempSelect[0]]
this.getList(true)
this.$refs.popup.open() this.$refs.popup.open()
}, },
// 弹窗关闭 // 弹窗关闭
close () { close () {
this.noData = false
this.$refs.popup.close() this.$refs.popup.close()
this.$emit('close') this.$emit('close')
}, },
selectShop(shop) { selectShop(shop) {
if (!shop) return if (!shop) return
const idx = this.tempSelect.findIndex(s => (((s || {}).id) || s) === (((shop || {}).id) || shop)) // 多选
if (idx !== -1) { // const idx = this.tempSelect.findIndex(s => (((s || {}).id) || s) === (((shop || {}).id) || shop))
this.tempSelect.splice(idx, 1) // if (idx !== -1) {
} else { // this.tempSelect.splice(idx, 1)
this.tempSelect.push(shop) // } else {
} // this.tempSelect.push(shop)
// }
// 单选
const selected = this.tempSelect[0]
const isSame = (((selected || {}).id) || selected) === (((shop || {}).id) || shop)
this.tempSelect = isSame ? [] : [shop]
}, },
isSelected(shop) { isSelected(shop) {
return this.tempSelect.some(s => (((s || {}).id) || s) === (((shop || {}).id) || shop)) return this.tempSelect.some(s => (((s || {}).id) || s) === (((shop || {}).id) || shop))
}, },
async getList(reset = false, searchKey = 'keyword') {
if (!this.api || !uni.$api || !uni.$api.commonApi || typeof uni.$api.commonApi[this.api] !== 'function') return
const params = {}
if (this.hasPage) {
if (reset) this.page.current = 1
params.pageNum = this.page.current
params.pageSize = this.page.size
}
if (this.searchValue) params[searchKey] = this.searchValue
this.loading = true
try {
const res = await uni.$api.commonApi[this.api](params)
let rows = []
if (Array.isArray(res)) {
rows = res
} else if (Array.isArray(res?.rows)) {
rows = res.rows
this.page.total = Number(res.total || 0)
} else if (Array.isArray(res?.data)) {
rows = res.data
this.page.total = Number(res.total || res.dataTotal || 0)
}
if (this.hasPage && this.page.current > 1 && !reset) {
this.renderList = this.renderList.concat(rows)
} else {
this.renderList = rows
}
this.noData = this.renderList.length === 0
if (this.hasPage) {
const size = this.page.size
this.finished = rows.length < size
}
} finally {
this.loading = false
}
},
loadMore() {
if (!this.hasPage || this.loading || this.finished) return
this.page.current += 1
this.getList(false)
}
} }
} }
</script> </script>
...@@ -253,6 +316,7 @@ ...@@ -253,6 +316,7 @@
height: toRpx(72); height: toRpx(72);
border: 1px solid #DCE0E6; border: 1px solid #DCE0E6;
border-radius: toRpx(8); border-radius: toRpx(8);
margin-bottom: toRpx(24);
.sprite-icon { .sprite-icon {
position: absolute; position: absolute;
top: 0; top: 0;
...@@ -266,4 +330,13 @@ ...@@ -266,4 +330,13 @@
padding: 0 toRpx(24); padding: 0 toRpx(24);
} }
} }
.nothing {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2;
justify-content: center;
}
</style> </style>
\ No newline at end of file \ No newline at end of file
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
</GlCell> </GlCell>
<view @click="submit" class="btn">直接下单</view> <view @click="submit" class="btn">直接下单</view>
</view> </view>
<ShopPopup ref="shopPopup" :title="shopTitle" :selectList="orderObj.shopList" @onConfirm="onConfirm"></ShopPopup> <ShopPopup ref="shopPopup" :title="shopTitle" api="getProductList" :hasPage="true" :selectList="orderObj.shopList" @onConfirm="onConfirm"></ShopPopup>
</view> </view>
</template> </template>
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
import GlCell from '@/components/Form/GlCell.vue' import GlCell from '@/components/Form/GlCell.vue'
import ShopPopup from './components/ShopPopup.vue' import ShopPopup from './components/ShopPopup.vue'
import Product from './components/Product.vue' import Product from './components/Product.vue'
import dayjs from 'dayjs';
export default { export default {
components: { components: {
GlCell, GlCell,
...@@ -128,12 +129,18 @@ export default { ...@@ -128,12 +129,18 @@ export default {
// 计算总价 // 计算总价
getTotalPrice() { getTotalPrice() {
let total = 0 let total = 0
const number = 1
this.orderObj.shopList.forEach(shop => { this.orderObj.shopList.forEach(shop => {
total += Number(shop.orderTotalAmount) total += Number(shop.price) * number
}) })
this.orderObj.totaPrice = total this.orderObj.totaPrice = this.formatPrice(total)
}, },
submit() { formatPrice(val) {
const num = Number(val)
if (isNaN(num)) return '--'
return num.toFixed(2)
},
async submit() {
// 校验购买人 // 校验购买人
if (!this.orderObj.purchaser) { if (!this.orderObj.purchaser) {
uni.showToast({ uni.showToast({
...@@ -166,12 +173,45 @@ export default { ...@@ -166,12 +173,45 @@ export default {
}) })
return return
} }
// 提交逻辑(此处可调用接口) const params = {
console.log('提交订单', this.orderObj) orderTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
uni.showToast({ orderStatus: '已支付',
title: '提交成功', purchaser: this.orderObj.purchaser,
icon: 'success' phone: this.orderObj.phone,
}) deptId: 1001,
userId: 10086,
source: 'pad',
productName: this.orderObj.shopList[0].describe,
productUrl: this.orderObj.shopList[0].picture,
productUnitPrice: this.orderObj.shopList[0].price,
amount: 1, // 默认1
totalPrice: this.orderObj.totaPrice,
actualPayment: this.orderObj.totaPrice,
returnedMoneyType: '微信支付',
returnedMoney: this.orderObj.totaPrice,
returnedDate: dayjs().format('YYYY-MM-DD HH:mm:ss'),
payer: this.orderObj.purchaser,
status: 1,
externalUserid: 'woAJ2GCAAAXtWyujaWJHDDGi0mACAAA'
}
const res = await uni.$api.commonApi.addOrder(params)
if (res.code == 200) {
uni.showToast({
title: '提交成功',
icon: 'success'
})
uni.$emit('ORDER_LIST_REFRESH')
setTimeout(() => {
uni.navigateBack({
delta: 1
})
}, 1500)
} else {
uni.showToast({
title: res.msg,
icon: 'none'
})
}
} }
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!