Compare commits

...

81 Commits

Author SHA1 Message Date
Agent
12da38d65d Merge branch 'dev' of https://gitea.violin-work.online/sales/todo-frontend into dev 2026-03-27 02:03:35 +00:00
Agent
2cb329edce 优化功能菜单布局:手机端2列,PC端横版 2026-03-27 02:02:33 +00:00
ca0f906590 更新 .drone.yml
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 01:49:16 +00:00
Agent
06145d27a5 新增种类管理功能:首页菜单+种类管理页面 2026-03-27 01:20:04 +00:00
Agent
39c119ffe4 优化商品选择页面:左侧分类栏+右侧商品列表
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 00:58:12 +00:00
Agent
244caf9bc6 fix: 修复product/list.vue模板语法错误
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-26 14:39:13 +00:00
Agent
84e2259be4 优化商品列表:左侧分类栏+右侧商品 2026-03-26 14:27:02 +00:00
Agent
f8ce079a4b 优化商品列表页:分类筛选移至左侧垂直显示
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-26 14:18:50 +00:00
Agent
798f6a97a8 优化图标组件,使用更干净的符号
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-26 13:48:56 +00:00
Agent
02c4b02092 添加SVG图标组件,替换emoji图标为矢量图标
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-26 13:47:50 +00:00
Agent
3dfba3d804 优化所有页面UI设计:登录页、商品列表、订单列表、创建订单、库存管理 2026-03-26 12:59:03 +00:00
Agent
fe35a48123 优化首页UI,美化界面设计
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-26 12:53:23 +00:00
Agent
e32758ecc5 fix: 登录时保存username,修复订单列表无数据 2026-03-25 16:34:32 +00:00
d834188c08 更新 .drone.yml
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-25 16:25:41 +00:00
Agent
8b49c32f63 fix: 修复语法错误,多余的花括号 2026-03-25 16:24:07 +00:00
Agent
aa36029818 fix: 修复methods重复定义问题
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-25 16:19:04 +00:00
Agent
1cb5f6b646 feat: 订单状态筛选+编辑功能
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-25 15:59:51 +00:00
Agent
34054065ed fix: 添加创建订单所需的用户头信息
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-25 15:41:07 +00:00
Agent
d8ba777fb4 fix: 修复商品选择页数据获取
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-25 15:03:58 +00:00
Agent
b7b11207ab fix: 加载客户列表数据
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-25 14:56:09 +00:00
Agent
af232815d3 fix: 库存页面从tabBar移除
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-24 15:45:44 +00:00
Agent
1e820fa0ca feat: Ingress配置/api转发到后端
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-24 15:24:47 +00:00
Agent
46e83862f4 fix: API域名改为sales.violin-work.online
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-24 15:19:10 +00:00
Agent
3e693882d0 fix: 添加customer.js,修复stock.js参数
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-24 15:11:20 +00:00
Agent
6cdfc47250 feat: 添加商品选择页面
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-24 11:57:19 +00:00
Agent
cd9e2edc8e fix: 修复重复代码
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-24 10:01:41 +00:00
Agent
3ee4a6cccd fix: 用picker替代popup修复添加商品
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-24 09:59:49 +00:00
Agent
295c61071b fix: 修复创建订单按钮跳转错误
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-24 09:40:11 +00:00
Agent
508abbc375 fix: 移除创建订单页面隐藏配置
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-24 09:12:22 +00:00
Agent
bf2033be21 fix: 订单列表使用switchTab跳转
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-24 09:03:28 +00:00
Agent
3a8f21effa fix: 首页库存管理跳转
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-24 08:55:40 +00:00
Agent
24375d6d00 feat: 库存管理前端页面
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-24 04:18:12 +00:00
Agent
f6e9c28f71 fix: 改用 kubectl set image 避免权限问题
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-24 01:05:48 +00:00
Agent
33d2532843 fix: 修复 sed 命令语法
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-24 01:02:50 +00:00
Agent
f581283155 fix: 修复 sed 权限问题
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-24 00:59:45 +00:00
Agent
3f317dd4cf fix: 修复 Vue 模板语法错误
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-24 00:57:35 +00:00
Agent
b79f951514 feat: 添加商品管理页面和角色权限控制
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-24 00:53:43 +00:00
Agent
17f6b49e5d feat: 添加假登录和权限控制
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-24 00:36:40 +00:00
Agent
7ca2e1d5a4 fix: 登录改为账号密码+微信登录
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-24 00:25:10 +00:00
Agent
af10a0b6f4 fix: dev 自动替换镜像 tag 并重启
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-23 15:57:54 +00:00
Agent
e68dc71611 fix: dev 模式始终拉取最新镜像
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-23 15:42:19 +00:00
Agent
2643027475 style: 美化登录页面
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-23 15:39:22 +00:00
a41773a801 更新 k8s/ingress.yaml
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-23 15:35:22 +00:00
90689cd3ac 更新 Dockerfile
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-23 15:28:27 +00:00
Agent
adc4576d13 fix: 修正 main.js 为 uni-app 3.x 写法
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-23 15:25:06 +00:00
Agent
7690907a45 fix: manifest.json 和 pages.json 放回 src 目录
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-23 15:21:46 +00:00
Agent
989e18fab8 fix: 修正 index.html 引用路径,移动配置文件到根目录
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-23 15:18:28 +00:00
Agent
b9823b01e5 fix: 移动 index.html 到根目录
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-23 15:16:44 +00:00
Agent
ead8818774 fix: 添加 index.html 和 vite.config.js
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-23 15:14:44 +00:00
2d734aa302 更新 .drone.yml
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-23 15:09:59 +00:00
a4b97b7298 更新 .drone.yml 2026-03-23 15:05:16 +00:00
Agent
a39c9ee8f7 fix: 调整项目结构,添加 src 目录 2026-03-23 15:03:37 +00:00
Agent
0b03f81b55 fix: 修正 uni-app 版本为 3.0.0-4080720251210001
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-23 14:53:12 +00:00
Agent
83f316f49b fix: 更新 uni-app 版本
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-23 14:50:57 +00:00
26cb69ed61 更新 .drone.yml
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-23 14:45:05 +00:00
926af54fed 更新 .drone.yml 2026-03-23 14:40:48 +00:00
934a997984 更新 k8s/ingress.yaml 2026-03-23 14:26:21 +00:00
9d22690f08 添加 k8s/ingress.yaml 2026-03-23 14:21:24 +00:00
Agent
38d68063a2 chore: 改用 node:22-bookworm 2026-03-23 13:45:59 +00:00
Agent
efac494063 chore: 添加 node_modules 缓存 2026-03-23 13:37:39 +00:00
Agent
3dc5b2f4e7 chore: 更新 node 到 24 版本 2026-03-23 13:30:56 +00:00
Agent
c4d83d18bb chore: 参照后端配置,使用 kaniko 构建,添加 k8s 部署文件 2026-03-23 13:27:55 +00:00
Agent
63da0788f8 fix: move clone disable to correct position 2026-03-21 14:46:10 +00:00
Agent
370a76bb45 fix: use disable instead of disabled 2026-03-21 14:35:00 +00:00
Agent
9fdf999835 fix: correct clone indentation 2026-03-21 14:31:54 +00:00
Agent
49155a7542 fix: disable default clone 2026-03-21 14:30:08 +00:00
Agent
1aa9894573 fix: add unique step names per pipeline 2026-03-21 14:27:55 +00:00
Agent
65876f401a chore: use custom git-alpine image 2026-03-21 14:24:32 +00:00
Agent
ef66e6c173 fix: add clone step with git credentials 2026-03-21 14:14:02 +00:00
Agent
15a3b7362d Clean config 2026-03-21 02:10:46 +00:00
Agent
061ccfe2c3 Use drone namespace 2026-03-21 01:26:30 +00:00
Agent
b9c032a3c5 Add git credentials 2026-03-20 16:38:11 +00:00
Agent
4d20d3e24d Simplify drone config 2026-03-20 16:25:25 +00:00
Agent
09377de909 Use private kubectl image 2026-03-20 16:17:45 +00:00
Agent
48ffb2ae79 Fix image names 2026-03-20 15:48:10 +00:00
Agent
92b7d69517 Fix Drone variable syntax to ${DRONE_COMMIT_SHA} 2026-03-20 15:35:10 +00:00
Agent
fab2216538 Use violin namespace for images 2026-03-20 15:32:52 +00:00
Agent
4df7cdc9c6 Fix Drone variable: DRONE_COMMIT_SHA 2026-03-20 15:27:40 +00:00
Agent
ebfe16a929 Change pipeline type to kubernetes 2026-03-20 15:18:22 +00:00
Agent
d21b35a02d Add K8s deployment in CI/CD 2026-03-20 14:29:31 +00:00
Agent
0ba6a5389d Add .drone.yml for CI/CD 2026-03-20 14:23:44 +00:00
35 changed files with 4313 additions and 1295 deletions

