Commit 70060cee by 胡悦

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

新增订单创建页面及相关API接口,支持商品分页查询和选择
重构订单列表组件,支持分页加载和状态筛选
优化商品展示组件,计算总价逻辑改为前端计算
1 parent a684c344
......@@ -441,5 +441,18 @@ module.exports = {
projectName: 'pad',
...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 @@
</view>
</view>
<template v-if="list.length > 0">
<view class="card-list">
<view v-for="(i, index) in list" :key="index" class="card">
<view class="card-left">
<view class="title">{{ maskName(i.purchaser) }}</view>
<view class="model">{{ i.productName }}</view>
<view class="row">
<view class="label">商品数量</view>
<view class="value">{{ i.amount || '--' }}</view>
<scroll-view scroll-y class="content-scroll" @scrolltolower="loadMore" lower-threshold="60">
<view class="card-list">
<view v-for="(i, index) in list" :key="index" class="card">
<view class="card-left">
<view class="title">{{ maskName(i.purchaser) }}</view>
<view class="model">{{ i.productName }}</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 class="row">
<view class="label">下单时间</view>
<view class="value">{{ i.orderTime || '--' }}</view>
<view class="card-right">
<image class="preview-img" :src="i.productUrl" />
</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 class="list-footer">
<view v-if="loading" class="loading">加载中...</view>
<view v-else-if="!hasMore">没有更多了</view>
</view>
</scroll-view>
</template>
<template v-else>
<view class="nothing flex">
......@@ -45,6 +52,8 @@
</view>
</template>
<script>
import tag from 'uview-ui/libs/config/props/tag';
export default {
components: {
},
......@@ -58,65 +67,76 @@ export default {
{ tabName: '已支付', num: () => '' },
{ tabName: '待支付', num: () => '' }
],
page: {
pageNum: 1,
pageSize: 12
},
list: [],
loading: false,
hasMore: true
}
},
computed: {
list() {
switch (this.firstIndex) {
case 1:
return []
case 2:
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
}
]
}
}
mounted() {
this.getOrderPage()
uni.$on('ORDER_LIST_REFRESH', this.reload)
},
beforeDestroy() {
uni.$off('ORDER_LIST_REFRESH', this.reload)
},
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.page.pageNum = 1
this.hasMore = true
this.list = []
const statusMap = { 1: '已支付', 2: '待支付' }
this.getOrderPage(statusMap[index])
},
// 脱敏显示姓名,如“张*”
maskName(name) {
if (!name) return '--'
const first = name[0]
return `${first}*`
},
// 金额格式化为两位小数
formatPrice(val) {
const num = Number(val)
if (isNaN(num)) return '--'
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>
......@@ -141,6 +161,8 @@ export default {
position: relative;
overflow: hidden;
padding: toRpx(40) toRpx(48);
display: flex;
flex-direction: column;
.type-box {
position: relative;
......@@ -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 {
width: 100%;
flex-direction: column;
......@@ -203,13 +243,15 @@ export default {
margin-bottom: toRpx(24);
}
}
.card-list {
margin-top: toRpx(48);
// margin-top: toRpx(48);
display: flex;
flex-wrap: wrap;
gap: toRpx(24);
width: 100%;
}
.card {
width: calc((100% - #{toRpx(52)}) / 3);
display: flex;
......@@ -221,44 +263,53 @@ export default {
box-shadow: 0 toRpx(8) toRpx(24) rgba(59, 115, 255, 0.08);
margin-bottom: 0;
}
.card-left {
flex: 1;
padding: toRpx(32);
}
.title {
font-size: toRpx(28);
font-weight: 600;
color: #596170;
}
.model {
margin-top: toRpx(8);
font-size: toRpx(28);
color: #3773F8;
}
.row {
display: flex;
align-items: center;
margin-top: toRpx(10);
font-size: toRpx(26);
}
.row .label {
width: toRpx(140);
color: #8B97A3;
}
.row .value {
flex: 1;
color: #596170;
}
.row.total .amount {
color: #21C060;
font-weight: 600;
}
.card-right {
width: toRpx(252);
height: 100%;
border-radius: 0 toRpx(24) toRpx(24) 0;
overflow: hidden;
}
.preview-img {
width: 100%;
height: 100%;
......
......@@ -23,6 +23,13 @@
}
},
{
"path": "pages/equity/createOrder",
"style": {
"navigationStyle": "custom",
"disableSwipeBack": true
}
},
{
"path": "pages/common/nothing",
"style": {
"navigationBarTitleText": "提示"
......
......@@ -6,9 +6,9 @@
</view>
<view class="info">
<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 class="total-price">总价:¥{{ formatPrice(item.orderTotalAmount) }}</view>
<view class="total-price">总价:¥{{ formatPrice(item.price * number) }}</view>
</view>
</view>
</template>
......@@ -24,6 +24,11 @@
default: () => []
}
},
data() {
return {
number: 1
}
},
methods: {
formatPrice(val) {
const num = Number(val)
......
......@@ -16,14 +16,14 @@
</view>
</template>
<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>
<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="info-box">
<view class="name">{{ shop.describe }}</view>
<view class="price">¥{{ shop.orderTotalAmount }}</view>
<view class="price">¥{{ shop.price }}</view>
</view>
</view>
</view>
......@@ -60,10 +60,6 @@
type: Boolean,
default: true
},
noData: {
type: Boolean,
default: false
},
loadComplete: {
type: Boolean,
default: true
......@@ -71,46 +67,63 @@
shopList: {
type: Array,
default: () => [
{
"id": 1,
"picture": "https://example.com/phone1.jpg",
"describe": "智能手机A",
"productSn": "PHONE001",
"price": "29.99",
"orderNum": 100,
"orderTotalAmount": "2999.00",
"createBy": "admin",
"updateTime": "2023-10-15 14:30:00"
},
{
"id": 2,
"picture": "https://example.com/phone2.jpg",
"describe": "智能手机B",
"productSn": "PHONE002",
"price": "19.99",
"orderNum": 50,
"orderTotalAmount": "999.50",
"createBy": "admin",
"updateTime": "2023-10-14 10:20:00"
}
// {
// "id": 1,
// "picture": "https://example.com/phone1.jpg",
// "describe": "智能手机A",
// "productSn": "PHONE001",
// "price": "29.99",
// "orderNum": 100,
// "orderTotalAmount": "2999.00",
// "createBy": "admin",
// "updateTime": "2023-10-15 14:30:00"
// },
// {
// "id": 2,
// "picture": "https://example.com/phone2.jpg",
// "describe": "智能手机B",
// "productSn": "PHONE002",
// "price": "19.99",
// "orderNum": 50,
// "orderTotalAmount": "999.50",
// "createBy": "admin",
// "updateTime": "2023-10-14 10:20:00"
// }
]
},
selectList: {
type: Array,
default: () => []
},
api: {
type: String,
default: ''
},
hasPage: {
type: Boolean,
default: false
}
},
data() {
return {
searchValue: '',
tempSelect: []
tempSelect: [],
renderList: [],
loading: false,
finished: false,
page: {
current: 1,
size: 10,
total: 0
},
noData: false
}
},
methods: {
// 搜索
handleSearch() {
console.log(this.searchValue)
this.$emit('handleSearch', this.searchValue)
this.getList(true, 'name')
},
clear() {
this.searchValue = ''
......@@ -134,31 +147,81 @@
// 弹窗取消
cancel() {
console.log('quxiao')
this.searchValue = ''
// this.$emit('cancel')
this.close()
},
// 弹窗打开
open () {
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()
},
// 弹窗关闭
close () {
this.noData = false
this.$refs.popup.close()
this.$emit('close')
},
selectShop(shop) {
if (!shop) return
const idx = this.tempSelect.findIndex(s => (((s || {}).id) || s) === (((shop || {}).id) || shop))
if (idx !== -1) {
this.tempSelect.splice(idx, 1)
} else {
this.tempSelect.push(shop)
}
// 多选
// const idx = this.tempSelect.findIndex(s => (((s || {}).id) || s) === (((shop || {}).id) || shop))
// if (idx !== -1) {
// this.tempSelect.splice(idx, 1)
// } else {
// this.tempSelect.push(shop)
// }
// 单选
const selected = this.tempSelect[0]
const isSame = (((selected || {}).id) || selected) === (((shop || {}).id) || shop)
this.tempSelect = isSame ? [] : [shop]
},
isSelected(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>
......@@ -253,6 +316,7 @@
height: toRpx(72);
border: 1px solid #DCE0E6;
border-radius: toRpx(8);
margin-bottom: toRpx(24);
.sprite-icon {
position: absolute;
top: 0;
......@@ -266,4 +330,13 @@
padding: 0 toRpx(24);
}
}
.nothing {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2;
justify-content: center;
}
</style>
\ No newline at end of file
......@@ -14,7 +14,7 @@
</GlCell>
<view @click="submit" class="btn">直接下单</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>
</template>
......@@ -22,6 +22,7 @@
import GlCell from '@/components/Form/GlCell.vue'
import ShopPopup from './components/ShopPopup.vue'
import Product from './components/Product.vue'
import dayjs from 'dayjs';
export default {
components: {
GlCell,
......@@ -128,12 +129,18 @@ export default {
// 计算总价
getTotalPrice() {
let total = 0
const number = 1
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) {
uni.showToast({
......@@ -166,12 +173,45 @@ export default {
})
return
}
// 提交逻辑(此处可调用接口)
console.log('提交订单', this.orderObj)
uni.showToast({
title: '提交成功',
icon: 'success'
})
const params = {
orderTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
orderStatus: '已支付',
purchaser: this.orderObj.purchaser,
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!