Compare commits
164 Commits
master
...
8e0122b08f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e0122b08f | ||
|
|
7052bb25c1 | ||
|
|
80b6fa0fe5 | ||
|
|
750875be74 | ||
|
|
58fc2a9d90 | ||
|
|
1c414036c7 | ||
|
|
f0daec8c06 | ||
|
|
7c25420c30 | ||
|
|
eb2b16f84f | ||
|
|
4921ee8d97 | ||
|
|
d5ae333176 | ||
|
|
615b688810 | ||
|
|
293d2dd8fe | ||
|
|
f90152f010 | ||
|
|
ac29a24199 | ||
|
|
6c3fd0fb31 | ||
|
|
c1477d973f | ||
| 393d920900 | |||
|
|
9905808664 | ||
|
|
ec89799970 | ||
|
|
8c71045175 | ||
|
|
2926f76a26 | ||
|
|
4b5b51ef59 | ||
|
|
c07c81e479 | ||
|
|
7140e0049f | ||
|
|
f47f078357 | ||
| 8c7e500fbb | |||
|
|
08c44da709 | ||
| bd228e1d6d | |||
|
|
dec77fd518 | ||
| dc847564c0 | |||
| 8c1b57160d | |||
|
|
e4063c0625 | ||
|
|
81ec7dd2cf | ||
| 01ad62e3f6 | |||
|
|
05e37b3abe | ||
|
|
6bce9ad6cf | ||
|
|
4539be1559 | ||
|
|
ef4dceba1b | ||
|
|
cd5c397617 | ||
|
|
38f68e06a1 | ||
| 4aa855ed41 | |||
|
|
41896a073f | ||
|
|
f3d01ca9ce | ||
|
|
bfab7b8d1d | ||
|
|
4841c49cbd | ||
|
|
e7d03c8558 | ||
|
|
430a5422ee | ||
|
|
848423faa3 | ||
|
|
5d2e13df79 | ||
|
|
d5ccf9d1e4 | ||
|
|
e98b283501 | ||
|
|
53326f3a48 | ||
|
|
031b8ccc25 | ||
|
|
35c65a7cb3 | ||
|
|
f9192a1486 | ||
|
|
494b0f195d | ||
|
|
161a5236e4 | ||
|
|
3fd6023a93 | ||
|
|
e681a4e99f | ||
|
|
b6c67ceaa8 | ||
|
|
f93aa242c9 | ||
|
|
228e71d580 | ||
|
|
5b790fbdfe | ||
|
|
ee5f2ab395 | ||
|
|
ab0d500308 | ||
| 310b61591e | |||
| 2ddf411050 | |||
|
|
b5f621c980 | ||
| b1211962ce | |||
|
|
b9a8a6dd71 | ||
| 781cca9a15 | |||
|
|
df9e2b722b | ||
| c2929ae00a | |||
| aea526d4bb | |||
| e704b1018c | |||
|
|
c399c54439 | ||
|
|
cd82ad2fa6 | ||
|
|
547a5bc7c7 | ||
|
|
345c3283e0 | ||
|
|
6e26355e7d | ||
|
|
42df88b654 | ||
|
|
3f9420d026 | ||
|
|
12da38d65d | ||
|
|
2cb329edce | ||
| ca0f906590 | |||
|
|
06145d27a5 | ||
|
|
39c119ffe4 | ||
|
|
244caf9bc6 | ||
|
|
84e2259be4 | ||
|
|
f8ce079a4b | ||
|
|
798f6a97a8 | ||
|
|
02c4b02092 | ||
|
|
3dfba3d804 | ||
|
|
fe35a48123 | ||
|
|
e32758ecc5 | ||
| d834188c08 | |||
|
|
8b49c32f63 | ||
|
|
aa36029818 | ||
|
|
1cb5f6b646 | ||
|
|
34054065ed | ||
|
|
d8ba777fb4 | ||
|
|
b7b11207ab | ||
|
|
af232815d3 | ||
|
|
1e820fa0ca | ||
|
|
46e83862f4 | ||
|
|
3e693882d0 | ||
|
|
6cdfc47250 | ||
|
|
cd9e2edc8e | ||
|
|
3ee4a6cccd | ||
|
|
295c61071b | ||
|
|
508abbc375 | ||
|
|
bf2033be21 | ||
|
|
3a8f21effa | ||
|
|
24375d6d00 | ||
|
|
f6e9c28f71 | ||
|
|
33d2532843 | ||
|
|
f581283155 | ||
|
|
3f317dd4cf | ||
|
|
b79f951514 | ||
|
|
17f6b49e5d | ||
|
|
7ca2e1d5a4 | ||
|
|
af10a0b6f4 | ||
|
|
e68dc71611 | ||
|
|
2643027475 | ||
| a41773a801 | |||
| 90689cd3ac | |||
|
|
adc4576d13 | ||
|
|
7690907a45 | ||
|
|
989e18fab8 | ||
|
|
b9823b01e5 | ||
|
|
ead8818774 | ||
| 2d734aa302 | |||
| a4b97b7298 | |||
|
|
a39c9ee8f7 | ||
|
|
0b03f81b55 | ||
|
|
83f316f49b | ||
| 26cb69ed61 | |||
| 926af54fed | |||
| 934a997984 | |||
| 9d22690f08 | |||
|
|
38d68063a2 | ||
|
|
efac494063 | ||
|
|
3dc5b2f4e7 | ||
|
|
c4d83d18bb | ||
|
|
63da0788f8 | ||
|
|
370a76bb45 | ||
|
|
9fdf999835 | ||
|
|
49155a7542 | ||
|
|
1aa9894573 | ||
|
|
65876f401a | ||
|
|
ef66e6c173 | ||
|
|
15a3b7362d | ||
|
|
061ccfe2c3 | ||
|
|
b9c032a3c5 | ||
|
|
4d20d3e24d | ||
|
|
09377de909 | ||
|
|
48ffb2ae79 | ||
|
|
92b7d69517 | ||
|
|
fab2216538 | ||
|
|
4df7cdc9c6 | ||
|
|
ebfe16a929 | ||
|
|
d21b35a02d | ||
|
|
0ba6a5389d |
112
.drone.yml
Normal file
112
.drone.yml
Normal file
@@ -0,0 +1,112 @@
|
||||
kind: pipeline
|
||||
type: kubernetes
|
||||
|
||||
name: build-and-deploy-dev
|
||||
|
||||
volumes:
|
||||
- name: node-cache
|
||||
claim:
|
||||
name: node-cache-pvc
|
||||
|
||||
service_account_name: drone-builder-sa
|
||||
|
||||
trigger:
|
||||
event:
|
||||
- push
|
||||
branch:
|
||||
- dev
|
||||
|
||||
steps:
|
||||
- name: dev-install
|
||||
image: ccr.ccs.tencentyun.com/violin/node:22-bookworm
|
||||
commands:
|
||||
- npm install
|
||||
volumes:
|
||||
- name: node-cache
|
||||
path: /root/.npm
|
||||
|
||||
- name: dev-build
|
||||
image: ccr.ccs.tencentyun.com/violin/node:22-bookworm
|
||||
commands:
|
||||
- npm run build:h5 -- --mode development
|
||||
volumes:
|
||||
- name: node-cache
|
||||
path: /root/.npm
|
||||
|
||||
- name: dev-build-image
|
||||
# # #####
|
||||
image: ccr.ccs.tencentyun.com/violin/drone-kaniko:latest
|
||||
settings:
|
||||
repo: ccr.ccs.tencentyun.com/violin/todo-frontend
|
||||
tags:
|
||||
- latest
|
||||
- ${DRONE_COMMIT_SHA:0:8}
|
||||
dockerfile: Dockerfile
|
||||
context: .
|
||||
registry: ccr.ccs.tencentyun.com
|
||||
username: 100024540033
|
||||
password:
|
||||
from_secret: docker_password
|
||||
|
||||
- name: dev-deploy
|
||||
image: ccr.ccs.tencentyun.com/violin/kubectl:latest
|
||||
cluster: kubernetes
|
||||
namespace: drone
|
||||
commands:
|
||||
- kubectl set image deployment/todo-frontend todo-frontend=ccr.ccs.tencentyun.com/violin/todo-frontend:${DRONE_COMMIT_SHA:0:8} -n drone
|
||||
- kubectl rollout restart deployment/todo-frontend -n drone
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
type: kubernetes
|
||||
|
||||
name: build-and-deploy-prod
|
||||
|
||||
volumes:
|
||||
- name: node-cache
|
||||
claim:
|
||||
name: node-cache-pvc
|
||||
|
||||
trigger:
|
||||
event:
|
||||
- push
|
||||
branch:
|
||||
- master
|
||||
|
||||
steps:
|
||||
- name: prod-install
|
||||
image: ccr.ccs.tencentyun.com/violin/node:22-bookworm
|
||||
commands:
|
||||
- npm install
|
||||
volumes:
|
||||
- name: node-cache
|
||||
path: /root/.npm
|
||||
|
||||
- name: prod-build
|
||||
image: ccr.ccs.tencentyun.com/violin/node:22-bookworm
|
||||
commands:
|
||||
- npm run build:h5 -- --mode production
|
||||
volumes:
|
||||
- name: node-cache
|
||||
path: /root/.npm
|
||||
|
||||
- name: prod-build-image
|
||||
image: ccr.ccs.tencentyun.com/violin/drone-kaniko:latest
|
||||
settings:
|
||||
repo: ccr.ccs.tencentyun.com/violin/todo-frontend
|
||||
tags:
|
||||
- v1.0.0
|
||||
dockerfile: Dockerfile
|
||||
context: .
|
||||
registry: ccr.ccs.tencentyun.com
|
||||
username: 100024540033
|
||||
password:
|
||||
from_secret: docker_password
|
||||
|
||||
- name: prod-deploy
|
||||
image: ccr.ccs.tencentyun.com/violin/kubectl:latest
|
||||
cluster: kubernetes
|
||||
namespace: drone
|
||||
commands:
|
||||
- kubectl set image deployment/todo-frontend todo-frontend=ccr.ccs.tencentyun.com/violin/todo-frontend:v1.0.0
|
||||
- kubectl rollout status deployment/todo-frontend
|
||||
3
.env.development
Normal file
3
.env.development
Normal file
@@ -0,0 +1,3 @@
|
||||
# 环境配置
|
||||
VITE_API_BASE_URL=https://sales.violin-work.online/api/v1
|
||||
VITE_H5_BASE_URL=https://sales.violin-work.online
|
||||
3
.env.production
Normal file
3
.env.production
Normal file
@@ -0,0 +1,3 @@
|
||||
# 环境配置
|
||||
VITE_API_BASE_URL=https://sales.violin-work.online/api/v1
|
||||
VITE_H5_BASE_URL=https://sales.violin-work.online
|
||||
16
.gitignore
vendored
Normal file
16
.gitignore
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
# 本地环境变量覆盖(不提交)
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# 构建输出
|
||||
dist/
|
||||
unpackage/
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
.vscode/
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
7
Dockerfile
Normal file
7
Dockerfile
Normal file
@@ -0,0 +1,7 @@
|
||||
FROM ccr.ccs.tencentyun.com/violin/nginx:latest
|
||||
|
||||
COPY dist/build/h5 /usr/share/nginx/html
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
41
api/index.js
41
api/index.js
@@ -1,41 +0,0 @@
|
||||
// API基础配置
|
||||
const BASE_URL = 'http://localhost:8080/api/v1'
|
||||
|
||||
// 请求拦截器
|
||||
const request = (url, method, data = {}) => {
|
||||
const token = uni.getStorageSync('token')
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: BASE_URL + url,
|
||||
method: method,
|
||||
data: data,
|
||||
header: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': token ? `Bearer ${token}` : ''
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.data.code === 0) {
|
||||
resolve(res.data.data)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.data.message || '请求失败',
|
||||
icon: 'none'
|
||||
})
|
||||
reject(res.data)
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.showToast({
|
||||
title: '网络请求失败',
|
||||
icon: 'none'
|
||||
})
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
request
|
||||
}
|
||||
14
index.html
Normal file
14
index.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>建材销售管家</title>
|
||||
<!-- IconFont 图标库 -->
|
||||
<link rel="stylesheet" href="https://at.alicdn.com/t/font_3410480_1x6a2sijq4i.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
38
k8s/deployment.yaml
Normal file
38
k8s/deployment.yaml
Normal file
@@ -0,0 +1,38 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: todo-frontend
|
||||
namespace: drone
|
||||
labels:
|
||||
app: todo-frontend
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: todo-frontend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: todo-frontend
|
||||
spec:
|
||||
imagePullSecrets:
|
||||
- name: tencentyun-secret
|
||||
containers:
|
||||
- name: todo-frontend
|
||||
image: ccr.ccs.tencentyun.com/violin/todo-frontend:latest
|
||||
imagePullPolicy: Always
|
||||
ports:
|
||||
- containerPort: 80
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: todo-frontend
|
||||
namespace: drone
|
||||
spec:
|
||||
selector:
|
||||
app: todo-frontend
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
type: ClusterIP
|
||||
33
k8s/ingress.yaml
Normal file
33
k8s/ingress.yaml
Normal file
@@ -0,0 +1,33 @@
|
||||
# ingress.yaml
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: sales-ingress
|
||||
namespace: drone
|
||||
annotations:
|
||||
traefik.ingress.kubernetes.io/router.entrypoints: websecure
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- sales.violin-work.online
|
||||
secretName: violin-tls
|
||||
rules:
|
||||
- host: sales.violin-work.online
|
||||
http:
|
||||
paths:
|
||||
# /api 路径转发到后端服务
|
||||
- path: /api
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: todo-backend
|
||||
port:
|
||||
number: 80
|
||||
# 其他路径转发到前端服务
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: todo-frontend
|
||||
port:
|
||||
number: 80
|
||||
11
main.js
11
main.js
@@ -1,11 +0,0 @@
|
||||
import Vue from 'vue'
|
||||
import App from './App'
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
App.mpType = 'page'
|
||||
|
||||
const app = new Vue({
|
||||
...App
|
||||
})
|
||||
app.$mount()
|
||||
18
package.json
18
package.json
@@ -9,16 +9,16 @@
|
||||
"build:mp-weixin": "uni build -p mp-weixin"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dcloudio/uni-app": "^2.0.0",
|
||||
"@dcloudio/uni-h5": "^2.0.0",
|
||||
"@dcloudio/uni-mp-weixin": "^2.0.0",
|
||||
"@dcloudio/uni-mp-alipay": "^2.0.0",
|
||||
"vue": "^3.2.45"
|
||||
"@dcloudio/uni-app": "3.0.0-4080720251210001",
|
||||
"@dcloudio/uni-h5": "3.0.0-4080720251210001",
|
||||
"@dcloudio/uni-mp-weixin": "3.0.0-4080720251210001",
|
||||
"@dcloudio/uni-mp-alipay": "3.0.0-4080720251210001",
|
||||
"vue": "^3.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@dcloudio/types": "^3.0.16",
|
||||
"@dcloudio/uni-cli-shared": "^2.0.0",
|
||||
"@dcloudio/vite-plugin-uni": "^2.0.0",
|
||||
"vite": "^4.0.0"
|
||||
"@dcloudio/types": "^3.4.0",
|
||||
"@dcloudio/uni-cli-shared": "3.0.0-4080720251210001",
|
||||
"@dcloudio/vite-plugin-uni": "3.0.0-4080720251210001",
|
||||
"vite": "^5.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
60
pages.json
60
pages.json
@@ -1,60 +0,0 @@
|
||||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/index/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "首页"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/login/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "登录"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/product/list",
|
||||
"style": {
|
||||
"navigationBarTitleText": "商品列表"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/order/create",
|
||||
"style": {
|
||||
"navigationBarTitleText": "创建订单"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/order/list",
|
||||
"style": {
|
||||
"navigationBarTitleText": "订单列表"
|
||||
}
|
||||
}
|
||||
],
|
||||
"globalStyle": {
|
||||
"navigationBarTextStyle": "black",
|
||||
"navigationBarTitleText": "建材销售管家",
|
||||
"navigationBarBackgroundColor": "#F8F8F8",
|
||||
"backgroundColor": "#F8F8F8"
|
||||
},
|
||||
"tabBar": {
|
||||
"color": "#7A7E83",
|
||||
"selectedColor": "#3cc51f",
|
||||
"borderStyle": "black",
|
||||
"backgroundColor": "#ffffff",
|
||||
"list": [
|
||||
{
|
||||
"pagePath": "pages/index/index",
|
||||
"text": "首页"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/product/list",
|
||||
"text": "商品"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/order/list",
|
||||
"text": "订单"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 用户信息 -->
|
||||
<view class="user-info">
|
||||
<view class="avatar">
|
||||
<text class="username">{{ userInfo.username || '用户' }}</text>
|
||||
</view>
|
||||
<view class="role-tag">{{ userInfo.role || '销售员' }}</view>
|
||||
</view>
|
||||
|
||||
<!-- 功能菜单 -->
|
||||
<view class="menu-grid">
|
||||
<view class="menu-item" @click="goTo('/pages/product/list')">
|
||||
<text class="menu-icon">📦</text>
|
||||
<text class="menu-text">商品管理</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goTo('/pages/order/create')">
|
||||
<text class="menu-icon">📝</text>
|
||||
<text class="menu-text">创建订单</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goTo('/pages/order/list')">
|
||||
<text class="menu-icon">📋</text>
|
||||
<text class="menu-text">订单列表</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goStock()">
|
||||
<text class="menu-icon">🏭</text>
|
||||
<text class="menu-text">库存管理</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 快捷操作 -->
|
||||
<view class="section">
|
||||
<view class="section-title">今日概览</view>
|
||||
<view class="stats-grid">
|
||||
<view class="stat-item">
|
||||
<text class="stat-value">{{ stats.orderCount || 0 }}</text>
|
||||
<text class="stat-label">今日订单</text>
|
||||
</view>
|
||||
<view class="stat-item">
|
||||
<text class="stat-value">¥{{ stats.actualAmount || 0 }}</text>
|
||||
<text class="stat-label">今日销售额</text>
|
||||
</view>
|
||||
<view class="stat-item">
|
||||
<text class="stat-value">{{ stats.stockAlerts || 0 }}</text>
|
||||
<text class="stat-label">库存预警</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 退出登录 -->
|
||||
<button class="logout-btn" @click="logout">退出登录</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import authApi from '@/api/auth'
|
||||
import orderApi from '@/api/order'
|
||||
import productApi from '@/api/product'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
userInfo: {},
|
||||
stats: {
|
||||
orderCount: 0,
|
||||
actualAmount: 0,
|
||||
stockAlerts: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.loadUserInfo()
|
||||
this.loadStats()
|
||||
},
|
||||
methods: {
|
||||
async loadUserInfo() {
|
||||
try {
|
||||
const userInfo = await authApi.getCurrentUser()
|
||||
this.userInfo = userInfo
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
async loadStats() {
|
||||
try {
|
||||
// 获取今日订单统计
|
||||
const today = new Date().toISOString().split('T')[0]
|
||||
const stats = await orderApi.getStatistics({ startDate: today })
|
||||
this.stats.orderCount = stats.orderCount || 0
|
||||
this.stats.actualAmount = stats.actualAmount || 0
|
||||
|
||||
// 获取库存预警
|
||||
const alerts = await productApi.getStockAlerts()
|
||||
this.stats.stockAlerts = alerts ? alerts.length : 0
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
goTo(url) {
|
||||
uni.navigateTo({ url })
|
||||
},
|
||||
goStock() {
|
||||
uni.showToast({ title: '库存管理功能开发中', icon: 'none' })
|
||||
},
|
||||
async logout() {
|
||||
try {
|
||||
await authApi.logout()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
uni.removeStorageSync('token')
|
||||
uni.reLaunch({ url: '/pages/login/index' })
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 120rpx;
|
||||
height: 120rpx;
|
||||
background: #3cc51f;
|
||||
border-radius: 60rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.username {
|
||||
color: #fff;
|
||||
font-size: 32rpx;
|
||||
}
|
||||
|
||||
.role-tag {
|
||||
margin-left: 20rpx;
|
||||
padding: 8rpx 16rpx;
|
||||
background: #e6f7ff;
|
||||
color: #1890ff;
|
||||
border-radius: 8rpx;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.menu-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
width: 25%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.menu-icon {
|
||||
font-size: 60rpx;
|
||||
}
|
||||
|
||||
.menu-text {
|
||||
margin-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.section {
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.stats-grid {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 10rpx;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
background: #fff;
|
||||
color: #ff4d4f;
|
||||
border: none;
|
||||
margin-top: 40rpx;
|
||||
}
|
||||
</style>
|
||||
@@ -1,293 +0,0 @@
|
||||
<template>
|
||||
<view class="login-page">
|
||||
<view class="logo">
|
||||
<text class="logo-text">🏠</text>
|
||||
<text class="app-name">建材销售管家</text>
|
||||
</view>
|
||||
|
||||
<!-- 手机号登录 -->
|
||||
<view class="login-form">
|
||||
<view class="form-item">
|
||||
<input
|
||||
class="input"
|
||||
type="number"
|
||||
v-model="phone"
|
||||
placeholder="请输入手机号"
|
||||
maxlength="11"
|
||||
/>
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<input
|
||||
class="input"
|
||||
type="number"
|
||||
v-model="code"
|
||||
placeholder="请输入验证码"
|
||||
maxlength="6"
|
||||
/>
|
||||
<button
|
||||
class="code-btn"
|
||||
:disabled="countdown > 0"
|
||||
@click="sendCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown}s` : '获取验证码' }}
|
||||
</button>
|
||||
</view>
|
||||
<button class="login-btn" @click="phoneLogin">登录</button>
|
||||
</view>
|
||||
|
||||
<!-- 其他登录方式 -->
|
||||
<view class="other-login">
|
||||
<view class="divider">
|
||||
<view class="line"></view>
|
||||
<text class="divider-text">其他登录方式</text>
|
||||
<view class="line"></view>
|
||||
</view>
|
||||
<view class="login-methods">
|
||||
<view class="method-item" @click="wechatLogin">
|
||||
<text class="method-icon">💬</text>
|
||||
<text class="method-text">微信登录</text>
|
||||
</view>
|
||||
<view class="method-item" @click="alipayLogin">
|
||||
<text class="method-icon">💰</text>
|
||||
<text class="method-text">支付宝登录</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import authApi from '@/api/auth'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
phone: '',
|
||||
code: '',
|
||||
countdown: 0
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 发送验证码
|
||||
async sendCode() {
|
||||
if (!this.phone || this.phone.length !== 11) {
|
||||
uni.showToast({ title: '请输入正确的手机号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await authApi.sendCode(this.phone)
|
||||
uni.showToast({ title: '验证码已发送', icon: 'success' })
|
||||
|
||||
// 开始倒计时
|
||||
this.countdown = 60
|
||||
const timer = setInterval(() => {
|
||||
this.countdown--
|
||||
if (this.countdown <= 0) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, 1000)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
|
||||
// 手机号登录
|
||||
async phoneLogin() {
|
||||
if (!this.phone || this.phone.length !== 11) {
|
||||
uni.showToast({ title: '请输入手机号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!this.code || this.code.length !== 6) {
|
||||
uni.showToast({ title: '请输入验证码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await authApi.phoneLogin(this.phone, this.code)
|
||||
uni.setStorageSync('token', data.token)
|
||||
uni.setStorageSync('refreshToken', data.refreshToken)
|
||||
uni.setStorageSync('userId', data.userId)
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}, 1000)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
|
||||
// 微信登录
|
||||
async wechatLogin() {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.getProvider({
|
||||
service: 'oauth',
|
||||
success: (res) => {
|
||||
if (res.provider.includes('weixin')) {
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: async (loginRes) => {
|
||||
try {
|
||||
const data = await authApi.wechatLogin(loginRes.code)
|
||||
uni.setStorageSync('token', data.token)
|
||||
uni.setStorageSync('refreshToken', data.refreshToken)
|
||||
uni.setStorageSync('userId', data.userId)
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}, 1000)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
uni.showToast({ title: '请在微信小程序中使用', icon: 'none' })
|
||||
// #endif
|
||||
},
|
||||
|
||||
// 支付宝登录
|
||||
alipayLogin() {
|
||||
// #ifdef MP-ALIPAY
|
||||
my.getAuthCode({
|
||||
scopes: 'auth_base',
|
||||
success: async (res) => {
|
||||
try {
|
||||
const data = await authApi.alipayLogin(res.authCode)
|
||||
uni.setStorageSync('token', data.token)
|
||||
uni.setStorageSync('refreshToken', data.refreshToken)
|
||||
uni.setStorageSync('userId', data.userId)
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}, 1000)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
// #ifndef MP-ALIPAY
|
||||
uni.showToast({ title: '请在支付宝小程序中使用', icon: 'none' })
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.login-page {
|
||||
padding: 100rpx 60rpx;
|
||||
min-height: 100vh;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-bottom: 80rpx;
|
||||
}
|
||||
|
||||
.logo-text {
|
||||
font-size: 120rpx;
|
||||
}
|
||||
|
||||
.app-name {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.login-form {
|
||||
margin-bottom: 60rpx;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-bottom: 1rpx solid #eee;
|
||||
padding: 20rpx 0;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.input {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.code-btn {
|
||||
width: 200rpx;
|
||||
font-size: 24rpx;
|
||||
background: #3cc51f;
|
||||
color: #fff;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.code-btn[disabled] {
|
||||
background: #ccc;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
background: #3cc51f;
|
||||
color: #fff;
|
||||
border-radius: 44rpx;
|
||||
font-size: 32rpx;
|
||||
border: none;
|
||||
margin-top: 40rpx;
|
||||
}
|
||||
|
||||
.other-login {
|
||||
margin-top: 60rpx;
|
||||
}
|
||||
|
||||
.divider {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
|
||||
.line {
|
||||
flex: 1;
|
||||
height: 1rpx;
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
.divider-text {
|
||||
padding: 0 20rpx;
|
||||
color: #999;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.login-methods {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.method-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin: 0 40rpx;
|
||||
}
|
||||
|
||||
.method-icon {
|
||||
font-size: 60rpx;
|
||||
}
|
||||
|
||||
.method-text {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
margin-top: 10rpx;
|
||||
}
|
||||
</style>
|
||||
@@ -1,537 +0,0 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 客户信息 -->
|
||||
<view class="section">
|
||||
<view class="section-title">客户信息</view>
|
||||
<view class="form-item">
|
||||
<text class="label">客户</text>
|
||||
<picker
|
||||
mode="selector"
|
||||
:range="customers"
|
||||
range-key="name"
|
||||
@change="selectCustomer"
|
||||
>
|
||||
<view class="picker-value">
|
||||
{{ selectedCustomer ? selectedCustomer.name : '请选择客户' }}
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 商品选择 -->
|
||||
<view class="section">
|
||||
<view class="section-header">
|
||||
<text class="section-title">商品明细</text>
|
||||
<text class="add-btn" @click="addProduct">+ 添加商品</text>
|
||||
</view>
|
||||
|
||||
<view v-for="(item, index) in orderItems" :key="index" class="order-item">
|
||||
<view class="item-info">
|
||||
<text class="item-name">{{ item.productName }}</text>
|
||||
<text class="item-spec">{{ item.spec || '-' }}</text>
|
||||
</view>
|
||||
<view class="item-edit">
|
||||
<view class="quantity-edit">
|
||||
<text class="qty-label">数量</text>
|
||||
<input
|
||||
class="qty-input"
|
||||
type="number"
|
||||
v-model="item.quantity"
|
||||
@change="calcAmount"
|
||||
/>
|
||||
</view>
|
||||
<view class="price-edit">
|
||||
<text class="qty-label">单价</text>
|
||||
<input
|
||||
class="price-input"
|
||||
type="digit"
|
||||
v-model="item.price"
|
||||
@change="calcAmount"
|
||||
/>
|
||||
</view>
|
||||
<text class="item-subtotal">¥{{ (item.price * item.quantity).toFixed(2) }}</text>
|
||||
<text class="delete-btn" @click="removeItem(index)">×</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="orderItems.length === 0" class="empty-tip">
|
||||
请添加商品
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 优惠设置 -->
|
||||
<view class="section">
|
||||
<view class="section-title">优惠设置</view>
|
||||
<view class="form-item">
|
||||
<text class="label">折扣率</text>
|
||||
<input
|
||||
class="discount-input"
|
||||
type="digit"
|
||||
v-model="discountRate"
|
||||
@change="calcAmount"
|
||||
/>
|
||||
<text class="unit">%</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 订单金额 -->
|
||||
<view class="section amount-section">
|
||||
<view class="amount-row">
|
||||
<text class="amount-label">原价合计</text>
|
||||
<text class="amount-value">¥{{ totalAmount.toFixed(2) }}</text>
|
||||
</view>
|
||||
<view class="amount-row">
|
||||
<text class="amount-label">优惠金额</text>
|
||||
<text class="amount-value discount">-¥{{ discountAmount.toFixed(2) }}</text>
|
||||
</view>
|
||||
<view class="amount-row actual">
|
||||
<text class="amount-label">实付金额</text>
|
||||
<text class="amount-value">¥{{ actualAmount.toFixed(2) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 支付方式 -->
|
||||
<view class="section">
|
||||
<view class="section-title">支付方式</view>
|
||||
<view class="payment-methods">
|
||||
<view
|
||||
class="method-item"
|
||||
:class="{ active: paymentMethod === 'cash' }"
|
||||
@click="paymentMethod = 'cash'"
|
||||
>
|
||||
💵 现金
|
||||
</view>
|
||||
<view
|
||||
class="method-item"
|
||||
:class="{ active: paymentMethod === 'wechat' }"
|
||||
@click="paymentMethod = 'wechat'"
|
||||
>
|
||||
💬 微信
|
||||
</view>
|
||||
<view
|
||||
class="method-item"
|
||||
:class="{ active: paymentMethod === 'alipay' }"
|
||||
@click="paymentMethod = 'alipay'"
|
||||
>
|
||||
💰 支付宝
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 备注 -->
|
||||
<view class="section">
|
||||
<view class="section-title">备注</view>
|
||||
<textarea
|
||||
class="remark-input"
|
||||
v-model="remark"
|
||||
placeholder="请输入备注信息"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 提交按钮 -->
|
||||
<view class="submit-bar">
|
||||
<view class="submit-info">
|
||||
<text>实付: </text>
|
||||
<text class="submit-amount">¥{{ actualAmount.toFixed(2) }}</text>
|
||||
</view>
|
||||
<button class="submit-btn" @click="createOrder">创建订单</button>
|
||||
</view>
|
||||
|
||||
<!-- 商品选择弹窗 -->
|
||||
<uni-popup ref="productPopup" type="bottom">
|
||||
<view class="product-popup">
|
||||
<view class="popup-header">
|
||||
<text>选择商品</text>
|
||||
<text @click="$refs.productPopup.close()">关闭</text>
|
||||
</view>
|
||||
<view class="popup-search">
|
||||
<input v-model="searchKeyword" placeholder="搜索商品" />
|
||||
</view>
|
||||
<scroll-view class="popup-list" scroll-y>
|
||||
<view
|
||||
v-for="p in productList"
|
||||
:key="p.productId"
|
||||
class="popup-item"
|
||||
@click="selectProduct(p)"
|
||||
>
|
||||
<text>{{ p.name }}</text>
|
||||
<text>¥{{ p.price }}</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</uni-popup>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import orderApi from '@/api/order'
|
||||
import productApi from '@/api/product'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
// 客户相关
|
||||
customers: [],
|
||||
selectedCustomer: null,
|
||||
|
||||
// 商品相关
|
||||
orderItems: [],
|
||||
productList: [],
|
||||
searchKeyword: '',
|
||||
|
||||
// 金额相关
|
||||
discountRate: 100, // 折扣率
|
||||
totalAmount: 0, // 原价
|
||||
discountAmount: 0, // 优惠金额
|
||||
actualAmount: 0, // 实付金额
|
||||
|
||||
// 其他
|
||||
paymentMethod: 'cash',
|
||||
remark: ''
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.loadProducts()
|
||||
},
|
||||
methods: {
|
||||
async loadProducts() {
|
||||
try {
|
||||
const res = await productApi.getProducts({ page: 1, pageSize: 100 })
|
||||
this.productList = res.records || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
selectCustomer(e) {
|
||||
this.selectedCustomer = this.customers[e.detail.value]
|
||||
},
|
||||
addProduct() {
|
||||
this.$refs.productPopup.open()
|
||||
},
|
||||
selectProduct(product) {
|
||||
// 检查是否已添加
|
||||
const exists = this.orderItems.find(item => item.productId === product.productId)
|
||||
if (exists) {
|
||||
uni.showToast({ title: '商品已添加', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
this.orderItems.push({
|
||||
productId: product.productId,
|
||||
productName: product.name,
|
||||
spec: product.spec,
|
||||
unit: product.unit,
|
||||
price: product.price,
|
||||
quantity: 1
|
||||
})
|
||||
|
||||
this.calcAmount()
|
||||
this.$refs.productPopup.close()
|
||||
},
|
||||
removeItem(index) {
|
||||
this.orderItems.splice(index, 1)
|
||||
this.calcAmount()
|
||||
},
|
||||
// 核心金额计算逻辑
|
||||
calcAmount() {
|
||||
// 1. 计算原价 = Σ(单价 × 数量)
|
||||
this.totalAmount = this.orderItems.reduce((sum, item) => {
|
||||
return sum + (item.price * item.quantity)
|
||||
}, 0)
|
||||
|
||||
// 2. 计算优惠金额 = 原价 × (100 - 折扣率) / 100
|
||||
this.discountAmount = this.totalAmount * (100 - this.discountRate) / 100
|
||||
|
||||
// 3. 计算实付金额 = 原价 - 优惠金额
|
||||
this.actualAmount = this.totalAmount - this.discountAmount
|
||||
},
|
||||
async createOrder() {
|
||||
if (this.orderItems.length === 0) {
|
||||
uni.showToast({ title: '请添加商品', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
const data = {
|
||||
customerId: this.selectedCustomer ? this.selectedCustomer.customerId : null,
|
||||
items: this.orderItems.map(item => ({
|
||||
productId: item.productId,
|
||||
quantity: item.quantity,
|
||||
price: item.price
|
||||
})),
|
||||
discountRate: parseFloat(this.discountRate),
|
||||
remark: this.remark,
|
||||
paymentMethod: this.paymentMethod
|
||||
}
|
||||
|
||||
try {
|
||||
const order = await orderApi.createOrder(data)
|
||||
|
||||
uni.showToast({ title: '订单创建成功', icon: 'success' })
|
||||
|
||||
// 跳转到订单详情或列表
|
||||
setTimeout(() => {
|
||||
uni.navigateTo({
|
||||
url: `/pages/order/list`
|
||||
})
|
||||
}, 1500)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
padding: 20rpx;
|
||||
padding-bottom: 160rpx;
|
||||
}
|
||||
|
||||
.section {
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 24rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
color: #3cc51f;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 16rpx 0;
|
||||
border-bottom: 1rpx solid #f5f5f5;
|
||||
}
|
||||
|
||||
.label {
|
||||
width: 120rpx;
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.picker-value {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.discount-input {
|
||||
width: 120rpx;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.order-item {
|
||||
padding: 20rpx;
|
||||
background: #f9f9f9;
|
||||
border-radius: 8rpx;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.item-info {
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.item-name {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.item-spec {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.item-edit {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.quantity-edit, .price-edit {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.qty-label, .qty-label {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
|
||||
.qty-input, .price-input {
|
||||
width: 100rpx;
|
||||
height: 56rpx;
|
||||
background: #fff;
|
||||
border: 1rpx solid #ddd;
|
||||
border-radius: 8rpx;
|
||||
text-align: center;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.item-subtotal {
|
||||
flex: 1;
|
||||
text-align: right;
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
margin-left: 20rpx;
|
||||
font-size: 36rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
padding: 40rpx;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.amount-section {
|
||||
background: #fff7e6;
|
||||
}
|
||||
|
||||
.amount-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 12rpx 0;
|
||||
}
|
||||
|
||||
.amount-label {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.amount-value {
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.amount-value.discount {
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.amount-row.actual {
|
||||
border-top: 1rpx dashed #ddd;
|
||||
padding-top: 20rpx;
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
|
||||
.amount-row.actual .amount-value {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.payment-methods {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.method-item {
|
||||
flex: 1;
|
||||
padding: 20rpx;
|
||||
text-align: center;
|
||||
background: #f5f5f5;
|
||||
border-radius: 8rpx;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.method-item.active {
|
||||
background: #e6f7ff;
|
||||
color: #1890ff;
|
||||
border: 1rpx solid #1890ff;
|
||||
}
|
||||
|
||||
.remark-input {
|
||||
width: 100%;
|
||||
height: 120rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.submit-bar {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 20rpx;
|
||||
background: #fff;
|
||||
box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.submit-info {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.submit-amount {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
width: 200rpx;
|
||||
height: 80rpx;
|
||||
line-height: 80rpx;
|
||||
background: #3cc51f;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 40rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.product-popup {
|
||||
background: #fff;
|
||||
height: 60vh;
|
||||
border-radius: 24rpx 24rpx 0 0;
|
||||
}
|
||||
|
||||
.popup-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 24rpx;
|
||||
border-bottom: 1rpx solid #eee;
|
||||
}
|
||||
|
||||
.popup-search {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.popup-search input {
|
||||
height: 60rpx;
|
||||
background: #f5f5f5;
|
||||
border-radius: 8rpx;
|
||||
padding: 0 20rpx;
|
||||
}
|
||||
|
||||
.popup-list {
|
||||
height: calc(60vh - 140rpx);
|
||||
}
|
||||
|
||||
.popup-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 24rpx;
|
||||
border-bottom: 1rpx solid #f5f5f5;
|
||||
}
|
||||
</style>
|
||||
@@ -1,372 +0,0 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 筛选栏 -->
|
||||
<view class="filter-bar">
|
||||
<view
|
||||
class="filter-item"
|
||||
:class="{ active: status === null }"
|
||||
@click="filterStatus(null)"
|
||||
>
|
||||
全部
|
||||
</view>
|
||||
<view
|
||||
class="filter-item"
|
||||
:class="{ active: status === 1 }"
|
||||
@click="filterStatus(1)"
|
||||
>
|
||||
已完成
|
||||
</view>
|
||||
<view
|
||||
class="filter-item"
|
||||
:class="{ active: status === 2 }"
|
||||
@click="filterStatus(2)"
|
||||
>
|
||||
已取消
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 订单列表 -->
|
||||
<view class="order-list">
|
||||
<view
|
||||
v-for="order in orders"
|
||||
:key="order.orderId"
|
||||
class="order-card"
|
||||
@click="viewDetail(order)"
|
||||
>
|
||||
<view class="order-header">
|
||||
<text class="order-no">{{ order.orderNo }}</text>
|
||||
<text class="order-status" :class="getStatusClass(order.status)">
|
||||
{{ getStatusText(order.status) }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<view class="order-customer">
|
||||
<text class="customer-name">{{ order.customerName || '散客' }}</text>
|
||||
<text class="customer-phone">{{ order.customerPhone || '-' }}</text>
|
||||
</view>
|
||||
|
||||
<view class="order-items">
|
||||
<text class="items-label">商品明细</text>
|
||||
<text class="items-count">{{ getItemCount(order.orderId) }}种商品</text>
|
||||
</view>
|
||||
|
||||
<view class="order-amount">
|
||||
<view class="amount-row">
|
||||
<text class="amount-label">原价</text>
|
||||
<text class="amount-value">¥{{ order.totalAmount }}</text>
|
||||
</view>
|
||||
<view class="amount-row">
|
||||
<text class="amount-label">优惠</text>
|
||||
<text class="amount-value discount">-¥{{ order.discountAmount }}</text>
|
||||
</view>
|
||||
<view class="amount-row actual">
|
||||
<text class="amount-label">实付</text>
|
||||
<text class="amount-value">¥{{ order.actualAmount }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="order-footer">
|
||||
<text class="order-time">{{ formatTime(order.createdAt) }}</text>
|
||||
<text class="operator">{{ order.operatorName }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view v-if="orders.length === 0" class="empty">
|
||||
<text>暂无订单</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<view v-if="orders.length > 0" class="load-more">
|
||||
<text>{{ loading ? '加载中...' : (hasMore ? '上拉加载更多' : '没有更多了') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import orderApi from '@/api/order'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
status: null,
|
||||
orders: [],
|
||||
orderItemsMap: {},
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
hasMore: true,
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.loadOrders()
|
||||
},
|
||||
onReachBottom() {
|
||||
if (this.hasMore && !this.loading) {
|
||||
this.page++
|
||||
this.loadOrders()
|
||||
}
|
||||
},
|
||||
onPullDownRefresh() {
|
||||
this.page = 1
|
||||
this.loadOrders().then(() => {
|
||||
uni.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
async loadOrders() {
|
||||
if (this.loading) return
|
||||
this.loading = true
|
||||
|
||||
try {
|
||||
const res = await orderApi.getOrders({
|
||||
status: this.status,
|
||||
page: this.page,
|
||||
pageSize: this.pageSize
|
||||
})
|
||||
|
||||
const list = res.records || []
|
||||
|
||||
// 加载每个订单的明细
|
||||
for (const order of list) {
|
||||
try {
|
||||
const detail = await orderApi.getOrderDetail(order.orderId)
|
||||
this.$set(this.orderItemsMap, order.orderId, detail.items || [])
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.page === 1) {
|
||||
this.orders = list
|
||||
} else {
|
||||
this.orders = [...this.orders, ...list]
|
||||
}
|
||||
this.hasMore = list.length >= this.pageSize
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
filterStatus(status) {
|
||||
this.status = status
|
||||
this.page = 1
|
||||
this.loadOrders()
|
||||
},
|
||||
viewDetail(order) {
|
||||
// 跳转到订单详情页或显示详情弹窗
|
||||
uni.showModal({
|
||||
title: '订单详情',
|
||||
content: `订单号: ${order.orderNo}\n原价: ¥${order.totalAmount}\n优惠: ¥${order.discountAmount}\n实付: ¥${order.actualAmount}`,
|
||||
showCancel: false
|
||||
})
|
||||
},
|
||||
getItemCount(orderId) {
|
||||
const items = this.orderItemsMap[orderId]
|
||||
return items ? items.length : 0
|
||||
},
|
||||
getStatusClass(status) {
|
||||
const map = {
|
||||
1: 'status-success',
|
||||
2: 'status-cancel',
|
||||
3: 'status-refunding',
|
||||
4: 'status-refunded'
|
||||
}
|
||||
return map[status] || ''
|
||||
},
|
||||
getStatusText(status) {
|
||||
const map = {
|
||||
1: '已完成',
|
||||
2: '已取消',
|
||||
3: '退款中',
|
||||
4: '已退款'
|
||||
}
|
||||
return map[status] || '未知'
|
||||
},
|
||||
formatTime(time) {
|
||||
if (!time) return '-'
|
||||
return time.substring(0, 16).replace('T', ' ')
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.filter-bar {
|
||||
display: flex;
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 16rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.filter-item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 12rpx;
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.filter-item.active {
|
||||
background: #3cc51f;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.order-card {
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 24rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.order-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.order-no {
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.order-status {
|
||||
font-size: 24rpx;
|
||||
padding: 4rpx 12rpx;
|
||||
border-radius: 4rpx;
|
||||
}
|
||||
|
||||
.status-success {
|
||||
background: #f6ffed;
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.status-cancel {
|
||||
background: #fff1f0;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.status-refunding {
|
||||
background: #fff7e6;
|
||||
color: #fa8c16;
|
||||
}
|
||||
|
||||
.status-refunded {
|
||||
background: #f9f0ff;
|
||||
color: #722ed1;
|
||||
}
|
||||
|
||||
.order-customer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.customer-name {
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.customer-phone {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.order-items {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 16rpx 0;
|
||||
border-top: 1rpx solid #f5f5f5;
|
||||
border-bottom: 1rpx solid #f5f5f5;
|
||||
}
|
||||
|
||||
.items-label {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.items-count {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.order-amount {
|
||||
padding: 16rpx 0;
|
||||
}
|
||||
|
||||
.amount-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 8rpx 0;
|
||||
}
|
||||
|
||||
.amount-label {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.amount-value {
|
||||
font-size: 24rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.amount-value.discount {
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.amount-row.actual {
|
||||
border-top: 1rpx dashed #ddd;
|
||||
padding-top: 16rpx;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.amount-row.actual .amount-label {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.amount-row.actual .amount-value {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.order-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding-top: 16rpx;
|
||||
border-top: 1rpx solid #f5f5f5;
|
||||
}
|
||||
|
||||
.order-time {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.operator {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.empty {
|
||||
padding: 100rpx;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.load-more {
|
||||
padding: 20rpx;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
</style>
|
||||
@@ -1,274 +0,0 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 搜索栏 -->
|
||||
<view class="search-bar">
|
||||
<input
|
||||
class="search-input"
|
||||
v-model="keyword"
|
||||
placeholder="搜索商品名称"
|
||||
@confirm="search"
|
||||
/>
|
||||
<button class="search-btn" @click="search">搜索</button>
|
||||
</view>
|
||||
|
||||
<!-- 分类筛选 -->
|
||||
<scroll-view class="category-scroll" scroll-x>
|
||||
<view
|
||||
class="category-item"
|
||||
:class="{ active: !categoryId }"
|
||||
@click="selectCategory('')"
|
||||
>
|
||||
全部
|
||||
</view>
|
||||
<view
|
||||
v-for="cat in categories"
|
||||
:key="cat.categoryId"
|
||||
class="category-item"
|
||||
:class="{ active: categoryId === cat.categoryId }"
|
||||
@click="selectCategory(cat.categoryId)"
|
||||
>
|
||||
{{ cat.name }}
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 商品列表 -->
|
||||
<view class="product-list">
|
||||
<view
|
||||
v-for="item in products"
|
||||
:key="item.productId"
|
||||
class="product-item"
|
||||
@click="viewDetail(item)"
|
||||
>
|
||||
<view class="product-info">
|
||||
<text class="product-name">{{ item.name }}</text>
|
||||
<text class="product-spec">{{ item.spec || '-' }}</text>
|
||||
<view class="product-price">
|
||||
<text class="price">¥{{ item.price }}</text>
|
||||
<text class="unit">/{{ item.unit }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="product-stock">
|
||||
<text class="stock-label">库存</text>
|
||||
<text class="stock-value">{{ getStock(item.productId) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view v-if="products.length === 0" class="empty">
|
||||
<text>暂无商品</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<view v-if="products.length > 0" class="load-more">
|
||||
<text>{{ loading ? '加载中...' : (hasMore ? '上拉加载更多' : '没有更多了') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import productApi from '@/api/product'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
keyword: '',
|
||||
categoryId: '',
|
||||
categories: [],
|
||||
products: [],
|
||||
stocks: {},
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
hasMore: true,
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.loadCategories()
|
||||
this.loadProducts()
|
||||
},
|
||||
onReachBottom() {
|
||||
if (this.hasMore && !this.loading) {
|
||||
this.page++
|
||||
this.loadProducts()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async loadCategories() {
|
||||
try {
|
||||
const categories = await productApi.getCategories()
|
||||
this.categories = categories || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
async loadProducts() {
|
||||
if (this.loading) return
|
||||
this.loading = true
|
||||
|
||||
try {
|
||||
const res = await productApi.getProducts({
|
||||
categoryId: this.categoryId,
|
||||
keyword: this.keyword,
|
||||
page: this.page,
|
||||
pageSize: this.pageSize
|
||||
})
|
||||
|
||||
const list = res.records || []
|
||||
if (this.page === 1) {
|
||||
this.products = list
|
||||
} else {
|
||||
this.products = [...this.products, ...list]
|
||||
}
|
||||
this.hasMore = list.length >= this.pageSize
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
selectCategory(id) {
|
||||
this.categoryId = id
|
||||
this.page = 1
|
||||
this.loadProducts()
|
||||
},
|
||||
search() {
|
||||
this.page = 1
|
||||
this.loadProducts()
|
||||
},
|
||||
viewDetail(item) {
|
||||
uni.showToast({ title: '商品详情开发中', icon: 'none' })
|
||||
},
|
||||
getStock(productId) {
|
||||
return this.stocks[productId] || 0
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
display: flex;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
height: 70rpx;
|
||||
padding: 0 20rpx;
|
||||
background: #fff;
|
||||
border-radius: 8rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.search-btn {
|
||||
width: 120rpx;
|
||||
height: 70rpx;
|
||||
line-height: 70rpx;
|
||||
background: #3cc51f;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 8rpx;
|
||||
margin-left: 20rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.category-scroll {
|
||||
white-space: nowrap;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
display: inline-block;
|
||||
padding: 12rpx 24rpx;
|
||||
margin-right: 16rpx;
|
||||
background: #fff;
|
||||
border-radius: 8rpx;
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.category-item.active {
|
||||
background: #3cc51f;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.product-list {
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
}
|
||||
|
||||
.product-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 24rpx;
|
||||
border-bottom: 1rpx solid #f5f5f5;
|
||||
}
|
||||
|
||||
.product-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.product-name {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.product-spec {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 8rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.product-price {
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
|
||||
.price {
|
||||
color: #ff4d4f;
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.unit {
|
||||
color: #999;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.product-stock {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.stock-label {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.stock-value {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.empty {
|
||||
padding: 100rpx;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.load-more {
|
||||
padding: 20rpx;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
</style>
|
||||
@@ -18,6 +18,13 @@ export default {
|
||||
return api.request('/auth/phone-login', 'POST', { phone, code })
|
||||
},
|
||||
|
||||
/**
|
||||
* 账号密码登录
|
||||
*/
|
||||
passwordLogin(username, password) {
|
||||
return api.request('/auth/login', 'POST', { username, password })
|
||||
},
|
||||
|
||||
/**
|
||||
* 微信登录
|
||||
*/
|
||||
41
src/api/customer.js
Normal file
41
src/api/customer.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import api from './index'
|
||||
|
||||
/**
|
||||
* 客户相关API
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* 获取客户列表
|
||||
*/
|
||||
getCustomers(params) {
|
||||
return api.request('/customers', 'GET', params)
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取客户详情
|
||||
*/
|
||||
getCustomer(id) {
|
||||
return api.request(`/customers/${id}`, 'GET')
|
||||
},
|
||||
|
||||
/**
|
||||
* 新增客户
|
||||
*/
|
||||
createCustomer(data) {
|
||||
return api.request('/customers', 'POST', {}, data)
|
||||
},
|
||||
|
||||
/**
|
||||
* 修改客户
|
||||
*/
|
||||
updateCustomer(id, data) {
|
||||
return api.request(`/customers/${id}`, 'PUT', {}, data)
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除客户
|
||||
*/
|
||||
deleteCustomer(id) {
|
||||
return api.request(`/customers/${id}`, 'DELETE')
|
||||
}
|
||||
}
|
||||
58
src/api/index.js
Normal file
58
src/api/index.js
Normal file
@@ -0,0 +1,58 @@
|
||||
// API基础配置
|
||||
const BASE_URL = import.meta.env.VITE_API_BASE_URL || 'https://sales.violin-work.online/api/v1'
|
||||
|
||||
// 请求拦截器
|
||||
const request = (url, method, query = {}, data = {}) => {
|
||||
const token = uni.getStorageSync('token')
|
||||
const userId = uni.getStorageSync('userId') || ''
|
||||
const username = uni.getStorageSync('username') || ''
|
||||
const role = uni.getStorageSync('role') || ''
|
||||
|
||||
// 特殊情况:入库和库存调整需要 form-urlencoded 格式
|
||||
const useFormData = (url.includes('/stock/in') || url.includes('/stock/adjust')) && Object.keys(data).length > 0
|
||||
|
||||
// GET 请求用 query 参数,其他请求有 data 时发 data,没 data 时发空对象
|
||||
let requestData = {}
|
||||
if (method === 'GET') {
|
||||
requestData = query
|
||||
} else if (Object.keys(data).length > 0) {
|
||||
requestData = data
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: BASE_URL + url,
|
||||
method: method,
|
||||
data: requestData,
|
||||
header: {
|
||||
'Content-Type': useFormData ? 'application/x-www-form-urlencoded' : 'application/json',
|
||||
'Authorization': token ? `Bearer ${token}` : '',
|
||||
'X-User-Id': userId,
|
||||
'X-Username': username,
|
||||
'X-User-Role': role
|
||||
},
|
||||
success: (res) => {
|
||||
if (res.data.code === 0) {
|
||||
resolve(res.data.data)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.data.message || '请求失败',
|
||||
icon: 'none'
|
||||
})
|
||||
reject(res.data)
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.showToast({
|
||||
title: '网络请求失败',
|
||||
icon: 'none'
|
||||
})
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
request
|
||||
}
|
||||
@@ -22,7 +22,7 @@ export default {
|
||||
* }
|
||||
*/
|
||||
createOrder(data) {
|
||||
return api.request('/orders', 'POST', data)
|
||||
return api.request('/orders', 'POST', {}, data)
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -53,6 +53,20 @@ export default {
|
||||
return api.request(`/orders/${id}/refund`, 'PUT')
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新订单状态
|
||||
*/
|
||||
updateOrderStatus(id, status) {
|
||||
return api.request(`/orders/${id}/status`, 'PUT', {}, { status })
|
||||
},
|
||||
|
||||
/**
|
||||
* 更新订单(编辑)
|
||||
*/
|
||||
updateOrder(id, data) {
|
||||
return api.request(`/orders/${id}`, 'PUT', {}, data)
|
||||
},
|
||||
|
||||
/**
|
||||
* 订单统计
|
||||
*/
|
||||
41
src/api/stock.js
Normal file
41
src/api/stock.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import api from './index'
|
||||
|
||||
/**
|
||||
* 库存相关API
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* 获取库存列表
|
||||
*/
|
||||
getStockList(params) {
|
||||
return api.request('/stock', 'GET', params)
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取单商品库存
|
||||
*/
|
||||
getStock(productId) {
|
||||
return api.request(`/stock/${productId}`, 'GET')
|
||||
},
|
||||
|
||||
/**
|
||||
* 入库
|
||||
*/
|
||||
stockIn(data) {
|
||||
return api.request('/stock/in', 'POST', null, data)
|
||||
},
|
||||
|
||||
/**
|
||||
* 库存调整
|
||||
*/
|
||||
adjustStock(data) {
|
||||
return api.request('/stock/adjust', 'POST', data)
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取库存流水
|
||||
*/
|
||||
getStockFlow(params) {
|
||||
return api.request('/stock/flow', 'GET', params)
|
||||
}
|
||||
}
|
||||
61
src/components/Icon.vue
Normal file
61
src/components/Icon.vue
Normal file
@@ -0,0 +1,61 @@
|
||||
<template>
|
||||
<text class="iconfont" :style="{ fontSize: size + 'rpx', color: color }">{{ iconChar }}</text>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// 使用专业图标符号(不是emoji,不是汉字)
|
||||
const icons = {
|
||||
home: '⌂', // 首页
|
||||
user: '⊙', // 用户
|
||||
chart: '◐', // 图表
|
||||
product: '▦', // 商品
|
||||
add: '+', // 添加
|
||||
search: '◎', // 搜索
|
||||
order: '☰', // 订单
|
||||
edit: '✎', // 编辑
|
||||
check: '✓', // 确认
|
||||
close: '✕', // 关闭
|
||||
stock: '⌖', // 库存
|
||||
alert: '⚡', // 警告
|
||||
in: '↓', // 入
|
||||
out: '↑', // 出
|
||||
customer: '☺', // 客户
|
||||
money: '¤', // 钱
|
||||
logout: '↺', // 退出
|
||||
right: '›', // 右
|
||||
left: '‹', // 左
|
||||
down: '⌄', // 下
|
||||
lock: '⌘', // 锁
|
||||
calendar: '▦', // 日历
|
||||
setting: '⚙', // 设置
|
||||
wechat: '✉', // 微信
|
||||
cash: '¤', // 现金
|
||||
alipay: '¤', // 支付宝
|
||||
plus: '+', // 加
|
||||
flow: '↔' // 流水
|
||||
}
|
||||
|
||||
export default {
|
||||
name: 'Icon',
|
||||
props: {
|
||||
name: { type: String, required: true },
|
||||
size: { type: [Number, String], default: 32 },
|
||||
color: { type: String, default: '' }
|
||||
},
|
||||
computed: {
|
||||
iconChar() {
|
||||
return icons[this.name] || '·'
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.iconfont {
|
||||
font-family: sans-serif;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
}
|
||||
</style>
|
||||
11
src/main.js
Normal file
11
src/main.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { createSSRApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
import Icon from './components/Icon.vue'
|
||||
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App)
|
||||
app.component('Icon', Icon)
|
||||
return {
|
||||
app
|
||||
}
|
||||
}
|
||||
141
src/pages.json
Normal file
141
src/pages.json
Normal file
@@ -0,0 +1,141 @@
|
||||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/index/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "首页"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/login/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "登录"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/product/list",
|
||||
"style": {
|
||||
"navigationBarTitleText": "商品列表"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/product/manage",
|
||||
"style": {
|
||||
"navigationBarTitleText": "商品管理"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/product/select",
|
||||
"style": {
|
||||
"navigationBarTitleText": "选择商品"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/product/detail",
|
||||
"style": {
|
||||
"navigationBarTitleText": "商品详情"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/order/create",
|
||||
"style": {
|
||||
"navigationBarTitleText": "创建订单"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/order/list",
|
||||
"style": {
|
||||
"navigationBarTitleText": "订单列表"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/order/search",
|
||||
"style": {
|
||||
"navigationBarTitleText": "订单查询"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/order/return",
|
||||
"style": {
|
||||
"navigationBarTitleText": "退货"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/order/detail",
|
||||
"style": {
|
||||
"navigationBarTitleText": "订单详情"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/stock/list",
|
||||
"style": {
|
||||
"navigationBarTitleText": "库存管理"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/stock/in",
|
||||
"style": {
|
||||
"navigationBarTitleText": "入库"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/stock/flow",
|
||||
"style": {
|
||||
"navigationBarTitleText": "库存流水"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/customer/create",
|
||||
"style": {
|
||||
"navigationBarTitleText": "新增客户"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/customer/list",
|
||||
"style": {
|
||||
"navigationBarTitleText": "客户列表"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/category/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "种类管理"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/share/order",
|
||||
"style": {
|
||||
"navigationBarTitleText": "订单详情",
|
||||
"navigationStyle": "custom"
|
||||
}
|
||||
}
|
||||
],
|
||||
"globalStyle": {
|
||||
"navigationBarTextStyle": "black",
|
||||
"navigationBarTitleText": "建材销售管家",
|
||||
"navigationBarBackgroundColor": "#F8F8F8",
|
||||
"backgroundColor": "#F8F8F8"
|
||||
},
|
||||
"tabBar": {
|
||||
"color": "#7A7E83",
|
||||
"selectedColor": "#3cc51f",
|
||||
"borderStyle": "black",
|
||||
"backgroundColor": "#ffffff",
|
||||
"list": [
|
||||
{
|
||||
"pagePath": "pages/index/index",
|
||||
"text": "首页"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/product/list",
|
||||
"text": "商品"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/order/list",
|
||||
"text": "订单"
|
||||
}
|
||||
]
|
||||
},
|
||||
"customerHidePages": [
|
||||
]
|
||||
}
|
||||
333
src/pages/category/index.vue
Normal file
333
src/pages/category/index.vue
Normal file
@@ -0,0 +1,333 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 顶部标题 -->
|
||||
<view class="header">
|
||||
<text class="title">种类管理</text>
|
||||
</view>
|
||||
|
||||
<!-- 分类列表 -->
|
||||
<scroll-view scroll-y class="category-list">
|
||||
<view v-for="cat in categories" :key="cat.categoryId" class="category-item">
|
||||
<view class="category-info">
|
||||
<text class="category-name">{{ cat.name }}</text>
|
||||
<text class="category-desc">{{ cat.description || '暂无描述' }}</text>
|
||||
</view>
|
||||
<view class="category-actions">
|
||||
<text class="action-btn edit" @click="editCategory(cat)">编辑</text>
|
||||
<text class="action-btn delete" @click="deleteCategory(cat)">删除</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="categories.length === 0" class="empty">
|
||||
<Icon name="product" :size="80" color="#ccc" />
|
||||
<text class="empty-text">暂无分类</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 添加按钮 -->
|
||||
<view class="add-btn" @click="showAddDialog">
|
||||
<Icon name="add" :size="40" color="#fff" />
|
||||
</view>
|
||||
|
||||
<!-- 添加/编辑弹窗 -->
|
||||
<view class="dialog-mask" v-if="showDialog" @click="closeDialog">
|
||||
<view class="dialog" @click.stop>
|
||||
<view class="dialog-header">
|
||||
<text class="dialog-title">{{ isEdit ? '编辑分类' : '新增分类' }}</text>
|
||||
</view>
|
||||
<view class="dialog-body">
|
||||
<view class="form-item">
|
||||
<text class="label">名称</text>
|
||||
<input class="input" v-model="form.name" placeholder="请输入分类名称" />
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="label">描述</text>
|
||||
<input class="input" v-model="form.description" placeholder="请输入分类描述" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="dialog-footer">
|
||||
<text class="btn-cancel" @click="closeDialog">取消</text>
|
||||
<text class="btn-confirm" @click="saveCategory">确定</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import productApi from '@/api/product'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
categories: [],
|
||||
showDialog: false,
|
||||
isEdit: false,
|
||||
form: {
|
||||
categoryId: '',
|
||||
name: '',
|
||||
description: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.loadCategories()
|
||||
},
|
||||
methods: {
|
||||
async loadCategories() {
|
||||
try {
|
||||
const categories = await productApi.getCategories()
|
||||
this.categories = categories || []
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
showAddDialog() {
|
||||
this.isEdit = false
|
||||
this.form = { categoryId: '', name: '', description: '' }
|
||||
this.showDialog = true
|
||||
},
|
||||
editCategory(cat) {
|
||||
this.isEdit = true
|
||||
this.form = { categoryId: cat.categoryId, name: cat.name, description: cat.description || '' }
|
||||
this.showDialog = true
|
||||
},
|
||||
closeDialog() {
|
||||
this.showDialog = false
|
||||
},
|
||||
async saveCategory() {
|
||||
if (!this.form.name) {
|
||||
uni.showToast({ title: '请输入名称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
try {
|
||||
if (this.isEdit) {
|
||||
await productApi.updateCategory(this.form.categoryId, {
|
||||
name: this.form.name,
|
||||
description: this.form.description
|
||||
})
|
||||
uni.showToast({ title: '修改成功', icon: 'success' })
|
||||
} else {
|
||||
await productApi.createCategory({
|
||||
name: this.form.name,
|
||||
description: this.form.description
|
||||
})
|
||||
uni.showToast({ title: '添加成功', icon: 'success' })
|
||||
}
|
||||
this.closeDialog()
|
||||
this.loadCategories()
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '操作失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
deleteCategory(cat) {
|
||||
// 先检查该分类下是否有商品
|
||||
uni.showLoading({ title: '检查中...' })
|
||||
productApi.getProducts({ categoryId: cat.categoryId, page: 1, pageSize: 1 }).then(res => {
|
||||
uni.hideLoading()
|
||||
if (res.records && res.records.length > 0) {
|
||||
uni.showToast({ title: '该分类下有商品,无法删除', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: '确认删除',
|
||||
content: `确定要删除 "${cat.name}" 吗?`,
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
await productApi.deleteCategory(cat.categoryId)
|
||||
uni.showToast({ title: '删除成功', icon: 'success' })
|
||||
this.loadCategories()
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}).catch(() => {
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '检查失败', icon: 'none' })
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 40rpx 30rpx;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.category-list {
|
||||
padding: 20rpx;
|
||||
height: calc(100vh - 140rpx);
|
||||
}
|
||||
|
||||
.category-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 20rpx;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.category-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.category-name {
|
||||
display: block;
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.category-desc {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.category-actions {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
font-size: 26rpx;
|
||||
padding: 10rpx 20rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.action-btn.edit {
|
||||
background: #e6f7ff;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.action-btn.delete {
|
||||
background: #fff1f0;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.empty {
|
||||
padding: 100rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
position: fixed;
|
||||
right: 40rpx;
|
||||
bottom: 40rpx;
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 50rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 8rpx 30rpx rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
/* 弹窗 */
|
||||
.dialog-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.dialog {
|
||||
width: 80%;
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.dialog-header {
|
||||
padding: 30rpx;
|
||||
border-bottom: 1rpx solid #f5f5f5;
|
||||
}
|
||||
|
||||
.dialog-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.dialog-body {
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.form-item .label {
|
||||
display: block;
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.form-item .input {
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
background: #f5f5f5;
|
||||
border-radius: 12rpx;
|
||||
padding: 0 20rpx;
|
||||
font-size: 28rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
border-top: 1rpx solid #f5f5f5;
|
||||
}
|
||||
|
||||
.btn-cancel, .btn-confirm {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 30rpx;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
|
||||
.btn-cancel {
|
||||
color: #666;
|
||||
border-right: 1rpx solid #f5f5f5;
|
||||
}
|
||||
|
||||
.btn-confirm {
|
||||
color: #667eea;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
197
src/pages/customer/create.vue
Normal file
197
src/pages/customer/create.vue
Normal file
@@ -0,0 +1,197 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<view class="form-card">
|
||||
<view class="form-item">
|
||||
<text class="label">客户种类 *</text>
|
||||
<picker :range="typeOptions" range-key="label" @change="onTypeChange">
|
||||
<view class="picker-input">
|
||||
<text :class="form.type ? '' : 'placeholder'">{{ form.typeLabel || '请选择客户种类' }}</text>
|
||||
<text class="arrow">›</text>
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="label">手机号 *</text>
|
||||
<input class="input" v-model="form.phone" placeholder="请输入手机号" type="number" />
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="label">客户姓名 *</text>
|
||||
<input class="input" v-model="form.name" placeholder="请输入客户姓名" />
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="label">微信号</text>
|
||||
<input class="input" v-model="form.wechat" placeholder="请输入微信号" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<button class="submit-btn" @click="submit">{{ isEdit ? '保存修改' : '保存' }}</button>
|
||||
<button class="delete-btn" v-if="isEdit" @click="deleteCustomer">删除客户</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import customerApi from '@/api/customer'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
customerId: '',
|
||||
typeOptions: [
|
||||
{ label: '顾客', value: 'customer' },
|
||||
{ label: '木匠', value: 'carpenter' },
|
||||
{ label: '装修公司', value: 'company' }
|
||||
],
|
||||
form: {
|
||||
type: '',
|
||||
typeLabel: '',
|
||||
phone: '',
|
||||
name: '',
|
||||
wechat: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
isEdit() {
|
||||
return !!this.customerId
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
if (options.id) {
|
||||
this.customerId = options.id
|
||||
this.form.type = options.type || ''
|
||||
this.form.typeLabel = options.typeLabel || ''
|
||||
this.form.phone = options.phone || ''
|
||||
this.form.name = options.name || ''
|
||||
this.form.wechat = options.wechat || ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onTypeChange(e) {
|
||||
const idx = e.detail.value
|
||||
this.form.type = this.typeOptions[idx].value
|
||||
this.form.typeLabel = this.typeOptions[idx].label
|
||||
},
|
||||
async submit() {
|
||||
if (!this.form.type) {
|
||||
uni.showToast({ title: '请选择客户种类', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!this.form.phone) {
|
||||
uni.showToast({ title: '请输入手机号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!this.form.name) {
|
||||
uni.showToast({ title: '请输入客户姓名', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.isEdit) {
|
||||
await customerApi.updateCustomer(this.customerId, this.form)
|
||||
uni.showToast({ title: '修改成功', icon: 'success' })
|
||||
} else {
|
||||
await customerApi.createCustomer(this.form)
|
||||
uni.showToast({ title: '添加成功', icon: 'success' })
|
||||
}
|
||||
setTimeout(() => uni.switchTab({ url: '/pages/index/index' }), 1500)
|
||||
} catch (e) {
|
||||
uni.showToast({ title: e.message || '操作失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
deleteCustomer() {
|
||||
uni.showModal({
|
||||
title: '确认删除',
|
||||
content: '确定要删除该客户吗?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
await customerApi.deleteCustomer(this.customerId)
|
||||
uni.showToast({ title: '删除成功', icon: 'success' })
|
||||
setTimeout(() => uni.switchTab({ url: '/pages/index/index' }), 1500)
|
||||
} catch (e) {
|
||||
uni.showToast({ title: e.message || '删除失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
padding: 30rpx;
|
||||
background: #f5f5f5;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.form-card {
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.label {
|
||||
display: block;
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.input {
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
background: #f5f5f5;
|
||||
border-radius: 12rpx;
|
||||
padding: 0 20rpx;
|
||||
font-size: 28rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.picker-input {
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
background: #f5f5f5;
|
||||
border-radius: 12rpx;
|
||||
padding: 0 20rpx;
|
||||
font-size: 28rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.picker-input .placeholder {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
font-size: 32rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
margin-top: 40rpx;
|
||||
height: 88rpx;
|
||||
background: #1890ff;
|
||||
color: #fff;
|
||||
border-radius: 44rpx;
|
||||
font-size: 30rpx;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
margin-top: 20rpx;
|
||||
height: 88rpx;
|
||||
background: #fff;
|
||||
color: #ff4d4f;
|
||||
border-radius: 44rpx;
|
||||
font-size: 30rpx;
|
||||
border: 2rpx solid #ff4d4f;
|
||||
}
|
||||
</style>
|
||||
145
src/pages/customer/list.vue
Normal file
145
src/pages/customer/list.vue
Normal file
@@ -0,0 +1,145 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<view class="search-bar">
|
||||
<input class="search-input" v-model="keyword" placeholder="搜索客户姓名或手机号" @input="search" />
|
||||
</view>
|
||||
|
||||
<scroll-view scroll-y class="list">
|
||||
<view
|
||||
v-for="item in customers"
|
||||
:key="item.customerId"
|
||||
class="customer-card"
|
||||
@click="viewDetail(item)"
|
||||
>
|
||||
<view class="info">
|
||||
<view class="name-row">
|
||||
<text class="name">{{ item.name }}</text>
|
||||
<text class="type-tag" v-if="item.type">{{ typeLabelMap[item.type] }}</text>
|
||||
</view>
|
||||
<text class="phone">{{ item.phone }}</text>
|
||||
<text class="wechat" v-if="item.wechat">{{ item.wechat }}</text>
|
||||
</view>
|
||||
<text class="arrow">›</text>
|
||||
</view>
|
||||
<view v-if="customers.length === 0" class="empty">暂无客户</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import customerApi from '@/api/customer'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
keyword: '',
|
||||
customers: [],
|
||||
typeLabelMap: { customer: '顾客', carpenter: '木匠', company: '装修公司' }
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.loadCustomers()
|
||||
},
|
||||
methods: {
|
||||
async loadCustomers() {
|
||||
try {
|
||||
const res = await customerApi.getCustomers({ keyword: this.keyword, page: 1, pageSize: 100 })
|
||||
this.customers = res.records || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
search() {
|
||||
this.loadCustomers()
|
||||
},
|
||||
viewDetail(item) {
|
||||
const typeLabelMap = { customer: '顾客', carpenter: '木匠', company: '装修公司' }
|
||||
uni.navigateTo({
|
||||
url: `/pages/customer/create?id=${item.customerId}&type=${item.type}&typeLabel=${typeLabelMap[item.type] || ''}&name=${item.name}&phone=${item.phone}&wechat=${item.wechat || ''}`
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
padding: 20rpx;
|
||||
background: #f5f5f5;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 20rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
height: 64rpx;
|
||||
background: #f5f5f5;
|
||||
border-radius: 32rpx;
|
||||
padding: 0 30rpx;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.list {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.customer-card {
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 24rpx;
|
||||
margin-bottom: 16rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.name {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.name-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.type-tag {
|
||||
font-size: 22rpx;
|
||||
color: #fff;
|
||||
background: #1890ff;
|
||||
padding: 4rpx 12rpx;
|
||||
border-radius: 20rpx;
|
||||
margin-left: 12rpx;
|
||||
}
|
||||
|
||||
.phone, .wechat {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 6rpx;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
font-size: 36rpx;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.empty {
|
||||
text-align: center;
|
||||
color: #999;
|
||||
padding: 60rpx;
|
||||
}
|
||||
</style>
|
||||
295
src/pages/index/index.vue
Normal file
295
src/pages/index/index.vue
Normal file
@@ -0,0 +1,295 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 顶部欢迎 -->
|
||||
<view class="header">
|
||||
<view class="user-section">
|
||||
<text class="welcome">{{ greeting }}</text>
|
||||
<text class="username" v-if="username">{{ username }}</text>
|
||||
<text class="username" v-else>请登录</text>
|
||||
</view>
|
||||
<view class="logout-btn" @click="logout" v-if="username">
|
||||
<text>退出</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 订单区域 -->
|
||||
<view class="section">
|
||||
<text class="section-title">订单</text>
|
||||
<view class="menu-grid">
|
||||
<template v-if="isAdmin">
|
||||
<view class="menu-item" @click="goTo('/pages/order/create')">
|
||||
<view class="menu-icon-box blue"><text class="icon-text">订</text></view>
|
||||
<text class="menu-text">创建订单</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goToTab('/pages/order/list')">
|
||||
<view class="menu-icon-box green"><text class="icon-text">列</text></view>
|
||||
<text class="menu-text">订单列表</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goTo('/pages/order/search')">
|
||||
<view class="menu-icon-box orange"><text class="icon-text">查</text></view>
|
||||
<text class="menu-text">订单查询</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goTo('/pages/order/return')">
|
||||
<view class="menu-icon-box red"><text class="icon-text">退</text></view>
|
||||
<text class="menu-text">退货</text>
|
||||
</view>
|
||||
</template>
|
||||
<template v-else-if="isSales">
|
||||
<view class="menu-item" @click="goTo('/pages/order/create')">
|
||||
<view class="menu-icon-box blue"><text class="icon-text">订</text></view>
|
||||
<text class="menu-text">创建订单</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goToTab('/pages/order/list')">
|
||||
<view class="menu-icon-box green"><text class="icon-text">列</text></view>
|
||||
<text class="menu-text">订单列表</text>
|
||||
</view>
|
||||
</template>
|
||||
<template v-else-if="isCustomer">
|
||||
<view class="menu-item" @click="goToTab('/pages/order/list')">
|
||||
<view class="menu-icon-box green"><text class="icon-text">列</text></view>
|
||||
<text class="menu-text">我的订单</text>
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 管理区域 -->
|
||||
<view class="section" v-if="isAdmin || isSales">
|
||||
<text class="section-title">管理</text>
|
||||
<view class="menu-grid">
|
||||
<template v-if="isAdmin">
|
||||
<view class="menu-item" @click="goTo('/pages/customer/create')">
|
||||
<view class="menu-icon-box blue"><text class="icon-text">新增</text></view>
|
||||
<text class="menu-text">新增客户</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goTo('/pages/customer/list')">
|
||||
<view class="menu-icon-box cyan"><text class="icon-text">客</text></view>
|
||||
<text class="menu-text">客户列表</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goTo('/pages/product/manage')">
|
||||
<view class="menu-icon-box purple"><text class="icon-text">商</text></view>
|
||||
<text class="menu-text">商品管理</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goTo('/pages/category/index')">
|
||||
<view class="menu-icon-box pink"><text class="icon-text">类</text></view>
|
||||
<text class="menu-text">种类管理</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goStock()">
|
||||
<view class="menu-icon-box cyan"><text class="icon-text">库</text></view>
|
||||
<text class="menu-text">库存管理</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goTo('/pages/stock/in')">
|
||||
<view class="menu-icon-box orange"><text class="icon-text">入</text></view>
|
||||
<text class="menu-text">入库</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="goTo('/pages/stock/flow')">
|
||||
<view class="menu-icon-box green"><text class="icon-text">流</text></view>
|
||||
<text class="menu-text">库存流水</text>
|
||||
</view>
|
||||
</template>
|
||||
<template v-else-if="isSales">
|
||||
<view class="menu-item" @click="goTo('/pages/product/list')">
|
||||
<view class="menu-icon-box purple"><text class="icon-text">商</text></view>
|
||||
<text class="menu-text">商品浏览</text>
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 商品区域(顾客) -->
|
||||
<view class="section" v-if="isCustomer">
|
||||
<text class="section-title">商品</text>
|
||||
<view class="menu-grid">
|
||||
<view class="menu-item" @click="goTo('/pages/product/list')">
|
||||
<view class="menu-icon-box purple"><text class="icon-text">商</text></view>
|
||||
<text class="menu-text">商品浏览</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 游客登录 -->
|
||||
<view class="guest-section" v-if="!username">
|
||||
<view class="guest-btn" @click="goTo('/pages/login/index')">
|
||||
<text class="guest-text">点击登录</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { isAdmin, isSales, isCustomer } from '@/utils/auth'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
username: '',
|
||||
greeting: ''
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
isAdmin() { return isAdmin() },
|
||||
isSales() { return isSales() },
|
||||
isCustomer() { return isCustomer() }
|
||||
},
|
||||
onShow() {
|
||||
this.username = uni.getStorageSync('username') || ''
|
||||
this.setGreeting()
|
||||
},
|
||||
methods: {
|
||||
setGreeting() {
|
||||
const hour = new Date().getHours()
|
||||
if (hour < 6) this.greeting = '凌晨好'
|
||||
else if (hour < 12) this.greeting = '上午好'
|
||||
else if (hour < 14) this.greeting = '中午好'
|
||||
else if (hour < 18) this.greeting = '下午好'
|
||||
else this.greeting = '晚上好'
|
||||
},
|
||||
goTo(url) {
|
||||
uni.navigateTo({ url })
|
||||
},
|
||||
goToTab(url) {
|
||||
uni.switchTab({ url })
|
||||
},
|
||||
goStock() {
|
||||
uni.navigateTo({ url: '/pages/stock/list' })
|
||||
},
|
||||
logout() {
|
||||
uni.showModal({
|
||||
title: '退出登录',
|
||||
content: '确定要退出吗?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.clearStorageSync()
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: #fff;
|
||||
padding: 30rpx;
|
||||
border-radius: 16rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.user-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.welcome {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.username {
|
||||
font-size: 34rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-top: 6rpx;
|
||||
}
|
||||
|
||||
.logout-btn {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
padding: 12rpx 24rpx;
|
||||
background: #f5f5f5;
|
||||
border-radius: 30rpx;
|
||||
}
|
||||
|
||||
.section {
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 24rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 24rpx;
|
||||
padding-left: 16rpx;
|
||||
border-left: 6rpx solid #1890ff;
|
||||
}
|
||||
|
||||
.menu-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
width: 25%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 16rpx 0;
|
||||
}
|
||||
|
||||
.menu-icon-box {
|
||||
width: 130rpx;
|
||||
height: 130rpx;
|
||||
border-radius: 28rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.menu-icon-box.blue { background: #e8f4ff; }
|
||||
.menu-icon-box.green { background: #f6ffed; }
|
||||
.menu-icon-box.orange { background: #fff7e6; }
|
||||
.menu-icon-box.red { background: #fff1f0; }
|
||||
.menu-icon-box.purple { background: #f9f0ff; }
|
||||
.menu-icon-box.pink { background: #fff0f6; }
|
||||
.menu-icon-box.cyan { background: #e6f7ff; }
|
||||
|
||||
.icon-text {
|
||||
font-size: 52rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.blue .icon-text { color: #1890ff; }
|
||||
.green .icon-text { color: #52c41a; }
|
||||
.orange .icon-text { color: #fa8c16; }
|
||||
.red .icon-text { color: #ff4d4f; }
|
||||
.purple .icon-text { color: #722ed1; }
|
||||
.pink .icon-text { color: #eb2f96; }
|
||||
.cyan .icon-text { color: #13c2c2; }
|
||||
|
||||
.menu-text {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.guest-section {
|
||||
margin-top: 200rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.guest-btn {
|
||||
background: #1890ff;
|
||||
padding: 30rpx 80rpx;
|
||||
border-radius: 50rpx;
|
||||
}
|
||||
|
||||
.guest-text {
|
||||
font-size: 32rpx;
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
450
src/pages/login/index.vue
Normal file
450
src/pages/login/index.vue
Normal file
@@ -0,0 +1,450 @@
|
||||
<template>
|
||||
<view class="login-container">
|
||||
<!-- 背景装饰 -->
|
||||
<view class="bg-decoration">
|
||||
<view class="circle circle-1"></view>
|
||||
<view class="circle circle-2"></view>
|
||||
<view class="circle circle-3"></view>
|
||||
</view>
|
||||
|
||||
<!-- Logo区域 -->
|
||||
<view class="logo-section">
|
||||
<view class="logo-wrapper">
|
||||
<text class="logo-icon">🏠</text>
|
||||
</view>
|
||||
<text class="app-title">建材销售管家</text>
|
||||
<text class="app-subtitle">高效 · 便捷 · 专业</text>
|
||||
</view>
|
||||
|
||||
<!-- 登录表单 -->
|
||||
<view class="form-section">
|
||||
<view class="input-group">
|
||||
<view class="input-wrapper">
|
||||
<text class="input-icon">👤</text>
|
||||
<input
|
||||
class="input"
|
||||
v-model="username"
|
||||
placeholder="请输入用户名"
|
||||
placeholder-class="placeholder"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="input-group">
|
||||
<view class="input-wrapper">
|
||||
<text class="input-icon">🔒</text>
|
||||
<input
|
||||
class="input"
|
||||
:password="!showPassword"
|
||||
v-model="password"
|
||||
placeholder="请输入密码"
|
||||
placeholder-class="placeholder"
|
||||
/>
|
||||
<text class="eye-icon" @click="showPassword = !showPassword">
|
||||
{{ showPassword ? '👁️' : '👁️🗨️' }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="login-btn-wrapper">
|
||||
<button class="login-btn" @click="passwordLogin">
|
||||
<text>账号密码登录</text>
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<!-- 微信登录 -->
|
||||
<view class="wechat-login" @click="wechatLogin">
|
||||
<text class="wechat-icon">💬</text>
|
||||
<text class="wechat-text">微信登录</text>
|
||||
</view>
|
||||
|
||||
<view class="agreement">
|
||||
<text class="agreement-text">登录即表示同意</text>
|
||||
<text class="link">《用户协议》</text>
|
||||
<text class="agreement-text">和</text>
|
||||
<text class="link">《隐私政策》</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 底部 -->
|
||||
<view class="footer">
|
||||
<text class="footer-text">© 2026 建材销售管家</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import authApi from '@/api/auth'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
username: '',
|
||||
password: '',
|
||||
showPassword: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async passwordLogin() {
|
||||
if (!this.username) {
|
||||
uni.showToast({ title: '请输入用户名', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!this.password) {
|
||||
uni.showToast({ title: '请输入密码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 假登录(演示用)
|
||||
// 管理员
|
||||
if (this.username === 'admin' && this.password === 'admin') {
|
||||
const mockData = {
|
||||
token: 'mock-token-admin',
|
||||
userId: 'admin-001',
|
||||
username: 'admin',
|
||||
role: 'admin'
|
||||
}
|
||||
uni.setStorageSync('token', mockData.token)
|
||||
uni.setStorageSync('userId', mockData.userId)
|
||||
uni.setStorageSync('username', mockData.username)
|
||||
uni.setStorageSync('role', mockData.role)
|
||||
|
||||
uni.showToast({ title: '管理员登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}, 1000)
|
||||
return
|
||||
}
|
||||
|
||||
// 销售人员
|
||||
if (this.username === 'sales' && this.password === 'sales') {
|
||||
const mockData = {
|
||||
token: 'mock-token-sales',
|
||||
userId: 'sales-001',
|
||||
username: '张三',
|
||||
role: 'sales'
|
||||
}
|
||||
uni.setStorageSync('token', mockData.token)
|
||||
uni.setStorageSync('userId', mockData.userId)
|
||||
uni.setStorageSync('username', mockData.username)
|
||||
uni.setStorageSync('role', mockData.role)
|
||||
|
||||
uni.showToast({ title: '销售人员登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}, 1000)
|
||||
return
|
||||
}
|
||||
|
||||
// 顾客登录
|
||||
if (this.username === 'customer' && this.password === 'customer') {
|
||||
const mockData = {
|
||||
token: 'mock-token-customer',
|
||||
userId: 'customer-001',
|
||||
username: '顾客',
|
||||
role: 'customer'
|
||||
}
|
||||
uni.setStorageSync('token', mockData.token)
|
||||
uni.setStorageSync('userId', mockData.userId)
|
||||
uni.setStorageSync('username', mockData.username)
|
||||
uni.setStorageSync('role', mockData.role)
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}, 1000)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await authApi.passwordLogin(this.username, this.password)
|
||||
uni.setStorageSync('token', data.token)
|
||||
uni.setStorageSync('refreshToken', data.refreshToken)
|
||||
uni.setStorageSync('userId', data.userId)
|
||||
uni.setStorageSync('username', data.username || this.username)
|
||||
uni.setStorageSync('role', data.role || 'customer')
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}, 1000)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
|
||||
async wechatLogin() {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.getProvider({
|
||||
service: 'oauth',
|
||||
success: (res) => {
|
||||
if (res.provider.includes('weixin')) {
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: async (loginRes) => {
|
||||
try {
|
||||
const data = await authApi.wechatLogin(loginRes.code)
|
||||
uni.setStorageSync('token', data.token)
|
||||
uni.setStorageSync('refreshToken', data.refreshToken)
|
||||
uni.setStorageSync('userId', data.userId)
|
||||
|
||||
uni.showToast({ title: '登录成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: '/pages/index/index' })
|
||||
}, 1000)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
uni.showToast({ title: '请在微信小程序中使用', icon: 'none' })
|
||||
// #endif
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.login-container {
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* 背景装饰 */
|
||||
.bg-decoration {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.circle {
|
||||
position: absolute;
|
||||
border-radius: 50%;
|
||||
opacity: 0.1;
|
||||
}
|
||||
|
||||
.circle-1 {
|
||||
width: 600rpx;
|
||||
height: 600rpx;
|
||||
background: #e94560;
|
||||
top: -200rpx;
|
||||
right: -200rpx;
|
||||
animation: float 8s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.circle-2 {
|
||||
width: 400rpx;
|
||||
height: 400rpx;
|
||||
background: #0f3460;
|
||||
bottom: -100rpx;
|
||||
left: -100rpx;
|
||||
animation: float 10s ease-in-out infinite reverse;
|
||||
}
|
||||
|
||||
.circle-3 {
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
background: #e94560;
|
||||
top: 30%;
|
||||
left: 10%;
|
||||
animation: float 6s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes float {
|
||||
0%, 100% { transform: translateY(0) rotate(0deg); }
|
||||
50% { transform: translateY(-30px) rotate(10deg); }
|
||||
}
|
||||
|
||||
/* Logo区域 */
|
||||
.logo-section {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
padding-top: 120rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.logo-wrapper {
|
||||
width: 180rpx;
|
||||
height: 180rpx;
|
||||
background: linear-gradient(135deg, #e94560 0%, #ff6b6b 100%);
|
||||
border-radius: 40rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 20rpx 60rpx rgba(233, 69, 96, 0.4);
|
||||
animation: pulse 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% { transform: scale(1); }
|
||||
50% { transform: scale(1.05); }
|
||||
}
|
||||
|
||||
.logo-icon {
|
||||
font-size: 80rpx;
|
||||
}
|
||||
|
||||
.app-title {
|
||||
font-size: 44rpx;
|
||||
font-weight: bold;
|
||||
color: #fff;
|
||||
margin-top: 40rpx;
|
||||
letter-spacing: 4rpx;
|
||||
}
|
||||
|
||||
.app-subtitle {
|
||||
font-size: 24rpx;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
margin-top: 16rpx;
|
||||
letter-spacing: 8rpx;
|
||||
}
|
||||
|
||||
/* 表单区域 */
|
||||
.form-section {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
padding: 80rpx 60rpx;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 16rpx;
|
||||
padding: 0 30rpx;
|
||||
height: 100rpx;
|
||||
border: 1rpx solid rgba(255, 255, 255, 0.1);
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.input-wrapper:focus-within {
|
||||
border-color: #e94560;
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
|
||||
.input-icon {
|
||||
font-size: 36rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.input {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
color: #fff;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
}
|
||||
|
||||
.eye-icon {
|
||||
font-size: 36rpx;
|
||||
padding: 10rpx;
|
||||
}
|
||||
|
||||
.login-btn-wrapper {
|
||||
margin-top: 50rpx;
|
||||
}
|
||||
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
height: 100rpx;
|
||||
line-height: 100rpx;
|
||||
background: linear-gradient(135deg, #e94560 0%, #ff6b6b 100%);
|
||||
color: #fff;
|
||||
border-radius: 50rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
border: none;
|
||||
box-shadow: 0 10rpx 40rpx rgba(233, 69, 96, 0.4);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.login-btn::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: -100%;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
|
||||
animation: shine 3s infinite;
|
||||
}
|
||||
|
||||
@keyframes shine {
|
||||
0% { left: -100%; }
|
||||
50%, 100% { left: 100%; }
|
||||
}
|
||||
|
||||
/* 微信登录 */
|
||||
.wechat-login {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-top: 40rpx;
|
||||
padding: 20rpx;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 16rpx;
|
||||
}
|
||||
|
||||
.wechat-icon {
|
||||
font-size: 40rpx;
|
||||
margin-right: 16rpx;
|
||||
}
|
||||
|
||||
.wechat-text {
|
||||
font-size: 28rpx;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* 协议 */
|
||||
.agreement {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: 40rpx;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.agreement-text {
|
||||
font-size: 22rpx;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
.link {
|
||||
font-size: 22rpx;
|
||||
color: #e94560;
|
||||
margin: 0 4rpx;
|
||||
}
|
||||
|
||||
/* 底部 */
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 60rpx;
|
||||
left: 0;
|
||||
right: 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.footer-text {
|
||||
font-size: 22rpx;
|
||||
color: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
</style>
|
||||
712
src/pages/order/create.vue
Normal file
712
src/pages/order/create.vue
Normal file
@@ -0,0 +1,712 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 客户信息 -->
|
||||
<view class="section card-section">
|
||||
<view class="section-header">
|
||||
<text class="section-icon">👤</text>
|
||||
<text class="section-title">客户信息</text>
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="label">客户种类</text>
|
||||
<picker
|
||||
mode="selector"
|
||||
:range="typeOptions"
|
||||
range-key="label"
|
||||
@change="selectType"
|
||||
>
|
||||
<view class="picker-value">
|
||||
{{ selectedTypeLabel || '请选择客户种类' }}
|
||||
<text class="arrow">›</text>
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="label">客户</text>
|
||||
<picker
|
||||
mode="selector"
|
||||
:range="filteredCustomers"
|
||||
range-key="name"
|
||||
@change="selectCustomer"
|
||||
>
|
||||
<view class="picker-value">
|
||||
{{ selectedCustomer ? selectedCustomer.name : '请选择客户' }}
|
||||
<text class="arrow">›</text>
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 商品选择 -->
|
||||
<view class="section card-section">
|
||||
<view class="section-header">
|
||||
<text class="section-icon">📦</text>
|
||||
<text class="section-title">商品明细</text>
|
||||
<text class="add-btn" @click="goToSelectProduct">+ 添加商品</text>
|
||||
</view>
|
||||
|
||||
<view v-for="(item, index) in orderItems" :key="index" class="order-item">
|
||||
<view class="item-info">
|
||||
<text class="item-name">{{ item.productName }}</text>
|
||||
<text class="item-spec">{{ item.spec || '-' }}</text>
|
||||
</view>
|
||||
<view class="item-edit">
|
||||
<view class="quantity-edit">
|
||||
<text class="qty-label">数量</text>
|
||||
<input
|
||||
class="qty-input"
|
||||
type="number"
|
||||
v-model="item.quantity"
|
||||
@change="calcAmount"
|
||||
/>
|
||||
</view>
|
||||
<view class="price-edit">
|
||||
<text class="qty-label">单价</text>
|
||||
<input
|
||||
class="price-input"
|
||||
type="digit"
|
||||
v-model="item.price"
|
||||
@change="calcAmount"
|
||||
/>
|
||||
</view>
|
||||
<text class="item-subtotal">¥{{ (item.price * item.quantity).toFixed(2) }}</text>
|
||||
<text class="delete-btn" @click="removeItem(index)">×</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="orderItems.length === 0" class="empty-tip">
|
||||
<text class="empty-icon">🛒</text>
|
||||
<text>请添加商品</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 优惠设置 -->
|
||||
<view class="section card-section">
|
||||
<view class="section-header">
|
||||
<text class="section-icon">🎫</text>
|
||||
<text class="section-title">优惠设置</text>
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="label">优惠金额</text>
|
||||
<input
|
||||
class="discount-input"
|
||||
type="digit"
|
||||
v-model="discountMoney"
|
||||
@input="calcAmount"
|
||||
/>
|
||||
<text class="unit">元</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 订单金额 -->
|
||||
<view class="section amount-section">
|
||||
<view class="amount-header">
|
||||
<text class="amount-icon">💰</text>
|
||||
<text class="amount-title">订单金额</text>
|
||||
</view>
|
||||
<view class="amount-row">
|
||||
<text class="amount-label">原价合计</text>
|
||||
<text class="amount-value">¥{{ totalAmount.toFixed(2) }}</text>
|
||||
</view>
|
||||
<view class="amount-row">
|
||||
<text class="amount-label">优惠金额</text>
|
||||
<text class="amount-value discount">-¥{{ discountAmount.toFixed(2) }}</text>
|
||||
</view>
|
||||
<view class="amount-row actual">
|
||||
<text class="amount-label">实付金额</text>
|
||||
<text class="amount-value">¥{{ actualAmount.toFixed(2) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 支付方式 -->
|
||||
<view class="section card-section">
|
||||
<view class="section-header">
|
||||
<text class="section-icon">💳</text>
|
||||
<text class="section-title">支付方式</text>
|
||||
</view>
|
||||
<view class="payment-methods">
|
||||
<view
|
||||
class="method-item"
|
||||
:class="{ active: paymentMethod === 'cash' }"
|
||||
@click="paymentMethod = 'cash'"
|
||||
>
|
||||
💵 现金
|
||||
</view>
|
||||
<view
|
||||
class="method-item"
|
||||
:class="{ active: paymentMethod === 'wechat' }"
|
||||
@click="paymentMethod = 'wechat'"
|
||||
>
|
||||
💬 微信
|
||||
</view>
|
||||
<view
|
||||
class="method-item"
|
||||
:class="{ active: paymentMethod === 'alipay' }"
|
||||
@click="paymentMethod = 'alipay'"
|
||||
>
|
||||
💰 支付宝
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 备注 -->
|
||||
<view class="section card-section">
|
||||
<view class="section-header">
|
||||
<text class="section-icon">📝</text>
|
||||
<text class="section-title">备注</text>
|
||||
</view>
|
||||
<textarea
|
||||
class="remark-input"
|
||||
v-model="remark"
|
||||
placeholder="请输入备注信息"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 提交按钮 -->
|
||||
<view class="submit-bar">
|
||||
<view class="submit-info">
|
||||
<text>实付: </text>
|
||||
<text class="submit-amount">¥{{ actualAmount.toFixed(2) }}</text>
|
||||
</view>
|
||||
<button class="submit-btn" @click="createOrder">{{ editingOrderId ? '保存订单' : '创建订单' }}</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import orderApi from '@/api/order'
|
||||
import productApi from '@/api/product'
|
||||
import customerApi from '@/api/customer'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
// 客户种类
|
||||
typeOptions: [
|
||||
{ label: '顾客', value: 'customer' },
|
||||
{ label: '木匠', value: 'carpenter' },
|
||||
{ label: '装修公司', value: 'company' }
|
||||
],
|
||||
selectedType: 'customer',
|
||||
selectedTypeLabel: '顾客',
|
||||
|
||||
// 客户相关
|
||||
customers: [],
|
||||
selectedCustomer: null,
|
||||
|
||||
// 商品相关
|
||||
orderItems: [],
|
||||
productList: [],
|
||||
searchKeyword: '',
|
||||
|
||||
// 金额相关
|
||||
discountRate: 100, // 折扣率(保留逻辑,默认100%不打折)
|
||||
discountMoney: 0, // 优惠金额
|
||||
totalAmount: 0, // 原价
|
||||
discountAmount: 0, // 优惠金额(计算结果)
|
||||
actualAmount: 0, // 实付金额
|
||||
|
||||
// 其他
|
||||
paymentMethod: 'cash',
|
||||
remark: '',
|
||||
|
||||
// 编辑模式
|
||||
editingOrderId: null,
|
||||
tempCustomerId: null, // 临时保存编辑时的客户ID
|
||||
tempCustomerType: null // 临时保存编辑时的客户种类
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
this.loadCustomersByType()
|
||||
this.loadProducts()
|
||||
if (options.orderId) {
|
||||
this.editingOrderId = options.orderId
|
||||
// 编辑模式
|
||||
uni.setNavigationBarTitle({ title: '编辑订单' })
|
||||
// 等客户列表加载完成后再加载订单
|
||||
setTimeout(() => {
|
||||
this.loadOrder(options.orderId)
|
||||
}, 500)
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
filteredCustomers() {
|
||||
return this.customers.filter(c => c.type === this.selectedType)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async loadOrder(orderId) {
|
||||
try {
|
||||
const detail = await orderApi.getOrderDetail(orderId)
|
||||
const order = detail.order
|
||||
|
||||
// 先保存 customerId,等客户列表加载完成后再匹配
|
||||
this.tempCustomerId = order.customerId
|
||||
this.tempCustomerType = order.customerType
|
||||
|
||||
this.orderItems = (detail.items || []).map(item => ({
|
||||
productId: item.productId,
|
||||
productName: item.productName,
|
||||
spec: item.productSpec,
|
||||
unit: item.unit,
|
||||
price: item.price,
|
||||
quantity: item.quantity
|
||||
}))
|
||||
|
||||
this.discountRate = order.discountRate
|
||||
this.discountMoney = order.discountMoney || 0
|
||||
this.remark = order.remark || ''
|
||||
this.paymentMethod = order.paymentMethod || 'cash'
|
||||
|
||||
this.calcAmount()
|
||||
|
||||
// 尝试匹配客户
|
||||
this.matchCustomer()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
matchCustomer() {
|
||||
if (this.tempCustomerId && this.customers.length > 0) {
|
||||
this.selectedCustomer = this.customers.find(c => c.customerId === this.tempCustomerId)
|
||||
if (this.tempCustomerType) {
|
||||
this.selectedType = this.tempCustomerType
|
||||
const typeOption = this.typeOptions.find(t => t.value === this.tempCustomerType)
|
||||
if (typeOption) {
|
||||
this.selectedTypeLabel = typeOption.label
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
async loadCustomers() {
|
||||
try {
|
||||
const res = await customerApi.getCustomers({ page: 1, pageSize: 100 })
|
||||
this.customers = res.records || []
|
||||
// 客户列表加载完成后,尝试匹配编辑订单的客户
|
||||
this.matchCustomer()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
async loadProducts() {
|
||||
try {
|
||||
const res = await productApi.getProducts({ page: 1, pageSize: 100 })
|
||||
this.productList = res.records || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
selectCustomer(e) {
|
||||
this.selectedCustomer = this.filteredCustomers[e.detail.value]
|
||||
},
|
||||
selectType(e) {
|
||||
const idx = e.detail.value
|
||||
this.selectedType = this.typeOptions[idx].value
|
||||
this.selectedTypeLabel = this.typeOptions[idx].label
|
||||
// 切换种类后清除已选客户,重新拉取该种类的客户
|
||||
this.selectedCustomer = null
|
||||
this.loadCustomersByType()
|
||||
},
|
||||
async loadCustomersByType() {
|
||||
try {
|
||||
const res = await customerApi.getCustomers({
|
||||
type: this.selectedType,
|
||||
page: 1,
|
||||
pageSize: 100
|
||||
})
|
||||
this.customers = res.records || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
goToSelectProduct() {
|
||||
uni.navigateTo({ url: '/pages/product/select' })
|
||||
},
|
||||
addProduct(product) {
|
||||
// 检查是否已添加
|
||||
const exists = this.orderItems.find(item => item.productId === product.productId)
|
||||
if (exists) {
|
||||
uni.showToast({ title: '商品已添加', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
this.orderItems.push({
|
||||
productId: product.productId,
|
||||
productName: product.name,
|
||||
spec: product.spec,
|
||||
unit: product.unit,
|
||||
price: product.price,
|
||||
quantity: 1
|
||||
})
|
||||
this.calcAmount()
|
||||
},
|
||||
removeItem(index) {
|
||||
this.orderItems.splice(index, 1)
|
||||
this.calcAmount()
|
||||
},
|
||||
// 核心金额计算逻辑
|
||||
calcAmount() {
|
||||
// 1. 计算原价 = Σ(单价 × 数量)
|
||||
this.totalAmount = this.orderItems.reduce((sum, item) => {
|
||||
return sum + (item.price * item.quantity)
|
||||
}, 0)
|
||||
|
||||
// 2. 优惠金额直接使用用户输入的值,不能为负
|
||||
let discountVal = parseFloat(this.discountMoney)
|
||||
if (isNaN(discountVal) || discountVal < 0) {
|
||||
discountVal = 0
|
||||
}
|
||||
this.discountAmount = discountVal
|
||||
|
||||
// 3. 计算实付金额 = 原价 - 优惠金额
|
||||
this.actualAmount = this.totalAmount - this.discountAmount
|
||||
},
|
||||
async createOrder() {
|
||||
if (this.orderItems.length === 0) {
|
||||
uni.showToast({ title: '请添加商品', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 校验:客户必须选择
|
||||
if (!this.selectedCustomer) {
|
||||
uni.showToast({ title: '请选择客户', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 校验:实付金额必须大于0
|
||||
if (this.actualAmount <= 0) {
|
||||
uni.showToast({ title: '实付金额必须大于0', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 校验:优惠金额不能为负
|
||||
const discountVal = parseFloat(this.discountMoney) || 0
|
||||
if (discountVal < 0) {
|
||||
uni.showToast({ title: '优惠金额不能为负', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
const data = {
|
||||
customerId: this.selectedCustomer ? this.selectedCustomer.customerId : null,
|
||||
items: this.orderItems.map(item => ({
|
||||
productId: item.productId,
|
||||
quantity: item.quantity,
|
||||
price: item.price
|
||||
})),
|
||||
discountRate: 100, // 保留折扣率逻辑,默认100%
|
||||
discountMoney: parseFloat(this.discountMoney) || 0,
|
||||
remark: this.remark,
|
||||
paymentMethod: this.paymentMethod
|
||||
}
|
||||
|
||||
try {
|
||||
let order
|
||||
if (this.editingOrderId) {
|
||||
order = await orderApi.updateOrder(this.editingOrderId, data)
|
||||
uni.showToast({ title: '订单更新成功', icon: 'success' })
|
||||
} else {
|
||||
order = await orderApi.createOrder(data)
|
||||
uni.showToast({ title: '订单创建成功', icon: 'success' })
|
||||
}
|
||||
|
||||
// 跳转到订单列表
|
||||
setTimeout(() => {
|
||||
uni.switchTab({
|
||||
url: '/pages/order/list'
|
||||
})
|
||||
}, 1500)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/* 全局 */
|
||||
.page {
|
||||
padding: 20rpx;
|
||||
padding-bottom: 180rpx;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
/* 卡片区块 */
|
||||
.card-section {
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
padding: 24rpx;
|
||||
margin-bottom: 20rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.section-icon {
|
||||
font-size: 32rpx;
|
||||
margin-right: 12rpx;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
color: #667eea;
|
||||
font-size: 26rpx;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 20rpx 0;
|
||||
border-bottom: 1rpx solid #f5f5f5;
|
||||
}
|
||||
|
||||
.label {
|
||||
width: 140rpx;
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.picker-value {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
font-size: 32rpx;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.discount-input {
|
||||
width: 120rpx;
|
||||
text-align: right;
|
||||
font-size: 28rpx;
|
||||
padding: 10rpx;
|
||||
background: #f5f5f5;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.unit {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
margin-left: 10rpx;
|
||||
}
|
||||
|
||||
/* 订单商品项 */
|
||||
.order-item {
|
||||
padding: 20rpx;
|
||||
background: #f9f9f9;
|
||||
border-radius: 12rpx;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.item-info {
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.item-name {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
display: block;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.item-spec {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.item-edit {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.quantity-edit, .price-edit {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.qty-label {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
|
||||
.qty-input, .price-input {
|
||||
width: 100rpx;
|
||||
height: 56rpx;
|
||||
background: #fff;
|
||||
border: 1rpx solid #ddd;
|
||||
border-radius: 8rpx;
|
||||
text-align: center;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.item-subtotal {
|
||||
flex: 1;
|
||||
text-align: right;
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
margin-left: 20rpx;
|
||||
font-size: 40rpx;
|
||||
color: #999;
|
||||
padding: 10rpx;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
padding: 40rpx;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 60rpx;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
/* 金额区域 */
|
||||
.amount-section {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 20rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.amount-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.amount-icon {
|
||||
font-size: 32rpx;
|
||||
margin-right: 12rpx;
|
||||
}
|
||||
|
||||
.amount-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.amount-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 12rpx 0;
|
||||
}
|
||||
|
||||
.amount-label {
|
||||
font-size: 26rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.amount-value {
|
||||
font-size: 26rpx;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.amount-value.discount {
|
||||
color: #7dff7d;
|
||||
}
|
||||
|
||||
.amount-row.actual {
|
||||
border-top: 1rpx solid rgba(255, 255, 255, 0.2);
|
||||
padding-top: 20rpx;
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
|
||||
.amount-row.actual .amount-value {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* 支付方式 */
|
||||
.payment-methods {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.method-item {
|
||||
flex: 1;
|
||||
padding: 24rpx;
|
||||
text-align: center;
|
||||
background: #f5f5f5;
|
||||
border-radius: 12rpx;
|
||||
font-size: 26rpx;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.method-item.active {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
box-shadow: 0 4rpx 16rpx rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
/* 备注 */
|
||||
.remark-input {
|
||||
width: 100%;
|
||||
height: 120rpx;
|
||||
font-size: 28rpx;
|
||||
background: #f9f9f9;
|
||||
border-radius: 12rpx;
|
||||
padding: 20rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* 底部提交 */
|
||||
.submit-bar {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 20rpx 30rpx;
|
||||
background: #fff;
|
||||
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.submit-info {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.submit-amount {
|
||||
font-size: 40rpx;
|
||||
font-weight: bold;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
width: 240rpx;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 44rpx;
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
box-shadow: 0 8rpx 30rpx rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
</style>
|
||||
428
src/pages/order/detail.vue
Normal file
428
src/pages/order/detail.vue
Normal file
@@ -0,0 +1,428 @@
|
||||
<template>
|
||||
<view class="page" v-if="order">
|
||||
<!-- 订单信息 -->
|
||||
<view class="order-header">
|
||||
<view class="header-row">
|
||||
<text class="label">订单编号</text>
|
||||
<text class="value">{{ order.orderNo }}</text>
|
||||
</view>
|
||||
<view class="header-row">
|
||||
<text class="label">订单状态</text>
|
||||
<text class="status" :class="getStatusClass(order.status)">{{ getStatusText(order.status) }}</text>
|
||||
</view>
|
||||
<view class="header-row">
|
||||
<text class="label">下单时间</text>
|
||||
<text class="value">{{ formatTime(order.createdAt) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 客户信息 -->
|
||||
<view class="section">
|
||||
<view class="section-title">客户信息</view>
|
||||
<view class="section-content">
|
||||
<view class="info-row">
|
||||
<text class="label">客户姓名</text>
|
||||
<text class="value">{{ order.customerName || '散客' }}</text>
|
||||
</view>
|
||||
<view class="info-row" v-if="order.customerPhone">
|
||||
<text class="label">联系电话</text>
|
||||
<text class="value">{{ order.customerPhone }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 商品明细 -->
|
||||
<view class="section">
|
||||
<view class="section-title">商品明细</view>
|
||||
<view class="items-list">
|
||||
<view class="item-row header">
|
||||
<text class="item-name">商品名称</text>
|
||||
<text class="item-qty">数量</text>
|
||||
<text class="item-price">单价</text>
|
||||
<text class="item-subtotal">小计</text>
|
||||
</view>
|
||||
<view
|
||||
v-for="(item, index) in orderItems"
|
||||
:key="index"
|
||||
class="item-row"
|
||||
>
|
||||
<text class="item-name">{{ item.productName }}</text>
|
||||
<text class="item-qty">{{ item.quantity }}</text>
|
||||
<text class="item-price">¥{{ item.price }}</text>
|
||||
<text class="item-subtotal">¥{{ (item.price * item.quantity).toFixed(2) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 金额信息 -->
|
||||
<view class="section">
|
||||
<view class="section-title">金额信息</view>
|
||||
<view class="section-content">
|
||||
<view class="info-row">
|
||||
<text class="label">原价合计</text>
|
||||
<text class="value">¥{{ order.totalAmount }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="label">优惠金额</text>
|
||||
<text class="value discount">-¥{{ order.discountAmount }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="label">实付金额</text>
|
||||
<text class="value actual">¥{{ order.actualAmount }}</text>
|
||||
</view>
|
||||
<view class="info-row" v-if="order.paymentMethod">
|
||||
<text class="label">支付方式</text>
|
||||
<text class="value">{{ getPaymentMethod(order.paymentMethod) }}</text>
|
||||
</view>
|
||||
<view class="info-row" v-if="order.remark">
|
||||
<text class="label">备注</text>
|
||||
<text class="value">{{ order.remark }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 操作信息 -->
|
||||
<view class="section" v-if="order.operatorName">
|
||||
<view class="section-title">操作信息</view>
|
||||
<view class="section-content">
|
||||
<view class="info-row">
|
||||
<text class="label">操作员</text>
|
||||
<text class="value">{{ order.operatorName }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 底部操作栏 -->
|
||||
<view class="bottom-bar">
|
||||
<button class="share-btn" v-if="order.status !== 2" @click="shareOrder">
|
||||
分享订单
|
||||
</button>
|
||||
<button class="print-btn" v-if="order.status !== 2" @click="printOrder">
|
||||
打印订单
|
||||
</button>
|
||||
<button
|
||||
class="action-btn"
|
||||
v-if="order.status === 0"
|
||||
@click="confirmOrder"
|
||||
>
|
||||
确认完成
|
||||
</button>
|
||||
<button
|
||||
class="action-btn cancel"
|
||||
v-if="order.status === 0"
|
||||
@click="cancelOrder"
|
||||
>
|
||||
取消订单
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import orderApi from '@/api/order'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
orderId: '',
|
||||
order: null,
|
||||
orderItems: []
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
if (options.orderId) {
|
||||
this.orderId = options.orderId
|
||||
this.loadOrderDetail()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async loadOrderDetail() {
|
||||
try {
|
||||
const res = await orderApi.getOrderDetail(this.orderId)
|
||||
this.order = res.order
|
||||
this.orderItems = res.items || []
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
getStatusClass(status) {
|
||||
const map = {
|
||||
1: 'status-success',
|
||||
2: 'status-cancel',
|
||||
3: 'status-refunding',
|
||||
4: 'status-refunded',
|
||||
9: 'status-returning'
|
||||
}
|
||||
return map[status] || ''
|
||||
},
|
||||
getStatusText(status) {
|
||||
const map = {
|
||||
0: '未完成',
|
||||
1: '已完成',
|
||||
2: '已取消',
|
||||
3: '退款中',
|
||||
4: '已退款',
|
||||
9: '退货中'
|
||||
}
|
||||
return map[status] || '未知'
|
||||
},
|
||||
formatTime(time) {
|
||||
if (!time) return ''
|
||||
return time.substring(0, 16).replace('T', ' ')
|
||||
},
|
||||
getPaymentMethod(method) {
|
||||
const map = {
|
||||
'cash': '现金',
|
||||
'wechat': '微信',
|
||||
'alipay': '支付宝'
|
||||
}
|
||||
return map[method] || method
|
||||
},
|
||||
async confirmOrder() {
|
||||
uni.showModal({
|
||||
title: '确认订单',
|
||||
content: '确认完成后订单将变为已完成状态',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
await orderApi.updateOrderStatus(this.orderId, 1)
|
||||
uni.showToast({ title: '已确认', icon: 'success' })
|
||||
this.loadOrderDetail()
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '操作失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
async cancelOrder() {
|
||||
uni.showModal({
|
||||
title: '取消订单',
|
||||
content: '确定要取消此订单吗?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
await orderApi.updateOrderStatus(this.orderId, 2)
|
||||
uni.showToast({ title: '已取消', icon: 'success' })
|
||||
this.loadOrderDetail()
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '操作失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
printOrder() {
|
||||
uni.showToast({ title: '打印功能开发中', icon: 'none' })
|
||||
},
|
||||
shareOrder() {
|
||||
// 构建分享链接(包含订单号和客户ID)
|
||||
const h5BaseUrl = import.meta.env.VITE_H5_BASE_URL
|
||||
const customerId = this.order.customerId || ''
|
||||
const shareUrl = `${h5BaseUrl}/#/pages/share/order?orderNo=${this.order.orderNo}&customerId=${customerId}`
|
||||
|
||||
// 复制链接到剪贴板
|
||||
uni.setClipboardData({
|
||||
data: shareUrl,
|
||||
success: () => {
|
||||
uni.showModal({
|
||||
title: '分享链接已复制',
|
||||
content: '订单分享链接已复制,可粘贴发送给客户',
|
||||
showCancel: false,
|
||||
confirmText: '知道了'
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #f8f9fa;
|
||||
padding-bottom: 180rpx;
|
||||
}
|
||||
|
||||
.order-header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 30rpx;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.header-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.header-row .label {
|
||||
font-size: 26rpx;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.header-row .value {
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.status {
|
||||
padding: 4rpx 16rpx;
|
||||
border-radius: 20rpx;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.status-success {
|
||||
background: #52c41a;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.status-cancel {
|
||||
background: #ff4d4f;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.status-returning {
|
||||
background: #fa8c16;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.section {
|
||||
background: #fff;
|
||||
margin: 20rpx;
|
||||
border-radius: 16rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
padding: 24rpx 30rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.section-content {
|
||||
padding: 10rpx 30rpx;
|
||||
}
|
||||
|
||||
.info-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 16rpx 0;
|
||||
border-bottom: 1rpx solid #f8f8f8;
|
||||
}
|
||||
|
||||
.info-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.info-row .label {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.info-row .value {
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.info-row .value.discount {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.info-row .value.actual {
|
||||
color: #ff4d4f;
|
||||
font-weight: bold;
|
||||
font-size: 30rpx;
|
||||
}
|
||||
|
||||
.items-list {
|
||||
padding: 0 30rpx;
|
||||
}
|
||||
|
||||
.item-row {
|
||||
display: flex;
|
||||
padding: 20rpx 0;
|
||||
border-bottom: 1rpx solid #f8f8f8;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.item-row.header {
|
||||
font-weight: bold;
|
||||
color: #666;
|
||||
background: #f8f9fa;
|
||||
padding: 16rpx 0;
|
||||
}
|
||||
|
||||
.item-name {
|
||||
flex: 2;
|
||||
}
|
||||
|
||||
.item-qty {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.item-price {
|
||||
flex: 1;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.item-subtotal {
|
||||
flex: 1;
|
||||
text-align: right;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.bottom-bar {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
display: flex;
|
||||
padding: 20rpx 30rpx;
|
||||
background: #fff;
|
||||
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.print-btn {
|
||||
flex: 1;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
background: #fff;
|
||||
color: #667eea;
|
||||
border: 2rpx solid #667eea;
|
||||
border-radius: 44rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.share-btn {
|
||||
flex: 1;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
background: linear-gradient(135deg, #52c41a 0%, #73d13d 100%);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 44rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
flex: 1;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 44rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.action-btn.cancel {
|
||||
background: #fff;
|
||||
color: #ff4d4f;
|
||||
border: 2rpx solid #ff4d4f;
|
||||
}
|
||||
</style>
|
||||
516
src/pages/order/list.vue
Normal file
516
src/pages/order/list.vue
Normal file
@@ -0,0 +1,516 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 筛选栏 -->
|
||||
<view class="filter-bar">
|
||||
<view
|
||||
class="filter-item"
|
||||
:class="{ active: status === null }"
|
||||
@click="filterStatus(null)"
|
||||
>
|
||||
全部
|
||||
</view>
|
||||
<view
|
||||
class="filter-item"
|
||||
:class="{ active: status === 0 }"
|
||||
@click="filterStatus(0)"
|
||||
>
|
||||
未完成
|
||||
</view>
|
||||
<view
|
||||
class="filter-item"
|
||||
:class="{ active: status === 1 }"
|
||||
@click="filterStatus(1)"
|
||||
>
|
||||
已完成
|
||||
</view>
|
||||
<view
|
||||
class="filter-item"
|
||||
:class="{ active: status === 2 }"
|
||||
@click="filterStatus(2)"
|
||||
>
|
||||
已取消
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 订单列表 -->
|
||||
<view class="order-list">
|
||||
<view
|
||||
v-for="order in orders"
|
||||
:key="order.orderId"
|
||||
class="order-card"
|
||||
@click="viewDetail(order)"
|
||||
>
|
||||
<view class="card-header">
|
||||
<view class="order-no-wrap">
|
||||
<text class="order-icon">📋</text>
|
||||
<text class="order-no">{{ order.orderNo }}</text>
|
||||
</view>
|
||||
<text class="order-status" :class="getStatusClass(order.status)">
|
||||
{{ getStatusText(order.status) }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<view class="card-body">
|
||||
<view class="customer-row">
|
||||
<text class="customer-label">👤 客户</text>
|
||||
<text class="customer-name">{{ order.customerName || '散客' }}</text>
|
||||
<text class="customer-phone">{{ order.customerPhone || '' }}</text>
|
||||
</view>
|
||||
|
||||
<view class="items-row">
|
||||
<text class="items-label">📦 商品</text>
|
||||
<text class="items-count">{{ getItemCount(order.orderId) }}种商品</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card-footer">
|
||||
<view class="amount-info">
|
||||
<view class="amount-row">
|
||||
<text class="amount-label">原价</text>
|
||||
<text class="amount-value">¥{{ order.totalAmount }}</text>
|
||||
</view>
|
||||
<view class="amount-row">
|
||||
<text class="amount-label">优惠</text>
|
||||
<text class="amount-value discount">-¥{{ order.discountAmount }}</text>
|
||||
</view>
|
||||
<view class="amount-row actual">
|
||||
<text class="amount-label">实付</text>
|
||||
<text class="amount-value">¥{{ order.actualAmount }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="action-section">
|
||||
<text class="order-time">{{ formatTime(order.createdAt) }}</text>
|
||||
<view class="order-actions" v-if="order.status === 0">
|
||||
<text class="action-btn confirm" @click.stop="confirmOrder(order)">确认</text>
|
||||
<text class="action-btn cancel" @click.stop="cancelOrder(order)">取消</text>
|
||||
<text class="action-btn edit" @click.stop="editOrder(order)">编辑</text>
|
||||
</view>
|
||||
<text class="operator" v-else>{{ order.operatorName }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view v-if="orders.length === 0" class="empty">
|
||||
<text class="empty-icon">📭</text>
|
||||
<text class="empty-text">暂无订单</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 加载更多 -->
|
||||
<view v-if="orders.length > 0" class="load-more">
|
||||
<text>{{ loading ? '加载中...' : (hasMore ? '上拉加载更多' : '没有更多了') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import orderApi from '@/api/order'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
status: null,
|
||||
orders: [],
|
||||
orderItemsMap: {},
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
hasMore: true,
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
// 默认加载全部订单,不筛选状态
|
||||
this.status = null
|
||||
console.log('onLoad - 加载订单列表')
|
||||
this.loadOrders()
|
||||
},
|
||||
onShow() {
|
||||
// 每次进入页面都刷新数据
|
||||
this.page = 1
|
||||
this.loadOrders()
|
||||
},
|
||||
onReachBottom() {
|
||||
if (this.hasMore && !this.loading) {
|
||||
this.page++
|
||||
this.loadOrders()
|
||||
}
|
||||
},
|
||||
onPullDownRefresh() {
|
||||
this.page = 1
|
||||
this.loadOrders().then(() => {
|
||||
uni.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
async loadOrders() {
|
||||
if (this.loading) return
|
||||
this.loading = true
|
||||
|
||||
try {
|
||||
const res = await orderApi.getOrders({
|
||||
status: this.status,
|
||||
page: this.page,
|
||||
pageSize: this.pageSize
|
||||
})
|
||||
console.log('订单列表响应:', res)
|
||||
|
||||
const list = res.records || []
|
||||
|
||||
// 加载每个订单的明细
|
||||
for (const order of list) {
|
||||
try {
|
||||
const detail = await orderApi.getOrderDetail(order.orderId)
|
||||
this.$set(this.orderItemsMap, order.orderId, detail.items || [])
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.page === 1) {
|
||||
this.orders = list
|
||||
} else {
|
||||
this.orders = [...this.orders, ...list]
|
||||
}
|
||||
this.hasMore = list.length >= this.pageSize
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
filterStatus(status) {
|
||||
this.status = status
|
||||
this.page = 1
|
||||
this.loadOrders()
|
||||
},
|
||||
// 调试用:查看所有订单(不筛选状态)
|
||||
loadAllOrders() {
|
||||
this.status = null
|
||||
this.page = 1
|
||||
this.loadOrders()
|
||||
},
|
||||
viewDetail(order) {
|
||||
// 跳转到订单详情页
|
||||
uni.navigateTo({
|
||||
url: `/pages/order/detail?orderId=${order.orderId}`
|
||||
})
|
||||
},
|
||||
getItemCount(orderId) {
|
||||
const items = this.orderItemsMap[orderId]
|
||||
return items ? items.length : 0
|
||||
},
|
||||
getStatusClass(status) {
|
||||
const map = {
|
||||
1: 'status-success',
|
||||
2: 'status-cancel',
|
||||
3: 'status-refunding',
|
||||
4: 'status-refunded',
|
||||
9: 'status-returning'
|
||||
}
|
||||
return map[status] || ''
|
||||
},
|
||||
getStatusText(status) {
|
||||
const map = {
|
||||
0: '未完成',
|
||||
1: '已完成',
|
||||
2: '已取消',
|
||||
3: '退款中',
|
||||
4: '已退款',
|
||||
9: '退货中'
|
||||
}
|
||||
return map[status] || '未知'
|
||||
},
|
||||
formatTime(time) {
|
||||
if (!time) return '-'
|
||||
return time.substring(0, 16).replace('T', ' ')
|
||||
},
|
||||
async confirmOrder(order) {
|
||||
uni.showModal({
|
||||
title: '确认订单',
|
||||
content: '确认完成后订单将变为已完成状态',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
await orderApi.updateOrderStatus(order.orderId, 1)
|
||||
uni.showToast({ title: '已确认', icon: 'success' })
|
||||
this.loadOrders()
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '操作失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
async cancelOrder(order) {
|
||||
uni.showModal({
|
||||
title: '取消订单',
|
||||
content: '确定要取消该订单吗?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
await orderApi.cancelOrder(order.orderId)
|
||||
uni.showToast({ title: '已取消', icon: 'success' })
|
||||
this.loadOrders()
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '操作失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
editOrder(order) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/order/create?orderId=${order.orderId}`
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/* 全局 */
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #f8f9fa;
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
/* 筛选栏 */
|
||||
.filter-bar {
|
||||
display: flex;
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 12rpx;
|
||||
margin-bottom: 20rpx;
|
||||
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.filter-item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
padding: 16rpx;
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
border-radius: 12rpx;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.filter-item.active {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* 订单列表 */
|
||||
.order-list {
|
||||
padding-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.order-card {
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
padding: 24rpx;
|
||||
margin-bottom: 20rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20rpx;
|
||||
padding-bottom: 16rpx;
|
||||
border-bottom: 1rpx solid #f5f5f5;
|
||||
}
|
||||
|
||||
.order-no-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.order-icon {
|
||||
font-size: 28rpx;
|
||||
margin-right: 10rpx;
|
||||
}
|
||||
|
||||
.order-no {
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.order-status {
|
||||
font-size: 22rpx;
|
||||
padding: 6rpx 16rpx;
|
||||
border-radius: 20rpx;
|
||||
}
|
||||
|
||||
.status-success {
|
||||
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.status-cancel {
|
||||
background: linear-gradient(135deg, #ff4d4f 0%, #ff7875 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.status-refunding {
|
||||
background: linear-gradient(135deg, #fa8c16 0%, #ffc069 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.status-refunded {
|
||||
background: linear-gradient(135deg, #722ed1 0%, #b37feb 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.status-returning {
|
||||
background: linear-gradient(135deg, #fa8c16 0%, #ffc069 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* 卡片主体 */
|
||||
.card-body {
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.customer-row, .items-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.customer-label, .items-label {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
width: 100rpx;
|
||||
}
|
||||
|
||||
.customer-name {
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.customer-phone {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-left: 20rpx;
|
||||
}
|
||||
|
||||
.items-count {
|
||||
font-size: 24rpx;
|
||||
color: #667eea;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 卡片底部 */
|
||||
.card-footer {
|
||||
border-top: 1rpx solid #f5f5f5;
|
||||
padding-top: 16rpx;
|
||||
}
|
||||
|
||||
.amount-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.amount-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.amount-label {
|
||||
font-size: 22rpx;
|
||||
color: #999;
|
||||
margin-right: 10rpx;
|
||||
}
|
||||
|
||||
.amount-value {
|
||||
font-size: 24rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.amount-value.discount {
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.amount-row.actual .amount-value {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
/* 操作区域 */
|
||||
.action-section {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.order-time {
|
||||
font-size: 22rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.operator {
|
||||
font-size: 22rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.order-actions {
|
||||
display: flex;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
font-size: 22rpx;
|
||||
padding: 10rpx 20rpx;
|
||||
border-radius: 20rpx;
|
||||
}
|
||||
|
||||
.action-btn.confirm {
|
||||
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.action-btn.cancel {
|
||||
background: linear-gradient(135deg, #ff4d4f 0%, #ff7875 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.action-btn.edit {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* 空状态 */
|
||||
.empty {
|
||||
padding: 100rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 100rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 加载更多 */
|
||||
.load-more {
|
||||
padding: 20rpx;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
</style>
|
||||
532
src/pages/order/return.vue
Normal file
532
src/pages/order/return.vue
Normal file
@@ -0,0 +1,532 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 搜索栏 -->
|
||||
<view class="search-section">
|
||||
<view class="search-bar">
|
||||
<text class="search-icon">🔍</text>
|
||||
<input
|
||||
class="search-input"
|
||||
v-model="keyword"
|
||||
placeholder="输入客户姓名或手机号搜索"
|
||||
placeholder-class="placeholder"
|
||||
@input="searchCustomers"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 搜索结果列表 -->
|
||||
<scroll-view scroll-y class="result-section">
|
||||
<view v-if="loading" class="loading">加载中...</view>
|
||||
<view v-else-if="customers.length === 0 && keyword" class="empty">
|
||||
<text class="empty-icon">👤</text>
|
||||
<text class="empty-text">未找到相关客户</text>
|
||||
</view>
|
||||
<view v-else-if="customers.length > 0" class="customer-list">
|
||||
<view
|
||||
v-for="customer in customers"
|
||||
:key="customer.customerId"
|
||||
class="customer-card"
|
||||
@click="selectCustomer(customer)"
|
||||
>
|
||||
<view class="customer-info">
|
||||
<text class="customer-name">{{ customer.name }}</text>
|
||||
<text class="customer-phone">{{ customer.phone || '' }}</text>
|
||||
</view>
|
||||
<text class="arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else-if="selectedCustomer" class="selected-info">
|
||||
<text>已选择: {{ selectedCustomer.name }}</text>
|
||||
<text class="clear-btn" @click="clearSelection">清除</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 已选客户的商品列表(可退货) -->
|
||||
<view class="goods-section" v-if="selectedCustomer">
|
||||
<view class="goods-header">
|
||||
<text class="goods-title">{{ selectedCustomer.name }} 可退货的商品</text>
|
||||
</view>
|
||||
<scroll-view scroll-y class="goods-list">
|
||||
<view
|
||||
v-for="item in returnableGoods"
|
||||
:key="item.productId + '_' + item.orderId"
|
||||
class="goods-card"
|
||||
>
|
||||
<view class="goods-info">
|
||||
<text class="goods-name">{{ item.productName }}</text>
|
||||
<text class="goods-spec">{{ item.spec || '-' }}</text>
|
||||
<text class="goods-order">订单: {{ item.orderNo }}</text>
|
||||
</view>
|
||||
<view class="goods-action">
|
||||
<text class="goods-qty">已购: {{ item.quantity }},可退: {{ item.returnableQty }}</text>
|
||||
<button
|
||||
class="return-btn"
|
||||
@click="showReturnDialog(item)"
|
||||
:disabled="item.returnableQty <= 0"
|
||||
>
|
||||
退货
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="returnableGoods.length === 0" class="empty-tip">
|
||||
暂无可退货商品
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<!-- 退货数量弹窗 -->
|
||||
<view class="popup-mask" v-if="showPopup" @click="closePopup"></view>
|
||||
<view class="popup-content" v-if="showPopup">
|
||||
<view class="popup-header">
|
||||
<text class="popup-title">退货 - {{ currentItem.productName }}</text>
|
||||
<text class="popup-close" @click="closePopup">×</text>
|
||||
</view>
|
||||
<view class="popup-body">
|
||||
<view class="popup-info">
|
||||
<text>订单: {{ currentItem.orderNo }}</text>
|
||||
<text>可退数量: {{ currentItem.returnableQty }}</text>
|
||||
</view>
|
||||
<view class="popup-qty">
|
||||
<text class="qty-label">退货数量</text>
|
||||
<view class="qty-input-wrapper">
|
||||
<text class="qty-minus" @click="qtyMinus">-</text>
|
||||
<input
|
||||
class="qty-input"
|
||||
type="number"
|
||||
v-model="returnQty"
|
||||
/>
|
||||
<text class="qty-plus" @click="qtyPlus">+</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="popup-footer">
|
||||
<button class="popup-btn cancel" @click="closePopup">取消</button>
|
||||
<button class="popup-btn confirm" @click="confirmReturn">确定</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import orderApi from '@/api/order'
|
||||
import customerApi from '@/api/customer'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
keyword: '',
|
||||
customers: [],
|
||||
selectedCustomer: null,
|
||||
returnableGoods: [],
|
||||
loading: false,
|
||||
// 弹窗相关
|
||||
showPopup: false,
|
||||
currentItem: {},
|
||||
returnQty: 1
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async searchCustomers() {
|
||||
if (!this.keyword.trim()) {
|
||||
this.customers = []
|
||||
return
|
||||
}
|
||||
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await customerApi.getCustomers({
|
||||
keyword: this.keyword.trim(),
|
||||
page: 1,
|
||||
pageSize: 20
|
||||
})
|
||||
this.customers = res.records || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
async selectCustomer(customer) {
|
||||
this.selectedCustomer = customer
|
||||
this.keyword = ''
|
||||
this.customers = []
|
||||
this.loadReturnableGoods()
|
||||
},
|
||||
clearSelection() {
|
||||
this.selectedCustomer = null
|
||||
this.returnableGoods = []
|
||||
},
|
||||
async loadReturnableGoods() {
|
||||
if (!this.selectedCustomer) return
|
||||
|
||||
try {
|
||||
const res = await orderApi.getOrders({
|
||||
customerId: this.selectedCustomer.customerId,
|
||||
status: 1, // 已完成
|
||||
page: 1,
|
||||
pageSize: 100
|
||||
})
|
||||
const orders = res.records || []
|
||||
|
||||
// 收集每个已完成订单的商品
|
||||
const goodsMap = {}
|
||||
for (const order of orders) {
|
||||
try {
|
||||
const detail = await orderApi.getOrderDetail(order.orderId)
|
||||
const items = detail.items || []
|
||||
for (const item of items) {
|
||||
const key = item.productId
|
||||
if (!goodsMap[key]) {
|
||||
goodsMap[key] = {
|
||||
productId: item.productId,
|
||||
productName: item.productName,
|
||||
spec: item.productSpec,
|
||||
orderId: order.orderId,
|
||||
orderNo: order.orderNo,
|
||||
quantity: 0,
|
||||
returnableQty: 0
|
||||
}
|
||||
}
|
||||
goodsMap[key].quantity += item.quantity
|
||||
// TODO: 需要查询已退货数量,这里暂用quantity
|
||||
goodsMap[key].returnableQty = goodsMap[key].quantity
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
this.returnableGoods = Object.values(goodsMap)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
showReturnDialog(item) {
|
||||
this.currentItem = item
|
||||
this.returnQty = 1
|
||||
this.showPopup = true
|
||||
},
|
||||
closePopup() {
|
||||
this.showPopup = false
|
||||
},
|
||||
qtyMinus() {
|
||||
if (this.returnQty > 1) {
|
||||
this.returnQty--
|
||||
}
|
||||
},
|
||||
qtyPlus() {
|
||||
if (this.returnQty < this.currentItem.returnableQty) {
|
||||
this.returnQty++
|
||||
}
|
||||
},
|
||||
confirmReturn() {
|
||||
if (this.returnQty <= 0 || this.returnQty > this.currentItem.returnableQty) {
|
||||
uni.showToast({ title: '退货数量无效', icon: 'none' })
|
||||
return
|
||||
}
|
||||
uni.showToast({ title: '退货成功', icon: 'success' })
|
||||
// TODO: 调用后端创建退货订单
|
||||
this.closePopup()
|
||||
this.loadReturnableGoods()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #f8f9fa;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.search-section {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
border-radius: 50rpx;
|
||||
padding: 0 30rpx;
|
||||
height: 80rpx;
|
||||
}
|
||||
|
||||
.search-icon {
|
||||
font-size: 32rpx;
|
||||
margin-right: 16rpx;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.result-section {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.loading, .empty {
|
||||
text-align: center;
|
||||
color: #999;
|
||||
padding: 60rpx;
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 60rpx;
|
||||
display: block;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.selected-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 20rpx;
|
||||
background: #e6f7ff;
|
||||
border-radius: 12rpx;
|
||||
margin: 20rpx;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
color: #ff4d4f;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.customer-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.customer-card {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: #fff;
|
||||
padding: 24rpx;
|
||||
margin-bottom: 16rpx;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.customer-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.customer-name {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.customer-phone {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
font-size: 36rpx;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.goods-section {
|
||||
flex: 1;
|
||||
background: #fff;
|
||||
padding: 20rpx;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.goods-header {
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.goods-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.goods-list {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.goods-card {
|
||||
padding: 20rpx;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.goods-info {
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.goods-name {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.goods-spec {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.goods-order {
|
||||
font-size: 22rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.goods-action {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.goods-qty {
|
||||
font-size: 24rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.return-btn {
|
||||
padding: 10rpx 30rpx;
|
||||
background: #ff4d4f;
|
||||
color: #fff;
|
||||
font-size: 24rpx;
|
||||
border-radius: 30rpx;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.return-btn[disabled] {
|
||||
background: #ccc;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
text-align: center;
|
||||
color: #999;
|
||||
padding: 60rpx;
|
||||
}
|
||||
|
||||
/* 弹窗 */
|
||||
.popup-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.popup-content {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: #fff;
|
||||
border-radius: 32rpx 32rpx 0 0;
|
||||
padding: 40rpx 30rpx;
|
||||
padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
|
||||
z-index: 101;
|
||||
}
|
||||
|
||||
.popup-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.popup-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.popup-close {
|
||||
font-size: 48rpx;
|
||||
color: #999;
|
||||
padding: 10rpx;
|
||||
}
|
||||
|
||||
.popup-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 30rpx;
|
||||
color: #666;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.popup-qty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.qty-label {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
width: 160rpx;
|
||||
}
|
||||
|
||||
.qty-input-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #f5f5f5;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.qty-minus, .qty-plus {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 40rpx;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.qty-input {
|
||||
width: 120rpx;
|
||||
height: 80rpx;
|
||||
text-align: center;
|
||||
font-size: 32rpx;
|
||||
background: transparent;
|
||||
border-left: 1rpx solid #eee;
|
||||
border-right: 1rpx solid #eee;
|
||||
}
|
||||
|
||||
.popup-footer {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
margin-top: 40rpx;
|
||||
}
|
||||
|
||||
.popup-btn {
|
||||
flex: 1;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
border-radius: 44rpx;
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.popup-btn.cancel {
|
||||
background: #f5f5f5;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.popup-btn.confirm {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
452
src/pages/order/search.vue
Normal file
452
src/pages/order/search.vue
Normal file
@@ -0,0 +1,452 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 搜索栏 -->
|
||||
<view class="search-section">
|
||||
<view class="search-bar">
|
||||
<text class="search-icon">🔍</text>
|
||||
<input
|
||||
class="search-input"
|
||||
v-model="keyword"
|
||||
placeholder="输入客户姓名或手机号搜索"
|
||||
placeholder-class="placeholder"
|
||||
@input="searchCustomers"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 搜索结果列表 -->
|
||||
<scroll-view scroll-y class="result-section">
|
||||
<view v-if="loading" class="loading">加载中...</view>
|
||||
<view v-else-if="customers.length === 0 && keyword" class="empty">
|
||||
<text class="empty-icon">👤</text>
|
||||
<text class="empty-text">未找到相关客户</text>
|
||||
</view>
|
||||
<view v-else-if="customers.length > 0" class="customer-list">
|
||||
<view
|
||||
v-for="customer in customers"
|
||||
:key="customer.customerId"
|
||||
class="customer-card"
|
||||
@click="selectCustomer(customer)"
|
||||
>
|
||||
<view class="customer-info">
|
||||
<text class="customer-name">{{ customer.name }}</text>
|
||||
<text class="customer-phone">{{ customer.phone || '' }}</text>
|
||||
</view>
|
||||
<text class="arrow">›</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else-if="selectedCustomer" class="selected-info">
|
||||
<text>已选择: {{ selectedCustomer.name }}</text>
|
||||
<text class="clear-btn" @click="clearSelection">清除</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 已选客户的订单列表 -->
|
||||
<view class="orders-section" v-if="selectedCustomer">
|
||||
<view class="orders-header">
|
||||
<text class="orders-title">{{ selectedCustomer.name }} 的订单</text>
|
||||
</view>
|
||||
<scroll-view scroll-y class="orders-list">
|
||||
<view
|
||||
v-for="order in orders"
|
||||
:key="order.orderId"
|
||||
class="order-card"
|
||||
:class="{ 'selected': merging && order.status === 1 && selectedOrders.includes(order.orderId) }"
|
||||
@click="toggleOrderSelection(order)"
|
||||
>
|
||||
<view class="card-checkbox" v-if="merging && order.status === 1">
|
||||
<text>{{ selectedOrders.includes(order.orderId) ? '☑' : '☐' }}</text>
|
||||
</view>
|
||||
<view class="card-content" :class="{ 'with-checkbox': merging && order.status === 1 }">
|
||||
<view class="card-header">
|
||||
<text class="order-no">{{ order.orderNo }}</text>
|
||||
<text class="order-status" :class="getStatusClass(order.status)">
|
||||
{{ getStatusText(order.status) }}
|
||||
</text>
|
||||
</view>
|
||||
<view class="card-body">
|
||||
<text class="order-amount">实付: ¥{{ order.actualAmount }}</text>
|
||||
<text class="order-time">{{ formatTime(order.createdAt) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<!-- 合并订单按钮 -->
|
||||
<view class="bottom-bar" v-if="selectedCustomer && orders.length > 0">
|
||||
<button
|
||||
class="merge-btn"
|
||||
@click="startMerge"
|
||||
v-if="!merging"
|
||||
>
|
||||
合并订单
|
||||
</button>
|
||||
<view class="merge-actions" v-else>
|
||||
<button class="cancel-btn" @click="cancelMerge">取消</button>
|
||||
<button
|
||||
class="confirm-btn"
|
||||
@click="confirmMerge"
|
||||
:disabled="selectedOrders.length < 2"
|
||||
>
|
||||
确定 ({{ selectedOrders.length }})
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import orderApi from '@/api/order'
|
||||
import customerApi from '@/api/customer'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
keyword: '',
|
||||
customers: [],
|
||||
selectedCustomer: null,
|
||||
orders: [],
|
||||
loading: false,
|
||||
// 合并订单相关
|
||||
merging: false,
|
||||
selectedOrders: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async searchCustomers() {
|
||||
if (!this.keyword.trim()) {
|
||||
this.customers = []
|
||||
return
|
||||
}
|
||||
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await customerApi.getCustomers({
|
||||
keyword: this.keyword.trim(),
|
||||
page: 1,
|
||||
pageSize: 20
|
||||
})
|
||||
this.customers = res.records || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
async selectCustomer(customer) {
|
||||
this.selectedCustomer = customer
|
||||
this.keyword = ''
|
||||
this.customers = []
|
||||
this.loadOrders()
|
||||
},
|
||||
clearSelection() {
|
||||
this.selectedCustomer = null
|
||||
this.orders = []
|
||||
this.merging = false
|
||||
this.selectedOrders = []
|
||||
},
|
||||
toggleOrderSelection(order) {
|
||||
if (!this.merging || order.status !== 1) return
|
||||
const index = this.selectedOrders.indexOf(order.orderId)
|
||||
if (index > -1) {
|
||||
this.selectedOrders.splice(index, 1)
|
||||
} else {
|
||||
this.selectedOrders.push(order.orderId)
|
||||
}
|
||||
},
|
||||
startMerge() {
|
||||
this.merging = true
|
||||
this.selectedOrders = []
|
||||
},
|
||||
cancelMerge() {
|
||||
this.merging = false
|
||||
this.selectedOrders = []
|
||||
},
|
||||
confirmMerge() {
|
||||
if (this.selectedOrders.length < 2) {
|
||||
uni.showToast({ title: '请至少选择2个订单', icon: 'none' })
|
||||
return
|
||||
}
|
||||
uni.showToast({ title: '选中 ' + this.selectedOrders.length + ' 个订单', icon: 'success' })
|
||||
// TODO: 后端合并订单逻辑
|
||||
},
|
||||
async loadOrders() {
|
||||
if (!this.selectedCustomer) return
|
||||
|
||||
try {
|
||||
const res = await orderApi.getOrders({
|
||||
customerId: this.selectedCustomer.customerId,
|
||||
page: 1,
|
||||
pageSize: 50
|
||||
})
|
||||
this.orders = res.records || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
getStatusClass(status) {
|
||||
const map = {
|
||||
1: 'status-success',
|
||||
2: 'status-cancel'
|
||||
}
|
||||
return map[status] || ''
|
||||
},
|
||||
getStatusText(status) {
|
||||
const map = {
|
||||
0: '未完成',
|
||||
1: '已完成',
|
||||
2: '已取消'
|
||||
}
|
||||
return map[status] || '未知'
|
||||
},
|
||||
formatTime(time) {
|
||||
if (!time) return ''
|
||||
return time.substring(0, 16).replace('T', ' ')
|
||||
},
|
||||
viewDetail(order) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/order/detail?orderId=${order.orderId}`
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.search-section {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
border-radius: 50rpx;
|
||||
padding: 0 30rpx;
|
||||
height: 80rpx;
|
||||
}
|
||||
|
||||
.search-icon {
|
||||
font-size: 32rpx;
|
||||
margin-right: 16rpx;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.result-section {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.loading, .empty {
|
||||
text-align: center;
|
||||
color: #999;
|
||||
padding: 60rpx;
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 60rpx;
|
||||
display: block;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.selected-info {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 20rpx;
|
||||
background: #e6f7ff;
|
||||
border-radius: 12rpx;
|
||||
margin: 20rpx;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
color: #ff4d4f;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.customer-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.customer-card {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: #fff;
|
||||
padding: 24rpx;
|
||||
margin-bottom: 16rpx;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.customer-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.customer-name {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.customer-phone {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
font-size: 36rpx;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.orders-section {
|
||||
background: #fff;
|
||||
padding: 20rpx;
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.orders-header {
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.orders-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.orders-list {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.order-card {
|
||||
padding: 20rpx;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.order-card.selected {
|
||||
background: #e6f7ff;
|
||||
}
|
||||
|
||||
.card-checkbox {
|
||||
margin-right: 16rpx;
|
||||
font-size: 36rpx;
|
||||
}
|
||||
|
||||
.card-content.with-checkbox {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.card-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.order-no {
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.order-status {
|
||||
font-size: 22rpx;
|
||||
padding: 4rpx 12rpx;
|
||||
border-radius: 16rpx;
|
||||
}
|
||||
|
||||
.status-success {
|
||||
background: #e6f7e6;
|
||||
color: #52c41a;
|
||||
}
|
||||
|
||||
.status-cancel {
|
||||
background: #fff1f0;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.card-body {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.order-amount {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.order-time {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.bottom-bar {
|
||||
padding: 20rpx;
|
||||
background: #fff;
|
||||
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.merge-btn {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 44rpx;
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.merge-actions {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.cancel-btn, .confirm-btn {
|
||||
flex: 1;
|
||||
height: 88rpx;
|
||||
border-radius: 44rpx;
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
background: #f5f5f5;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.confirm-btn {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.confirm-btn[disabled] {
|
||||
background: #ccc;
|
||||
}
|
||||
</style>
|
||||
250
src/pages/product/detail.vue
Normal file
250
src/pages/product/detail.vue
Normal file
@@ -0,0 +1,250 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 商品图片区域 -->
|
||||
<view class="image-section">
|
||||
<view class="product-image">
|
||||
<Icon name="product" :size="120" color="#fff" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 商品基本信息 -->
|
||||
<view class="info-section">
|
||||
<view class="price-row">
|
||||
<text class="price">¥{{ product.price }}</text>
|
||||
<text class="unit">/{{ product.unit }}</text>
|
||||
</view>
|
||||
<text class="product-name">{{ product.name }}</text>
|
||||
<text class="product-spec">规格: {{ product.spec || '-' }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 商品详情 -->
|
||||
<view class="detail-section">
|
||||
<view class="detail-header">
|
||||
<text class="detail-title">商品详情</text>
|
||||
</view>
|
||||
<view class="detail-content">
|
||||
<view class="detail-item">
|
||||
<text class="detail-label">商品分类</text>
|
||||
<text class="detail-value">{{ categoryName }}</text>
|
||||
</view>
|
||||
<view class="detail-item">
|
||||
<text class="detail-label">商品编码</text>
|
||||
<text class="detail-value">{{ product.productId }}</text>
|
||||
</view>
|
||||
<view class="detail-item">
|
||||
<text class="detail-label">成本价</text>
|
||||
<text class="detail-value">¥{{ product.costPrice || '-' }}</text>
|
||||
</view>
|
||||
<view class="detail-item">
|
||||
<text class="detail-label">库存预警</text>
|
||||
<text class="detail-value">{{ product.stockAlert || '-' }}</text>
|
||||
</view>
|
||||
<view class="detail-item">
|
||||
<text class="detail-label">当前库存</text>
|
||||
<text class="detail-value stock">{{ stock }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 底部操作按钮 -->
|
||||
<view class="bottom-bar">
|
||||
<button class="btn-edit" @click="editProduct" v-if="isAdmin">
|
||||
<Icon name="edit" :size="32" color="#fff" style="margin-right: 10rpx" />
|
||||
编辑商品
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import productApi from '@/api/product'
|
||||
import stockApi from '@/api/stock'
|
||||
import { isAdmin } from '@/utils/auth'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
productId: '',
|
||||
product: {},
|
||||
categoryName: '',
|
||||
stock: 0,
|
||||
isAdmin: false
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
if (options.productId) {
|
||||
this.productId = options.productId
|
||||
this.isAdmin = isAdmin()
|
||||
this.loadProductDetail()
|
||||
this.loadStock()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async loadProductDetail() {
|
||||
try {
|
||||
const res = await productApi.getProduct(this.productId)
|
||||
this.product = res
|
||||
// 获取分类名称
|
||||
const categories = await productApi.getCategories()
|
||||
const category = categories.find(c => c.categoryId === this.product.categoryId)
|
||||
this.categoryName = category ? category.name : '-'
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
async loadStock() {
|
||||
try {
|
||||
const res = await stockApi.getStock(this.productId)
|
||||
this.stock = res.quantity || 0
|
||||
} catch (e) {
|
||||
this.stock = 0
|
||||
}
|
||||
},
|
||||
editProduct() {
|
||||
uni.navigateTo({
|
||||
url: `/pages/product/manage?productId=${this.productId}`
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #f8f9fa;
|
||||
padding-bottom: 120rpx;
|
||||
}
|
||||
|
||||
/* 图片区域 */
|
||||
.image-section {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 60rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.product-image {
|
||||
width: 300rpx;
|
||||
height: 300rpx;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 24rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* 商品信息 */
|
||||
.info-section {
|
||||
background: #fff;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.price-row {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.price {
|
||||
font-size: 48rpx;
|
||||
font-weight: bold;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.unit {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
margin-left: 8rpx;
|
||||
}
|
||||
|
||||
.product-name {
|
||||
display: block;
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.product-spec {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* 详情区域 */
|
||||
.detail-section {
|
||||
background: #fff;
|
||||
margin: 0 20rpx;
|
||||
border-radius: 20rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.detail-header {
|
||||
padding: 24rpx 30rpx;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.detail-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.detail-content {
|
||||
padding: 10rpx 0;
|
||||
}
|
||||
|
||||
.detail-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 24rpx 30rpx;
|
||||
border-bottom: 1rpx solid #f8f8f8;
|
||||
}
|
||||
|
||||
.detail-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.detail-label {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.detail-value {
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.detail-value.stock {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
/* 底部按钮 */
|
||||
.bottom-bar {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding: 20rpx 30rpx;
|
||||
background: #fff;
|
||||
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.btn-edit {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 44rpx;
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
347
src/pages/product/list.vue
Normal file
347
src/pages/product/list.vue
Normal file
@@ -0,0 +1,347 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 搜索栏 -->
|
||||
<view class="search-section">
|
||||
<view class="search-bar">
|
||||
<Icon name="search" :size="32" color="#999" />
|
||||
<input
|
||||
class="search-input"
|
||||
v-model="keyword"
|
||||
placeholder="搜索商品名称"
|
||||
placeholder-class="placeholder"
|
||||
@confirm="search"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 分类筛选 + 商品列表 -->
|
||||
<view class="content-wrapper">
|
||||
<!-- 左侧分类 -->
|
||||
<scroll-view scroll-y class="category-sidebar">
|
||||
<view class="category-item" :class="{ active: !categoryId }" @click="selectCategory('')">
|
||||
全部
|
||||
</view>
|
||||
<view v-for="cat in categories" :key="cat.categoryId" class="category-item" :class="{ active: categoryId === cat.categoryId }" @click="selectCategory(cat.categoryId)">
|
||||
{{ cat.name }}
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 右侧商品列表 -->
|
||||
<scroll-view scroll-y class="product-scroll">
|
||||
<view class="product-list">
|
||||
<view v-for="item in products" :key="item.productId" class="product-card" @click="viewDetail(item)">
|
||||
<view class="product-image">
|
||||
<Icon name="product" :size="60" color="#fff" />
|
||||
</view>
|
||||
<view class="product-content">
|
||||
<text class="product-name">{{ item.name }}</text>
|
||||
<text class="product-spec">{{ item.spec || '-' }}</text>
|
||||
<view class="product-footer">
|
||||
<view class="price-wrapper">
|
||||
<text class="price">¥{{ item.price }}</text>
|
||||
<text class="unit">/{{ item.unit }}</text>
|
||||
</view>
|
||||
<view class="stock-badge">
|
||||
<text class="stock-label">库存</text>
|
||||
<text class="stock-value">{{ getStock(item.productId) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="products.length === 0" class="empty">
|
||||
<Icon name="product" :size="80" color="#ccc" />
|
||||
<text class="empty-text">暂无商品</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="products.length > 0" class="load-more">
|
||||
<text>{{ loading ? '加载中...' : (hasMore ? '上拉加载更多' : '没有更多了') }}</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import productApi from '@/api/product'
|
||||
import stockApi from '@/api/stock'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
keyword: '',
|
||||
categoryId: '',
|
||||
categories: [],
|
||||
products: [],
|
||||
stocks: {},
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
hasMore: true,
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.loadCategories()
|
||||
this.loadProducts()
|
||||
},
|
||||
onShow() {
|
||||
// 每次进入页面都刷新数据
|
||||
this.page = 1
|
||||
this.loadProducts()
|
||||
},
|
||||
onReachBottom() {
|
||||
if (this.hasMore && !this.loading) {
|
||||
this.page++
|
||||
this.loadProducts()
|
||||
}
|
||||
},
|
||||
onPullDownRefresh() {
|
||||
this.page = 1
|
||||
this.loadProducts().then(() => {
|
||||
uni.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
async loadCategories() {
|
||||
try {
|
||||
const categories = await productApi.getCategories()
|
||||
this.categories = categories || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
async loadProducts() {
|
||||
if (this.loading) return
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await productApi.getProducts({
|
||||
categoryId: this.categoryId,
|
||||
keyword: this.keyword,
|
||||
page: this.page,
|
||||
pageSize: this.pageSize
|
||||
})
|
||||
const list = res.records || []
|
||||
if (this.page === 1) {
|
||||
this.products = list
|
||||
} else {
|
||||
this.products = [...this.products, ...list]
|
||||
}
|
||||
this.hasMore = list.length >= this.pageSize
|
||||
|
||||
// 加载库存数据
|
||||
this.loadStocks()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
async loadStocks() {
|
||||
try {
|
||||
const res = await stockApi.getStockList({ page: 1, pageSize: 500 })
|
||||
const stockList = res.records || []
|
||||
const stockMap = {}
|
||||
stockList.forEach(item => {
|
||||
stockMap[item.productId] = item.quantity || 0
|
||||
})
|
||||
this.stocks = stockMap
|
||||
} catch (e) {
|
||||
console.error('加载库存失败', e)
|
||||
}
|
||||
},
|
||||
selectCategory(id) {
|
||||
this.categoryId = id
|
||||
this.page = 1
|
||||
this.loadProducts()
|
||||
},
|
||||
search() {
|
||||
this.page = 1
|
||||
this.loadProducts()
|
||||
},
|
||||
viewDetail(item) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/product/detail?productId=${item.productId}`
|
||||
})
|
||||
},
|
||||
getStock(productId) {
|
||||
return this.stocks[productId] || 0
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.search-section {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 30rpx 30rpx 10rpx;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
border-radius: 50rpx;
|
||||
padding: 0 30rpx;
|
||||
height: 80rpx;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
margin-left: 16rpx;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
display: flex;
|
||||
height: calc(100vh - 130rpx);
|
||||
}
|
||||
|
||||
.category-sidebar {
|
||||
width: 140rpx;
|
||||
background: #fff;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
padding: 28rpx 20rpx;
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
text-align: center;
|
||||
border-left: 6rpx solid transparent;
|
||||
}
|
||||
|
||||
.category-item.active {
|
||||
background: #f8f9fa;
|
||||
color: #667eea;
|
||||
font-weight: bold;
|
||||
border-left-color: #667eea;
|
||||
}
|
||||
|
||||
.product-scroll {
|
||||
flex: 1;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.product-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.product-card {
|
||||
width: 48%;
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
margin-bottom: 20rpx;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.product-card:nth-child(odd) {
|
||||
margin-right: 4%;
|
||||
}
|
||||
|
||||
.product-image {
|
||||
height: 200rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.product-content {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.product-name {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.product-spec {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 8rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.product-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 16rpx;
|
||||
}
|
||||
|
||||
.price-wrapper {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.price {
|
||||
color: #ff4d4f;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.unit {
|
||||
color: #999;
|
||||
font-size: 22rpx;
|
||||
margin-left: 4rpx;
|
||||
}
|
||||
|
||||
.stock-badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #f0f0f0;
|
||||
border-radius: 20rpx;
|
||||
padding: 6rpx 16rpx;
|
||||
}
|
||||
|
||||
.stock-label {
|
||||
font-size: 20rpx;
|
||||
color: #999;
|
||||
margin-right: 6rpx;
|
||||
}
|
||||
|
||||
.stock-value {
|
||||
font-size: 24rpx;
|
||||
color: #333;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.empty {
|
||||
width: 100%;
|
||||
padding: 100rpx 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.load-more {
|
||||
padding: 30rpx;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
</style>
|
||||
496
src/pages/product/manage.vue
Normal file
496
src/pages/product/manage.vue
Normal file
@@ -0,0 +1,496 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 搜索栏 -->
|
||||
<view class="search-bar">
|
||||
<input
|
||||
class="search-input"
|
||||
v-model="keyword"
|
||||
placeholder="搜索商品名称"
|
||||
@confirm="search"
|
||||
/>
|
||||
<button class="search-btn" @click="search">搜索</button>
|
||||
<button class="add-btn" @click="addProduct">+</button>
|
||||
</view>
|
||||
|
||||
<!-- 商品列表 -->
|
||||
<view class="product-list">
|
||||
<view
|
||||
v-for="item in products"
|
||||
:key="item.productId"
|
||||
class="product-item"
|
||||
>
|
||||
<view class="product-info" @click="editProduct(item)">
|
||||
<text class="product-name">{{ item.name }}</text>
|
||||
<text class="product-spec">{{ item.spec || '-' }}</text>
|
||||
<view class="product-price">
|
||||
<text class="price">¥{{ item.price }}</text>
|
||||
<text class="unit">/{{ item.unit }}</text>
|
||||
</view>
|
||||
<view class="product-status">
|
||||
<text :class="['status', item.status === 1 ? 'on' : 'off']">
|
||||
{{ item.status === 1 ? '上架' : '下架' }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="product-actions">
|
||||
<view class="action-btn" @click="toggleStatus(item)">
|
||||
{{ item.status === 1 ? '下架' : '上架' }}
|
||||
</view>
|
||||
<view class="action-btn delete" @click="deleteProduct(item)">
|
||||
删除
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view v-if="products.length === 0" class="empty">
|
||||
<text>暂无商品</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 商品表单弹窗 -->
|
||||
<view class="modal" v-if="showModal">
|
||||
<view class="modal-mask" @click="closeModal"></view>
|
||||
<view class="modal-content">
|
||||
<view class="modal-header">
|
||||
<text>{{ isEdit ? '编辑商品' : '新增商品' }}</text>
|
||||
<text class="close-btn" @click="closeModal">×</text>
|
||||
</view>
|
||||
<view class="modal-body">
|
||||
<view class="form-item">
|
||||
<text class="label">商品名称*</text>
|
||||
<input class="input" v-model="form.name" placeholder="请输入商品名称" />
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="label">规格</text>
|
||||
<input class="input" v-model="form.spec" placeholder="请输入规格" />
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="label">单位*</text>
|
||||
<input class="input" v-model="form.unit" placeholder="如:个、箱、米" />
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="label">价格*</text>
|
||||
<input class="input" type="digit" v-model="form.price" placeholder="请输入价格" />
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="label">分类</text>
|
||||
<picker :range="categories" range-key="name" @change="onCategoryChange">
|
||||
<view class="picker">
|
||||
{{ form.categoryId ? getCategoryName(form.categoryId) : '请选择分类' }}
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="form-item">
|
||||
<text class="label">备注</text>
|
||||
<textarea class="textarea" v-model="form.remark" placeholder="请输入备注" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="modal-footer">
|
||||
<button class="cancel-btn" @click="closeModal">取消</button>
|
||||
<button class="confirm-btn" @click="saveProduct">保存</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import productApi from '@/api/product'
|
||||
import { canManageProduct } from '@/utils/auth'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
keyword: '',
|
||||
products: [],
|
||||
categories: [],
|
||||
showModal: false,
|
||||
isEdit: false,
|
||||
form: {
|
||||
productId: '',
|
||||
name: '',
|
||||
spec: '',
|
||||
unit: '',
|
||||
price: '',
|
||||
categoryId: '',
|
||||
remark: '',
|
||||
status: 1
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
if (!canManageProduct()) {
|
||||
uni.showToast({ title: '无权限', icon: 'none' })
|
||||
uni.navigateBack()
|
||||
return
|
||||
}
|
||||
this.loadCategories()
|
||||
this.loadProducts()
|
||||
},
|
||||
methods: {
|
||||
async loadCategories() {
|
||||
try {
|
||||
const categories = await productApi.getCategories()
|
||||
this.categories = categories || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
async loadProducts() {
|
||||
try {
|
||||
const res = await productApi.getProducts({
|
||||
keyword: this.keyword,
|
||||
page: 1,
|
||||
pageSize: 100
|
||||
})
|
||||
this.products = res.records || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
search() {
|
||||
this.loadProducts()
|
||||
},
|
||||
addProduct() {
|
||||
this.isEdit = false
|
||||
this.form = {
|
||||
productId: '',
|
||||
name: '',
|
||||
spec: '',
|
||||
unit: '',
|
||||
price: '',
|
||||
categoryId: '',
|
||||
remark: '',
|
||||
status: 1
|
||||
}
|
||||
this.showModal = true
|
||||
},
|
||||
editProduct(item) {
|
||||
this.isEdit = true
|
||||
this.form = { ...item }
|
||||
this.showModal = true
|
||||
},
|
||||
closeModal() {
|
||||
this.showModal = false
|
||||
},
|
||||
onCategoryChange(e) {
|
||||
const index = e.detail.value
|
||||
this.form.categoryId = this.categories[index].categoryId
|
||||
},
|
||||
getCategoryName(categoryId) {
|
||||
const cat = this.categories.find(c => c.categoryId === categoryId)
|
||||
return cat ? cat.name : ''
|
||||
},
|
||||
async saveProduct() {
|
||||
if (!this.form.name) {
|
||||
uni.showToast({ title: '请输入商品名称', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!this.form.unit) {
|
||||
uni.showToast({ title: '请输入单位', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!this.form.price) {
|
||||
uni.showToast({ title: '请输入价格', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.isEdit) {
|
||||
await productApi.updateProduct(this.form)
|
||||
uni.showToast({ title: '更新成功', icon: 'success' })
|
||||
} else {
|
||||
await productApi.createProduct(this.form)
|
||||
uni.showToast({ title: '创建成功', icon: 'success' })
|
||||
}
|
||||
this.closeModal()
|
||||
this.loadProducts()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
uni.showToast({ title: e.message || '操作失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
async toggleStatus(item) {
|
||||
const newStatus = item.status === 1 ? 0 : 1
|
||||
try {
|
||||
await productApi.updateProduct({
|
||||
productId: item.productId,
|
||||
status: newStatus
|
||||
})
|
||||
uni.showToast({ title: newStatus === 1 ? '已上架' : '已下架', icon: 'success' })
|
||||
this.loadProducts()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
uni.showToast({ title: '操作失败', icon: 'none' })
|
||||
}
|
||||
},
|
||||
async deleteProduct(item) {
|
||||
uni.showModal({
|
||||
title: '确认删除',
|
||||
content: `确定要删除商品"${item.name}"吗?`,
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
await productApi.deleteProduct(item.productId)
|
||||
uni.showToast({ title: '删除成功', icon: 'success' })
|
||||
this.loadProducts()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
uni.showToast({ title: '删除失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
display: flex;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
height: 70rpx;
|
||||
padding: 0 20rpx;
|
||||
background: #fff;
|
||||
border-radius: 8rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.search-btn {
|
||||
width: 120rpx;
|
||||
height: 70rpx;
|
||||
line-height: 70rpx;
|
||||
background: #3cc51f;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 8rpx;
|
||||
margin-left: 20rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
width: 70rpx;
|
||||
height: 70rpx;
|
||||
line-height: 70rpx;
|
||||
background: #1890ff;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 8rpx;
|
||||
margin-left: 20rpx;
|
||||
font-size: 40rpx;
|
||||
}
|
||||
|
||||
.product-list {
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
}
|
||||
|
||||
.product-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 24rpx;
|
||||
border-bottom: 1rpx solid #f5f5f5;
|
||||
}
|
||||
|
||||
.product-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.product-name {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.product-spec {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 8rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.product-price {
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
|
||||
.price {
|
||||
color: #ff4d4f;
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.unit {
|
||||
color: #999;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.product-status {
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.status {
|
||||
font-size: 22rpx;
|
||||
padding: 4rpx 12rpx;
|
||||
border-radius: 4rpx;
|
||||
}
|
||||
|
||||
.status.on {
|
||||
background: #e6f7ff;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
.status.off {
|
||||
background: #fff7e6;
|
||||
color: #fa8c16;
|
||||
}
|
||||
|
||||
.product-actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
padding: 8rpx 20rpx;
|
||||
background: #e6f7ff;
|
||||
color: #1890ff;
|
||||
border-radius: 4rpx;
|
||||
font-size: 24rpx;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.action-btn.delete {
|
||||
background: #fff1f0;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.empty {
|
||||
padding: 100rpx;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 弹窗 */
|
||||
.modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 999;
|
||||
}
|
||||
|
||||
.modal-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: #fff;
|
||||
border-radius: 24rpx 24rpx 0 0;
|
||||
max-height: 80vh;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 30rpx;
|
||||
border-bottom: 1rpx solid #f5f5f5;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
font-size: 48rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 30rpx;
|
||||
max-height: 60vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.label {
|
||||
display: block;
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
margin-bottom: 10rpx;
|
||||
}
|
||||
|
||||
.input {
|
||||
width: 100%;
|
||||
height: 70rpx;
|
||||
padding: 0 20rpx;
|
||||
background: #f5f5f5;
|
||||
border-radius: 8rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.picker {
|
||||
width: 100%;
|
||||
height: 70rpx;
|
||||
padding: 0 20rpx;
|
||||
background: #f5f5f5;
|
||||
border-radius: 8rpx;
|
||||
font-size: 28rpx;
|
||||
line-height: 70rpx;
|
||||
}
|
||||
|
||||
.textarea {
|
||||
width: 100%;
|
||||
height: 150rpx;
|
||||
padding: 20rpx;
|
||||
background: #f5f5f5;
|
||||
border-radius: 8rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
display: flex;
|
||||
padding: 30rpx;
|
||||
border-top: 1rpx solid #f5f5f5;
|
||||
}
|
||||
|
||||
.cancel-btn, .confirm-btn {
|
||||
flex: 1;
|
||||
height: 80rpx;
|
||||
line-height: 80rpx;
|
||||
border-radius: 40rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.cancel-btn {
|
||||
background: #f5f5f5;
|
||||
color: #666;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.confirm-btn {
|
||||
background: #3cc51f;
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
238
src/pages/product/select.vue
Normal file
238
src/pages/product/select.vue
Normal file
@@ -0,0 +1,238 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 搜索栏 -->
|
||||
<view class="search-section">
|
||||
<view class="search-bar">
|
||||
<Icon name="search" :size="32" color="#999" />
|
||||
<input
|
||||
class="search-input"
|
||||
v-model="keyword"
|
||||
placeholder="搜索商品名称"
|
||||
placeholder-class="placeholder"
|
||||
@confirm="search"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 分类 + 商品列表 -->
|
||||
<view class="content-wrapper">
|
||||
<!-- 左侧分类 -->
|
||||
<scroll-view scroll-y class="category-sidebar">
|
||||
<view class="category-item" :class="{ active: !categoryId }" @click="selectCategory('')">
|
||||
全部
|
||||
</view>
|
||||
<view v-for="cat in categories" :key="cat.categoryId" class="category-item" :class="{ active: categoryId === cat.categoryId }" @click="selectCategory(cat.categoryId)">
|
||||
{{ cat.name }}
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 右侧商品列表 -->
|
||||
<scroll-view scroll-y class="product-scroll">
|
||||
<view class="product-list">
|
||||
<view v-for="item in productList" :key="item.productId" class="product-item" @click="selectProduct(item)">
|
||||
<view class="product-info">
|
||||
<text class="product-name">{{ item.name }}</text>
|
||||
<text class="product-spec">{{ item.spec || '-' }}</text>
|
||||
</view>
|
||||
<view class="product-price">
|
||||
<text class="price">¥{{ item.price }}</text>
|
||||
<text class="unit">{{ item.unit || '个' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="productList.length === 0" class="empty">
|
||||
<Icon name="product" :size="80" color="#ccc" />
|
||||
<text class="empty-text">暂无商品</text>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import productApi from '@/api/product'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
keyword: '',
|
||||
categoryId: '',
|
||||
categories: [],
|
||||
productList: [],
|
||||
page: 1,
|
||||
pageSize: 50,
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.loadCategories()
|
||||
this.getProducts()
|
||||
},
|
||||
methods: {
|
||||
async loadCategories() {
|
||||
try {
|
||||
const categories = await productApi.getCategories()
|
||||
this.categories = categories || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
async getProducts() {
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await productApi.getProducts({
|
||||
keyword: this.keyword,
|
||||
categoryId: this.categoryId,
|
||||
page: this.page,
|
||||
pageSize: this.pageSize
|
||||
})
|
||||
this.productList = res.records || []
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
selectCategory(id) {
|
||||
this.categoryId = id
|
||||
this.page = 1
|
||||
this.getProducts()
|
||||
},
|
||||
search() {
|
||||
this.page = 1
|
||||
this.getProducts()
|
||||
},
|
||||
selectProduct(item) {
|
||||
const pages = getCurrentPages()
|
||||
const prevPage = pages[pages.length - 2]
|
||||
prevPage.$vm.addProduct(item)
|
||||
uni.navigateBack()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.search-section {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 30rpx 30rpx 10rpx;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
border-radius: 50rpx;
|
||||
padding: 0 30rpx;
|
||||
height: 80rpx;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
margin-left: 16rpx;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
display: flex;
|
||||
height: calc(100vh - 130rpx);
|
||||
}
|
||||
|
||||
.category-sidebar {
|
||||
width: 140rpx;
|
||||
background: #fff;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
padding: 28rpx 20rpx;
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
text-align: center;
|
||||
border-left: 6rpx solid transparent;
|
||||
}
|
||||
|
||||
.category-item.active {
|
||||
background: #f8f9fa;
|
||||
color: #667eea;
|
||||
font-weight: bold;
|
||||
border-left-color: #667eea;
|
||||
}
|
||||
|
||||
.product-scroll {
|
||||
flex: 1;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.product-list {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.product-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20rpx;
|
||||
padding: 30rpx;
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.product-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.product-name {
|
||||
display: block;
|
||||
font-size: 30rpx;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.product-spec {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.product-price {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.price {
|
||||
display: block;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.unit {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.empty {
|
||||
padding: 100rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
</style>
|
||||
331
src/pages/share/order.vue
Normal file
331
src/pages/share/order.vue
Normal file
@@ -0,0 +1,331 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 自定义导航 -->
|
||||
<view class="custom-nav">
|
||||
<text class="nav-title">订单详情</text>
|
||||
</view>
|
||||
|
||||
<!-- 加载中 -->
|
||||
<view class="loading" v-if="loading">
|
||||
<text>加载中...</text>
|
||||
</view>
|
||||
|
||||
<!-- 错误 -->
|
||||
<view class="error" v-else-if="error">
|
||||
<text class="error-icon">❌</text>
|
||||
<text class="error-text">{{ error }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 订单详情 -->
|
||||
<view class="order-content" v-else-if="order">
|
||||
<!-- 头部状态 -->
|
||||
<view class="order-header">
|
||||
<view class="status-badge" :class="getStatusClass(order.status)">
|
||||
{{ order.statusText }}
|
||||
</view>
|
||||
<text class="order-no">订单号: {{ order.orderNo }}</text>
|
||||
</view>
|
||||
|
||||
<!-- 客户信息 -->
|
||||
<view class="section">
|
||||
<view class="section-title">客户信息</view>
|
||||
<view class="section-content">
|
||||
<view class="info-row">
|
||||
<text class="label">客户姓名</text>
|
||||
<text class="value">{{ order.customerName }}</text>
|
||||
</view>
|
||||
<view class="info-row" v-if="order.customerPhone">
|
||||
<text class="label">联系电话</text>
|
||||
<text class="value">{{ order.customerPhone }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="label">下单时间</text>
|
||||
<text class="value">{{ formatTime(order.createdAt) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 商品明细 -->
|
||||
<view class="section">
|
||||
<view class="section-title">商品明细</view>
|
||||
<view class="items-list">
|
||||
<view class="item-row header">
|
||||
<text class="item-name">商品</text>
|
||||
<text class="item-qty">数量</text>
|
||||
<text class="item-price">单价</text>
|
||||
<text class="item-subtotal">小计</text>
|
||||
</view>
|
||||
<view
|
||||
v-for="(item, index) in order.items"
|
||||
:key="index"
|
||||
class="item-row"
|
||||
>
|
||||
<text class="item-name">{{ item.productName }}</text>
|
||||
<text class="item-qty">{{ item.quantity }}</text>
|
||||
<text class="item-price">¥{{ item.price }}</text>
|
||||
<text class="item-subtotal">¥{{ (item.price * item.quantity).toFixed(2) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 金额信息 -->
|
||||
<view class="section amount-section">
|
||||
<view class="info-row">
|
||||
<text class="label">原价合计</text>
|
||||
<text class="value">¥{{ order.totalAmount }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="label">优惠金额</text>
|
||||
<text class="value discount">-¥{{ order.discountAmount }}</text>
|
||||
</view>
|
||||
<view class="info-row actual">
|
||||
<text class="label">实付金额</text>
|
||||
<text class="value">¥{{ order.actualAmount }}</text>
|
||||
</view>
|
||||
<view class="info-row">
|
||||
<text class="label">支付方式</text>
|
||||
<text class="value">{{ order.paymentMethod }}</text>
|
||||
</view>
|
||||
<view class="info-row" v-if="order.remark">
|
||||
<text class="label">备注</text>
|
||||
<text class="value">{{ order.remark }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 店铺信息 -->
|
||||
<view class="footer">
|
||||
<text class="shop-name">建材销售管家</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
loading: true,
|
||||
error: '',
|
||||
order: null,
|
||||
orderNo: '',
|
||||
customerId: ''
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
if (options.orderNo && options.customerId) {
|
||||
this.orderNo = options.orderNo
|
||||
this.customerId = options.customerId
|
||||
this.loadOrder()
|
||||
} else {
|
||||
this.error = '参数不完整'
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async loadOrder() {
|
||||
try {
|
||||
const res = await uni.request({
|
||||
url: `https://sales.violin-work.online/api/v1/public/orders/${this.orderNo}?customerId=${this.customerId}`,
|
||||
method: 'GET'
|
||||
})
|
||||
this.loading = false
|
||||
if (res.data.code === 0) {
|
||||
this.order = res.data.data
|
||||
} else {
|
||||
this.error = res.data.message || '订单不存在'
|
||||
}
|
||||
} catch (e) {
|
||||
this.loading = false
|
||||
this.error = '加载失败,请检查网络'
|
||||
}
|
||||
},
|
||||
getStatusClass(status) {
|
||||
const map = {
|
||||
0: 'status-progress',
|
||||
1: 'status-success',
|
||||
2: 'status-cancel',
|
||||
3: 'status-refunding',
|
||||
4: 'status-refunded',
|
||||
9: 'status-returning'
|
||||
}
|
||||
return map[status] || ''
|
||||
},
|
||||
formatTime(time) {
|
||||
if (!time) return ''
|
||||
return time.substring(0, 16).replace('T', ' ')
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.custom-nav {
|
||||
height: 88rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
}
|
||||
|
||||
.nav-title {
|
||||
font-size: 32rpx;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.loading, .error {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.error-icon {
|
||||
font-size: 80rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.order-content {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.order-header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 40rpx 30rpx;
|
||||
border-radius: 20rpx 20rpx 0 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: inline-block;
|
||||
padding: 10rpx 30rpx;
|
||||
border-radius: 30rpx;
|
||||
font-size: 26rpx;
|
||||
color: #fff;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.status-progress { background: #1890ff; }
|
||||
.status-success { background: #52c41a; }
|
||||
.status-cancel { background: #999; }
|
||||
.status-refunding { background: #fa8c16; }
|
||||
.status-refunded { background: #ff4d4f; }
|
||||
.status-returning { background: #722ed1; }
|
||||
|
||||
.order-no {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.section {
|
||||
background: #fff;
|
||||
margin-bottom: 20rpx;
|
||||
border-radius: 16rpx;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
padding: 24rpx 30rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
border-bottom: 1rpx solid #f0f0f0;
|
||||
}
|
||||
|
||||
.section-content {
|
||||
padding: 0 30rpx;
|
||||
}
|
||||
|
||||
.info-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 20rpx 0;
|
||||
border-bottom: 1rpx solid #f8f8f8;
|
||||
}
|
||||
|
||||
.info-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.value {
|
||||
font-size: 26rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.value.discount {
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.info-row.actual .value {
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.items-list {
|
||||
padding: 0 30rpx;
|
||||
}
|
||||
|
||||
.item-row {
|
||||
display: flex;
|
||||
padding: 20rpx 0;
|
||||
border-bottom: 1rpx solid #f8f8f8;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.item-row.header {
|
||||
background: #f8f9fa;
|
||||
font-weight: bold;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.item-name {
|
||||
flex: 2;
|
||||
}
|
||||
|
||||
.item-qty {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.item-price {
|
||||
flex: 1;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.item-subtotal {
|
||||
flex: 1;
|
||||
text-align: right;
|
||||
color: #ff4d4f;
|
||||
}
|
||||
|
||||
.amount-section {
|
||||
padding: 20rpx 30rpx;
|
||||
}
|
||||
|
||||
.footer {
|
||||
text-align: center;
|
||||
padding: 40rpx;
|
||||
}
|
||||
|
||||
.shop-name {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
252
src/pages/stock/flow.vue
Normal file
252
src/pages/stock/flow.vue
Normal file
@@ -0,0 +1,252 @@
|
||||
<template>
|
||||
<view class="stock-flow">
|
||||
<!-- 筛选 -->
|
||||
<view class="filter-bar">
|
||||
<picker
|
||||
mode="selector"
|
||||
:range="typeOptions"
|
||||
range-key="label"
|
||||
@change="onTypeChange"
|
||||
>
|
||||
<view class="filter-picker">
|
||||
{{ selectedTypeLabel }}
|
||||
</view>
|
||||
</picker>
|
||||
<picker
|
||||
mode="selector"
|
||||
:range="productList"
|
||||
range-key="name"
|
||||
@change="onProductChange"
|
||||
>
|
||||
<view class="filter-picker">
|
||||
{{ selectedProduct ? selectedProduct.name : '全部商品' }}
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
<!-- 流水列表 -->
|
||||
<scroll-view scroll-y class="flow-scroll">
|
||||
<view
|
||||
v-for="item in flowList"
|
||||
:key="item.flowId"
|
||||
class="flow-item"
|
||||
>
|
||||
<view class="flow-left">
|
||||
<text class="flow-type" :class="item.type === 1 ? 'in' : 'out'">
|
||||
{{ item.type === 1 ? '入库' : item.type === 2 ? '出库' : '调整' }}
|
||||
</text>
|
||||
<text class="flow-product">{{ item.productName || '商品' + item.productId }}</text>
|
||||
<text class="flow-time">{{ formatTime(item.createdAt) }}</text>
|
||||
</view>
|
||||
<view class="flow-right">
|
||||
<text class="flow-quantity" :class="item.type === 1 ? 'in' : 'out'">
|
||||
{{ item.type === 1 ? '+' : '-' }}{{ item.quantity }}
|
||||
</text>
|
||||
<text class="flow-remark" v-if="item.remark">{{ item.remark }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="flowList.length === 0" class="empty">
|
||||
<text>暂无流水记录</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import stockApi from '@/api/stock'
|
||||
import productApi from '@/api/product'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
typeOptions: [
|
||||
{ label: '全部类型', value: null },
|
||||
{ label: '入库', value: 1 },
|
||||
{ label: '出库', value: 2 },
|
||||
{ label: '调整', value: 3 }
|
||||
],
|
||||
selectedType: null,
|
||||
selectedTypeLabel: '全部类型',
|
||||
productList: [],
|
||||
selectedProduct: null,
|
||||
flowList: [],
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.getProducts()
|
||||
this.getFlowList()
|
||||
},
|
||||
onPullDownRefresh() {
|
||||
this.page = 1
|
||||
Promise.all([this.getProducts(), this.getFlowList()]).then(() => {
|
||||
uni.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
onReachBottom() {
|
||||
if (!this.loading) {
|
||||
this.page++
|
||||
this.getFlowList(true)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async getProducts() {
|
||||
try {
|
||||
const res = await productApi.getProducts({ page: 1, pageSize: 100 })
|
||||
if (res.code === 0) {
|
||||
this.productList = [{ productId: '', name: '全部商品' }, ...(res.data.records || [])]
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载商品失败', e)
|
||||
}
|
||||
},
|
||||
async getFlowList(append = false) {
|
||||
this.loading = true
|
||||
try {
|
||||
const params = {
|
||||
page: this.page,
|
||||
pageSize: this.pageSize
|
||||
}
|
||||
if (this.selectedType) {
|
||||
params.type = this.selectedType
|
||||
}
|
||||
if (this.selectedProduct && this.selectedProduct.productId) {
|
||||
params.productId = this.selectedProduct.productId
|
||||
}
|
||||
|
||||
const res = await stockApi.getStockFlow(params)
|
||||
if (res.code === 0) {
|
||||
this.flowList = append ? [...this.flowList, ...res.data.records] : res.data.records
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
onTypeChange(e) {
|
||||
const item = this.typeOptions[e.detail.value]
|
||||
this.selectedType = item.value
|
||||
this.selectedTypeLabel = item.label
|
||||
this.page = 1
|
||||
this.getFlowList()
|
||||
},
|
||||
onProductChange(e) {
|
||||
this.selectedProduct = this.productList[e.detail.value]
|
||||
this.page = 1
|
||||
this.getFlowList()
|
||||
},
|
||||
formatTime(time) {
|
||||
if (!time) return ''
|
||||
const date = new Date(time)
|
||||
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.stock-flow {
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.filter-bar {
|
||||
display: flex;
|
||||
padding: 20rpx;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.filter-picker {
|
||||
flex: 1;
|
||||
height: 64rpx;
|
||||
line-height: 64rpx;
|
||||
text-align: center;
|
||||
background: #f5f5f5;
|
||||
border-radius: 8rpx;
|
||||
margin: 0 10rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
.flow-scroll {
|
||||
height: calc(100vh - 180rpx);
|
||||
}
|
||||
|
||||
.flow-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin: 20rpx;
|
||||
padding: 24rpx;
|
||||
background: #fff;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.flow-left {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.flow-type {
|
||||
display: inline-block;
|
||||
padding: 4rpx 12rpx;
|
||||
font-size: 24rpx;
|
||||
border-radius: 4rpx;
|
||||
margin-right: 16rpx;
|
||||
}
|
||||
|
||||
.flow-type.in {
|
||||
background: #e6f7e6;
|
||||
color: #3cc51f;
|
||||
}
|
||||
|
||||
.flow-type.out {
|
||||
background: #fff0e6;
|
||||
color: #ff6600;
|
||||
}
|
||||
|
||||
.flow-product {
|
||||
display: block;
|
||||
font-size: 28rpx;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.flow-time {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.flow-right {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.flow-quantity {
|
||||
display: block;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.flow-quantity.in {
|
||||
color: #3cc51f;
|
||||
}
|
||||
|
||||
.flow-quantity.out {
|
||||
color: #ff6600;
|
||||
}
|
||||
|
||||
.flow-remark {
|
||||
display: block;
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 8rpx;
|
||||
max-width: 200rpx;
|
||||
}
|
||||
|
||||
.empty {
|
||||
text-align: center;
|
||||
padding: 100rpx;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
606
src/pages/stock/in.vue
Normal file
606
src/pages/stock/in.vue
Normal file
@@ -0,0 +1,606 @@
|
||||
<template>
|
||||
<view class="page">
|
||||
<!-- 分类 + 商品列表 -->
|
||||
<view class="content-wrapper">
|
||||
<!-- 左侧分类 -->
|
||||
<scroll-view scroll-y class="category-sidebar">
|
||||
<view
|
||||
class="category-item"
|
||||
:class="{ active: !categoryId }"
|
||||
@click="selectCategory('')"
|
||||
>
|
||||
全部
|
||||
</view>
|
||||
<view
|
||||
v-for="cat in categories"
|
||||
:key="cat.categoryId"
|
||||
class="category-item"
|
||||
:class="{ active: categoryId === cat.categoryId }"
|
||||
@click="selectCategory(cat.categoryId)"
|
||||
>
|
||||
{{ cat.name }}
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 右侧商品列表 -->
|
||||
<scroll-view scroll-y class="product-scroll">
|
||||
<view class="product-list">
|
||||
<view
|
||||
v-for="item in productList"
|
||||
:key="item.productId"
|
||||
class="product-item"
|
||||
@click="openQuantityPopup(item)"
|
||||
>
|
||||
<view class="product-info">
|
||||
<text class="product-name">{{ item.name }}</text>
|
||||
<text class="product-spec">{{ item.spec || '-' }}</text>
|
||||
</view>
|
||||
<view class="product-add">
|
||||
<text class="add-icon">+</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="productList.length === 0" class="empty">
|
||||
<text class="empty-icon">📭</text>
|
||||
<text class="empty-text">暂无商品</text>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<!-- 已添加商品列表 -->
|
||||
<view class="selected-section" v-if="selectedItems.length > 0">
|
||||
<view class="selected-header">
|
||||
<text class="selected-title">已选择商品</text>
|
||||
<text class="selected-count">{{ selectedItems.length }} 项</text>
|
||||
</view>
|
||||
<scroll-view scroll-x class="selected-list">
|
||||
<view
|
||||
v-for="(item, index) in selectedItems"
|
||||
:key="index"
|
||||
class="selected-item"
|
||||
>
|
||||
<view class="selected-info">
|
||||
<text class="selected-name">{{ item.productName }}</text>
|
||||
<text class="selected-qty">× {{ item.quantity }}</text>
|
||||
</view>
|
||||
<text class="selected-delete" @click="removeItem(index)">×</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<!-- 底部提交按钮 -->
|
||||
<view class="submit-bar" v-if="selectedItems.length > 0">
|
||||
<view class="submit-info">
|
||||
<text class="submit-label">共 {{ totalQuantity }} 件</text>
|
||||
</view>
|
||||
<button class="submit-btn" @click="submit" :disabled="submitting">
|
||||
{{ submitting ? '提交中...' : '确认入库' }}
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<!-- 数量填写弹窗 -->
|
||||
<view class="popup-mask" v-if="showPopup" @click="closePopup"></view>
|
||||
<view class="popup-content" v-if="showPopup">
|
||||
<view class="popup-header">
|
||||
<text class="popup-title">{{ currentProduct.name }}</text>
|
||||
<text class="popup-close" @click="closePopup">×</text>
|
||||
</view>
|
||||
<view class="popup-body">
|
||||
<view class="popup-spec" v-if="currentProduct.spec">
|
||||
规格: {{ currentProduct.spec }}
|
||||
</view>
|
||||
<view class="popup-qty">
|
||||
<text class="qty-label">入库数量</text>
|
||||
<view class="qty-input-wrapper">
|
||||
<text class="qty-minus" @click="qtyMinus">-</text>
|
||||
<input
|
||||
class="qty-input"
|
||||
type="number"
|
||||
v-model="inputQuantity"
|
||||
/>
|
||||
<text class="qty-plus" @click="qtyPlus">+</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="popup-remark">
|
||||
<text class="remark-label">备注(可选)</text>
|
||||
<input
|
||||
class="remark-input"
|
||||
v-model="inputRemark"
|
||||
placeholder="填写备注"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<view class="popup-footer">
|
||||
<button class="popup-btn cancel" @click="closePopup">取消</button>
|
||||
<button class="popup-btn confirm" @click="confirmAdd">确定</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import stockApi from '@/api/stock'
|
||||
import productApi from '@/api/product'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
categoryId: '',
|
||||
categories: [],
|
||||
productList: [],
|
||||
page: 1,
|
||||
pageSize: 50,
|
||||
loading: false,
|
||||
|
||||
// 已选择的商品
|
||||
selectedItems: [],
|
||||
|
||||
// 弹窗相关
|
||||
showPopup: false,
|
||||
currentProduct: {},
|
||||
inputQuantity: 1,
|
||||
inputRemark: '',
|
||||
|
||||
// 提交状态
|
||||
submitting: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
totalQuantity() {
|
||||
return this.selectedItems.reduce((sum, item) => sum + item.quantity, 0)
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.loadCategories()
|
||||
this.getProducts()
|
||||
},
|
||||
methods: {
|
||||
async loadCategories() {
|
||||
try {
|
||||
const categories = await productApi.getCategories()
|
||||
this.categories = categories || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
async getProducts() {
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await productApi.getProducts({
|
||||
categoryId: this.categoryId,
|
||||
page: this.page,
|
||||
pageSize: this.pageSize
|
||||
})
|
||||
this.productList = res.records || []
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
selectCategory(id) {
|
||||
this.categoryId = id
|
||||
this.page = 1
|
||||
this.getProducts()
|
||||
},
|
||||
openQuantityPopup(product) {
|
||||
this.currentProduct = product
|
||||
this.inputQuantity = 1
|
||||
this.inputRemark = ''
|
||||
this.showPopup = true
|
||||
},
|
||||
closePopup() {
|
||||
this.showPopup = false
|
||||
},
|
||||
qtyMinus() {
|
||||
if (this.inputQuantity > 1) {
|
||||
this.inputQuantity--
|
||||
}
|
||||
},
|
||||
qtyPlus() {
|
||||
this.inputQuantity++
|
||||
},
|
||||
confirmAdd() {
|
||||
if (this.inputQuantity <= 0) {
|
||||
uni.showToast({ title: '请输入有效数量', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否已存在,存在则累加
|
||||
const existsIndex = this.selectedItems.findIndex(
|
||||
item => item.productId === this.currentProduct.productId
|
||||
)
|
||||
|
||||
if (existsIndex > -1) {
|
||||
this.selectedItems[existsIndex].quantity += parseInt(this.inputQuantity)
|
||||
this.selectedItems[existsIndex].remark = this.inputRemark || this.selectedItems[existsIndex].remark
|
||||
} else {
|
||||
this.selectedItems.push({
|
||||
productId: this.currentProduct.productId,
|
||||
productName: this.currentProduct.name,
|
||||
quantity: parseInt(this.inputQuantity),
|
||||
remark: this.inputRemark
|
||||
})
|
||||
}
|
||||
|
||||
this.closePopup()
|
||||
uni.showToast({ title: '已添加', icon: 'success' })
|
||||
},
|
||||
removeItem(index) {
|
||||
this.selectedItems.splice(index, 1)
|
||||
},
|
||||
async submit() {
|
||||
if (this.selectedItems.length === 0) {
|
||||
uni.showToast({ title: '请先添加商品', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
this.submitting = true
|
||||
try {
|
||||
// 逐个入库
|
||||
for (const item of this.selectedItems) {
|
||||
await stockApi.stockIn({
|
||||
productId: item.productId,
|
||||
quantity: item.quantity,
|
||||
remark: item.remark || ''
|
||||
})
|
||||
}
|
||||
|
||||
uni.showToast({ title: '入库成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '入库失败', icon: 'none' })
|
||||
} finally {
|
||||
this.submitting = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.page {
|
||||
min-height: 100vh;
|
||||
background: #f8f9fa;
|
||||
padding-bottom: 180rpx;
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
display: flex;
|
||||
height: calc(100vh - 200rpx);
|
||||
}
|
||||
|
||||
/* 左侧分类 */
|
||||
.category-sidebar {
|
||||
width: 140rpx;
|
||||
background: #fff;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.category-item {
|
||||
padding: 28rpx 20rpx;
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
text-align: center;
|
||||
border-left: 6rpx solid transparent;
|
||||
}
|
||||
|
||||
.category-item.active {
|
||||
background: #f8f9fa;
|
||||
color: #667eea;
|
||||
font-weight: bold;
|
||||
border-left-color: #667eea;
|
||||
}
|
||||
|
||||
/* 右侧商品 */
|
||||
.product-scroll {
|
||||
flex: 1;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.product-list {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.product-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20rpx;
|
||||
padding: 30rpx;
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.product-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.product-name {
|
||||
display: block;
|
||||
font-size: 30rpx;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.product-spec {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.product-add {
|
||||
width: 60rpx;
|
||||
height: 60rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 30rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.add-icon {
|
||||
font-size: 36rpx;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.empty {
|
||||
padding: 100rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 80rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 已选择商品 */
|
||||
.selected-section {
|
||||
position: fixed;
|
||||
bottom: 120rpx;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: #fff;
|
||||
padding: 20rpx 30rpx;
|
||||
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.selected-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.selected-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.selected-count {
|
||||
font-size: 24rpx;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.selected-list {
|
||||
white-space: nowrap;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.selected-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 12rpx;
|
||||
padding: 16rpx 24rpx;
|
||||
margin-right: 16rpx;
|
||||
}
|
||||
|
||||
.selected-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.selected-name {
|
||||
font-size: 24rpx;
|
||||
color: #fff;
|
||||
max-width: 200rpx;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.selected-qty {
|
||||
font-size: 22rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
margin-top: 4rpx;
|
||||
}
|
||||
|
||||
.selected-delete {
|
||||
margin-left: 16rpx;
|
||||
font-size: 32rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
padding: 8rpx;
|
||||
}
|
||||
|
||||
/* 底部提交 */
|
||||
.submit-bar {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 20rpx 30rpx;
|
||||
background: #fff;
|
||||
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.submit-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.submit-label {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
width: 240rpx;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 44rpx;
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
box-shadow: 0 8rpx 30rpx rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
/* 弹窗 */
|
||||
.popup-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.popup-content {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: #fff;
|
||||
border-radius: 32rpx 32rpx 0 0;
|
||||
padding: 40rpx 30rpx;
|
||||
padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
|
||||
z-index: 101;
|
||||
}
|
||||
|
||||
.popup-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.popup-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.popup-close {
|
||||
font-size: 48rpx;
|
||||
color: #999;
|
||||
padding: 10rpx;
|
||||
}
|
||||
|
||||
.popup-spec {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.popup-qty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.qty-label {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
width: 160rpx;
|
||||
}
|
||||
|
||||
.qty-input-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: #f5f5f5;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.qty-minus, .qty-plus {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 40rpx;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.qty-input {
|
||||
width: 120rpx;
|
||||
height: 80rpx;
|
||||
text-align: center;
|
||||
font-size: 32rpx;
|
||||
background: transparent;
|
||||
border-left: 1rpx solid #eee;
|
||||
border-right: 1rpx solid #eee;
|
||||
}
|
||||
|
||||
.popup-remark {
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.remark-label {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
display: block;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.remark-input {
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
background: #f5f5f5;
|
||||
border-radius: 12rpx;
|
||||
padding: 0 20rpx;
|
||||
font-size: 28rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.popup-footer {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.popup-btn {
|
||||
flex: 1;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
border-radius: 44rpx;
|
||||
font-size: 30rpx;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.popup-btn.cancel {
|
||||
background: #f5f5f5;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.popup-btn.confirm {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
box-shadow: 0 8rpx 30rpx rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
</style>
|
||||
302
src/pages/stock/list.vue
Normal file
302
src/pages/stock/list.vue
Normal file
@@ -0,0 +1,302 @@
|
||||
<template>
|
||||
<view class="stock-list">
|
||||
<!-- 搜索栏 -->
|
||||
<view class="search-section">
|
||||
<view class="search-bar">
|
||||
<text class="search-icon">🔍</text>
|
||||
<input
|
||||
class="search-input"
|
||||
v-model="keyword"
|
||||
placeholder="搜索商品名称"
|
||||
placeholder-class="placeholder"
|
||||
@confirm="search"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 库存列表 -->
|
||||
<scroll-view scroll-y class="stock-scroll">
|
||||
<view
|
||||
v-for="item in stockList"
|
||||
:key="item.stockId"
|
||||
class="stock-card"
|
||||
@click="goToDetail(item)"
|
||||
>
|
||||
<view class="stock-left">
|
||||
<view class="product-icon">📦</view>
|
||||
<view class="stock-info">
|
||||
<text class="product-name">{{ item.productName || '商品' + item.productId }}</text>
|
||||
<text class="warehouse">🏠 仓库: {{ item.warehouseId || '默认' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="stock-right">
|
||||
<view class="stock-num">
|
||||
<text class="quantity">{{ item.quantity || 0 }}</text>
|
||||
<text class="label">库存</text>
|
||||
</view>
|
||||
<text class="locked" v-if="item.lockedQuantity > 0">🔒 锁定: {{ item.lockedQuantity }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-if="stockList.length === 0" class="empty">
|
||||
<text class="empty-icon">📭</text>
|
||||
<text class="empty-text">暂无库存数据</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 底部操作 -->
|
||||
<view class="bottom-action">
|
||||
<button class="action-btn primary" @click="goToIn">📥 入库</button>
|
||||
<button class="action-btn" @click="goToFlow">📊 流水</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import stockApi from '@/api/stock'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
keyword: '',
|
||||
stockList: [],
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.getStockList()
|
||||
},
|
||||
onShow() {
|
||||
// 每次进入页面都刷新数据
|
||||
this.page = 1
|
||||
this.getStockList()
|
||||
},
|
||||
onPullDownRefresh() {
|
||||
this.page = 1
|
||||
this.getStockList().then(() => {
|
||||
uni.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
onReachBottom() {
|
||||
if (!this.loading) {
|
||||
this.page++
|
||||
this.getStockList(true)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async getStockList(append = false) {
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await stockApi.getStockList({
|
||||
keyword: this.keyword,
|
||||
page: this.page,
|
||||
pageSize: this.pageSize
|
||||
})
|
||||
if (res.code === 0) {
|
||||
this.stockList = append ? [...this.stockList, ...res.data.records] : res.data.records
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({ title: '加载失败', icon: 'none' })
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
search() {
|
||||
this.page = 1
|
||||
this.getStockList()
|
||||
},
|
||||
goToDetail(item) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/stock/detail?productId=${item.productId}`
|
||||
})
|
||||
},
|
||||
goToIn() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/stock/in'
|
||||
})
|
||||
},
|
||||
goToFlow() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/stock/flow'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 全局 */
|
||||
.stock-list {
|
||||
min-height: 100vh;
|
||||
background: #f8f9fa;
|
||||
padding-bottom: 120rpx;
|
||||
}
|
||||
|
||||
/* 搜索区域 */
|
||||
.search-section {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 30rpx 30rpx 20rpx;
|
||||
}
|
||||
|
||||
.search-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
border-radius: 50rpx;
|
||||
padding: 0 30rpx;
|
||||
height: 80rpx;
|
||||
}
|
||||
|
||||
.search-icon {
|
||||
font-size: 32rpx;
|
||||
margin-right: 16rpx;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.placeholder {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 库存列表 */
|
||||
.stock-scroll {
|
||||
height: calc(100vh - 280rpx);
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.stock-card {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 30rpx;
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
margin-bottom: 20rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.stock-card:active {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
.stock-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.product-icon {
|
||||
width: 90rpx;
|
||||
height: 90rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 20rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 44rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.stock-info {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.product-name {
|
||||
display: block;
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.warehouse {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.stock-right {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.stock-num {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.quantity {
|
||||
display: block;
|
||||
font-size: 44rpx;
|
||||
font-weight: bold;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
}
|
||||
|
||||
.label {
|
||||
font-size: 22rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.locked {
|
||||
display: block;
|
||||
font-size: 22rpx;
|
||||
color: #fa8c16;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
/* 空状态 */
|
||||
.empty {
|
||||
padding: 100rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.empty-icon {
|
||||
font-size: 100rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 底部操作 */
|
||||
.bottom-action {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
display: flex;
|
||||
padding: 20rpx 30rpx;
|
||||
background: #fff;
|
||||
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
flex: 1;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
font-size: 30rpx;
|
||||
border-radius: 44rpx;
|
||||
margin: 0 10rpx;
|
||||
background: #f5f5f5;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.action-btn.primary {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
box-shadow: 0 8rpx 30rpx rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
</style>
|
||||
51
src/utils/auth.js
Normal file
51
src/utils/auth.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 权限判断工具
|
||||
*/
|
||||
|
||||
export function getRole() {
|
||||
return uni.getStorageSync('role') || 'guest'
|
||||
}
|
||||
|
||||
export function isAdmin() {
|
||||
return getRole() === 'admin'
|
||||
}
|
||||
|
||||
export function isSales() {
|
||||
return getRole() === 'sales'
|
||||
}
|
||||
|
||||
export function isCustomer() {
|
||||
return getRole() === 'customer'
|
||||
}
|
||||
|
||||
export function isGuest() {
|
||||
return getRole() === 'guest' || !uni.getStorageSync('token')
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有商品维护权限(仅管理员)
|
||||
*/
|
||||
export function canManageProduct() {
|
||||
return isAdmin()
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有创建订单权限(管理员/销售)
|
||||
*/
|
||||
export function canCreateOrder() {
|
||||
return isAdmin() || isSales()
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有查看全部订单权限(管理员/销售)
|
||||
*/
|
||||
export function canViewAllOrders() {
|
||||
return isAdmin() || isSales()
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可以查看首页统计(管理员/销售)
|
||||
*/
|
||||
export function canViewStats() {
|
||||
return isAdmin() || isSales()
|
||||
}
|
||||
22
vite.config.js
Normal file
22
vite.config.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import uni from '@dcloudio/vite-plugin-uni'
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd())
|
||||
|
||||
return {
|
||||
plugins: [
|
||||
uni()
|
||||
],
|
||||
root: '.',
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: './index.html'
|
||||
}
|
||||
},
|
||||
define: {
|
||||
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(env.VITE_API_BASE_URL || 'https://sales.violin-work.online/api/v1'),
|
||||
'import.meta.env.VITE_H5_BASE_URL': JSON.stringify(env.VITE_H5_BASE_URL || 'https://sales.violin-work.online')
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user