112
.drone.yml Normal file
View 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
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
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

7
Dockerfile Normal file
View 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;"]

14
index.html Normal file
View 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
View 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
View 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
View File

@@ -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()

View File

@@ -9,16 +9,16 @@
"build:mp-weixin": "uni build -p mp-weixin" "build:mp-weixin": "uni build -p mp-weixin"
}, },
"dependencies": { "dependencies": {
"@dcloudio/uni-app": "^2.0.0", "@dcloudio/uni-app": "3.0.0-4080720251210001",
"@dcloudio/uni-h5": "^2.0.0", "@dcloudio/uni-h5": "3.0.0-4080720251210001",
"@dcloudio/uni-mp-weixin": "^2.0.0", "@dcloudio/uni-mp-weixin": "3.0.0-4080720251210001",
"@dcloudio/uni-mp-alipay": "^2.0.0", "@dcloudio/uni-mp-alipay": "3.0.0-4080720251210001",
"vue": "^3.2.45" "vue": "^3.4.0"
}, },
"devDependencies": { "devDependencies": {
"@dcloudio/types": "^3.0.16", "@dcloudio/types": "^3.4.0",
"@dcloudio/uni-cli-shared": "^2.0.0", "@dcloudio/uni-cli-shared": "3.0.0-4080720251210001",
"@dcloudio/vite-plugin-uni": "^2.0.0", "@dcloudio/vite-plugin-uni": "3.0.0-4080720251210001",
"vite": "^4.0.0" "vite": "^5.0.0"
} }
} }

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -18,6 +18,13 @@ export default {
return api.request('/auth/phone-login', 'POST', { phone, code }) 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
View 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')
}
}

View File

@@ -1,9 +1,11 @@
// API基础配置 // API基础配置
const BASE_URL = 'http://localhost:8080/api/v1' const BASE_URL = 'https://sales.violin-work.online/api/v1'
// 请求拦截器 // 请求拦截器
const request = (url, method, data = {}) => { const request = (url, method, data = {}) => {
const token = uni.getStorageSync('token') const token = uni.getStorageSync('token')
const userId = uni.getStorageSync('userId') || ''
const username = uni.getStorageSync('username') || ''
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.request({ uni.request({
@@ -12,7 +14,9 @@ const request = (url, method, data = {}) => {
data: data, data: data,
header: { header: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': token ? `Bearer ${token}` : '' 'Authorization': token ? `Bearer ${token}` : '',
'X-User-Id': userId,
'X-Username': username
}, },
success: (res) => { success: (res) => {
if (res.data.code === 0) { if (res.data.code === 0) {

View File

@@ -53,6 +53,20 @@ export default {
return api.request(`/orders/${id}/refund`, 'PUT') 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
View 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', data)
},
/**
* 库存调整
*/
adjustStock(data) {
return api.request('/stock/adjust', 'POST', data)
},
/**
* 获取库存流水
*/
getStockFlow(params) {
return api.request('/stock/flow', 'GET', params)
}
}

88
src/components/Icon.vue Normal file
View File

@@ -0,0 +1,88 @@
<template>
<text class="icon" :class="'icon-' + name" :style="iconStyle"></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: '🔐',
filter: '▼',
calendar: '📅',
setting: '⚙',
wechat: '💬',
cash: '💵',
alipay: '💙'
}
export default {
name: 'Icon',
props: {
name: {
type: String,
required: true
},
size: {
type: [Number, String],
default: 32
},
color: {
type: String,
default: ''
}
},
computed: {
iconStyle() {
const style = {}
if (this.size) {
style.fontSize = typeof this.size === 'number' ? `${this.size}rpx` : this.size
}
if (this.color) {
style.color = this.color
}
return style
},
iconChar() {
return icons[this.name] || '•'
}
}
}
</script>
<style>
.icon {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
display: inline-block;
text-align: center;
line-height: 1;
font-weight: 500;
}
.icon-add { font-size: 1.3em; font-weight: 300; }
.icon-check { color: #52c41a; }
.icon-close { color: #ff4d4f; }
.icon-alert { color: #fa8c16; }
.icon-right, .icon-left { font-size: 1.4em; font-weight: bold; color: #999; }
.icon-down, .icon-filter { font-size: 0.8em; }
.icon-in { color: #52c41a; }
.icon-out { color: #ff4d4f; }
</style>

11
src/main.js Normal file
View 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
}
}

View File

@@ -18,6 +18,18 @@
"navigationBarTitleText": "商品列表" "navigationBarTitleText": "商品列表"
} }
}, },
{
"path": "pages/product/manage",
"style": {
"navigationBarTitleText": "商品管理"
}
},
{
"path": "pages/product/select",
"style": {
"navigationBarTitleText": "选择商品"
}
},
{ {
"path": "pages/order/create", "path": "pages/order/create",
"style": { "style": {
@@ -29,6 +41,30 @@
"style": { "style": {
"navigationBarTitleText": "订单列表" "navigationBarTitleText": "订单列表"
} }
},
{
"path": "pages/stock/list",
"style": {
"navigationBarTitleText": "库存管理"
}
},
{
"path": "pages/stock/in",
"style": {
"navigationBarTitleText": "入库"
}
},
{
"path": "pages/stock/flow",
"style": {
"navigationBarTitleText": "库存流水"
}
},
{
"path": "pages/category/index",
"style": {
"navigationBarTitleText": "种类管理"
}
} }
], ],
"globalStyle": { "globalStyle": {
@@ -56,5 +92,7 @@
"text": "订单" "text": "订单"
} }
] ]
} },
"customerHidePages": [
]
} }

View File

@@ -0,0 +1,320 @@
<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.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' })
}
}
}
})
}
}
}
</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>

565
src/pages/index/index.vue Normal file
View File

@@ -0,0 +1,565 @@
<template>
<view class="page">
<!-- 顶部欢迎区域 -->
<view class="header">
<view class="welcome-section">
<text class="welcome-text">欢迎回来</text>
<text class="username">{{ userInfo.username || '用户' }}</text>
</view>
<view class="role-badge" :class="roleClass">
<Icon name="user" :size="24" color="#fff" />
<text class="role-text">{{ roleText }}</text>
</view>
</view>
<!-- 快捷操作 - 管理员/销售 -->
<view class="stats-card" v-if="!isCustomer && !isGuest">
<view class="card-header">
<text class="card-title">今日概览</text>
</view>
<view class="stats-grid">
<view class="stat-item">
<view class="stat-icon order-icon">
<Icon name="order" :size="40" color="#667eea" />
</view>
<view class="stat-info">
<text class="stat-value">{{ stats.orderCount || 0 }}</text>
<text class="stat-label">今日订单</text>
</view>
</view>
<view class="stat-item">
<view class="stat-icon money-icon">
<Icon name="money" :size="40" color="#fa8c16" />
</view>
<view class="stat-info">
<text class="stat-value">¥{{ stats.actualAmount || 0 }}</text>
<text class="stat-label">今日销售额</text>
</view>
</view>
<view class="stat-item">
<view class="stat-icon alert-icon">
<Icon name="alert" :size="40" color="#ff4d4f" />
</view>
<view class="stat-info">
<text class="stat-value">{{ stats.stockAlerts || 0 }}</text>
<text class="stat-label">库存预警</text>
</view>
</view>
</view>
</view>
<!-- 功能菜单 -->
<view class="menu-section">
<text class="section-title">功能菜单</text>
<view class="menu-grid">
<!-- 管理员菜单 -->
<template v-if="isAdmin">
<view class="menu-card" @click="goTo('/pages/product/manage')">
<view class="menu-card-icon blue">
<Icon name="product" :size="40" color="#fff" />
</view>
<text class="menu-card-title">商品管理</text>
<text class="menu-card-desc">管理商品库存</text>
</view>
<view class="menu-card" @click="goTo('/pages/category/index')">
<view class="menu-card-icon purple">
<Icon name="setting" :size="40" color="#fff" />
</view>
<text class="menu-card-title">种类管理</text>
<text class="menu-card-desc">管理商品种类</text>
</view>
<view class="menu-card" @click="goTo('/pages/order/create')">
<view class="menu-card-icon green">
<Icon name="edit" :size="40" color="#fff" />
</view>
<text class="menu-card-title">创建订单</text>
<text class="menu-card-desc">新增销售订单</text>
</view>
<view class="menu-card" @click="goToTab('/pages/order/list')">
<view class="menu-card-icon orange">
<Icon name="order" :size="40" color="#fff" />
</view>
<text class="menu-card-title">订单列表</text>
<text class="menu-card-desc">查看所有订单</text>
</view>
<view class="menu-card" @click="goStock()">
<view class="menu-card-icon red">
<Icon name="stock" :size="40" color="#fff" />
</view>
<text class="menu-card-title">库存管理</text>
<text class="menu-card-desc">库存预警监控</text>
</view>
</template>
<!-- 销售菜单 -->
<template v-else-if="isSales">
<view class="menu-card" @click="goTo('/pages/product/list')">
<view class="menu-card-icon blue">
<Icon name="product" :size="40" color="#fff" />
</view>
<text class="menu-card-title">商品浏览</text>
<text class="menu-card-desc">查看商品列表</text>
</view>
<view class="menu-card" @click="goTo('/pages/order/create')">
<view class="menu-card-icon green">
<Icon name="edit" :size="40" color="#fff" />
</view>
<text class="menu-card-title">创建订单</text>
<text class="menu-card-desc">新增销售订单</text>
</view>
<view class="menu-card" @click="goToTab('/pages/order/list')">
<view class="menu-card-icon orange">
<Icon name="order" :size="40" color="#fff" />
</view>
<text class="menu-card-title">订单列表</text>
<text class="menu-card-desc">查看所有订单</text>
</view>
</template>
<!-- 顾客菜单 -->
<template v-else-if="isCustomer">
<view class="menu-card" @click="goTo('/pages/product/list')">
<view class="menu-card-icon blue">
<Icon name="product" :size="40" color="#fff" />
</view>
<text class="menu-card-title">商品浏览</text>
<text class="menu-card-desc">查看商品列表</text>
</view>
<view class="menu-card" @click="goToTab('/pages/order/list')">
<view class="menu-card-icon orange">
<Icon name="order" :size="40" color="#fff" />
</view>
<text class="menu-card-title">我的订单</text>
<text class="menu-card-desc">查看订单记录</text>
</view>
</template>
<!-- 游客菜单 -->
<template v-else-if="isGuest">
<view class="guest-card" @click="goTo('/pages/login/index')">
<view class="guest-icon">
<Icon name="user" :size="80" color="#fff" />
</view>
<text class="guest-text">点击登录</text>
<text class="guest-desc">登录后使用完整功能</text>
</view>
</template>
</view>
</view>
<!-- 提示区域 -->
<view class="tips-section" v-if="isCustomer">
<view class="tip-card">
<text class="tip-title">温馨提示</text>
<view class="tip-list">
<text class="tip-item"> 您可以浏览商品</text>
<text class="tip-item"> 您可以查看半年内的订单</text>
<text class="tip-item"> 如需下单请联系销售人员</text>
</view>
</view>
</view>
<view class="tips-section" v-if="isGuest">
<view class="tip-card">
<text class="tip-title">欢迎使用</text>
<view class="tip-list">
<text class="tip-item"> 请登录后使用完整功能</text>
<text class="tip-item"> 登录后可浏览商品和查看订单</text>
</view>
</view>
</view>
<!-- 退出登录 -->
<view class="logout-section" v-if="!isGuest">
<button class="logout-btn" @click="logout">
<Icon name="logout" :size="32" color="#fff" style="margin-right: 10rpx" />
退出登录
</button>
</view>
</view>
</template>
<script>
import authApi from '@/api/auth'
import orderApi from '@/api/order'
import productApi from '@/api/product'
import { getRole, isAdmin, isSales, isCustomer as checkIsCustomer, isGuest as checkIsGuest, canManageProduct, canCreateOrder, canViewStats } from '@/utils/auth'
export default {
data() {
return {
userInfo: {},
role: 'guest',
isAdmin: false,
isSales: false,
isCustomer: false,
isGuest: false,
stats: {
orderCount: 0,
actualAmount: 0,
stockAlerts: 0
}
}
},
computed: {
roleText() {
if (this.isAdmin) return '管理员'
if (this.isSales) return '销售员'
if (this.isCustomer) return '顾客'
return '游客'
},
roleClass() {
if (this.isAdmin) return 'admin'
if (this.isCustomer) return 'customer'
return ''
}
},
onLoad() {
this.role = getRole()
this.isAdmin = isAdmin()
this.isSales = isSales()
this.isCustomer = checkIsCustomer()
this.isGuest = checkIsGuest()
this.loadUserInfo()
if (canViewStats()) {
this.loadStats()
}
},
methods: {
async loadUserInfo() {
const localRole = uni.getStorageSync('role')
if (localRole) {
this.userInfo = {
username: localRole === 'admin' ? '管理员' : '顾客',
role: localRole
}
return
}
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 })
},
goToTab(url) {
uni.switchTab({ url })
},
goStock() {
uni.navigateTo({ url: '/pages/stock/list' })
},
async logout() {
try {
await authApi.logout()
} catch (e) {
console.error(e)
}
uni.removeStorageSync('token')
uni.removeStorageSync('userId')
uni.removeStorageSync('role')
uni.reLaunch({ url: '/pages/login/index' })
}
}
}
</script>
<style>
.page {
min-height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 30rpx;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 40rpx 20rpx;
margin-bottom: 30rpx;
}
.welcome-section {
display: flex;
flex-direction: column;
}
.welcome-text {
font-size: 28rpx;
color: rgba(255, 255, 255, 0.8);
margin-bottom: 8rpx;
}
.username {
font-size: 48rpx;
font-weight: bold;
color: #fff;
}
.role-badge {
display: flex;
align-items: center;
padding: 12rpx 24rpx;
border-radius: 30rpx;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
}
.role-badge.admin {
background: rgba(255, 215, 0, 0.3);
}
.role-badge.customer {
background: rgba(255, 255, 255, 0.2);
}
.role-text {
font-size: 24rpx;
color: #fff;
margin-left: 8rpx;
}
.stats-card {
background: #fff;
border-radius: 24rpx;
padding: 30rpx;
margin-bottom: 30rpx;
box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.1);
}
.card-header {
margin-bottom: 20rpx;
}
.card-title {
font-size: 30rpx;
font-weight: bold;
color: #333;
}
.stats-grid {
display: flex;
justify-content: space-between;
}
.stat-item {
display: flex;
align-items: center;
flex: 1;
}
.stat-icon {
width: 80rpx;
height: 80rpx;
border-radius: 20rpx;
display: flex;
align-items: center;
justify-content: center;
margin-right: 16rpx;
}
.order-icon {
background: #e6f7ff;
}
.money-icon {
background: #fff7e6;
}
.alert-icon {
background: #fff1f0;
}
.stat-info {
display: flex;
flex-direction: column;
}
.stat-value {
font-size: 36rpx;
font-weight: bold;
color: #333;
}
.stat-label {
font-size: 22rpx;
color: #999;
margin-top: 4rpx;
}
.menu-section {
margin-bottom: 30rpx;
}
.section-title {
font-size: 32rpx;
font-weight: bold;
color: #fff;
margin-bottom: 20rpx;
display: block;
}
.menu-grid {
display: flex;
flex-wrap: wrap;
}
/* 手机端 - 2列布局 */
.menu-card {
width: 44%;
background: #fff;
border-radius: 24rpx;
padding: 30rpx;
margin: 10rpx;
box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
}
/* 平板/PC端 - 横版布局超过4个换行 */
@media (min-width: 768px) {
.menu-card {
width: 22%;
margin: 10rpx;
}
}
.menu-card:active {
transform: scale(0.98);
opacity: 0.9;
}
.menu-card-icon {
width: 80rpx;
height: 80rpx;
border-radius: 20rpx;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 16rpx;
}
.menu-card-icon.blue {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.menu-card-icon.green {
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}
.menu-card-icon.orange {
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}
.menu-card-icon.red {
background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}
.menu-card-icon.purple {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.menu-card-title {
font-size: 28rpx;
font-weight: bold;
color: #333;
margin-bottom: 8rpx;
}
.menu-card-desc {
font-size: 22rpx;
color: #999;
}
.guest-card {
width: 100%;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
border-radius: 24rpx;
padding: 60rpx;
display: flex;
flex-direction: column;
align-items: center;
border: 2rpx dashed rgba(255, 255, 255, 0.5);
}
.guest-icon {
margin-bottom: 20rpx;
}
.guest-text {
font-size: 32rpx;
font-weight: bold;
color: #fff;
margin-bottom: 10rpx;
}
.guest-desc {
font-size: 24rpx;
color: rgba(255, 255, 255, 0.7);
}
.tips-section {
margin-bottom: 30rpx;
}
.tip-card {
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
border-radius: 24rpx;
padding: 30rpx;
}
.tip-title {
font-size: 28rpx;
font-weight: bold;
color: #fff;
display: block;
margin-bottom: 16rpx;
}
.tip-list {
display: flex;
flex-direction: column;
}
.tip-item {
font-size: 24rpx;
color: rgba(255, 255, 255, 0.8);
line-height: 36rpx;
}
.logout-section {
padding: 0 20rpx;
}
.logout-btn {
width: 100%;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
border: 2rpx solid rgba(255, 255, 255, 0.3);
border-radius: 50rpx;
padding: 24rpx;
color: #fff;
font-size: 28rpx;
font-weight: bold;
display: flex;
align-items: center;
justify-content: center;
}
.logout-btn:active {
background: rgba(255, 255, 255, 0.3);
}
</style>

450
src/pages/login/index.vue Normal file
View 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>

View File

@@ -1,8 +1,11 @@
<template> <template>
<view class="page"> <view class="page">
<!-- 客户信息 --> <!-- 客户信息 -->
<view class="section"> <view class="section card-section">
<view class="section-title">客户信息</view> <view class="section-header">
<text class="section-icon">👤</text>
<text class="section-title">客户信息</text>
</view>
<view class="form-item"> <view class="form-item">
<text class="label">客户</text> <text class="label">客户</text>
<picker <picker
@@ -13,16 +16,18 @@
> >
<view class="picker-value"> <view class="picker-value">
{{ selectedCustomer ? selectedCustomer.name : '请选择客户' }} {{ selectedCustomer ? selectedCustomer.name : '请选择客户' }}
<text class="arrow"></text>
</view> </view>
</picker> </picker>
</view> </view>
</view> </view>
<!-- 商品选择 --> <!-- 商品选择 -->
<view class="section"> <view class="section card-section">
<view class="section-header"> <view class="section-header">
<text class="section-icon">📦</text>
<text class="section-title">商品明细</text> <text class="section-title">商品明细</text>
<text class="add-btn" @click="addProduct">+ 添加商品</text> <text class="add-btn" @click="goToSelectProduct">+ 添加商品</text>
</view> </view>
<view v-for="(item, index) in orderItems" :key="index" class="order-item"> <view v-for="(item, index) in orderItems" :key="index" class="order-item">
@@ -55,13 +60,17 @@
</view> </view>
<view v-if="orderItems.length === 0" class="empty-tip"> <view v-if="orderItems.length === 0" class="empty-tip">
请添加商品 <text class="empty-icon">🛒</text>
<text>请添加商品</text>
</view> </view>
</view> </view>
<!-- 优惠设置 --> <!-- 优惠设置 -->
<view class="section"> <view class="section card-section">
<view class="section-title">优惠设置</view> <view class="section-header">
<text class="section-icon">🎫</text>
<text class="section-title">优惠设置</text>
</view>
<view class="form-item"> <view class="form-item">
<text class="label">折扣率</text> <text class="label">折扣率</text>
<input <input
@@ -76,6 +85,10 @@
<!-- 订单金额 --> <!-- 订单金额 -->
<view class="section amount-section"> <view class="section amount-section">
<view class="amount-header">
<text class="amount-icon">💰</text>
<text class="amount-title">订单金额</text>
</view>
<view class="amount-row"> <view class="amount-row">
<text class="amount-label">原价合计</text> <text class="amount-label">原价合计</text>
<text class="amount-value">¥{{ totalAmount.toFixed(2) }}</text> <text class="amount-value">¥{{ totalAmount.toFixed(2) }}</text>
@@ -91,8 +104,11 @@
</view> </view>
<!-- 支付方式 --> <!-- 支付方式 -->
<view class="section"> <view class="section card-section">
<view class="section-title">支付方式</view> <view class="section-header">
<text class="section-icon">💳</text>
<text class="section-title">支付方式</text>
</view>
<view class="payment-methods"> <view class="payment-methods">
<view <view
class="method-item" class="method-item"
@@ -119,8 +135,11 @@
</view> </view>
<!-- 备注 --> <!-- 备注 -->
<view class="section"> <view class="section card-section">
<view class="section-title">备注</view> <view class="section-header">
<text class="section-icon">📝</text>
<text class="section-title">备注</text>
</view>
<textarea <textarea
class="remark-input" class="remark-input"
v-model="remark" v-model="remark"
@@ -136,36 +155,13 @@
</view> </view>
<button class="submit-btn" @click="createOrder">创建订单</button> <button class="submit-btn" @click="createOrder">创建订单</button>
</view> </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> </view>
</template> </template>
<script> <script>
import orderApi from '@/api/order' import orderApi from '@/api/order'
import productApi from '@/api/product' import productApi from '@/api/product'
import customerApi from '@/api/customer'
export default { export default {
data() { data() {
@@ -187,13 +183,57 @@ export default {
// //
paymentMethod: 'cash', paymentMethod: 'cash',
remark: '' remark: '',
//
editingOrderId: null
} }
}, },
onLoad() { onLoad(options) {
this.loadCustomers()
this.loadProducts() this.loadProducts()
if (options.orderId) {
this.editingOrderId = options.orderId
this.loadOrder(options.orderId)
}
}, },
methods: { methods: {
async loadOrder(orderId) {
try {
const detail = await orderApi.getOrderDetail(orderId)
const order = detail.order
//
if (order.customerId) {
this.selectedCustomer = this.customers.find(c => c.customerId === order.customerId)
}
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.remark = order.remark || ''
this.paymentMethod = order.paymentMethod || 'cash'
this.calcAmount()
} catch (e) {
console.error(e)
}
},
async loadCustomers() {
try {
const res = await customerApi.getCustomers({ page: 1, pageSize: 100 })
this.customers = res.records || []
} catch (e) {
console.error(e)
}
},
async loadProducts() { async loadProducts() {
try { try {
const res = await productApi.getProducts({ page: 1, pageSize: 100 }) const res = await productApi.getProducts({ page: 1, pageSize: 100 })
@@ -205,10 +245,10 @@ export default {
selectCustomer(e) { selectCustomer(e) {
this.selectedCustomer = this.customers[e.detail.value] this.selectedCustomer = this.customers[e.detail.value]
}, },
addProduct() { goToSelectProduct() {
this.$refs.productPopup.open() uni.navigateTo({ url: '/pages/product/select' })
}, },
selectProduct(product) { addProduct(product) {
// //
const exists = this.orderItems.find(item => item.productId === product.productId) const exists = this.orderItems.find(item => item.productId === product.productId)
if (exists) { if (exists) {
@@ -224,9 +264,7 @@ export default {
price: product.price, price: product.price,
quantity: 1 quantity: 1
}) })
this.calcAmount() this.calcAmount()
this.$refs.productPopup.close()
}, },
removeItem(index) { removeItem(index) {
this.orderItems.splice(index, 1) this.orderItems.splice(index, 1)
@@ -264,14 +302,19 @@ export default {
} }
try { try {
const order = await orderApi.createOrder(data) 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' }) uni.showToast({ title: '订单创建成功', icon: 'success' })
}
// //
setTimeout(() => { setTimeout(() => {
uni.navigateTo({ uni.switchTab({
url: `/pages/order/list` url: '/pages/order/list?status=0'
}) })
}, 1500) }, 1500)
} catch (e) { } catch (e) {
@@ -283,44 +326,54 @@ export default {
</script> </script>
<style> <style>
/* 全局 */
.page { .page {
padding: 20rpx; padding: 20rpx;
padding-bottom: 160rpx; padding-bottom: 180rpx;
background: #f8f9fa;
} }
.section { /* 卡片区块 */
.card-section {
background: #fff; background: #fff;
border-radius: 16rpx; border-radius: 20rpx;
padding: 24rpx; padding: 24rpx;
margin-bottom: 20rpx; margin-bottom: 20rpx;
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.06);
} }
.section-header { .section-header {
display: flex; display: flex;
justify-content: space-between;
align-items: center; align-items: center;
margin-bottom: 20rpx; margin-bottom: 20rpx;
} }
.section-icon {
font-size: 32rpx;
margin-right: 12rpx;
}
.section-title { .section-title {
font-size: 28rpx; font-size: 28rpx;
font-weight: bold; font-weight: bold;
flex: 1;
} }
.add-btn { .add-btn {
color: #3cc51f; color: #667eea;
font-size: 26rpx; font-size: 26rpx;
font-weight: 500;
} }
.form-item { .form-item {
display: flex; display: flex;
align-items: center; align-items: center;
padding: 16rpx 0; padding: 20rpx 0;
border-bottom: 1rpx solid #f5f5f5; border-bottom: 1rpx solid #f5f5f5;
} }
.label { .label {
width: 120rpx; width: 140rpx;
font-size: 28rpx; font-size: 28rpx;
color: #666; color: #666;
} }
@@ -328,17 +381,37 @@ export default {
.picker-value { .picker-value {
flex: 1; flex: 1;
font-size: 28rpx; font-size: 28rpx;
color: #333;
display: flex;
justify-content: space-between;
align-items: center;
}
.arrow {
font-size: 32rpx;
color: #ccc;
} }
.discount-input { .discount-input {
width: 120rpx; width: 120rpx;
text-align: right; text-align: right;
font-size: 28rpx;
padding: 10rpx;
background: #f5f5f5;
border-radius: 8rpx;
} }
.unit {
font-size: 28rpx;
color: #666;
margin-left: 10rpx;
}
/* 订单商品项 */
.order-item { .order-item {
padding: 20rpx; padding: 20rpx;
background: #f9f9f9; background: #f9f9f9;
border-radius: 8rpx; border-radius: 12rpx;
margin-bottom: 16rpx; margin-bottom: 16rpx;
} }
@@ -350,6 +423,7 @@ export default {
font-size: 28rpx; font-size: 28rpx;
font-weight: bold; font-weight: bold;
display: block; display: block;
color: #333;
} }
.item-spec { .item-spec {
@@ -368,7 +442,7 @@ export default {
margin-right: 20rpx; margin-right: 20rpx;
} }
.qty-label, .qty-label { .qty-label {
font-size: 24rpx; font-size: 24rpx;
color: #666; color: #666;
margin-right: 8rpx; margin-right: 8rpx;
@@ -394,18 +468,48 @@ export default {
.delete-btn { .delete-btn {
margin-left: 20rpx; margin-left: 20rpx;
font-size: 36rpx; font-size: 40rpx;
color: #999; color: #999;
padding: 10rpx;
} }
.empty-tip { .empty-tip {
padding: 40rpx; padding: 40rpx;
text-align: center; text-align: center;
color: #999; color: #999;
display: flex;
flex-direction: column;
align-items: center;
} }
.empty-icon {
font-size: 60rpx;
margin-bottom: 10rpx;
}
/* 金额区域 */
.amount-section { .amount-section {
background: #fff7e6; 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 { .amount-row {
@@ -416,30 +520,30 @@ export default {
.amount-label { .amount-label {
font-size: 26rpx; font-size: 26rpx;
color: #666; color: rgba(255, 255, 255, 0.8);
} }
.amount-value { .amount-value {
font-size: 26rpx; font-size: 26rpx;
color: #333; color: #fff;
} }
.amount-value.discount { .amount-value.discount {
color: #52c41a; color: #7dff7d;
} }
.amount-row.actual { .amount-row.actual {
border-top: 1rpx dashed #ddd; border-top: 1rpx solid rgba(255, 255, 255, 0.2);
padding-top: 20rpx; padding-top: 20rpx;
margin-top: 12rpx; margin-top: 12rpx;
} }
.amount-row.actual .amount-value { .amount-row.actual .amount-value {
font-size: 32rpx; font-size: 36rpx;
font-weight: bold; font-weight: bold;
color: #ff4d4f;
} }
/* 支付方式 */
.payment-methods { .payment-methods {
display: flex; display: flex;
gap: 20rpx; gap: 20rpx;
@@ -447,25 +551,32 @@ export default {
.method-item { .method-item {
flex: 1; flex: 1;
padding: 20rpx; padding: 24rpx;
text-align: center; text-align: center;
background: #f5f5f5; background: #f5f5f5;
border-radius: 8rpx; border-radius: 12rpx;
font-size: 26rpx; font-size: 26rpx;
transition: all 0.3s;
} }
.method-item.active { .method-item.active {
background: #e6f7ff; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #1890ff; color: #fff;
border: 1rpx solid #1890ff; box-shadow: 0 4rpx 16rpx rgba(102, 126, 234, 0.4);
} }
/* 备注 */
.remark-input { .remark-input {
width: 100%; width: 100%;
height: 120rpx; height: 120rpx;
font-size: 28rpx; font-size: 28rpx;
background: #f9f9f9;
border-radius: 12rpx;
padding: 20rpx;
box-sizing: border-box;
} }
/* 底部提交 */
.submit-bar { .submit-bar {
position: fixed; position: fixed;
bottom: 0; bottom: 0;
@@ -473,9 +584,9 @@ export default {
right: 0; right: 0;
display: flex; display: flex;
align-items: center; align-items: center;
padding: 20rpx; padding: 20rpx 30rpx;
background: #fff; background: #fff;
box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.1); box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
} }
.submit-info { .submit-info {
@@ -484,54 +595,21 @@ export default {
} }
.submit-amount { .submit-amount {
font-size: 36rpx; font-size: 40rpx;
font-weight: bold; font-weight: bold;
color: #ff4d4f; color: #ff4d4f;
} }
.submit-btn { .submit-btn {
width: 200rpx; width: 240rpx;
height: 80rpx; height: 88rpx;
line-height: 80rpx; line-height: 88rpx;
background: #3cc51f; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff; color: #fff;
border: none; border: none;
border-radius: 40rpx; border-radius: 44rpx;
font-size: 28rpx; font-size: 30rpx;
} font-weight: bold;
box-shadow: 0 8rpx 30rpx rgba(102, 126, 234, 0.4);
.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> </style>

499
src/pages/order/list.vue Normal file
View File

@@ -0,0 +1,499 @@
<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) {
if (options.status) {
this.status = parseInt(options.status)
}
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 = {
0: '未完成',
1: '已完成',
2: '已取消',
3: '退款中',
4: '已退款'
}
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;
}
/* 卡片主体 */
.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>

317
src/pages/product/list.vue Normal file
View File

@@ -0,0 +1,317 @@
<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'
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 {
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: 180rpx;
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>

View 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>

View 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: 180rpx;
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>

252
src/pages/stock/flow.vue Normal file
View 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>

162
src/pages/stock/in.vue Normal file
View File

@@ -0,0 +1,162 @@
<template>
<view class="stock-in">
<view class="form">
<view class="form-item">
<text class="label">商品</text>
<picker
mode="selector"
:range="productList"
range-key="name"
@change="onProductChange"
>
<view class="picker">
{{ selectedProduct ? selectedProduct.name : '请选择商品' }}
</view>
</picker>
</view>
<view class="form-item">
<text class="label">入库数量</text>
<input
class="input"
v-model="quantity"
type="number"
placeholder="请输入数量"
/>
</view>
<view class="form-item">
<text class="label">备注</text>
<input
class="input"
v-model="remark"
placeholder="可选填写"
/>
</view>
</view>
<view class="btn-area">
<button class="submit-btn" @click="submit" :disabled="submitting">
{{ submitting ? '提交中...' : '确认入库' }}
</button>
</view>
</view>
</template>
<script>
import stockApi from '@/api/stock'
import productApi from '@/api/product'
export default {
data() {
return {
productList: [],
selectedProduct: null,
quantity: '',
remark: '',
submitting: false
}
},
onLoad() {
this.getProducts()
},
methods: {
async getProducts() {
try {
const res = await productApi.getProducts({ page: 1, pageSize: 100 })
if (res.code === 0) {
this.productList = res.data.records || []
}
} catch (e) {
uni.showToast({ title: '加载商品失败', icon: 'none' })
}
},
onProductChange(e) {
this.selectedProduct = this.productList[e.detail.value]
},
async submit() {
if (!this.selectedProduct) {
uni.showToast({ title: '请选择商品', icon: 'none' })
return
}
if (!this.quantity || this.quantity <= 0) {
uni.showToast({ title: '请输入有效数量', icon: 'none' })
return
}
this.submitting = true
try {
const res = await stockApi.stockIn({
productId: this.selectedProduct.productId,
quantity: parseInt(this.quantity),
remark: this.remark
})
if (res.code === 0) {
uni.showToast({ title: '入库成功', icon: 'success' })
setTimeout(() => {
uni.navigateBack()
}, 1500)
} else {
uni.showToast({ title: res.message || '入库失败', icon: 'none' })
}
} catch (e) {
uni.showToast({ title: '入库失败', icon: 'none' })
} finally {
this.submitting = false
}
}
}
}
</script>
<style scoped>
.stock-in {
min-height: 100vh;
background: #f5f5f5;
}
.form {
background: #fff;
margin: 20rpx;
border-radius: 12rpx;
padding: 0 30rpx;
}
.form-item {
display: flex;
align-items: center;
padding: 30rpx 0;
border-bottom: 1rpx solid #eee;
}
.form-item:last-child {
border-bottom: none;
}
.label {
width: 160rpx;
font-size: 30rpx;
}
.picker, .input {
flex: 1;
font-size: 30rpx;
}
.btn-area {
padding: 40rpx 30rpx;
}
.submit-btn {
height: 88rpx;
line-height: 88rpx;
background: #3cc51f;
color: #fff;
font-size: 32rpx;
border-radius: 8rpx;
}
.submit-btn[disabled] {
background: #ccc;
}
</style>

297
src/pages/stock/list.vue Normal file
View File

@@ -0,0 +1,297 @@
<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()
},
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
View 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()
}

14
vite.config.js Normal file
View File

@@ -0,0 +1,14 @@
import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
export default defineConfig({
plugins: [
uni()
],
root: '.',
build: {
rollupOptions: {
input: './index.html'
}
}
})