Compare commits

..

137 Commits

Author SHA1 Message Date
Agent
646f69bb56 fix: 修复createCategory参数顺序
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-04 08:09:25 +00:00
Agent
756444ef2b fix: 退货页面调用后端退款接口恢复库存
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-03 06:58:31 +00:00
Agent
6dfc201c66 fix: 增加数量和单价输入框宽度
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-03 02:18:23 +00:00
Agent
870e1c612d fix: 商品名称固定宽度,库存移到最后
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-03 01:45:14 +00:00
Agent
fbcd930887 fix: 订单创建页面商品名称规格长宽放同一行
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-03 01:38:46 +00:00
Agent
a1bcc2e478 feat: 订单创建页面商品数量支持+号-号,且不超过库存
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-03 01:32:24 +00:00
Agent
a84cd57fad feat: 选择商品页面显示库存,库存为0不可选中
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-03 01:23:47 +00:00
Agent
c49a6d8288 fix: 入库页面商品卡片参照商品管理页面显示
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 13:31:17 +00:00
Agent
796d083823 fix: 移除库存管理入口,保留入库和库存流水
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 13:28:01 +00:00
Agent
817f6e3436 fix: 首页商品管理入口改为switchTab跳转tabbar页面
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 13:24:04 +00:00
Agent
3e32aa6313 debug: 添加success fail回调
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 13:21:38 +00:00
Agent
255a0be7f2 debug: 添加alert测试
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 13:19:12 +00:00
Agent
1c422f5436 fix: 移除商品管理页面权限限制
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 13:13:06 +00:00
Agent
46894e04fe fix: 底部导航商品入口改为商品管理页面
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 13:01:08 +00:00
Agent
1ea0fc04bf feat: 商品列表查看详情跳转到商品管理进行编辑
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 12:56:32 +00:00
Agent
7a9c31ca27 fix: 增加总面积列宽度
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 12:07:02 +00:00
Agent
7b24ea86f5 fix: 商品名称规格长宽显示在同一行
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 11:58:16 +00:00
Agent
b789a4af92 fix: 分享订单页商品明细与订单详情保持一致
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 11:53:32 +00:00
Agent
c6f93aaa44 fix: 面积数值不显示单位
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 11:07:10 +00:00
Agent
3fe8c80696 fix: 商品名称和规格同一行显示,不同颜色
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 10:04:01 +00:00
Agent
3860c9583b fix: 合并商品名称规格长宽为一列
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 09:59:10 +00:00
Agent
82bebc0dd8 fix: 订单详情小计显示整数
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 09:51:31 +00:00
Agent
2c68fe898a fix: 编辑订单时加载length、width、area字段
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 09:12:26 +00:00
Agent
e8259fbf91 fix: 创建订单时传递length、width、area参数
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 09:04:53 +00:00
Agent
84b0d15a0c feat: 订单详情页显示商品规格、长度宽度和总面积
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-02 04:23:43 +00:00
Agent
d932d26830 fix: 订单列表直接使用返回的items,不再单独请求
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 16:39:54 +00:00
Agent
b62c62c6e0 feat: 订单商品明细显示颜色长度宽高度数量总面面积
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 16:25:41 +00:00
Agent
10b421d682 fix: 商品种类放左侧,分类侧栏
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 16:18:59 +00:00
Agent
1899ebf226 fix: 点击商品直接选中,显示长宽面积与颜色同一行
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 16:14:42 +00:00
Agent
02f151307d fix: 恢复选择商品页面正确版本,修复模板标签平衡
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 16:12:58 +00:00
Agent
c0adc172c1 fix: 点击商品卡片直接选中,不再弹窗编辑长度
Some checks failed
continuous-integration/drone/push Build is failing
2026-04-01 16:08:23 +00:00
Agent
b90847a0f1 fix: 修复选择商品页面模板结构,分类侧栏
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 15:59:54 +00:00
Agent
e25d288fae fix: 选择商品页面分类改回左侧侧栏
Some checks failed
continuous-integration/drone/push Build is failing
2026-04-01 15:53:17 +00:00
Agent
0500d3e688 feat: 选择商品页面卡片显示长宽面积与颜色同一行
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 15:48:40 +00:00
Agent
45d6cc53ca feat: 商品卡片颜色单位价格显示一行
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 15:37:28 +00:00
Agent
d9881a50c1 feat: 商品卡片颜色单位显示一行,有面积时另起一行显示规格
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 15:30:50 +00:00
Agent
6df829cf90 feat: 商品卡片增加编辑按钮,仅上架商品可编辑,状态改为已上架/已下架
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 15:24:27 +00:00
Agent
5dc15bb2a9 fix: 商品管理使用getAllProducts接口显示所有商品(包括下架)
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 15:18:48 +00:00
Agent
08f440f7c8 fix: 修复下架按钮API参数位置
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 15:11:02 +00:00
Agent
826973f42a feat: 商品管理增加分类侧栏,商品卡片显示分类
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 15:01:29 +00:00
Agent
e040f6d93b fix: 修复API参数顺序确保data传值
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 14:53:09 +00:00
Agent
a38039f4aa fix: 修复API参数位置
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 14:48:42 +00:00
Agent
5af9b7c0ff fix: 修复商品保存时数据为空的问题
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 14:45:39 +00:00
Agent
10ebbd6b6f feat: 规格改为颜色
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 14:41:03 +00:00
Agent
0772a91c26 feat: 分类改为必填项
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 14:36:48 +00:00
Agent
3d827c0033 style: 输入框增加边框,更明显
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 14:33:23 +00:00
Agent
f388a0c5b1 fix: 增加长度宽度面积输入框间距
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 14:29:44 +00:00
Agent
324bd1166f feat: 商品表单调整顺序,必填项*改为红色
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 14:24:14 +00:00
Agent
64767e9ca0 fix: 修复长度宽度面积三列在一行的样式
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 14:15:26 +00:00
Agent
a4f548b847 feat: 商品管理长度宽度单位改为mm,面积改为m²,最多5位数字
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 14:11:48 +00:00
Agent
82efb8c251 fix: 商品管理面积计算改为平方米
All checks were successful
continuous-integration/drone/push Build is passing
2026-04-01 14:06:46 +00:00
Agent
d7995d8cc5 feat: 选择商品弹窗增加长度、宽度、面积字段,自动计算面积 2026-04-01 14:01:50 +00:00
Agent
8e0122b08f chore: dev-build用development模式
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 08:47:25 +00:00
Agent
7052bb25c1 chore: 环境变量统一用正式环境配置
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 08:45:18 +00:00
Agent
80b6fa0fe5 fix: 登录后保存role,API请求携带X-User-Role头
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 08:42:02 +00:00
Agent
750875be74 feat: 环境变量方案管理API和H5地址
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 08:40:09 +00:00
Agent
58fc2a9d90 fix: 分享页面隐藏原生导航栏,使用自定义标题栏
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 07:32:59 +00:00
Agent
1c414036c7 fix: 修正分享API地址
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 07:24:46 +00:00
Agent
f0daec8c06 fix: 分享链接增加customerId参数
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 07:18:52 +00:00
Agent
7c25420c30 feat: 订单分享链接,公开页面查看订单
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 07:10:17 +00:00
Agent
eb2b16f84f feat: 非取消订单增加分享功能,复制订单信息到剪贴板
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 07:05:24 +00:00
Agent
4921ee8d97 revert: 回滚打印机管理页面
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 06:45:49 +00:00
Agent
d5ae333176 feat: 添加打印机管理页面,订单详情调用打印接口
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-29 06:39:48 +00:00
Agent
615b688810 fix: 已取消订单隐藏打印按钮
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 06:32:29 +00:00
Agent
293d2dd8fe fix: 切换客户种类时重新拉取对应种类客户列表
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 05:39:18 +00:00
Agent
f90152f010 feat: 创建订单时先选客户种类再选客户,默认顾客
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 05:35:01 +00:00
Agent
ac29a24199 feat: 客户增加种类选择(顾客/木匠/装修公司)
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 05:25:08 +00:00
Agent
6c3fd0fb31 feat: 客户列表点击进入编辑模式,支持删除客户
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 05:23:32 +00:00
Agent
c1477d973f feat: 创建客户成功后跳转到首页
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 05:22:21 +00:00
393d920900 更新 .drone.yml
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-29 05:12:55 +00:00
Agent
9905808664 fix: 修复所有POST/PUT接口data参数位置 2026-03-29 03:50:10 +00:00
Agent
ec89799970 feat: 新增客户功能,新增客户和客户列表页面,添加到管理区域
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 15:10:06 +00:00
Agent
8c71045175 fix: 卡片图标继续放大到130rpx
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 14:54:55 +00:00
Agent
2926f76a26 fix: 卡片图标放大到110rpx
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 14:50:13 +00:00
Agent
4b5b51ef59 fix: 图标改用专业符号(不是emoji不是汉字)
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 14:20:17 +00:00
Agent
c07c81e479 fix: 图标改为彩色方块+汉字 2026-03-28 14:12:23 +00:00
Agent
7140e0049f refactor: 首页改用简洁卡片布局,emoji图标
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 14:08:21 +00:00
Agent
f47f078357 fix: 图标改用简洁线条风格符号 2026-03-28 14:01:33 +00:00
8c7e500fbb 更新 .drone.yml
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 13:47:47 +00:00
Agent
08c44da709 fix: 图标改为简洁的中文字符 2026-03-28 13:44:42 +00:00
bd228e1d6d 更新 .drone.yml
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 13:40:19 +00:00
Agent
dec77fd518 fix: 修复getUsername未导出的错误,改用uni.getStorageSync直接获取 2026-03-28 13:37:02 +00:00
dc847564c0 更新 .drone.yml
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-28 13:33:41 +00:00
8c1b57160d 更新 .drone.yml 2026-03-28 13:33:11 +00:00
Agent
e4063c0625 fix: 修复isLoggedIn未导出的错误 2026-03-28 13:30:44 +00:00
Agent
81ec7dd2cf refactor: 重新设计首页布局,美化样式和图标
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-28 13:27:04 +00:00
01ad62e3f6 更新 .drone.yml
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 13:12:03 +00:00
Agent
05e37b3abe fix: 卡片改为纯白底,图标和文字改为深色,简洁美观 2026-03-28 13:10:53 +00:00
Agent
6bce9ad6cf fix: 图标改为更简洁的Element UI风格符号
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 13:03:50 +00:00
Agent
4539be1559 fix: 背景改为浅白色,图标改为更清晰的样式,卡片改为浅色系
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 12:59:02 +00:00
Agent
ef4dceba1b fix: 按钮等间距分布,宽度调为18%
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 12:54:55 +00:00
Agent
cd5c397617 fix: 功能按钮宽度调小,图标和文字缩小
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 12:51:32 +00:00
Agent
38f68e06a1 feat: 功能菜单分为订单和管理两部分,图标调小为36rpx
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 12:47:22 +00:00
4aa855ed41 更新 .drone.yml 2026-03-28 12:42:23 +00:00
Agent
41896a073f feat: 新增订单详情页面,点击订单跳转详情,支持打印和订单操作
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 10:32:14 +00:00
Agent
f3d01ca9ce fix: 左侧分类宽度从180rpx调整为140rpx
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 10:24:03 +00:00
Agent
bfab7b8d1d feat: 新增退货功能,订单列表增加退货状态(9)
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 04:01:18 +00:00
Agent
4841c49cbd feat: 订单查询增加合并订单功能,选择已完成订单合并
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 03:41:42 +00:00
Agent
e7d03c8558 fix: 订单查询页面布局优化,订单列表占满剩余空间
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 03:35:47 +00:00
Agent
430a5422ee fix: 订单查询改为先搜客户再查该客户的订单
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 03:28:57 +00:00
Agent
848423faa3 feat: 新增订单查询页面,按客户姓名查询
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 03:25:22 +00:00
Agent
5d2e13df79 fix: 修复updateOrder传参,data应作为第四参数
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 03:15:36 +00:00
Agent
d5ccf9d1e4 fix: 编辑订单时标题和按钮文字动态显示
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 03:06:55 +00:00
Agent
e98b283501 fix: 修复订单编辑时客户无法匹配的问题
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 02:49:37 +00:00
Agent
53326f3a48 fix: 前端优惠金额不能为负数 2026-03-28 02:44:31 +00:00
Agent
031b8ccc25 fix: 简化API请求逻辑,PUT也有data时正常发送
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 02:32:39 +00:00
Agent
35c65a7cb3 fix: 修复updateOrderStatus参数位置,data应作为第四参数
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-28 02:29:37 +00:00
Agent
f9192a1486 debug: 增加订单列表调试日志
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 16:00:49 +00:00
Agent
494b0f195d feat: 商品、订单、库存列表页增加onShow刷新数据
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 15:55:26 +00:00
Agent
161a5236e4 fix: 订单列表默认加载全部订单,不再默认筛选未完成
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 15:51:14 +00:00
Agent
3fd6023a93 feat: 创建订单增加校验-客户必选、实付金额>0
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 15:39:43 +00:00
Agent
e681a4e99f fix: 优惠金额输入时实时计算实付金额,改用@input事件
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 15:37:04 +00:00
Agent
b6c67ceaa8 fix: 修复创建订单传参,data应作为第四参数
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 15:35:27 +00:00
Agent
f93aa242c9 fix: 简化优惠金额逻辑,前后端都用0作为默认值
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 15:33:59 +00:00
Agent
228e71d580 fix: 修复优惠金额空值判断,默认为空字符串
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 15:30:56 +00:00
Agent
5b790fbdfe fix: 修复优惠金额计算逻辑
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 15:29:28 +00:00
Agent
ee5f2ab395 fix: 修复创建订单请求格式,POST JSON正常发送
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 15:26:48 +00:00
Agent
ab0d500308 feat: 新增商品详情页,点击商品卡片可查看详情
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 15:12:55 +00:00
310b61591e 更新 .drone.yml
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 13:56:22 +00:00
2ddf411050 更新 .drone.yml 2026-03-27 13:55:40 +00:00
Agent
b5f621c980 feat: 订单创建改用优惠金额字段,保留折扣率逻辑 2026-03-27 13:45:02 +00:00
b1211962ce 更新 .drone.yml
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 13:26:57 +00:00
Agent
b9a8a6dd71 fix: 商品列表页加载库存数据 2026-03-27 10:27:17 +00:00
781cca9a15 更新 .drone.yml
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 07:51:37 +00:00
Agent
df9e2b722b fix: 修复API请求,POST使用form-urlencoded格式匹配后端@RequestParam 2026-03-27 07:47:35 +00:00
c2929ae00a 更新 .drone.yml
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 07:37:47 +00:00
aea526d4bb 更新 .drone.yml
Some checks failed
continuous-integration/drone/push Build is failing
2026-03-27 06:03:37 +00:00
e704b1018c 更新 .drone.yml 2026-03-27 05:16:49 +00:00
Agent
c399c54439 feat: 入库页面改为先选种类->商品->弹窗填数量,支持多商品批量入库 2026-03-27 04:39:35 +00:00
Agent
cd82ad2fa6 fix: 补充plus和flow图标 2026-03-27 04:09:27 +00:00
Agent
547a5bc7c7 feat: 首页增加入库和库存流水快捷入口
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 04:07:02 +00:00
Agent
345c3283e0 优化首页背景为淡粉色系
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 03:40:22 +00:00
Agent
6e26355e7d 优化菜单样式:彩色背景+白色图标文字
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 02:59:13 +00:00
Agent
42df88b654 优化功能菜单:正方形图标+去掉描述文字
All checks were successful
continuous-integration/drone/push Build is passing
2026-03-27 02:47:47 +00:00
Agent
3f9420d026 修复:删除种类时检查是否有商品 2026-03-27 02:10:25 +00:00
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
28 changed files with 4263 additions and 791 deletions

View File

@@ -28,7 +28,7 @@ steps:
- name: dev-build - name: dev-build
image: ccr.ccs.tencentyun.com/violin/node:22-bookworm image: ccr.ccs.tencentyun.com/violin/node:22-bookworm
commands: commands:
- npm run build:h5 - npm run build:h5 -- --mode development
volumes: volumes:
- name: node-cache - name: node-cache
path: /root/.npm path: /root/.npm
@@ -85,7 +85,7 @@ steps:
- name: prod-build - name: prod-build
image: ccr.ccs.tencentyun.com/violin/node:22-bookworm image: ccr.ccs.tencentyun.com/violin/node:22-bookworm
commands: commands:
- npm run build:h5 - npm run build:h5 -- --mode production
volumes: volumes:
- name: node-cache - name: node-cache
path: /root/.npm path: /root/.npm

3
.env.development Normal file
View File

@@ -0,0 +1,3 @@
# 环境配置
VITE_API_BASE_URL=https://sales.violin-work.online/api/v1
VITE_H5_BASE_URL=https://sales.violin-work.online

3
.env.production Normal file
View File

@@ -0,0 +1,3 @@
# 环境配置
VITE_API_BASE_URL=https://sales.violin-work.online/api/v1
VITE_H5_BASE_URL=https://sales.violin-work.online

16
.gitignore vendored Normal file
View File

@@ -0,0 +1,16 @@
# 本地环境变量覆盖(不提交)
.env.local
.env.*.local
# 构建输出
dist/
unpackage/
# IDE
.idea/
.vscode/
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@@ -22,14 +22,14 @@ export default {
* 新增客户 * 新增客户
*/ */
createCustomer(data) { createCustomer(data) {
return api.request('/customers', 'POST', data) return api.request('/customers', 'POST', {}, data)
}, },
/** /**
* 修改客户 * 修改客户
*/ */
updateCustomer(id, data) { updateCustomer(id, data) {
return api.request(`/customers/${id}`, 'PUT', data) return api.request(`/customers/${id}`, 'PUT', {}, data)
}, },
/** /**

View File

@@ -1,22 +1,35 @@
// API基础配置 // API基础配置
const BASE_URL = 'https://sales.violin-work.online/api/v1' const BASE_URL = import.meta.env.VITE_API_BASE_URL || 'https://sales.violin-work.online/api/v1'
// 请求拦截器 // 请求拦截器
const request = (url, method, data = {}) => { const request = (url, method, query = {}, data = {}) => {
const token = uni.getStorageSync('token') const token = uni.getStorageSync('token')
const userId = uni.getStorageSync('userId') || '' const userId = uni.getStorageSync('userId') || ''
const username = uni.getStorageSync('username') || '' const username = uni.getStorageSync('username') || ''
const role = uni.getStorageSync('role') || ''
// 特殊情况:入库和库存调整需要 form-urlencoded 格式
const useFormData = (url.includes('/stock/in') || url.includes('/stock/adjust')) && Object.keys(data).length > 0
// GET 请求用 query 参数,其他请求有 data 时发 data没 data 时发空对象
let requestData = {}
if (method === 'GET') {
requestData = query
} else if (Object.keys(data).length > 0) {
requestData = data
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.request({ uni.request({
url: BASE_URL + url, url: BASE_URL + url,
method: method, method: method,
data: data, data: requestData,
header: { header: {
'Content-Type': 'application/json', 'Content-Type': useFormData ? 'application/x-www-form-urlencoded' : 'application/json',
'Authorization': token ? `Bearer ${token}` : '', 'Authorization': token ? `Bearer ${token}` : '',
'X-User-Id': userId, 'X-User-Id': userId,
'X-Username': username 'X-Username': username,
'X-User-Role': role
}, },
success: (res) => { success: (res) => {
if (res.data.code === 0) { if (res.data.code === 0) {

View File

@@ -22,7 +22,7 @@ export default {
* } * }
*/ */
createOrder(data) { createOrder(data) {
return api.request('/orders', 'POST', data) return api.request('/orders', 'POST', {}, data)
}, },
/** /**
@@ -57,14 +57,14 @@ export default {
* 更新订单状态 * 更新订单状态
*/ */
updateOrderStatus(id, status) { updateOrderStatus(id, status) {
return api.request(`/orders/${id}/status`, 'PUT', { status }) return api.request(`/orders/${id}/status`, 'PUT', {}, { status })
}, },
/** /**
* 更新订单(编辑) * 更新订单(编辑)
*/ */
updateOrder(id, data) { updateOrder(id, data) {
return api.request(`/orders/${id}`, 'PUT', data) return api.request(`/orders/${id}`, 'PUT', {}, data)
}, },
/** /**

View File

@@ -15,7 +15,7 @@ export default {
* 新增分类 * 新增分类
*/ */
createCategory(data) { createCategory(data) {
return api.request('/products/categories', 'POST', data) return api.request('/products/categories', 'POST', {}, data)
}, },
/** /**
@@ -33,12 +33,19 @@ export default {
}, },
/** /**
* 获取商品列表 * 获取商品列表(只显示上架)
*/ */
getProducts(params) { getProducts(params) {
return api.request('/products', 'GET', params) return api.request('/products', 'GET', params)
}, },
/**
* 获取所有商品(包括下架,用于管理)
*/
getAllProducts(params) {
return api.request('/products/all', 'GET', params)
},
/** /**
* 获取商品详情 * 获取商品详情
*/ */
@@ -50,14 +57,14 @@ export default {
* 新增商品 * 新增商品
*/ */
createProduct(data) { createProduct(data) {
return api.request('/products', 'POST', data) return api.request('/products', 'POST', {}, data)
}, },
/** /**
* 修改商品 * 修改商品
*/ */
updateProduct(id, data) { updateProduct(id, data) {
return api.request(`/products/${id}`, 'PUT', data) return api.request(`/products/${id}`, 'PUT', {}, data)
}, },
/** /**

View File

@@ -22,7 +22,7 @@ export default {
* 入库 * 入库
*/ */
stockIn(data) { stockIn(data) {
return api.request('/stock/in', 'POST', data) return api.request('/stock/in', 'POST', null, data)
}, },
/** /**

View File

@@ -1,88 +1,61 @@
<template> <template>
<text class="icon" :class="'icon-' + name" :style="iconStyle"></text> <text class="iconfont" :style="{ fontSize: size + 'rpx', color: color }">{{ iconChar }}</text>
</template> </template>
<script> <script>
// 干净的非emoji符号 // 使用专业图标符号不是emoji不是汉字
const icons = { const icons = {
home: '🏠', home: '', // 首页
user: '👤', user: '', // 用户
chart: '📊', chart: '', // 图表
product: '📦', product: '', // 商品
add: '+', add: '+', // 添加
search: '🔍', search: '', // 搜索
order: '📋', order: '', // 订单
edit: '✎', edit: '✎', // 编辑
check: '✓', check: '✓', // 确认
close: '✕', close: '✕', // 关闭
stock: '🏭', stock: '', // 库存
alert: '⚡', alert: '⚡', // 警告
in: '↓', in: '↓', // 入
out: '↑', out: '↑', // 出
customer: '👥', customer: '', // 客户
money: '💳', money: '¤', // 钱
logout: '', logout: '', // 退出
right: '', right: '', // 右
left: '', left: '', // 左
down: '⌄', down: '⌄', // 下
lock: '🔐', lock: '', // 锁
filter: '', calendar: '', // 日历
calendar: '📅', setting: '', // 设置
setting: '', wechat: '', // 微信
wechat: '💬', cash: '¤', // 现金
cash: '💵', alipay: '¤', // 支付宝
alipay: '💙' plus: '+', // 加
flow: '↔' // 流水
} }
export default { export default {
name: 'Icon', name: 'Icon',
props: { props: {
name: { name: { type: String, required: true },
type: String, size: { type: [Number, String], default: 32 },
required: true color: { type: String, default: '' }
},
size: {
type: [Number, String],
default: 32
},
color: {
type: String,
default: ''
}
}, },
computed: { 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() { iconChar() {
return icons[this.name] || '' return icons[this.name] || '·'
} }
} }
} }
</script> </script>
<style> <style>
.icon { .iconfont {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-family: sans-serif;
font-weight: normal;
font-style: normal;
text-decoration: none;
display: inline-block; 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> </style>

View File

@@ -30,6 +30,12 @@
"navigationBarTitleText": "选择商品" "navigationBarTitleText": "选择商品"
} }
}, },
{
"path": "pages/product/detail",
"style": {
"navigationBarTitleText": "商品详情"
}
},
{ {
"path": "pages/order/create", "path": "pages/order/create",
"style": { "style": {
@@ -42,6 +48,24 @@
"navigationBarTitleText": "订单列表" "navigationBarTitleText": "订单列表"
} }
}, },
{
"path": "pages/order/search",
"style": {
"navigationBarTitleText": "订单查询"
}
},
{
"path": "pages/order/return",
"style": {
"navigationBarTitleText": "退货"
}
},
{
"path": "pages/order/detail",
"style": {
"navigationBarTitleText": "订单详情"
}
},
{ {
"path": "pages/stock/list", "path": "pages/stock/list",
"style": { "style": {
@@ -60,11 +84,30 @@
"navigationBarTitleText": "库存流水" "navigationBarTitleText": "库存流水"
} }
}, },
{
"path": "pages/customer/create",
"style": {
"navigationBarTitleText": "新增客户"
}
},
{
"path": "pages/customer/list",
"style": {
"navigationBarTitleText": "客户列表"
}
},
{ {
"path": "pages/category/index", "path": "pages/category/index",
"style": { "style": {
"navigationBarTitleText": "种类管理" "navigationBarTitleText": "种类管理"
} }
},
{
"path": "pages/share/order",
"style": {
"navigationBarTitleText": "订单详情",
"navigationStyle": "custom"
}
} }
], ],
"globalStyle": { "globalStyle": {
@@ -84,7 +127,7 @@
"text": "首页" "text": "首页"
}, },
{ {
"pagePath": "pages/product/list", "pagePath": "pages/product/manage",
"text": "商品" "text": "商品"
}, },
{ {

View File

@@ -121,6 +121,15 @@ export default {
} }
}, },
deleteCategory(cat) { deleteCategory(cat) {
// 先检查该分类下是否有商品
uni.showLoading({ title: '检查中...' })
productApi.getProducts({ categoryId: cat.categoryId, page: 1, pageSize: 1 }).then(res => {
uni.hideLoading()
if (res.records && res.records.length > 0) {
uni.showToast({ title: '该分类下有商品,无法删除', icon: 'none' })
return
}
uni.showModal({ uni.showModal({
title: '确认删除', title: '确认删除',
content: `确定要删除 "${cat.name}" 吗?`, content: `确定要删除 "${cat.name}" 吗?`,
@@ -136,6 +145,10 @@ export default {
} }
} }
}) })
}).catch(() => {
uni.hideLoading()
uni.showToast({ title: '检查失败', icon: 'none' })
})
} }
} }
} }

View File

@@ -0,0 +1,197 @@
<template>
<view class="page">
<view class="form-card">
<view class="form-item">
<text class="label">客户种类 *</text>
<picker :range="typeOptions" range-key="label" @change="onTypeChange">
<view class="picker-input">
<text :class="form.type ? '' : 'placeholder'">{{ form.typeLabel || '请选择客户种类' }}</text>
<text class="arrow"></text>
</view>
</picker>
</view>
<view class="form-item">
<text class="label">手机号 *</text>
<input class="input" v-model="form.phone" placeholder="请输入手机号" type="number" />
</view>
<view class="form-item">
<text class="label">客户姓名 *</text>
<input class="input" v-model="form.name" placeholder="请输入客户姓名" />
</view>
<view class="form-item">
<text class="label">微信号</text>
<input class="input" v-model="form.wechat" placeholder="请输入微信号" />
</view>
</view>
<button class="submit-btn" @click="submit">{{ isEdit ? '保存修改' : '保存' }}</button>
<button class="delete-btn" v-if="isEdit" @click="deleteCustomer">删除客户</button>
</view>
</template>
<script>
import customerApi from '@/api/customer'
export default {
data() {
return {
customerId: '',
typeOptions: [
{ label: '顾客', value: 'customer' },
{ label: '木匠', value: 'carpenter' },
{ label: '装修公司', value: 'company' }
],
form: {
type: '',
typeLabel: '',
phone: '',
name: '',
wechat: ''
}
}
},
computed: {
isEdit() {
return !!this.customerId
}
},
onLoad(options) {
if (options.id) {
this.customerId = options.id
this.form.type = options.type || ''
this.form.typeLabel = options.typeLabel || ''
this.form.phone = options.phone || ''
this.form.name = options.name || ''
this.form.wechat = options.wechat || ''
}
},
methods: {
onTypeChange(e) {
const idx = e.detail.value
this.form.type = this.typeOptions[idx].value
this.form.typeLabel = this.typeOptions[idx].label
},
async submit() {
if (!this.form.type) {
uni.showToast({ title: '请选择客户种类', icon: 'none' })
return
}
if (!this.form.phone) {
uni.showToast({ title: '请输入手机号', icon: 'none' })
return
}
if (!this.form.name) {
uni.showToast({ title: '请输入客户姓名', icon: 'none' })
return
}
try {
if (this.isEdit) {
await customerApi.updateCustomer(this.customerId, this.form)
uni.showToast({ title: '修改成功', icon: 'success' })
} else {
await customerApi.createCustomer(this.form)
uni.showToast({ title: '添加成功', icon: 'success' })
}
setTimeout(() => uni.switchTab({ url: '/pages/index/index' }), 1500)
} catch (e) {
uni.showToast({ title: e.message || '操作失败', icon: 'none' })
}
},
deleteCustomer() {
uni.showModal({
title: '确认删除',
content: '确定要删除该客户吗?',
success: async (res) => {
if (res.confirm) {
try {
await customerApi.deleteCustomer(this.customerId)
uni.showToast({ title: '删除成功', icon: 'success' })
setTimeout(() => uni.switchTab({ url: '/pages/index/index' }), 1500)
} catch (e) {
uni.showToast({ title: e.message || '删除失败', icon: 'none' })
}
}
}
})
}
}
}
</script>
<style>
.page {
padding: 30rpx;
background: #f5f5f5;
min-height: 100vh;
}
.form-card {
background: #fff;
border-radius: 16rpx;
padding: 30rpx;
}
.form-item {
margin-bottom: 30rpx;
}
.label {
display: block;
font-size: 26rpx;
color: #333;
margin-bottom: 16rpx;
}
.input {
width: 100%;
height: 80rpx;
background: #f5f5f5;
border-radius: 12rpx;
padding: 0 20rpx;
font-size: 28rpx;
box-sizing: border-box;
}
.picker-input {
width: 100%;
height: 80rpx;
background: #f5f5f5;
border-radius: 12rpx;
padding: 0 20rpx;
font-size: 28rpx;
display: flex;
justify-content: space-between;
align-items: center;
box-sizing: border-box;
}
.picker-input .placeholder {
color: #999;
}
.arrow {
font-size: 32rpx;
color: #999;
}
.submit-btn {
margin-top: 40rpx;
height: 88rpx;
background: #1890ff;
color: #fff;
border-radius: 44rpx;
font-size: 30rpx;
border: none;
}
.delete-btn {
margin-top: 20rpx;
height: 88rpx;
background: #fff;
color: #ff4d4f;
border-radius: 44rpx;
font-size: 30rpx;
border: 2rpx solid #ff4d4f;
}
</style>

145
src/pages/customer/list.vue Normal file
View File

@@ -0,0 +1,145 @@
<template>
<view class="page">
<view class="search-bar">
<input class="search-input" v-model="keyword" placeholder="搜索客户姓名或手机号" @input="search" />
</view>
<scroll-view scroll-y class="list">
<view
v-for="item in customers"
:key="item.customerId"
class="customer-card"
@click="viewDetail(item)"
>
<view class="info">
<view class="name-row">
<text class="name">{{ item.name }}</text>
<text class="type-tag" v-if="item.type">{{ typeLabelMap[item.type] }}</text>
</view>
<text class="phone">{{ item.phone }}</text>
<text class="wechat" v-if="item.wechat">{{ item.wechat }}</text>
</view>
<text class="arrow"></text>
</view>
<view v-if="customers.length === 0" class="empty">暂无客户</view>
</scroll-view>
</view>
</template>
<script>
import customerApi from '@/api/customer'
export default {
data() {
return {
keyword: '',
customers: [],
typeLabelMap: { customer: '顾客', carpenter: '木匠', company: '装修公司' }
}
},
onLoad() {
this.loadCustomers()
},
methods: {
async loadCustomers() {
try {
const res = await customerApi.getCustomers({ keyword: this.keyword, page: 1, pageSize: 100 })
this.customers = res.records || []
} catch (e) {
console.error(e)
}
},
search() {
this.loadCustomers()
},
viewDetail(item) {
const typeLabelMap = { customer: '顾客', carpenter: '木匠', company: '装修公司' }
uni.navigateTo({
url: `/pages/customer/create?id=${item.customerId}&type=${item.type}&typeLabel=${typeLabelMap[item.type] || ''}&name=${item.name}&phone=${item.phone}&wechat=${item.wechat || ''}`
})
}
}
}
</script>
<style>
.page {
padding: 20rpx;
background: #f5f5f5;
height: 100vh;
display: flex;
flex-direction: column;
}
.search-bar {
background: #fff;
border-radius: 16rpx;
padding: 20rpx;
margin-bottom: 20rpx;
}
.search-input {
width: 100%;
height: 64rpx;
background: #f5f5f5;
border-radius: 32rpx;
padding: 0 30rpx;
font-size: 26rpx;
}
.list {
flex: 1;
}
.customer-card {
background: #fff;
border-radius: 16rpx;
padding: 24rpx;
margin-bottom: 16rpx;
display: flex;
justify-content: space-between;
align-items: center;
}
.info {
display: flex;
flex-direction: column;
}
.name {
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.name-row {
display: flex;
align-items: center;
}
.type-tag {
font-size: 22rpx;
color: #fff;
background: #1890ff;
padding: 4rpx 12rpx;
border-radius: 20rpx;
margin-left: 12rpx;
}
.phone, .wechat {
font-size: 24rpx;
color: #999;
margin-top: 6rpx;
}
.arrow {
font-size: 36rpx;
color: #ccc;
}
.empty {
text-align: center;
color: #999;
padding: 60rpx;
}
</style>

View File

@@ -1,275 +1,167 @@
<template> <template>
<view class="page"> <view class="page">
<!-- 顶部欢迎区域 --> <!-- 顶部欢迎 -->
<view class="header"> <view class="header">
<view class="welcome-section"> <view class="user-section">
<text class="welcome-text">欢迎回来</text> <text class="welcome">{{ greeting }}</text>
<text class="username">{{ userInfo.username || '用户' }}</text> <text class="username" v-if="username">{{ username }}</text>
<text class="username" v-else>请登录</text>
</view> </view>
<view class="role-badge" :class="roleClass"> <view class="logout-btn" @click="logout" v-if="username">
<Icon name="user" :size="24" color="#fff" /> <text>退出</text>
<text class="role-text">{{ roleText }}</text>
</view> </view>
</view> </view>
<!-- 快捷操作 - 管理员/销售 --> <!-- 订单区域 -->
<view class="stats-card" v-if="!isCustomer && !isGuest"> <view class="section">
<view class="card-header"> <text class="section-title">订单</text>
<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"> <view class="menu-grid">
<!-- 管理员菜单 -->
<template v-if="isAdmin"> <template v-if="isAdmin">
<view class="menu-card" @click="goTo('/pages/product/manage')"> <view class="menu-item" @click="goTo('/pages/order/create')">
<view class="menu-card-icon blue"> <view class="menu-icon-box blue"><text class="icon-text"></text></view>
<Icon name="product" :size="40" color="#fff" /> <text class="menu-text">创建订单</text>
</view> </view>
<text class="menu-card-title">商品管理</text> <view class="menu-item" @click="goToTab('/pages/order/list')">
<text class="menu-card-desc">管理商品库存</text> <view class="menu-icon-box green"><text class="icon-text"></text></view>
<text class="menu-text">订单列表</text>
</view> </view>
<view class="menu-card" @click="goTo('/pages/category/index')"> <view class="menu-item" @click="goTo('/pages/order/search')">
<view class="menu-card-icon purple"> <view class="menu-icon-box orange"><text class="icon-text"></text></view>
<Icon name="setting" :size="40" color="#fff" /> <text class="menu-text">订单查询</text>
</view> </view>
<text class="menu-card-title">种类管理</text> <view class="menu-item" @click="goTo('/pages/order/return')">
<text class="menu-card-desc">管理商品种类</text> <view class="menu-icon-box red"><text class="icon-text">退</text></view>
</view> <text class="menu-text">退货</text>
<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> </view>
</template> </template>
<!-- 销售菜单 -->
<template v-else-if="isSales"> <template v-else-if="isSales">
<view class="menu-card" @click="goTo('/pages/product/list')"> <view class="menu-item" @click="goTo('/pages/order/create')">
<view class="menu-card-icon blue"> <view class="menu-icon-box blue"><text class="icon-text"></text></view>
<Icon name="product" :size="40" color="#fff" /> <text class="menu-text">创建订单</text>
</view> </view>
<text class="menu-card-title">商品浏览</text> <view class="menu-item" @click="goToTab('/pages/order/list')">
<text class="menu-card-desc">查看商品列表</text> <view class="menu-icon-box green"><text class="icon-text"></text></view>
</view> <text class="menu-text">订单列表</text>
<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>
</template> </template>
<!-- 顾客菜单 -->
<template v-else-if="isCustomer"> <template v-else-if="isCustomer">
<view class="menu-card" @click="goTo('/pages/product/list')"> <view class="menu-item" @click="goToTab('/pages/order/list')">
<view class="menu-card-icon blue"> <view class="menu-icon-box green"><text class="icon-text"></text></view>
<Icon name="product" :size="40" color="#fff" /> <text class="menu-text">我的订单</text>
</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>
</template> </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> </view>
</view>
<!-- 管理区域 -->
<view class="section" v-if="isAdmin || isSales">
<text class="section-title">管理</text>
<view class="menu-grid">
<template v-if="isAdmin">
<view class="menu-item" @click="goTo('/pages/customer/create')">
<view class="menu-icon-box blue"><text class="icon-text">新增</text></view>
<text class="menu-text">新增客户</text>
</view>
<view class="menu-item" @click="goTo('/pages/customer/list')">
<view class="menu-icon-box cyan"><text class="icon-text"></text></view>
<text class="menu-text">客户列表</text>
</view>
<view class="menu-item" @click="goTo('/pages/product/manage')">
<view class="menu-icon-box purple"><text class="icon-text"></text></view>
<text class="menu-text">商品管理</text>
</view>
<view class="menu-item" @click="goTo('/pages/category/index')">
<view class="menu-icon-box pink"><text class="icon-text"></text></view>
<text class="menu-text">种类管理</text>
</view>
<view class="menu-item" @click="goTo('/pages/stock/in')">
<view class="menu-icon-box orange"><text class="icon-text"></text></view>
<text class="menu-text">入库</text>
</view>
<view class="menu-item" @click="goTo('/pages/stock/flow')">
<view class="menu-icon-box green"><text class="icon-text"></text></view>
<text class="menu-text">库存流水</text>
</view>
</template>
<template v-else-if="isSales">
<view class="menu-item" @click="goTo('/pages/product/list')">
<view class="menu-icon-box purple"><text class="icon-text"></text></view>
<text class="menu-text">商品浏览</text>
</view>
</template>
</view>
</view>
<!-- 商品区域顾客 -->
<view class="section" v-if="isCustomer">
<text class="section-title">商品</text>
<view class="menu-grid">
<view class="menu-item" @click="goTo('/pages/product/list')">
<view class="menu-icon-box purple"><text class="icon-text"></text></view>
<text class="menu-text">商品浏览</text>
</view>
</view>
</view>
<!-- 游客登录 -->
<view class="guest-section" v-if="!username">
<view class="guest-btn" @click="goTo('/pages/login/index')">
<text class="guest-text">点击登录</text> <text class="guest-text">点击登录</text>
<text class="guest-desc">登录后使用完整功能</text>
</view> </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>
</view> </view>
</template> </template>
<script> <script>
import authApi from '@/api/auth' import { isAdmin, isSales, isCustomer } from '@/utils/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 { export default {
data() { data() {
return { return {
userInfo: {}, username: '',
role: 'guest', greeting: ''
isAdmin: false,
isSales: false,
isCustomer: false,
isGuest: false,
stats: {
orderCount: 0,
actualAmount: 0,
stockAlerts: 0
}
} }
}, },
computed: { computed: {
roleText() { isAdmin() { return isAdmin() },
if (this.isAdmin) return '管理员' isSales() { return isSales() },
if (this.isSales) return '销售员' isCustomer() { return isCustomer() }
if (this.isCustomer) return '顾客'
return '游客'
}, },
roleClass() { onShow() {
if (this.isAdmin) return 'admin' this.username = uni.getStorageSync('username') || ''
if (this.isCustomer) return 'customer' this.setGreeting()
return ''
}
},
onLoad() {
this.role = getRole()
this.isAdmin = isAdmin()
this.isSales = isSales()
this.isCustomer = checkIsCustomer()
this.isGuest = checkIsGuest()
this.loadUserInfo()
if (canViewStats()) {
this.loadStats()
}
}, },
methods: { methods: {
async loadUserInfo() { setGreeting() {
const localRole = uni.getStorageSync('role') const hour = new Date().getHours()
if (localRole) { if (hour < 6) this.greeting = '凌晨好'
this.userInfo = { else if (hour < 12) this.greeting = '上午好'
username: localRole === 'admin' ? '管理员' : '顾客', else if (hour < 14) this.greeting = '中午好'
role: localRole else if (hour < 18) this.greeting = '下午好'
} else this.greeting = '晚上好'
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) { goTo(url) {
// tabBar 页面需要用 switchTab
if (url.startsWith('/pages/product/manage') || url.startsWith('/pages/order/list') || url.startsWith('/pages/index/index')) {
uni.switchTab({ url })
} else {
uni.navigateTo({ url }) uni.navigateTo({ url })
}
}, },
goToTab(url) { goToTab(url) {
uni.switchTab({ url }) uni.switchTab({ url })
}, },
goStock() { logout() {
uni.navigateTo({ url: '/pages/stock/list' }) uni.showModal({
}, title: '退出登录',
async logout() { content: '确定要退出吗?',
try { success: (res) => {
await authApi.logout() if (res.confirm) {
} catch (e) { uni.clearStorageSync()
console.error(e) uni.reLaunch({ url: '/pages/index/index' })
} }
uni.removeStorageSync('token') }
uni.removeStorageSync('userId') })
uni.removeStorageSync('role')
uni.reLaunch({ url: '/pages/login/index' })
} }
} }
} }
@@ -278,280 +170,124 @@ export default {
<style> <style>
.page { .page {
min-height: 100vh; min-height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); background: #f5f5f5;
padding: 30rpx; padding: 20rpx;
} }
.header { .header {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
padding: 40rpx 20rpx; background: #fff;
margin-bottom: 30rpx; padding: 30rpx;
border-radius: 16rpx;
margin-bottom: 20rpx;
} }
.welcome-section { .user-section {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
.welcome-text { .welcome {
font-size: 28rpx; font-size: 24rpx;
color: rgba(255, 255, 255, 0.8); color: #999;
margin-bottom: 8rpx;
} }
.username { .username {
font-size: 48rpx; font-size: 34rpx;
font-weight: bold; font-weight: bold;
color: #fff; color: #333;
margin-top: 6rpx;
} }
.role-badge { .logout-btn {
display: flex; font-size: 26rpx;
align-items: center; color: #666;
padding: 12rpx 24rpx; padding: 12rpx 24rpx;
background: #f5f5f5;
border-radius: 30rpx; border-radius: 30rpx;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
} }
.role-badge.admin { .section {
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; background: #fff;
border-radius: 24rpx; border-radius: 16rpx;
padding: 30rpx; padding: 24rpx;
margin-bottom: 30rpx;
box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.1);
}
.card-header {
margin-bottom: 20rpx; 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 { .section-title {
font-size: 32rpx; font-size: 28rpx;
font-weight: bold; font-weight: bold;
color: #fff; color: #333;
margin-bottom: 20rpx; margin-bottom: 24rpx;
display: block; padding-left: 16rpx;
border-left: 6rpx solid #1890ff;
} }
.menu-grid { .menu-grid {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
justify-content: space-between;
} }
.menu-card { .menu-item {
width: 48%; width: 25%;
background: #fff;
border-radius: 24rpx;
padding: 30rpx;
margin-bottom: 20rpx;
box-shadow: 0 8rpx 30rpx rgba(0, 0, 0, 0.1);
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center;
padding: 16rpx 0;
} }
.menu-card:active { .menu-icon-box {
transform: scale(0.98); width: 130rpx;
opacity: 0.9; height: 130rpx;
} border-radius: 28rpx;
.menu-card-icon {
width: 80rpx;
height: 80rpx;
border-radius: 20rpx;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: 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; margin-bottom: 20rpx;
} }
.menu-icon-box.blue { background: #e8f4ff; }
.menu-icon-box.green { background: #f6ffed; }
.menu-icon-box.orange { background: #fff7e6; }
.menu-icon-box.red { background: #fff1f0; }
.menu-icon-box.purple { background: #f9f0ff; }
.menu-icon-box.pink { background: #fff0f6; }
.menu-icon-box.cyan { background: #e6f7ff; }
.icon-text {
font-size: 52rpx;
font-weight: bold;
}
.blue .icon-text { color: #1890ff; }
.green .icon-text { color: #52c41a; }
.orange .icon-text { color: #fa8c16; }
.red .icon-text { color: #ff4d4f; }
.purple .icon-text { color: #722ed1; }
.pink .icon-text { color: #eb2f96; }
.cyan .icon-text { color: #13c2c2; }
.menu-text {
font-size: 24rpx;
color: #666;
}
.guest-section {
margin-top: 200rpx;
display: flex;
justify-content: center;
}
.guest-btn {
background: #1890ff;
padding: 30rpx 80rpx;
border-radius: 50rpx;
}
.guest-text { .guest-text {
font-size: 32rpx; font-size: 32rpx;
font-weight: bold;
color: #fff; 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> </style>

View File

@@ -6,11 +6,25 @@
<text class="section-icon">👤</text> <text class="section-icon">👤</text>
<text class="section-title">客户信息</text> <text class="section-title">客户信息</text>
</view> </view>
<view class="form-item">
<text class="label">客户种类</text>
<picker
mode="selector"
:range="typeOptions"
range-key="label"
@change="selectType"
>
<view class="picker-value">
{{ selectedTypeLabel || '请选择客户种类' }}
<text class="arrow"></text>
</view>
</picker>
</view>
<view class="form-item"> <view class="form-item">
<text class="label">客户</text> <text class="label">客户</text>
<picker <picker
mode="selector" mode="selector"
:range="customers" :range="filteredCustomers"
range-key="name" range-key="name"
@change="selectCustomer" @change="selectCustomer"
> >
@@ -32,18 +46,24 @@
<view v-for="(item, index) in orderItems" :key="index" class="order-item"> <view v-for="(item, index) in orderItems" :key="index" class="order-item">
<view class="item-info"> <view class="item-info">
<text class="item-name">{{ item.productName }}</text> <text class="item-name-box">{{ item.productName }}</text>
<text class="item-spec">{{ item.spec || '-' }}</text> <text class="item-spec">{{ item.spec ? ' ' + item.spec : '' }}</text>
<text class="item-dims" v-if="item.length && item.width">{{ item.length }}x{{ item.width }}</text>
<text class="item-stock">库存: {{ stocks[item.productId] || 0 }}</text>
</view> </view>
<view class="item-edit"> <view class="item-edit">
<view class="quantity-edit"> <view class="quantity-edit">
<text class="qty-label">数量</text> <text class="qty-label">数量</text>
<view class="qty-wrapper">
<text class="qty-btn" @click="qtyMinus(index)">-</text>
<input <input
class="qty-input" class="qty-input"
type="number" type="number"
v-model="item.quantity" v-model="item.quantity"
@change="calcAmount" @change="onQuantityChange(index)"
/> />
<text class="qty-btn" @click="qtyPlus(index)">+</text>
</view>
</view> </view>
<view class="price-edit"> <view class="price-edit">
<text class="qty-label">单价</text> <text class="qty-label">单价</text>
@@ -72,14 +92,14 @@
<text class="section-title">优惠设置</text> <text class="section-title">优惠设置</text>
</view> </view>
<view class="form-item"> <view class="form-item">
<text class="label">折扣率</text> <text class="label">优惠金额</text>
<input <input
class="discount-input" class="discount-input"
type="digit" type="digit"
v-model="discountRate" v-model="discountMoney"
@change="calcAmount" @input="calcAmount"
/> />
<text class="unit">%</text> <text class="unit"></text>
</view> </view>
</view> </view>
@@ -153,19 +173,29 @@
<text>实付: </text> <text>实付: </text>
<text class="submit-amount">¥{{ actualAmount.toFixed(2) }}</text> <text class="submit-amount">¥{{ actualAmount.toFixed(2) }}</text>
</view> </view>
<button class="submit-btn" @click="createOrder">创建订单</button> <button class="submit-btn" @click="createOrder">{{ editingOrderId ? '保存订单' : '创建订单' }}</button>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import orderApi from '@/api/order' import orderApi from '@/api/order'
import stockApi from '@/api/stock'
import productApi from '@/api/product' import productApi from '@/api/product'
import customerApi from '@/api/customer' import customerApi from '@/api/customer'
export default { export default {
data() { data() {
return { return {
// 客户种类
typeOptions: [
{ label: '顾客', value: 'customer' },
{ label: '木匠', value: 'carpenter' },
{ label: '装修公司', value: 'company' }
],
selectedType: 'customer',
selectedTypeLabel: '顾客',
// 客户相关 // 客户相关
customers: [], customers: [],
selectedCustomer: null, selectedCustomer: null,
@@ -174,11 +204,13 @@ export default {
orderItems: [], orderItems: [],
productList: [], productList: [],
searchKeyword: '', searchKeyword: '',
stocks: {}, // 商品库存
// 金额相关 // 金额相关
discountRate: 100, // 折扣率 discountRate: 100, // 折扣率保留逻辑默认100%不打折)
discountMoney: 0, // 优惠金额
totalAmount: 0, // 原价 totalAmount: 0, // 原价
discountAmount: 0, // 优惠金额 discountAmount: 0, // 优惠金额(计算结果)
actualAmount: 0, // 实付金额 actualAmount: 0, // 实付金额
// 其他 // 其他
@@ -186,15 +218,28 @@ export default {
remark: '', remark: '',
// 编辑模式 // 编辑模式
editingOrderId: null editingOrderId: null,
tempCustomerId: null, // 临时保存编辑时的客户ID
tempCustomerType: null // 临时保存编辑时的客户种类
} }
}, },
onLoad(options) { onLoad(options) {
this.loadCustomers() this.loadCustomersByType()
this.loadProducts() this.loadProducts()
this.loadStocks()
if (options.orderId) { if (options.orderId) {
this.editingOrderId = options.orderId this.editingOrderId = options.orderId
// 编辑模式
uni.setNavigationBarTitle({ title: '编辑订单' })
// 等客户列表加载完成后再加载订单
setTimeout(() => {
this.loadOrder(options.orderId) this.loadOrder(options.orderId)
}, 500)
}
},
computed: {
filteredCustomers() {
return this.customers.filter(c => c.type === this.selectedType)
} }
}, },
methods: { methods: {
@@ -203,10 +248,9 @@ export default {
const detail = await orderApi.getOrderDetail(orderId) const detail = await orderApi.getOrderDetail(orderId)
const order = detail.order const order = detail.order
// 设置订单信息 // 先保存 customerId等客户列表加载完成后再匹配
if (order.customerId) { this.tempCustomerId = order.customerId
this.selectedCustomer = this.customers.find(c => c.customerId === order.customerId) this.tempCustomerType = order.customerType
}
this.orderItems = (detail.items || []).map(item => ({ this.orderItems = (detail.items || []).map(item => ({
productId: item.productId, productId: item.productId,
@@ -214,22 +258,43 @@ export default {
spec: item.productSpec, spec: item.productSpec,
unit: item.unit, unit: item.unit,
price: item.price, price: item.price,
quantity: item.quantity quantity: item.quantity,
length: item.length || '',
width: item.width || '',
area: item.area || ''
})) }))
this.discountRate = order.discountRate this.discountRate = order.discountRate
this.discountMoney = order.discountMoney || 0
this.remark = order.remark || '' this.remark = order.remark || ''
this.paymentMethod = order.paymentMethod || 'cash' this.paymentMethod = order.paymentMethod || 'cash'
this.calcAmount() this.calcAmount()
// 尝试匹配客户
this.matchCustomer()
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
}, },
matchCustomer() {
if (this.tempCustomerId && this.customers.length > 0) {
this.selectedCustomer = this.customers.find(c => c.customerId === this.tempCustomerId)
if (this.tempCustomerType) {
this.selectedType = this.tempCustomerType
const typeOption = this.typeOptions.find(t => t.value === this.tempCustomerType)
if (typeOption) {
this.selectedTypeLabel = typeOption.label
}
}
}
},
async loadCustomers() { async loadCustomers() {
try { try {
const res = await customerApi.getCustomers({ page: 1, pageSize: 100 }) const res = await customerApi.getCustomers({ page: 1, pageSize: 100 })
this.customers = res.records || [] this.customers = res.records || []
// 客户列表加载完成后,尝试匹配编辑订单的客户
this.matchCustomer()
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
@@ -242,8 +307,42 @@ export default {
console.error(e) console.error(e)
} }
}, },
async loadStocks() {
try {
const res = await stockApi.getStockList({ page: 1, pageSize: 500 })
const stockMap = {}
if (res.records) {
res.records.forEach(s => {
stockMap[s.productId] = s.quantity || 0
})
}
this.stocks = stockMap
} catch (e) {
console.error(e)
}
},
selectCustomer(e) { selectCustomer(e) {
this.selectedCustomer = this.customers[e.detail.value] this.selectedCustomer = this.filteredCustomers[e.detail.value]
},
selectType(e) {
const idx = e.detail.value
this.selectedType = this.typeOptions[idx].value
this.selectedTypeLabel = this.typeOptions[idx].label
// 切换种类后清除已选客户,重新拉取该种类的客户
this.selectedCustomer = null
this.loadCustomersByType()
},
async loadCustomersByType() {
try {
const res = await customerApi.getCustomers({
type: this.selectedType,
page: 1,
pageSize: 100
})
this.customers = res.records || []
} catch (e) {
console.error(e)
}
}, },
goToSelectProduct() { goToSelectProduct() {
uni.navigateTo({ url: '/pages/product/select' }) uni.navigateTo({ url: '/pages/product/select' })
@@ -262,6 +361,9 @@ export default {
spec: product.spec, spec: product.spec,
unit: product.unit, unit: product.unit,
price: product.price, price: product.price,
length: product.length || '',
width: product.width || '',
area: product.area || '',
quantity: 1 quantity: 1
}) })
this.calcAmount() this.calcAmount()
@@ -270,6 +372,38 @@ export default {
this.orderItems.splice(index, 1) this.orderItems.splice(index, 1)
this.calcAmount() this.calcAmount()
}, },
qtyMinus(index) {
const item = this.orderItems[index]
const stock = this.stocks[item.productId] || 0
if (item.quantity > 1) {
item.quantity--
this.calcAmount()
}
},
qtyPlus(index) {
const item = this.orderItems[index]
const stock = this.stocks[item.productId] || 0
if (item.quantity < stock) {
item.quantity++
this.calcAmount()
} else {
uni.showToast({ title: '库存不足', icon: 'none' })
}
},
onQuantityChange(index) {
const item = this.orderItems[index]
const stock = this.stocks[item.productId] || 0
let qty = parseInt(item.quantity)
if (isNaN(qty) || qty < 1) {
qty = 1
}
if (qty > stock) {
qty = stock
uni.showToast({ title: '库存不足,已调整为最大库存', icon: 'none' })
}
item.quantity = qty
this.calcAmount()
},
// 核心金额计算逻辑 // 核心金额计算逻辑
calcAmount() { calcAmount() {
// 1. 计算原价 = Σ(单价 × 数量) // 1. 计算原价 = Σ(单价 × 数量)
@@ -277,8 +411,12 @@ export default {
return sum + (item.price * item.quantity) return sum + (item.price * item.quantity)
}, 0) }, 0)
// 2. 计算优惠金额 = 原价 × (100 - 折扣率) / 100 // 2. 优惠金额直接使用用户输入的值,不能为负
this.discountAmount = this.totalAmount * (100 - this.discountRate) / 100 let discountVal = parseFloat(this.discountMoney)
if (isNaN(discountVal) || discountVal < 0) {
discountVal = 0
}
this.discountAmount = discountVal
// 3. 计算实付金额 = 原价 - 优惠金额 // 3. 计算实付金额 = 原价 - 优惠金额
this.actualAmount = this.totalAmount - this.discountAmount this.actualAmount = this.totalAmount - this.discountAmount
@@ -289,14 +427,37 @@ export default {
return return
} }
// 校验:客户必须选择
if (!this.selectedCustomer) {
uni.showToast({ title: '请选择客户', icon: 'none' })
return
}
// 校验实付金额必须大于0
if (this.actualAmount <= 0) {
uni.showToast({ title: '实付金额必须大于0', icon: 'none' })
return
}
// 校验:优惠金额不能为负
const discountVal = parseFloat(this.discountMoney) || 0
if (discountVal < 0) {
uni.showToast({ title: '优惠金额不能为负', icon: 'none' })
return
}
const data = { const data = {
customerId: this.selectedCustomer ? this.selectedCustomer.customerId : null, customerId: this.selectedCustomer ? this.selectedCustomer.customerId : null,
items: this.orderItems.map(item => ({ items: this.orderItems.map(item => ({
productId: item.productId, productId: item.productId,
quantity: item.quantity, quantity: item.quantity,
price: item.price price: item.price,
length: item.length || null,
width: item.width || null,
area: item.area || null
})), })),
discountRate: parseFloat(this.discountRate), discountRate: 100, // 保留折扣率逻辑默认100%
discountMoney: parseFloat(this.discountMoney) || 0,
remark: this.remark, remark: this.remark,
paymentMethod: this.paymentMethod paymentMethod: this.paymentMethod
} }
@@ -311,10 +472,10 @@ export default {
uni.showToast({ title: '订单创建成功', icon: 'success' }) uni.showToast({ title: '订单创建成功', icon: 'success' })
} }
// 跳转到订单列表(未完成) // 跳转到订单列表
setTimeout(() => { setTimeout(() => {
uni.switchTab({ uni.switchTab({
url: '/pages/order/list?status=0' url: '/pages/order/list'
}) })
}, 1500) }, 1500)
} catch (e) { } catch (e) {
@@ -417,13 +578,19 @@ export default {
.item-info { .item-info {
margin-bottom: 16rpx; margin-bottom: 16rpx;
display: flex;
align-items: center;
flex-wrap: wrap;
} }
.item-name { .item-name-box {
font-size: 28rpx; font-size: 28rpx;
font-weight: bold; font-weight: bold;
display: block;
color: #333; color: #333;
width: 170rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
} }
.item-spec { .item-spec {
@@ -431,6 +598,21 @@ export default {
color: #999; color: #999;
} }
.item-dims {
font-size: 22rpx;
color: #667eea;
background: #f0f0ff;
padding: 2rpx 8rpx;
border-radius: 4rpx;
margin-left: 8rpx;
}
.item-stock {
font-size: 22rpx;
color: #999;
margin-left: auto;
}
.item-edit { .item-edit {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -439,23 +621,69 @@ export default {
.quantity-edit, .price-edit { .quantity-edit, .price-edit {
display: flex; display: flex;
align-items: center; align-items: center;
margin-right: 20rpx; margin-right: 24rpx;
} }
.qty-label { .qty-label {
font-size: 24rpx; font-size: 24rpx;
color: #666; color: #666;
margin-right: 8rpx; margin-right: 8rpx;
white-space: nowrap;
} }
.qty-input, .price-input { .qty-wrapper {
display: flex;
align-items: center;
background: #f5f5f5;
border-radius: 8rpx;
}
.qty-btn {
width: 48rpx;
height: 48rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 32rpx;
color: #667eea;
background: #fff;
border: 1rpx solid #ddd;
}
.qty-btn:first-child {
border-radius: 8rpx 0 0 8rpx;
}
.qty-btn:last-child {
border-radius: 0 8rpx 8rpx 0;
}
.qty-input {
width: 100rpx; width: 100rpx;
height: 56rpx; height: 48rpx;
background: #fff;
border: 1rpx solid #ddd;
border-left: none;
border-right: none;
text-align: center;
font-size: 24rpx;
}
.price-input {
width: 120rpx;
height: 48rpx;
background: #fff; background: #fff;
border: 1rpx solid #ddd; border: 1rpx solid #ddd;
border-radius: 8rpx; border-radius: 8rpx;
text-align: center; text-align: center;
font-size: 24rpx; font-size: 24rpx;
margin-left: 8rpx;
}
.stock-info {
font-size: 20rpx;
color: #999;
margin-left: 12rpx;
} }
.item-subtotal { .item-subtotal {

461
src/pages/order/detail.vue Normal file
View File

@@ -0,0 +1,461 @@
<template>
<view class="page" v-if="order">
<!-- 订单信息 -->
<view class="order-header">
<view class="header-row">
<text class="label">订单编号</text>
<text class="value">{{ order.orderNo }}</text>
</view>
<view class="header-row">
<text class="label">订单状态</text>
<text class="status" :class="getStatusClass(order.status)">{{ getStatusText(order.status) }}</text>
</view>
<view class="header-row">
<text class="label">下单时间</text>
<text class="value">{{ formatTime(order.createdAt) }}</text>
</view>
</view>
<!-- 客户信息 -->
<view class="section">
<view class="section-title">客户信息</view>
<view class="section-content">
<view class="info-row">
<text class="label">客户姓名</text>
<text class="value">{{ order.customerName || '散客' }}</text>
</view>
<view class="info-row" v-if="order.customerPhone">
<text class="label">联系电话</text>
<text class="value">{{ order.customerPhone }}</text>
</view>
</view>
</view>
<!-- 商品明细 -->
<view class="section">
<view class="section-title">商品明细</view>
<view class="items-list">
<view class="item-row header">
<text class="item-info">商品信息</text>
<text class="item-area">总面积()</text>
<text class="item-qty">数量</text>
<text class="item-price">单价</text>
<text class="item-subtotal">小计</text>
</view>
<view
v-for="(item, index) in orderItems"
:key="index"
class="item-row"
>
<text class="item-info"><text class="item-name-text">{{ item.productName }}</text><text class="item-spec-text">{{ item.productSpec ? ' ' + item.productSpec : '' }}</text><text class="item-dims-text">{{ item.length || '-' }}x{{ item.width || '-' }}</text></text>
<text class="item-area">{{ calcArea(item) }}</text>
<text class="item-qty">{{ item.quantity }}</text>
<text class="item-price">¥{{ item.price }}</text>
<text class="item-subtotal">¥{{ (item.price * item.quantity).toFixed(0) }}</text>
</view>
</view>
</view>
<!-- 金额信息 -->
<view class="section">
<view class="section-title">金额信息</view>
<view class="section-content">
<view class="info-row">
<text class="label">原价合计</text>
<text class="value">¥{{ order.totalAmount }}</text>
</view>
<view class="info-row">
<text class="label">优惠金额</text>
<text class="value discount">-¥{{ order.discountAmount }}</text>
</view>
<view class="info-row">
<text class="label">实付金额</text>
<text class="value actual">¥{{ order.actualAmount }}</text>
</view>
<view class="info-row" v-if="order.paymentMethod">
<text class="label">支付方式</text>
<text class="value">{{ getPaymentMethod(order.paymentMethod) }}</text>
</view>
<view class="info-row" v-if="order.remark">
<text class="label">备注</text>
<text class="value">{{ order.remark }}</text>
</view>
</view>
</view>
<!-- 操作信息 -->
<view class="section" v-if="order.operatorName">
<view class="section-title">操作信息</view>
<view class="section-content">
<view class="info-row">
<text class="label">操作员</text>
<text class="value">{{ order.operatorName }}</text>
</view>
</view>
</view>
<!-- 底部操作栏 -->
<view class="bottom-bar">
<button class="share-btn" v-if="order.status !== 2" @click="shareOrder">
分享订单
</button>
<button class="print-btn" v-if="order.status !== 2" @click="printOrder">
打印订单
</button>
<button
class="action-btn"
v-if="order.status === 0"
@click="confirmOrder"
>
确认完成
</button>
<button
class="action-btn cancel"
v-if="order.status === 0"
@click="cancelOrder"
>
取消订单
</button>
</view>
</view>
</template>
<script>
import orderApi from '@/api/order'
export default {
data() {
return {
orderId: '',
order: null,
orderItems: []
}
},
onLoad(options) {
if (options.orderId) {
this.orderId = options.orderId
this.loadOrderDetail()
}
},
methods: {
async loadOrderDetail() {
try {
const res = await orderApi.getOrderDetail(this.orderId)
this.order = res.order
this.orderItems = res.items || []
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
}
},
getStatusClass(status) {
const map = {
1: 'status-success',
2: 'status-cancel',
3: 'status-refunding',
4: 'status-refunded',
9: 'status-returning'
}
return map[status] || ''
},
getStatusText(status) {
const map = {
0: '未完成',
1: '已完成',
2: '已取消',
3: '退款中',
4: '已退款',
9: '退货中'
}
return map[status] || '未知'
},
formatTime(time) {
if (!time) return ''
return time.substring(0, 16).replace('T', ' ')
},
calcArea(item) {
if (item.length && item.width && item.quantity) {
return (item.length * item.width * item.quantity / 1000000).toFixed(4)
}
return '-'
},
getPaymentMethod(method) {
const map = {
'cash': '现金',
'wechat': '微信',
'alipay': '支付宝'
}
return map[method] || method
},
async confirmOrder() {
uni.showModal({
title: '确认订单',
content: '确认完成后订单将变为已完成状态',
success: async (res) => {
if (res.confirm) {
try {
await orderApi.updateOrderStatus(this.orderId, 1)
uni.showToast({ title: '已确认', icon: 'success' })
this.loadOrderDetail()
} catch (e) {
uni.showToast({ title: '操作失败', icon: 'none' })
}
}
}
})
},
async cancelOrder() {
uni.showModal({
title: '取消订单',
content: '确定要取消此订单吗?',
success: async (res) => {
if (res.confirm) {
try {
await orderApi.updateOrderStatus(this.orderId, 2)
uni.showToast({ title: '已取消', icon: 'success' })
this.loadOrderDetail()
} catch (e) {
uni.showToast({ title: '操作失败', icon: 'none' })
}
}
}
})
},
printOrder() {
uni.showToast({ title: '打印功能开发中', icon: 'none' })
},
shareOrder() {
// 构建分享链接包含订单号和客户ID
const h5BaseUrl = import.meta.env.VITE_H5_BASE_URL
const customerId = this.order.customerId || ''
const shareUrl = `${h5BaseUrl}/#/pages/share/order?orderNo=${this.order.orderNo}&customerId=${customerId}`
// 复制链接到剪贴板
uni.setClipboardData({
data: shareUrl,
success: () => {
uni.showModal({
title: '分享链接已复制',
content: '订单分享链接已复制,可粘贴发送给客户',
showCancel: false,
confirmText: '知道了'
})
}
})
},
}
}
</script>
<style>
.page {
min-height: 100vh;
background: #f8f9fa;
padding-bottom: 180rpx;
}
.order-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 30rpx;
color: #fff;
}
.header-row {
display: flex;
justify-content: space-between;
margin-bottom: 16rpx;
}
.header-row .label {
font-size: 26rpx;
opacity: 0.8;
}
.header-row .value {
font-size: 26rpx;
}
.status {
padding: 4rpx 16rpx;
border-radius: 20rpx;
font-size: 24rpx;
}
.status-success {
background: #52c41a;
color: #fff;
}
.status-cancel {
background: #ff4d4f;
color: #fff;
}
.status-returning {
background: #fa8c16;
color: #fff;
}
.section {
background: #fff;
margin: 20rpx;
border-radius: 16rpx;
overflow: hidden;
}
.section-title {
padding: 24rpx 30rpx;
font-size: 28rpx;
font-weight: bold;
color: #333;
border-bottom: 1rpx solid #f0f0f0;
}
.section-content {
padding: 10rpx 30rpx;
}
.info-row {
display: flex;
justify-content: space-between;
padding: 16rpx 0;
border-bottom: 1rpx solid #f8f8f8;
}
.info-row:last-child {
border-bottom: none;
}
.info-row .label {
font-size: 26rpx;
color: #666;
}
.info-row .value {
font-size: 26rpx;
color: #333;
}
.info-row .value.discount {
color: #ff4d4f;
}
.info-row .value.actual {
color: #ff4d4f;
font-weight: bold;
font-size: 30rpx;
}
.items-list {
padding: 0 30rpx;
}
.item-row {
display: flex;
padding: 20rpx 0;
border-bottom: 1rpx solid #f8f8f8;
font-size: 24rpx;
align-items: center;
}
.item-row.header {
font-weight: bold;
color: #666;
background: #f8f9fa;
padding: 16rpx 0;
}
.item-info {
flex: 3;
font-size: 24rpx;
color: #333;
line-height: 1.6;
}
.item-name-text {
color: #333;
font-weight: 500;
}
.item-spec-text {
color: #999;
}
.item-dims-text {
color: #666;
margin-left: 8rpx;
}
.item-area {
flex: 1.5;
text-align: center;
color: #667eea;
font-weight: 500;
}
.item-qty {
flex: 0.8;
text-align: center;
}
.item-price {
flex: 1;
text-align: right;
}
.item-subtotal {
flex: 1;
text-align: right;
color: #ff4d4f;
}
.bottom-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
display: flex;
padding: 20rpx 30rpx;
background: #fff;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
gap: 20rpx;
}
.print-btn {
flex: 1;
height: 88rpx;
line-height: 88rpx;
background: #fff;
color: #667eea;
border: 2rpx solid #667eea;
border-radius: 44rpx;
font-size: 28rpx;
}
.share-btn {
flex: 1;
height: 88rpx;
line-height: 88rpx;
background: linear-gradient(135deg, #52c41a 0%, #73d13d 100%);
color: #fff;
border: none;
border-radius: 44rpx;
font-size: 28rpx;
}
.action-btn {
flex: 1;
height: 88rpx;
line-height: 88rpx;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
border: none;
border-radius: 44rpx;
font-size: 28rpx;
}
.action-btn.cancel {
background: #fff;
color: #ff4d4f;
border: 2rpx solid #ff4d4f;
}
</style>

View File

@@ -121,9 +121,14 @@ export default {
} }
}, },
onLoad(options) { onLoad(options) {
if (options.status) { // 默认加载全部订单,不筛选状态
this.status = parseInt(options.status) this.status = null
} console.log('onLoad - 加载订单列表')
this.loadOrders()
},
onShow() {
// 每次进入页面都刷新数据
this.page = 1
this.loadOrders() this.loadOrders()
}, },
onReachBottom() { onReachBottom() {
@@ -149,17 +154,13 @@ export default {
page: this.page, page: this.page,
pageSize: this.pageSize pageSize: this.pageSize
}) })
console.log('订单列表响应:', res)
const list = res.records || [] const list = res.records || []
// 加载每个订单的明细 // 直接使用订单中的items不再单独请求
for (const order of list) { for (const order of list) {
try { this.$set(this.orderItemsMap, order.orderId, order.items || [])
const detail = await orderApi.getOrderDetail(order.orderId)
this.$set(this.orderItemsMap, order.orderId, detail.items || [])
} catch (e) {
console.error(e)
}
} }
if (this.page === 1) { if (this.page === 1) {
@@ -179,12 +180,16 @@ export default {
this.page = 1 this.page = 1
this.loadOrders() this.loadOrders()
}, },
// 调试用:查看所有订单(不筛选状态)
loadAllOrders() {
this.status = null
this.page = 1
this.loadOrders()
},
viewDetail(order) { viewDetail(order) {
// 跳转到订单详情页或显示详情弹窗 // 跳转到订单详情页
uni.showModal({ uni.navigateTo({
title: '订单详情', url: `/pages/order/detail?orderId=${order.orderId}`
content: `订单号: ${order.orderNo}\n原价: ¥${order.totalAmount}\n优惠: ¥${order.discountAmount}\n实付: ¥${order.actualAmount}`,
showCancel: false
}) })
}, },
getItemCount(orderId) { getItemCount(orderId) {
@@ -196,7 +201,8 @@ export default {
1: 'status-success', 1: 'status-success',
2: 'status-cancel', 2: 'status-cancel',
3: 'status-refunding', 3: 'status-refunding',
4: 'status-refunded' 4: 'status-refunded',
9: 'status-returning'
} }
return map[status] || '' return map[status] || ''
}, },
@@ -206,7 +212,8 @@ export default {
1: '已完成', 1: '已完成',
2: '已取消', 2: '已取消',
3: '退款中', 3: '退款中',
4: '已退款' 4: '已退款',
9: '退货中'
} }
return map[status] || '未知' return map[status] || '未知'
}, },
@@ -355,6 +362,11 @@ export default {
color: #fff; color: #fff;
} }
.status-returning {
background: linear-gradient(135deg, #fa8c16 0%, #ffc069 100%);
color: #fff;
}
/* 卡片主体 */ /* 卡片主体 */
.card-body { .card-body {
margin-bottom: 20rpx; margin-bottom: 20rpx;

538
src/pages/order/return.vue Normal file
View File

@@ -0,0 +1,538 @@
<template>
<view class="page">
<!-- 搜索栏 -->
<view class="search-section">
<view class="search-bar">
<text class="search-icon">🔍</text>
<input
class="search-input"
v-model="keyword"
placeholder="输入客户姓名或手机号搜索"
placeholder-class="placeholder"
@input="searchCustomers"
/>
</view>
</view>
<!-- 搜索结果列表 -->
<scroll-view scroll-y class="result-section">
<view v-if="loading" class="loading">加载中...</view>
<view v-else-if="customers.length === 0 && keyword" class="empty">
<text class="empty-icon">👤</text>
<text class="empty-text">未找到相关客户</text>
</view>
<view v-else-if="customers.length > 0" class="customer-list">
<view
v-for="customer in customers"
:key="customer.customerId"
class="customer-card"
@click="selectCustomer(customer)"
>
<view class="customer-info">
<text class="customer-name">{{ customer.name }}</text>
<text class="customer-phone">{{ customer.phone || '' }}</text>
</view>
<text class="arrow"></text>
</view>
</view>
<view v-else-if="selectedCustomer" class="selected-info">
<text>已选择: {{ selectedCustomer.name }}</text>
<text class="clear-btn" @click="clearSelection">清除</text>
</view>
</scroll-view>
<!-- 已选客户的商品列表可退货 -->
<view class="goods-section" v-if="selectedCustomer">
<view class="goods-header">
<text class="goods-title">{{ selectedCustomer.name }} 可退货的商品</text>
</view>
<scroll-view scroll-y class="goods-list">
<view
v-for="item in returnableGoods"
:key="item.productId + '_' + item.orderId"
class="goods-card"
>
<view class="goods-info">
<text class="goods-name">{{ item.productName }}</text>
<text class="goods-spec">{{ item.spec || '-' }}</text>
<text class="goods-order">订单: {{ item.orderNo }}</text>
</view>
<view class="goods-action">
<text class="goods-qty">已购: {{ item.quantity }}可退: {{ item.returnableQty }}</text>
<button
class="return-btn"
@click="showReturnDialog(item)"
:disabled="item.returnableQty <= 0"
>
退货
</button>
</view>
</view>
<view v-if="returnableGoods.length === 0" class="empty-tip">
暂无可退货商品
</view>
</scroll-view>
</view>
<!-- 退货数量弹窗 -->
<view class="popup-mask" v-if="showPopup" @click="closePopup"></view>
<view class="popup-content" v-if="showPopup">
<view class="popup-header">
<text class="popup-title">退货 - {{ currentItem.productName }}</text>
<text class="popup-close" @click="closePopup">×</text>
</view>
<view class="popup-body">
<view class="popup-info">
<text>订单: {{ currentItem.orderNo }}</text>
<text>可退数量: {{ currentItem.returnableQty }}</text>
</view>
<view class="popup-qty">
<text class="qty-label">退货数量</text>
<view class="qty-input-wrapper">
<text class="qty-minus" @click="qtyMinus">-</text>
<input
class="qty-input"
type="number"
v-model="returnQty"
/>
<text class="qty-plus" @click="qtyPlus">+</text>
</view>
</view>
</view>
<view class="popup-footer">
<button class="popup-btn cancel" @click="closePopup">取消</button>
<button class="popup-btn confirm" @click="confirmReturn">确定</button>
</view>
</view>
</view>
</template>
<script>
import orderApi from '@/api/order'
import customerApi from '@/api/customer'
export default {
data() {
return {
keyword: '',
customers: [],
selectedCustomer: null,
returnableGoods: [],
loading: false,
// 弹窗相关
showPopup: false,
currentItem: {},
returnQty: 1
}
},
methods: {
async searchCustomers() {
if (!this.keyword.trim()) {
this.customers = []
return
}
this.loading = true
try {
const res = await customerApi.getCustomers({
keyword: this.keyword.trim(),
page: 1,
pageSize: 20
})
this.customers = res.records || []
} catch (e) {
console.error(e)
} finally {
this.loading = false
}
},
async selectCustomer(customer) {
this.selectedCustomer = customer
this.keyword = ''
this.customers = []
this.loadReturnableGoods()
},
clearSelection() {
this.selectedCustomer = null
this.returnableGoods = []
},
async loadReturnableGoods() {
if (!this.selectedCustomer) return
try {
const res = await orderApi.getOrders({
customerId: this.selectedCustomer.customerId,
status: 1, // 已完成
page: 1,
pageSize: 100
})
const orders = res.records || []
// 收集每个已完成订单的商品
const goodsMap = {}
for (const order of orders) {
try {
const detail = await orderApi.getOrderDetail(order.orderId)
const items = detail.items || []
for (const item of items) {
const key = item.productId
if (!goodsMap[key]) {
goodsMap[key] = {
productId: item.productId,
productName: item.productName,
spec: item.productSpec,
orderId: order.orderId,
orderNo: order.orderNo,
quantity: 0,
returnableQty: 0
}
}
goodsMap[key].quantity += item.quantity
// TODO: 需要查询已退货数量这里暂用quantity
goodsMap[key].returnableQty = goodsMap[key].quantity
}
} catch (e) {
console.error(e)
}
}
this.returnableGoods = Object.values(goodsMap)
} catch (e) {
console.error(e)
}
},
showReturnDialog(item) {
this.currentItem = item
this.returnQty = 1
this.showPopup = true
},
closePopup() {
this.showPopup = false
},
qtyMinus() {
if (this.returnQty > 1) {
this.returnQty--
}
},
qtyPlus() {
if (this.returnQty < this.currentItem.returnableQty) {
this.returnQty++
}
},
async confirmReturn() {
if (this.returnQty <= 0 || this.returnQty > this.currentItem.returnableQty) {
uni.showToast({ title: '退货数量无效', icon: 'none' })
return
}
try {
await orderApi.refundOrder(this.currentItem.orderId)
uni.showToast({ title: '退货成功', icon: 'success' })
this.closePopup()
this.loadReturnableGoods()
} catch (e) {
console.error(e)
uni.showToast({ title: e.message || '退货失败', icon: 'none' })
}
}
}
}
</script>
<style>
.page {
min-height: 100vh;
background: #f8f9fa;
display: flex;
flex-direction: column;
}
.search-section {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 30rpx;
}
.search-bar {
display: flex;
align-items: center;
background: rgba(255, 255, 255, 0.95);
border-radius: 50rpx;
padding: 0 30rpx;
height: 80rpx;
}
.search-icon {
font-size: 32rpx;
margin-right: 16rpx;
}
.search-input {
flex: 1;
font-size: 28rpx;
color: #333;
}
.placeholder {
color: #999;
}
.result-section {
padding: 20rpx;
}
.loading, .empty {
text-align: center;
color: #999;
padding: 60rpx;
}
.empty-icon {
font-size: 60rpx;
display: block;
margin-bottom: 16rpx;
}
.selected-info {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20rpx;
background: #e6f7ff;
border-radius: 12rpx;
margin: 20rpx;
color: #1890ff;
}
.clear-btn {
color: #ff4d4f;
font-size: 26rpx;
}
.customer-list {
display: flex;
flex-direction: column;
}
.customer-card {
display: flex;
justify-content: space-between;
align-items: center;
background: #fff;
padding: 24rpx;
margin-bottom: 16rpx;
border-radius: 12rpx;
}
.customer-info {
display: flex;
flex-direction: column;
}
.customer-name {
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.customer-phone {
font-size: 24rpx;
color: #999;
margin-top: 8rpx;
}
.arrow {
font-size: 36rpx;
color: #ccc;
}
.goods-section {
flex: 1;
background: #fff;
padding: 20rpx;
overflow: hidden;
display: flex;
flex-direction: column;
}
.goods-header {
margin-bottom: 20rpx;
}
.goods-title {
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.goods-list {
flex: 1;
}
.goods-card {
padding: 20rpx;
border-bottom: 1rpx solid #f0f0f0;
}
.goods-info {
margin-bottom: 12rpx;
}
.goods-name {
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.goods-spec {
font-size: 24rpx;
color: #999;
}
.goods-order {
font-size: 22rpx;
color: #666;
}
.goods-action {
display: flex;
justify-content: space-between;
align-items: center;
}
.goods-qty {
font-size: 24rpx;
color: #666;
}
.return-btn {
padding: 10rpx 30rpx;
background: #ff4d4f;
color: #fff;
font-size: 24rpx;
border-radius: 30rpx;
border: none;
}
.return-btn[disabled] {
background: #ccc;
}
.empty-tip {
text-align: center;
color: #999;
padding: 60rpx;
}
/* 弹窗 */
.popup-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 100;
}
.popup-content {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: #fff;
border-radius: 32rpx 32rpx 0 0;
padding: 40rpx 30rpx;
padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
z-index: 101;
}
.popup-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30rpx;
}
.popup-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
}
.popup-close {
font-size: 48rpx;
color: #999;
padding: 10rpx;
}
.popup-info {
display: flex;
justify-content: space-between;
margin-bottom: 30rpx;
color: #666;
font-size: 26rpx;
}
.popup-qty {
display: flex;
align-items: center;
}
.qty-label {
font-size: 28rpx;
color: #333;
width: 160rpx;
}
.qty-input-wrapper {
display: flex;
align-items: center;
background: #f5f5f5;
border-radius: 12rpx;
}
.qty-minus, .qty-plus {
width: 80rpx;
height: 80rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 40rpx;
color: #667eea;
}
.qty-input {
width: 120rpx;
height: 80rpx;
text-align: center;
font-size: 32rpx;
background: transparent;
border-left: 1rpx solid #eee;
border-right: 1rpx solid #eee;
}
.popup-footer {
display: flex;
gap: 20rpx;
margin-top: 40rpx;
}
.popup-btn {
flex: 1;
height: 88rpx;
line-height: 88rpx;
border-radius: 44rpx;
font-size: 30rpx;
font-weight: bold;
}
.popup-btn.cancel {
background: #f5f5f5;
color: #666;
}
.popup-btn.confirm {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
}
</style>

452
src/pages/order/search.vue Normal file
View File

@@ -0,0 +1,452 @@
<template>
<view class="page">
<!-- 搜索栏 -->
<view class="search-section">
<view class="search-bar">
<text class="search-icon">🔍</text>
<input
class="search-input"
v-model="keyword"
placeholder="输入客户姓名或手机号搜索"
placeholder-class="placeholder"
@input="searchCustomers"
/>
</view>
</view>
<!-- 搜索结果列表 -->
<scroll-view scroll-y class="result-section">
<view v-if="loading" class="loading">加载中...</view>
<view v-else-if="customers.length === 0 && keyword" class="empty">
<text class="empty-icon">👤</text>
<text class="empty-text">未找到相关客户</text>
</view>
<view v-else-if="customers.length > 0" class="customer-list">
<view
v-for="customer in customers"
:key="customer.customerId"
class="customer-card"
@click="selectCustomer(customer)"
>
<view class="customer-info">
<text class="customer-name">{{ customer.name }}</text>
<text class="customer-phone">{{ customer.phone || '' }}</text>
</view>
<text class="arrow"></text>
</view>
</view>
<view v-else-if="selectedCustomer" class="selected-info">
<text>已选择: {{ selectedCustomer.name }}</text>
<text class="clear-btn" @click="clearSelection">清除</text>
</view>
</scroll-view>
<!-- 已选客户的订单列表 -->
<view class="orders-section" v-if="selectedCustomer">
<view class="orders-header">
<text class="orders-title">{{ selectedCustomer.name }} 的订单</text>
</view>
<scroll-view scroll-y class="orders-list">
<view
v-for="order in orders"
:key="order.orderId"
class="order-card"
:class="{ 'selected': merging && order.status === 1 && selectedOrders.includes(order.orderId) }"
@click="toggleOrderSelection(order)"
>
<view class="card-checkbox" v-if="merging && order.status === 1">
<text>{{ selectedOrders.includes(order.orderId) ? '☑' : '☐' }}</text>
</view>
<view class="card-content" :class="{ 'with-checkbox': merging && order.status === 1 }">
<view class="card-header">
<text class="order-no">{{ order.orderNo }}</text>
<text class="order-status" :class="getStatusClass(order.status)">
{{ getStatusText(order.status) }}
</text>
</view>
<view class="card-body">
<text class="order-amount">实付: ¥{{ order.actualAmount }}</text>
<text class="order-time">{{ formatTime(order.createdAt) }}</text>
</view>
</view>
</view>
</scroll-view>
</view>
<!-- 合并订单按钮 -->
<view class="bottom-bar" v-if="selectedCustomer && orders.length > 0">
<button
class="merge-btn"
@click="startMerge"
v-if="!merging"
>
合并订单
</button>
<view class="merge-actions" v-else>
<button class="cancel-btn" @click="cancelMerge">取消</button>
<button
class="confirm-btn"
@click="confirmMerge"
:disabled="selectedOrders.length < 2"
>
确定 ({{ selectedOrders.length }})
</button>
</view>
</view>
</view>
</template>
<script>
import orderApi from '@/api/order'
import customerApi from '@/api/customer'
export default {
data() {
return {
keyword: '',
customers: [],
selectedCustomer: null,
orders: [],
loading: false,
// 合并订单相关
merging: false,
selectedOrders: []
}
},
methods: {
async searchCustomers() {
if (!this.keyword.trim()) {
this.customers = []
return
}
this.loading = true
try {
const res = await customerApi.getCustomers({
keyword: this.keyword.trim(),
page: 1,
pageSize: 20
})
this.customers = res.records || []
} catch (e) {
console.error(e)
} finally {
this.loading = false
}
},
async selectCustomer(customer) {
this.selectedCustomer = customer
this.keyword = ''
this.customers = []
this.loadOrders()
},
clearSelection() {
this.selectedCustomer = null
this.orders = []
this.merging = false
this.selectedOrders = []
},
toggleOrderSelection(order) {
if (!this.merging || order.status !== 1) return
const index = this.selectedOrders.indexOf(order.orderId)
if (index > -1) {
this.selectedOrders.splice(index, 1)
} else {
this.selectedOrders.push(order.orderId)
}
},
startMerge() {
this.merging = true
this.selectedOrders = []
},
cancelMerge() {
this.merging = false
this.selectedOrders = []
},
confirmMerge() {
if (this.selectedOrders.length < 2) {
uni.showToast({ title: '请至少选择2个订单', icon: 'none' })
return
}
uni.showToast({ title: '选中 ' + this.selectedOrders.length + ' 个订单', icon: 'success' })
// TODO: 后端合并订单逻辑
},
async loadOrders() {
if (!this.selectedCustomer) return
try {
const res = await orderApi.getOrders({
customerId: this.selectedCustomer.customerId,
page: 1,
pageSize: 50
})
this.orders = res.records || []
} catch (e) {
console.error(e)
}
},
getStatusClass(status) {
const map = {
1: 'status-success',
2: 'status-cancel'
}
return map[status] || ''
},
getStatusText(status) {
const map = {
0: '未完成',
1: '已完成',
2: '已取消'
}
return map[status] || '未知'
},
formatTime(time) {
if (!time) return ''
return time.substring(0, 16).replace('T', ' ')
},
viewDetail(order) {
uni.navigateTo({
url: `/pages/order/detail?orderId=${order.orderId}`
})
}
}
}
</script>
<style>
.page {
min-height: 100vh;
background: #f8f9fa;
}
.search-section {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 30rpx;
}
.search-bar {
display: flex;
align-items: center;
background: rgba(255, 255, 255, 0.95);
border-radius: 50rpx;
padding: 0 30rpx;
height: 80rpx;
}
.search-icon {
font-size: 32rpx;
margin-right: 16rpx;
}
.search-input {
flex: 1;
font-size: 28rpx;
color: #333;
}
.placeholder {
color: #999;
}
.result-section {
padding: 20rpx;
}
.loading, .empty {
text-align: center;
color: #999;
padding: 60rpx;
}
.empty-icon {
font-size: 60rpx;
display: block;
margin-bottom: 16rpx;
}
.selected-info {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20rpx;
background: #e6f7ff;
border-radius: 12rpx;
margin: 20rpx;
color: #1890ff;
}
.clear-btn {
color: #ff4d4f;
font-size: 26rpx;
}
.customer-list {
display: flex;
flex-direction: column;
}
.customer-card {
display: flex;
justify-content: space-between;
align-items: center;
background: #fff;
padding: 24rpx;
margin-bottom: 16rpx;
border-radius: 12rpx;
}
.customer-info {
display: flex;
flex-direction: column;
}
.customer-name {
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.customer-phone {
font-size: 24rpx;
color: #999;
margin-top: 8rpx;
}
.arrow {
font-size: 36rpx;
color: #ccc;
}
.orders-section {
background: #fff;
padding: 20rpx;
flex: 1;
overflow-y: auto;
}
.orders-header {
margin-bottom: 20rpx;
}
.orders-title {
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.orders-list {
flex: 1;
}
.order-card {
padding: 20rpx;
border-bottom: 1rpx solid #f0f0f0;
display: flex;
align-items: center;
}
.order-card.selected {
background: #e6f7ff;
}
.card-checkbox {
margin-right: 16rpx;
font-size: 36rpx;
}
.card-content.with-checkbox {
flex: 1;
}
.card-content {
flex: 1;
}
.card-header {
display: flex;
justify-content: space-between;
margin-bottom: 12rpx;
}
.order-no {
font-size: 26rpx;
color: #333;
}
.order-status {
font-size: 22rpx;
padding: 4rpx 12rpx;
border-radius: 16rpx;
}
.status-success {
background: #e6f7e6;
color: #52c41a;
}
.status-cancel {
background: #fff1f0;
color: #ff4d4f;
}
.card-body {
display: flex;
justify-content: space-between;
}
.order-amount {
font-size: 28rpx;
font-weight: bold;
color: #ff4d4f;
}
.order-time {
font-size: 24rpx;
color: #999;
}
.bottom-bar {
padding: 20rpx;
background: #fff;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.merge-btn {
width: 100%;
height: 88rpx;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
border: none;
border-radius: 44rpx;
font-size: 30rpx;
font-weight: bold;
}
.merge-actions {
display: flex;
gap: 20rpx;
}
.cancel-btn, .confirm-btn {
flex: 1;
height: 88rpx;
border-radius: 44rpx;
font-size: 30rpx;
font-weight: bold;
border: none;
}
.cancel-btn {
background: #f5f5f5;
color: #666;
}
.confirm-btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
}
.confirm-btn[disabled] {
background: #ccc;
}
</style>

View File

@@ -0,0 +1,250 @@
<template>
<view class="page">
<!-- 商品图片区域 -->
<view class="image-section">
<view class="product-image">
<Icon name="product" :size="120" color="#fff" />
</view>
</view>
<!-- 商品基本信息 -->
<view class="info-section">
<view class="price-row">
<text class="price">¥{{ product.price }}</text>
<text class="unit">/{{ product.unit }}</text>
</view>
<text class="product-name">{{ product.name }}</text>
<text class="product-spec">规格: {{ product.spec || '-' }}</text>
</view>
<!-- 商品详情 -->
<view class="detail-section">
<view class="detail-header">
<text class="detail-title">商品详情</text>
</view>
<view class="detail-content">
<view class="detail-item">
<text class="detail-label">商品分类</text>
<text class="detail-value">{{ categoryName }}</text>
</view>
<view class="detail-item">
<text class="detail-label">商品编码</text>
<text class="detail-value">{{ product.productId }}</text>
</view>
<view class="detail-item">
<text class="detail-label">成本价</text>
<text class="detail-value">¥{{ product.costPrice || '-' }}</text>
</view>
<view class="detail-item">
<text class="detail-label">库存预警</text>
<text class="detail-value">{{ product.stockAlert || '-' }}</text>
</view>
<view class="detail-item">
<text class="detail-label">当前库存</text>
<text class="detail-value stock">{{ stock }}</text>
</view>
</view>
</view>
<!-- 底部操作按钮 -->
<view class="bottom-bar">
<button class="btn-edit" @click="editProduct" v-if="isAdmin">
<Icon name="edit" :size="32" color="#fff" style="margin-right: 10rpx" />
编辑商品
</button>
</view>
</view>
</template>
<script>
import productApi from '@/api/product'
import stockApi from '@/api/stock'
import { isAdmin } from '@/utils/auth'
export default {
data() {
return {
productId: '',
product: {},
categoryName: '',
stock: 0,
isAdmin: false
}
},
onLoad(options) {
if (options.productId) {
this.productId = options.productId
this.isAdmin = isAdmin()
this.loadProductDetail()
this.loadStock()
}
},
methods: {
async loadProductDetail() {
try {
const res = await productApi.getProduct(this.productId)
this.product = res
// 获取分类名称
const categories = await productApi.getCategories()
const category = categories.find(c => c.categoryId === this.product.categoryId)
this.categoryName = category ? category.name : '-'
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
}
},
async loadStock() {
try {
const res = await stockApi.getStock(this.productId)
this.stock = res.quantity || 0
} catch (e) {
this.stock = 0
}
},
editProduct() {
uni.navigateTo({
url: `/pages/product/manage?productId=${this.productId}`
})
}
}
}
</script>
<style>
.page {
min-height: 100vh;
background: #f8f9fa;
padding-bottom: 120rpx;
}
/* 图片区域 */
.image-section {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 60rpx;
display: flex;
justify-content: center;
}
.product-image {
width: 300rpx;
height: 300rpx;
background: rgba(255, 255, 255, 0.2);
border-radius: 24rpx;
display: flex;
align-items: center;
justify-content: center;
}
/* 商品信息 */
.info-section {
background: #fff;
padding: 30rpx;
margin-bottom: 20rpx;
}
.price-row {
display: flex;
align-items: baseline;
margin-bottom: 16rpx;
}
.price {
font-size: 48rpx;
font-weight: bold;
color: #ff4d4f;
}
.unit {
font-size: 28rpx;
color: #999;
margin-left: 8rpx;
}
.product-name {
display: block;
font-size: 36rpx;
font-weight: bold;
color: #333;
margin-bottom: 12rpx;
}
.product-spec {
font-size: 26rpx;
color: #666;
}
/* 详情区域 */
.detail-section {
background: #fff;
margin: 0 20rpx;
border-radius: 20rpx;
overflow: hidden;
}
.detail-header {
padding: 24rpx 30rpx;
border-bottom: 1rpx solid #f0f0f0;
}
.detail-title {
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.detail-content {
padding: 10rpx 0;
}
.detail-item {
display: flex;
justify-content: space-between;
padding: 24rpx 30rpx;
border-bottom: 1rpx solid #f8f8f8;
}
.detail-item:last-child {
border-bottom: none;
}
.detail-label {
font-size: 26rpx;
color: #666;
}
.detail-value {
font-size: 26rpx;
color: #333;
}
.detail-value.stock {
font-size: 32rpx;
font-weight: bold;
color: #667eea;
}
/* 底部按钮 */
.bottom-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 20rpx 30rpx;
background: #fff;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.btn-edit {
width: 100%;
height: 88rpx;
line-height: 88rpx;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
border: none;
border-radius: 44rpx;
font-size: 30rpx;
font-weight: bold;
display: flex;
align-items: center;
justify-content: center;
}
</style>

View File

@@ -64,6 +64,7 @@
<script> <script>
import productApi from '@/api/product' import productApi from '@/api/product'
import stockApi from '@/api/stock'
export default { export default {
data() { data() {
@@ -83,12 +84,23 @@ export default {
this.loadCategories() this.loadCategories()
this.loadProducts() this.loadProducts()
}, },
onShow() {
// 每次进入页面都刷新数据
this.page = 1
this.loadProducts()
},
onReachBottom() { onReachBottom() {
if (this.hasMore && !this.loading) { if (this.hasMore && !this.loading) {
this.page++ this.page++
this.loadProducts() this.loadProducts()
} }
}, },
onPullDownRefresh() {
this.page = 1
this.loadProducts().then(() => {
uni.stopPullDownRefresh()
})
},
methods: { methods: {
async loadCategories() { async loadCategories() {
try { try {
@@ -115,12 +127,28 @@ export default {
this.products = [...this.products, ...list] this.products = [...this.products, ...list]
} }
this.hasMore = list.length >= this.pageSize this.hasMore = list.length >= this.pageSize
// 加载库存数据
this.loadStocks()
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} finally { } finally {
this.loading = false this.loading = false
} }
}, },
async loadStocks() {
try {
const res = await stockApi.getStockList({ page: 1, pageSize: 500 })
const stockList = res.records || []
const stockMap = {}
stockList.forEach(item => {
stockMap[item.productId] = item.quantity || 0
})
this.stocks = stockMap
} catch (e) {
console.error('加载库存失败', e)
}
},
selectCategory(id) { selectCategory(id) {
this.categoryId = id this.categoryId = id
this.page = 1 this.page = 1
@@ -131,7 +159,10 @@ export default {
this.loadProducts() this.loadProducts()
}, },
viewDetail(item) { viewDetail(item) {
uni.showToast({ title: '商品详情开发中', icon: 'none' }) // 跳转到商品管理页面进行编辑
uni.navigateTo({
url: `/pages/product/manage?productId=${item.productId}`
})
}, },
getStock(productId) { getStock(productId) {
return this.stocks[productId] || 0 return this.stocks[productId] || 0
@@ -177,7 +208,7 @@ export default {
} }
.category-sidebar { .category-sidebar {
width: 180rpx; width: 140rpx;
background: #fff; background: #fff;
flex-shrink: 0; flex-shrink: 0;
} }

View File

@@ -1,6 +1,7 @@
<template> <template>
<view class="page"> <view class="page">
<!-- 搜索栏 --> <!-- 搜索栏 -->
<view class="search-section">
<view class="search-bar"> <view class="search-bar">
<input <input
class="search-input" class="search-input"
@@ -8,31 +9,53 @@
placeholder="搜索商品名称" placeholder="搜索商品名称"
@confirm="search" @confirm="search"
/> />
<button class="search-btn" @click="search">搜索</button>
<button class="add-btn" @click="addProduct">+</button> <button class="add-btn" @click="addProduct">+</button>
</view> </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 class="product-list">
<view <view
v-for="item in products" v-for="item in productList"
:key="item.productId" :key="item.productId"
class="product-item" class="product-item"
> >
<view class="product-info" @click="editProduct(item)"> <view class="product-info">
<view class="product-header">
<text class="product-name">{{ item.name }}</text> <text class="product-name">{{ item.name }}</text>
<text class="product-category" v-if="item.categoryName">{{ item.categoryName }}</text>
</view>
<view class="product-row">
<text class="product-spec">{{ item.spec || '-' }}</text> <text class="product-spec">{{ item.spec || '-' }}</text>
<view class="product-price"> <text class="product-unit">/{{ item.unit }}</text>
<text class="price">¥{{ item.price }}</text> <text class="product-price-text">¥{{ item.price }}</text>
<text class="unit">/{{ item.unit }}</text> </view>
<view class="product-spec-row" v-if="item.length && item.width">
<text class="spec-text">规格{{ item.length }} x {{ item.width }} = {{ item.area }} </text>
</view> </view>
<view class="product-status"> <view class="product-status">
<text :class="['status', item.status === 1 ? 'on' : 'off']"> <text :class="['status', item.status === 1 ? 'on' : 'off']">
{{ item.status === 1 ? '上架' : '下架' }} {{ item.status === 1 ? '上架' : '下架' }}
</text> </text>
</view> </view>
</view> </view>
<view class="product-actions"> <view class="product-actions">
<view class="action-btn edit" @click="editProduct(item)" v-if="item.status === 1">
编辑
</view>
<view class="action-btn" @click="toggleStatus(item)"> <view class="action-btn" @click="toggleStatus(item)">
{{ item.status === 1 ? '下架' : '上架' }} {{ item.status === 1 ? '下架' : '上架' }}
</view> </view>
@@ -43,10 +66,12 @@
</view> </view>
<!-- 空状态 --> <!-- 空状态 -->
<view v-if="products.length === 0" class="empty"> <view v-if="productList.length === 0" class="empty">
<text>暂无商品</text> <text>暂无商品</text>
</view> </view>
</view> </view>
</scroll-view>
</view>
<!-- 商品表单弹窗 --> <!-- 商品表单弹窗 -->
<view class="modal" v-if="showModal"> <view class="modal" v-if="showModal">
@@ -58,32 +83,48 @@
</view> </view>
<view class="modal-body"> <view class="modal-body">
<view class="form-item"> <view class="form-item">
<text class="label">商品名称*</text> <text class="label"><text class="required">*</text>分类</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"> <picker :range="categories" range-key="name" @change="onCategoryChange">
<view class="picker"> <view class="picker">
{{ form.categoryId ? getCategoryName(form.categoryId) : '请选择分类' }} {{ form.categoryId ? getCategoryName(form.categoryId) : '请选择分类' }}
</view> </view>
</picker> </picker>
</view> </view>
<view class="form-item">
<text class="label"><text class="required">*</text>商品名称</text>
<input class="input" v-model="form.name" placeholder="请输入商品名称" />
</view>
<view class="form-row size-row">
<view class="form-item half">
<text class="label">长度(mm)</text>
<input class="input" type="digit" v-model="form.length" maxlength="5" />
</view>
<view class="form-item half">
<text class="label">宽度(mm)</text>
<input class="input" type="digit" v-model="form.width" maxlength="5" />
</view>
<view class="form-item half">
<text class="label">面积()</text>
<input class="input" type="digit" v-model="form.area" disabled />
</view>
</view>
<view class="form-row">
<view class="form-item half">
<text class="label">颜色</text>
<input class="input" v-model="form.spec" />
</view>
<view class="form-item half">
<text class="label"><text class="required">*</text>单位</text>
<input class="input" v-model="form.unit" placeholder="如:个、箱、米" />
</view>
</view>
<view class="form-item">
<text class="label"><text class="required">*</text>价格</text>
<input class="input" type="digit" v-model="form.price" placeholder="请输入价格" />
</view>
<view class="form-item"> <view class="form-item">
<text class="label">备注</text> <text class="label">备注</text>
<textarea class="textarea" v-model="form.remark" placeholder="请输入备注" /> <textarea class="textarea" v-model="form.remark" />
</view> </view>
</view> </view>
<view class="modal-footer"> <view class="modal-footer">
@@ -103,30 +144,55 @@ export default {
data() { data() {
return { return {
keyword: '', keyword: '',
products: [], categoryId: '',
productList: [],
categories: [], categories: [],
showModal: false, showModal: false,
isEdit: false, isEdit: false,
form: { form: {
productId: '', productId: '',
categoryId: '',
name: '', name: '',
spec: '', spec: '',
unit: '', unit: '',
price: '', price: '',
categoryId: '', length: '',
width: '',
area: '',
remark: '', remark: '',
status: 1 status: 1
} }
} }
}, },
onLoad() { onLoad(options) {
if (!canManageProduct()) { // 移除权限检查,允许所有用户访问
uni.showToast({ title: '无权限', icon: 'none' })
uni.navigateBack()
return
}
this.loadCategories() this.loadCategories()
this.loadProducts() this.loadProducts()
// 如果传入了 productId则打开编辑弹窗
if (options.productId) {
this.$nextTick(() => {
const item = this.productList.find(p => p.productId === options.productId)
if (item) {
this.editProduct(item)
}
})
}
},
computed: {
computedArea() {
const l = parseFloat(this.form.length)
const w = parseFloat(this.form.width)
// 长度(mm) × 宽度(mm) ÷ 1000000 = 面积(m²)
if (!isNaN(l) && !isNaN(w) && l > 0 && w > 0) {
return (l * w / 1000000).toFixed(4)
}
return ''
}
},
watch: {
computedArea(val) {
this.form.area = val
}
}, },
methods: { methods: {
async loadCategories() { async loadCategories() {
@@ -139,16 +205,21 @@ export default {
}, },
async loadProducts() { async loadProducts() {
try { try {
const res = await productApi.getProducts({ const res = await productApi.getAllProducts({
keyword: this.keyword, keyword: this.keyword,
categoryId: this.categoryId,
page: 1, page: 1,
pageSize: 100 pageSize: 100
}) })
this.products = res.records || [] this.productList = res.records || []
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
}, },
selectCategory(id) {
this.categoryId = id
this.loadProducts()
},
search() { search() {
this.loadProducts() this.loadProducts()
}, },
@@ -161,6 +232,9 @@ export default {
unit: '', unit: '',
price: '', price: '',
categoryId: '', categoryId: '',
length: '',
width: '',
area: '',
remark: '', remark: '',
status: 1 status: 1
} }
@@ -183,6 +257,10 @@ export default {
return cat ? cat.name : '' return cat ? cat.name : ''
}, },
async saveProduct() { async saveProduct() {
if (!this.form.categoryId) {
uni.showToast({ title: '请选择分类', icon: 'none' })
return
}
if (!this.form.name) { if (!this.form.name) {
uni.showToast({ title: '请输入商品名称', icon: 'none' }) uni.showToast({ title: '请输入商品名称', icon: 'none' })
return return
@@ -197,11 +275,12 @@ export default {
} }
try { try {
const formData = JSON.parse(JSON.stringify(this.form))
if (this.isEdit) { if (this.isEdit) {
await productApi.updateProduct(this.form) await productApi.updateProduct(formData.productId, formData)
uni.showToast({ title: '更新成功', icon: 'success' }) uni.showToast({ title: '更新成功', icon: 'success' })
} else { } else {
await productApi.createProduct(this.form) await productApi.createProduct(formData)
uni.showToast({ title: '创建成功', icon: 'success' }) uni.showToast({ title: '创建成功', icon: 'success' })
} }
this.closeModal() this.closeModal()
@@ -214,8 +293,7 @@ export default {
async toggleStatus(item) { async toggleStatus(item) {
const newStatus = item.status === 1 ? 0 : 1 const newStatus = item.status === 1 ? 0 : 1
try { try {
await productApi.updateProduct({ await productApi.updateProduct(item.productId, {
productId: item.productId,
status: newStatus status: newStatus
}) })
uni.showToast({ title: newStatus === 1 ? '已上架' : '已下架', icon: 'success' }) uni.showToast({ title: newStatus === 1 ? '已上架' : '已下架', icon: 'success' })
@@ -249,6 +327,81 @@ export default {
<style> <style>
.page { .page {
display: flex;
flex-direction: column;
height: 100vh;
}
/* 搜索区域 */
.search-section {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 20rpx;
}
.search-bar {
display: flex;
align-items: center;
background: rgba(255, 255, 255, 0.95);
border-radius: 50rpx;
padding: 0 20rpx;
height: 70rpx;
}
.search-input {
flex: 1;
font-size: 28rpx;
color: #333;
}
.add-btn {
width: 60rpx;
height: 60rpx;
line-height: 60rpx;
background: #3cc51f;
color: #fff;
border: none;
border-radius: 50%;
font-size: 36rpx;
margin-left: 16rpx;
}
/* 内容区域:侧栏+列表 */
.content-wrapper {
display: flex;
flex: 1;
overflow: hidden;
}
/* 分类侧栏 */
.category-sidebar {
width: 160rpx;
background: #fff;
flex-shrink: 0;
border-right: 1rpx solid #eee;
}
.category-item {
padding: 28rpx 16rpx;
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; padding: 20rpx;
} }
@@ -312,13 +465,57 @@ export default {
display: block; display: block;
} }
.product-header {
display: flex;
align-items: center;
justify-content: space-between;
}
.product-category {
font-size: 22rpx;
color: #667eea;
background: #f0f0ff;
padding: 4rpx 12rpx;
border-radius: 4rpx;
}
.product-spec { .product-spec {
font-size: 24rpx; font-size: 24rpx;
color: #999; color: #999;
margin-top: 8rpx;
display: block; display: block;
} }
.product-row {
display: flex;
align-items: center;
margin-top: 8rpx;
}
.product-unit {
color: #999;
font-size: 24rpx;
margin-left: 4rpx;
}
.product-price-text {
color: #ff4d4f;
font-size: 24rpx;
font-weight: bold;
margin-left: 16rpx;
}
.product-spec-row {
margin-top: 8rpx;
}
.spec-text {
font-size: 24rpx;
color: #666;
background: #f5f5f5;
padding: 4rpx 12rpx;
border-radius: 4rpx;
}
.product-price { .product-price {
margin-top: 12rpx; margin-top: 12rpx;
} }
@@ -369,6 +566,11 @@ export default {
margin-bottom: 10rpx; margin-bottom: 10rpx;
} }
.action-btn.edit {
background: #f0f5ff;
color: #667eea;
}
.action-btn.delete { .action-btn.delete {
background: #fff1f0; background: #fff1f0;
color: #ff4d4f; color: #ff4d4f;
@@ -434,6 +636,28 @@ export default {
margin-bottom: 24rpx; margin-bottom: 24rpx;
} }
.form-row {
display: flex;
gap: 20rpx;
}
.form-row .half {
flex: 1;
}
.size-row {
display: flex;
gap: 16rpx;
}
.size-row .half {
flex: 1;
}
.form-row.three .half {
flex: 1;
}
.label { .label {
display: block; display: block;
font-size: 26rpx; font-size: 26rpx;
@@ -441,13 +665,25 @@ export default {
margin-bottom: 10rpx; margin-bottom: 10rpx;
} }
.required {
color: #ff4d4f;
margin-right: 4rpx;
}
.input[disabled] {
background: #f5f5f5;
color: #999;
}
.input { .input {
width: 100%; width: 100%;
height: 70rpx; height: 70rpx;
padding: 0 20rpx; padding: 0 20rpx;
background: #f5f5f5; background: #fff;
border: 2rpx solid #e5e5e5;
border-radius: 8rpx; border-radius: 8rpx;
font-size: 28rpx; font-size: 28rpx;
box-sizing: border-box;
} }
.picker { .picker {

View File

@@ -14,7 +14,7 @@
</view> </view>
</view> </view>
<!-- 分类 + 商品列表 --> <!-- 分类侧栏 + 商品列表 -->
<view class="content-wrapper"> <view class="content-wrapper">
<!-- 左侧分类 --> <!-- 左侧分类 -->
<scroll-view scroll-y class="category-sidebar"> <scroll-view scroll-y class="category-sidebar">
@@ -29,10 +29,17 @@
<!-- 右侧商品列表 --> <!-- 右侧商品列表 -->
<scroll-view scroll-y class="product-scroll"> <scroll-view scroll-y class="product-scroll">
<view class="product-list"> <view class="product-list">
<view v-for="item in productList" :key="item.productId" class="product-item" @click="selectProduct(item)"> <view v-for="item in productList" :key="item.productId" class="product-item" :class="{ disabled: stocks[item.productId] === 0 }" @click="selectProduct(item)">
<view class="product-info"> <view class="product-info">
<text class="product-name">{{ item.name }}</text> <text class="product-name">{{ item.name }}</text>
<view class="product-row">
<text class="product-spec">{{ item.spec || '-' }}</text> <text class="product-spec">{{ item.spec || '-' }}</text>
<text class="product-size" v-if="item.length && item.width">{{ item.length }} x {{ item.width }} = {{ item.area }} m²</text>
</view>
<view class="product-stock">
<text class="stock-label">库存:</text>
<text class="stock-value" :class="{ 'stock-zero': stocks[item.productId] === 0 }">{{ stocks[item.productId] || 0 }}</text>
</view>
</view> </view>
<view class="product-price"> <view class="product-price">
<text class="price">¥{{ item.price }}</text> <text class="price">¥{{ item.price }}</text>
@@ -47,11 +54,42 @@
</view> </view>
</scroll-view> </scroll-view>
</view> </view>
<!-- 商品详情/选择弹窗 -->
<view class="modal-mask" v-if="showModal" @click="closeModal">
<view class="modal-content" @click.stop>
<view class="modal-header">
<text class="modal-title">{{ selectedProduct.name }}</text>
<text class="modal-close" @click="closeModal">×</text>
</view>
<view class="modal-body">
<view class="size-row">
<view class="size-item">
<text class="size-label">长度(cm)</text>
<input class="size-input" type="digit" v-model="selectedProduct.length" placeholder="非必填" />
</view>
<view class="size-item">
<text class="size-label">宽度(cm)</text>
<input class="size-input" type="digit" v-model="selectedProduct.width" placeholder="非必填" />
</view>
<view class="size-item">
<text class="size-label">面积()</text>
<input class="size-input" type="digit" v-model="selectedProduct.area" disabled />
</view>
</view>
</view>
<view class="modal-footer">
<button class="cancel-btn" @click="closeModal">取消</button>
<button class="confirm-btn" @click="confirmProduct">确认</button>
</view>
</view>
</view>
</view> </view>
</template> </template>
<script> <script>
import productApi from '@/api/product' import productApi from '@/api/product'
import stockApi from '@/api/stock'
export default { export default {
data() { data() {
@@ -60,9 +98,29 @@ export default {
categoryId: '', categoryId: '',
categories: [], categories: [],
productList: [], productList: [],
stocks: {}, // 商品库存
page: 1, page: 1,
pageSize: 50, pageSize: 50,
loading: false loading: false,
showModal: false,
selectedProduct: {
productId: '',
name: '',
spec: '',
unit: '',
price: 0,
length: '',
width: '',
area: ''
}
}
},
watch: {
'selectedProduct.length'(val) {
this.calcArea()
},
'selectedProduct.width'(val) {
this.calcArea()
} }
}, },
onLoad() { onLoad() {
@@ -70,6 +128,23 @@ export default {
this.getProducts() this.getProducts()
}, },
methods: { methods: {
selectProduct(item) {
// 库存为0不可选中
if (this.stocks[item.productId] === 0) {
uni.showToast({ title: '库存不足', icon: 'none' })
return
}
const pages = getCurrentPages()
const prevPage = pages[pages.length - 2]
prevPage.$vm.addProduct(item)
uni.navigateBack()
},
calcArea() {
const length = parseFloat(this.selectedProduct.length) || 0
const width = parseFloat(this.selectedProduct.width) || 0
// 长度(cm) * 宽度(cm) / 10000 = 面积(m²)
this.selectedProduct.area = length && width ? (length * width / 10000).toFixed(2) : ''
},
async loadCategories() { async loadCategories() {
try { try {
const categories = await productApi.getCategories() const categories = await productApi.getCategories()
@@ -88,6 +163,16 @@ export default {
pageSize: this.pageSize pageSize: this.pageSize
}) })
this.productList = res.records || [] this.productList = res.records || []
// 获取每个商品的库存
const stockRes = await stockApi.getStockList({ page: 1, pageSize: 500 })
const stockMap = {}
if (stockRes.records) {
stockRes.records.forEach(s => {
stockMap[s.productId] = s.quantity || 0
})
}
this.stocks = stockMap
} catch (e) { } catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' }) uni.showToast({ title: '加载失败', icon: 'none' })
} finally { } finally {
@@ -103,10 +188,31 @@ export default {
this.page = 1 this.page = 1
this.getProducts() this.getProducts()
}, },
selectProduct(item) { openProductDetail(item) {
this.selectedProduct = {
productId: item.productId,
name: item.name,
spec: item.spec,
unit: item.unit,
price: item.price,
length: '',
width: '',
area: ''
}
this.showModal = true
},
closeModal() {
this.showModal = false
},
confirmProduct() {
const pages = getCurrentPages() const pages = getCurrentPages()
const prevPage = pages[pages.length - 2] const prevPage = pages[pages.length - 2]
prevPage.$vm.addProduct(item) prevPage.$vm.addProduct({
...this.selectedProduct,
length: this.selectedProduct.length,
width: this.selectedProduct.width,
area: this.selectedProduct.area
})
uni.navigateBack() uni.navigateBack()
} }
} }
@@ -144,26 +250,29 @@ export default {
color: #999; color: #999;
} }
/* 内容区域:侧栏+列表 */
.content-wrapper { .content-wrapper {
display: flex; display: flex;
height: calc(100vh - 130rpx); height: calc(100vh - 130rpx);
} }
/* 分类侧栏 */
.category-sidebar { .category-sidebar {
width: 180rpx; width: 160rpx;
background: #fff; background: #fff;
flex-shrink: 0; flex-shrink: 0;
border-right: 1rpx solid #eee;
} }
.category-item { .category-sidebar .category-item {
padding: 28rpx 20rpx; padding: 28rpx 16rpx;
font-size: 26rpx; font-size: 26rpx;
color: #666; color: #666;
text-align: center; text-align: center;
border-left: 6rpx solid transparent; border-left: 6rpx solid transparent;
} }
.category-item.active { .category-sidebar .category-item.active {
background: #f8f9fa; background: #f8f9fa;
color: #667eea; color: #667eea;
font-weight: bold; font-weight: bold;
@@ -190,6 +299,11 @@ export default {
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06); box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.06);
} }
.product-item.disabled {
opacity: 0.5;
background: #f5f5f5;
}
.product-info { .product-info {
flex: 1; flex: 1;
} }
@@ -207,6 +321,42 @@ export default {
color: #999; color: #999;
} }
.product-row {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8rpx;
}
.product-size {
font-size: 22rpx;
color: #667eea;
background: #f0f0ff;
padding: 2rpx 8rpx;
border-radius: 4rpx;
}
.product-stock {
display: flex;
align-items: center;
margin-top: 8rpx;
}
.stock-label {
font-size: 22rpx;
color: #999;
}
.stock-value {
font-size: 22rpx;
color: #333;
margin-left: 4rpx;
}
.stock-value.stock-zero {
color: #ff4d4f;
}
.product-price { .product-price {
text-align: right; text-align: right;
} }
@@ -235,4 +385,97 @@ export default {
color: #999; color: #999;
margin-top: 20rpx; margin-top: 20rpx;
} }
/* 弹窗 */
.modal-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: 999;
}
.modal-content {
width: 80%;
background: #fff;
border-radius: 20rpx;
overflow: hidden;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 30rpx;
border-bottom: 1rpx solid #eee;
}
.modal-title {
font-size: 32rpx;
font-weight: bold;
}
.modal-close {
font-size: 48rpx;
color: #999;
}
.modal-body {
padding: 30rpx;
}
.size-row {
display: flex;
gap: 20rpx;
}
.size-item {
flex: 1;
}
.size-label {
display: block;
font-size: 26rpx;
color: #666;
margin-bottom: 10rpx;
}
.size-input {
width: 100%;
height: 70rpx;
background: #f5f5f5;
border-radius: 10rpx;
padding: 0 20rpx;
font-size: 28rpx;
box-sizing: border-box;
}
.modal-footer {
display: flex;
gap: 20rpx;
padding: 30rpx;
}
.cancel-btn, .confirm-btn {
flex: 1;
height: 80rpx;
line-height: 80rpx;
border-radius: 40rpx;
font-size: 30rpx;
}
.cancel-btn {
background: #f5f5f5;
color: #666;
}
.confirm-btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
}
</style> </style>

364
src/pages/share/order.vue Normal file
View File

@@ -0,0 +1,364 @@
<template>
<view class="page">
<!-- 自定义导航 -->
<view class="custom-nav">
<text class="nav-title">订单详情</text>
</view>
<!-- 加载中 -->
<view class="loading" v-if="loading">
<text>加载中...</text>
</view>
<!-- 错误 -->
<view class="error" v-else-if="error">
<text class="error-icon"></text>
<text class="error-text">{{ error }}</text>
</view>
<!-- 订单详情 -->
<view class="order-content" v-else-if="order">
<!-- 头部状态 -->
<view class="order-header">
<view class="status-badge" :class="getStatusClass(order.status)">
{{ order.statusText }}
</view>
<text class="order-no">订单号: {{ order.orderNo }}</text>
</view>
<!-- 客户信息 -->
<view class="section">
<view class="section-title">客户信息</view>
<view class="section-content">
<view class="info-row">
<text class="label">客户姓名</text>
<text class="value">{{ order.customerName }}</text>
</view>
<view class="info-row" v-if="order.customerPhone">
<text class="label">联系电话</text>
<text class="value">{{ order.customerPhone }}</text>
</view>
<view class="info-row">
<text class="label">下单时间</text>
<text class="value">{{ formatTime(order.createdAt) }}</text>
</view>
</view>
</view>
<!-- 商品明细 -->
<view class="section">
<view class="section-title">商品明细</view>
<view class="items-list">
<view class="item-row header">
<text class="item-info">商品信息</text>
<text class="item-area">总面积()</text>
<text class="item-qty">数量</text>
<text class="item-price">单价</text>
<text class="item-subtotal">小计</text>
</view>
<view
v-for="(item, index) in order.items"
:key="index"
class="item-row"
>
<text class="item-info"><text class="item-name-text">{{ item.productName }}</text><text class="item-spec-text">{{ item.productSpec ? ' ' + item.productSpec : '' }}</text><text class="item-dims-text">{{ item.length || '-' }}x{{ item.width || '-' }}</text></text>
<text class="item-area">{{ calcArea(item) }}</text>
<text class="item-qty">{{ item.quantity }}</text>
<text class="item-price">¥{{ item.price }}</text>
<text class="item-subtotal">¥{{ (item.price * item.quantity).toFixed(0) }}</text>
</view>
</view>
</view>
<!-- 金额信息 -->
<view class="section amount-section">
<view class="info-row">
<text class="label">原价合计</text>
<text class="value">¥{{ order.totalAmount }}</text>
</view>
<view class="info-row">
<text class="label">优惠金额</text>
<text class="value discount">-¥{{ order.discountAmount }}</text>
</view>
<view class="info-row actual">
<text class="label">实付金额</text>
<text class="value">¥{{ order.actualAmount }}</text>
</view>
<view class="info-row">
<text class="label">支付方式</text>
<text class="value">{{ order.paymentMethod }}</text>
</view>
<view class="info-row" v-if="order.remark">
<text class="label">备注</text>
<text class="value">{{ order.remark }}</text>
</view>
</view>
<!-- 店铺信息 -->
<view class="footer">
<text class="shop-name">建材销售管家</text>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
loading: true,
error: '',
order: null,
orderNo: '',
customerId: ''
}
},
onLoad(options) {
if (options.orderNo && options.customerId) {
this.orderNo = options.orderNo
this.customerId = options.customerId
this.loadOrder()
} else {
this.error = '参数不完整'
this.loading = false
}
},
methods: {
async loadOrder() {
try {
const res = await uni.request({
url: `https://sales.violin-work.online/api/v1/public/orders/${this.orderNo}?customerId=${this.customerId}`,
method: 'GET'
})
this.loading = false
if (res.data.code === 0) {
this.order = res.data.data
} else {
this.error = res.data.message || '订单不存在'
}
} catch (e) {
this.loading = false
this.error = '加载失败,请检查网络'
}
},
getStatusClass(status) {
const map = {
0: 'status-progress',
1: 'status-success',
2: 'status-cancel',
3: 'status-refunding',
4: 'status-refunded',
9: 'status-returning'
}
return map[status] || ''
},
formatTime(time) {
if (!time) return ''
return time.substring(0, 16).replace('T', ' ')
},
calcArea(item) {
if (item.length && item.width && item.quantity) {
return (item.length * item.width * item.quantity / 1000000).toFixed(4)
}
return '-'
}
}
}
</script>
<style>
.page {
min-height: 100vh;
background: #f5f5f5;
}
.custom-nav {
height: 88rpx;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.nav-title {
font-size: 32rpx;
color: #fff;
font-weight: bold;
}
.loading, .error {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
}
.error-icon {
font-size: 80rpx;
margin-bottom: 20rpx;
}
.error-text {
font-size: 28rpx;
color: #999;
}
.order-content {
padding: 20rpx;
}
.order-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 40rpx 30rpx;
border-radius: 20rpx 20rpx 0 0;
text-align: center;
}
.status-badge {
display: inline-block;
padding: 10rpx 30rpx;
border-radius: 30rpx;
font-size: 26rpx;
color: #fff;
margin-bottom: 16rpx;
}
.status-progress { background: #1890ff; }
.status-success { background: #52c41a; }
.status-cancel { background: #999; }
.status-refunding { background: #fa8c16; }
.status-refunded { background: #ff4d4f; }
.status-returning { background: #722ed1; }
.order-no {
color: rgba(255, 255, 255, 0.8);
font-size: 24rpx;
}
.section {
background: #fff;
margin-bottom: 20rpx;
border-radius: 16rpx;
overflow: hidden;
}
.section-title {
padding: 24rpx 30rpx;
font-size: 28rpx;
font-weight: bold;
color: #333;
border-bottom: 1rpx solid #f0f0f0;
}
.section-content {
padding: 0 30rpx;
}
.info-row {
display: flex;
justify-content: space-between;
padding: 20rpx 0;
border-bottom: 1rpx solid #f8f8f8;
}
.info-row:last-child {
border-bottom: none;
}
.label {
font-size: 26rpx;
color: #666;
}
.value {
font-size: 26rpx;
color: #333;
}
.value.discount {
color: #ff4d4f;
}
.info-row.actual .value {
font-size: 36rpx;
font-weight: bold;
color: #ff4d4f;
}
.items-list {
padding: 0 30rpx;
}
.item-row {
display: flex;
padding: 16rpx 0;
border-bottom: 1rpx solid #f8f8f8;
font-size: 24rpx;
align-items: center;
}
.item-row.header {
background: #f8f9fa;
font-weight: bold;
color: #666;
}
.item-info {
flex: 3;
font-size: 24rpx;
color: #333;
line-height: 1.6;
}
.item-name-text {
color: #333;
font-weight: 500;
}
.item-spec-text {
color: #999;
}
.item-dims-text {
color: #666;
margin-left: 8rpx;
}
.item-area {
flex: 1.5;
text-align: center;
color: #667eea;
font-weight: 500;
}
.item-qty {
flex: 0.8;
text-align: center;
}
.item-price {
flex: 1;
text-align: right;
}
.item-subtotal {
flex: 1;
text-align: right;
color: #ff4d4f;
}
.amount-section {
padding: 20rpx 30rpx;
}
.footer {
text-align: center;
padding: 40rpx;
}
.shop-name {
font-size: 24rpx;
color: #999;
}
</style>

View File

@@ -1,45 +1,131 @@
<template> <template>
<view class="stock-in"> <view class="page">
<view class="form"> <!-- 分类 + 商品列表 -->
<view class="form-item"> <view class="content-wrapper">
<text class="label">商品</text> <!-- 左侧分类 -->
<picker <scroll-view scroll-y class="category-sidebar">
mode="selector" <view
:range="productList" class="category-item"
range-key="name" :class="{ active: !categoryId }"
@change="onProductChange" @click="selectCategory('')"
> >
<view class="picker"> 全部
{{ selectedProduct ? selectedProduct.name : '请选择商品' }}
</view> </view>
</picker> <view
v-for="cat in categories"
:key="cat.categoryId"
class="category-item"
:class="{ active: categoryId === cat.categoryId }"
@click="selectCategory(cat.categoryId)"
>
{{ cat.name }}
</view> </view>
</scroll-view>
<view class="form-item"> <!-- 右侧商品列表 -->
<text class="label">入库数量</text> <scroll-view scroll-y class="product-scroll">
<input <view class="product-list">
class="input" <view
v-model="quantity" v-for="item in productList"
type="number" :key="item.productId"
placeholder="请输入数量" class="product-item"
/> @click="openQuantityPopup(item)"
>
<view class="product-info">
<view class="product-header">
<text class="product-name">{{ item.name }}</text>
<text class="product-category" v-if="item.categoryName">{{ item.categoryName }}</text>
</view> </view>
<view class="product-row">
<view class="form-item"> <text class="product-spec">{{ item.spec || '-' }}</text>
<text class="label">备注</text> <text class="product-unit">/{{ item.unit }}</text>
<input <text class="product-price-text">¥{{ item.price }}</text>
class="input" </view>
v-model="remark" <view class="product-spec-row" v-if="item.length && item.width">
placeholder="可选填写" <text class="spec-text">{{ item.length }} x {{ item.width }} = {{ item.area }} </text>
/> </view>
</view>
<view class="product-add">
<text class="add-icon">+</text>
</view> </view>
</view> </view>
<view class="btn-area"> <view v-if="productList.length === 0" class="empty">
<text class="empty-icon">📭</text>
<text class="empty-text">暂无商品</text>
</view>
</view>
</scroll-view>
</view>
<!-- 已添加商品列表 -->
<view class="selected-section" v-if="selectedItems.length > 0">
<view class="selected-header">
<text class="selected-title">已选择商品</text>
<text class="selected-count">{{ selectedItems.length }} </text>
</view>
<scroll-view scroll-x class="selected-list">
<view
v-for="(item, index) in selectedItems"
:key="index"
class="selected-item"
>
<view class="selected-info">
<text class="selected-name">{{ item.productName }}</text>
<text class="selected-qty">× {{ item.quantity }}</text>
</view>
<text class="selected-delete" @click="removeItem(index)">×</text>
</view>
</scroll-view>
</view>
<!-- 底部提交按钮 -->
<view class="submit-bar" v-if="selectedItems.length > 0">
<view class="submit-info">
<text class="submit-label"> {{ totalQuantity }} </text>
</view>
<button class="submit-btn" @click="submit" :disabled="submitting"> <button class="submit-btn" @click="submit" :disabled="submitting">
{{ submitting ? '提交中...' : '确认入库' }} {{ submitting ? '提交中...' : '确认入库' }}
</button> </button>
</view> </view>
<!-- 数量填写弹窗 -->
<view class="popup-mask" v-if="showPopup" @click="closePopup"></view>
<view class="popup-content" v-if="showPopup">
<view class="popup-header">
<text class="popup-title">{{ currentProduct.name }}</text>
<text class="popup-close" @click="closePopup">×</text>
</view>
<view class="popup-body">
<view class="popup-spec" v-if="currentProduct.spec">
规格: {{ currentProduct.spec }}
</view>
<view class="popup-qty">
<text class="qty-label">入库数量</text>
<view class="qty-input-wrapper">
<text class="qty-minus" @click="qtyMinus">-</text>
<input
class="qty-input"
type="number"
v-model="inputQuantity"
/>
<text class="qty-plus" @click="qtyPlus">+</text>
</view>
</view>
<view class="popup-remark">
<text class="remark-label">备注可选</text>
<input
class="remark-input"
v-model="inputRemark"
placeholder="填写备注"
/>
</view>
</view>
<view class="popup-footer">
<button class="popup-btn cancel" @click="closePopup">取消</button>
<button class="popup-btn confirm" @click="confirmAdd">确定</button>
</view>
</view>
</view> </view>
</template> </template>
@@ -50,55 +136,131 @@ import productApi from '@/api/product'
export default { export default {
data() { data() {
return { return {
categoryId: '',
categories: [],
productList: [], productList: [],
selectedProduct: null, page: 1,
quantity: '', pageSize: 50,
remark: '', loading: false,
// 已选择的商品
selectedItems: [],
// 弹窗相关
showPopup: false,
currentProduct: {},
inputQuantity: 1,
inputRemark: '',
// 提交状态
submitting: false submitting: false
} }
}, },
computed: {
totalQuantity() {
return this.selectedItems.reduce((sum, item) => sum + item.quantity, 0)
}
},
onLoad() { onLoad() {
this.loadCategories()
this.getProducts() this.getProducts()
}, },
methods: { methods: {
async getProducts() { async loadCategories() {
try { try {
const res = await productApi.getProducts({ page: 1, pageSize: 100 }) const categories = await productApi.getCategories()
if (res.code === 0) { this.categories = categories || []
this.productList = res.data.records || []
}
} catch (e) { } catch (e) {
uni.showToast({ title: '加载商品失败', icon: 'none' }) console.error(e)
} }
}, },
onProductChange(e) { async getProducts() {
this.selectedProduct = this.productList[e.detail.value] this.loading = true
try {
const res = await productApi.getProducts({
categoryId: this.categoryId,
page: this.page,
pageSize: this.pageSize
})
this.productList = res.records || []
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
this.loading = false
}
}, },
async submit() { selectCategory(id) {
if (!this.selectedProduct) { this.categoryId = id
uni.showToast({ title: '请选择商品', icon: 'none' }) this.page = 1
this.getProducts()
},
openQuantityPopup(product) {
this.currentProduct = product
this.inputQuantity = 1
this.inputRemark = ''
this.showPopup = true
},
closePopup() {
this.showPopup = false
},
qtyMinus() {
if (this.inputQuantity > 1) {
this.inputQuantity--
}
},
qtyPlus() {
this.inputQuantity++
},
confirmAdd() {
if (this.inputQuantity <= 0) {
uni.showToast({ title: '请输入有效数量', icon: 'none' })
return return
} }
if (!this.quantity || this.quantity <= 0) {
uni.showToast({ title: '请输入有效数量', icon: 'none' }) // 检查是否已存在,存在则累加
const existsIndex = this.selectedItems.findIndex(
item => item.productId === this.currentProduct.productId
)
if (existsIndex > -1) {
this.selectedItems[existsIndex].quantity += parseInt(this.inputQuantity)
this.selectedItems[existsIndex].remark = this.inputRemark || this.selectedItems[existsIndex].remark
} else {
this.selectedItems.push({
productId: this.currentProduct.productId,
productName: this.currentProduct.name,
quantity: parseInt(this.inputQuantity),
remark: this.inputRemark
})
}
this.closePopup()
uni.showToast({ title: '已添加', icon: 'success' })
},
removeItem(index) {
this.selectedItems.splice(index, 1)
},
async submit() {
if (this.selectedItems.length === 0) {
uni.showToast({ title: '请先添加商品', icon: 'none' })
return return
} }
this.submitting = true this.submitting = true
try { try {
const res = await stockApi.stockIn({ // 逐个入库
productId: this.selectedProduct.productId, for (const item of this.selectedItems) {
quantity: parseInt(this.quantity), await stockApi.stockIn({
remark: this.remark productId: item.productId,
quantity: item.quantity,
remark: item.remark || ''
}) })
if (res.code === 0) { }
uni.showToast({ title: '入库成功', icon: 'success' }) uni.showToast({ title: '入库成功', icon: 'success' })
setTimeout(() => { setTimeout(() => {
uni.navigateBack() uni.navigateBack()
}, 1500) }, 1500)
} else {
uni.showToast({ title: res.message || '入库失败', icon: 'none' })
}
} catch (e) { } catch (e) {
uni.showToast({ title: '入库失败', icon: 'none' }) uni.showToast({ title: '入库失败', icon: 'none' })
} finally { } finally {
@@ -109,54 +271,387 @@ export default {
} }
</script> </script>
<style scoped> <style>
.stock-in { .page {
min-height: 100vh; min-height: 100vh;
background: #f5f5f5; background: #f8f9fa;
padding-bottom: 180rpx;
} }
.form { .content-wrapper {
display: flex;
height: calc(100vh - 200rpx);
}
/* 左侧分类 */
.category-sidebar {
width: 140rpx;
background: #fff; background: #fff;
margin: 20rpx; flex-shrink: 0;
border-radius: 12rpx;
padding: 0 30rpx;
} }
.form-item { .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-header {
display: flex; display: flex;
align-items: center; align-items: center;
padding: 30rpx 0; margin-bottom: 8rpx;
border-bottom: 1rpx solid #eee;
} }
.form-item:last-child { .product-name {
border-bottom: none;
}
.label {
width: 160rpx;
font-size: 30rpx; font-size: 30rpx;
font-weight: 500;
color: #333;
} }
.picker, .input { .product-category {
font-size: 22rpx;
color: #667eea;
background: #f0f4ff;
padding: 4rpx 12rpx;
border-radius: 8rpx;
margin-left: 12rpx;
}
.product-row {
display: flex;
align-items: center;
margin-bottom: 8rpx;
}
.product-spec {
font-size: 24rpx;
color: #999;
}
.product-unit {
font-size: 22rpx;
color: #999;
}
.product-price-text {
font-size: 26rpx;
color: #ff4d4f;
font-weight: 500;
margin-left: 16rpx;
}
.product-spec-row {
display: flex;
align-items: center;
}
.spec-text {
font-size: 22rpx;
color: #666;
}
.product-add {
width: 60rpx;
height: 60rpx;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 30rpx;
display: flex;
align-items: center;
justify-content: center;
}
.add-icon {
font-size: 36rpx;
color: #fff;
font-weight: bold;
}
.empty {
padding: 100rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.empty-icon {
font-size: 80rpx;
margin-bottom: 20rpx;
}
.empty-text {
font-size: 28rpx;
color: #999;
}
/* 已选择商品 */
.selected-section {
position: fixed;
bottom: 120rpx;
left: 0;
right: 0;
background: #fff;
padding: 20rpx 30rpx;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.selected-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16rpx;
}
.selected-title {
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.selected-count {
font-size: 24rpx;
color: #667eea;
}
.selected-list {
white-space: nowrap;
width: 100%;
}
.selected-item {
display: inline-flex;
align-items: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
border-radius: 12rpx;
padding: 16rpx 24rpx;
margin-right: 16rpx;
}
.selected-info {
display: flex;
flex-direction: column;
}
.selected-name {
font-size: 24rpx;
color: #fff;
max-width: 200rpx;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.selected-qty {
font-size: 22rpx;
color: rgba(255, 255, 255, 0.8);
margin-top: 4rpx;
}
.selected-delete {
margin-left: 16rpx;
font-size: 32rpx;
color: rgba(255, 255, 255, 0.8);
padding: 8rpx;
}
/* 底部提交 */
.submit-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
display: flex;
align-items: center;
padding: 20rpx 30rpx;
background: #fff;
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.submit-info {
flex: 1; flex: 1;
font-size: 30rpx;
} }
.btn-area { .submit-label {
padding: 40rpx 30rpx; font-size: 28rpx;
color: #666;
} }
.submit-btn { .submit-btn {
width: 240rpx;
height: 88rpx; height: 88rpx;
line-height: 88rpx; line-height: 88rpx;
background: #3cc51f; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff; color: #fff;
font-size: 32rpx; border: none;
border-radius: 8rpx; border-radius: 44rpx;
font-size: 30rpx;
font-weight: bold;
box-shadow: 0 8rpx 30rpx rgba(102, 126, 234, 0.4);
} }
.submit-btn[disabled] { /* 弹窗 */
background: #ccc; .popup-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 100;
}
.popup-content {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: #fff;
border-radius: 32rpx 32rpx 0 0;
padding: 40rpx 30rpx;
padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
z-index: 101;
}
.popup-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30rpx;
}
.popup-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
}
.popup-close {
font-size: 48rpx;
color: #999;
padding: 10rpx;
}
.popup-spec {
font-size: 26rpx;
color: #666;
margin-bottom: 30rpx;
}
.popup-qty {
display: flex;
align-items: center;
margin-bottom: 30rpx;
}
.qty-label {
font-size: 28rpx;
color: #333;
width: 160rpx;
}
.qty-input-wrapper {
display: flex;
align-items: center;
background: #f5f5f5;
border-radius: 12rpx;
}
.qty-minus, .qty-plus {
width: 80rpx;
height: 80rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 40rpx;
color: #667eea;
}
.qty-input {
width: 120rpx;
height: 80rpx;
text-align: center;
font-size: 32rpx;
background: transparent;
border-left: 1rpx solid #eee;
border-right: 1rpx solid #eee;
}
.popup-remark {
margin-bottom: 30rpx;
}
.remark-label {
font-size: 28rpx;
color: #333;
display: block;
margin-bottom: 16rpx;
}
.remark-input {
width: 100%;
height: 80rpx;
background: #f5f5f5;
border-radius: 12rpx;
padding: 0 20rpx;
font-size: 28rpx;
box-sizing: border-box;
}
.popup-footer {
display: flex;
gap: 20rpx;
}
.popup-btn {
flex: 1;
height: 88rpx;
line-height: 88rpx;
border-radius: 44rpx;
font-size: 30rpx;
font-weight: bold;
}
.popup-btn.cancel {
background: #f5f5f5;
color: #666;
}
.popup-btn.confirm {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
box-shadow: 0 8rpx 30rpx rgba(102, 126, 234, 0.4);
} }
</style> </style>

View File

@@ -68,6 +68,11 @@ export default {
onLoad() { onLoad() {
this.getStockList() this.getStockList()
}, },
onShow() {
// 每次进入页面都刷新数据
this.page = 1
this.getStockList()
},
onPullDownRefresh() { onPullDownRefresh() {
this.page = 1 this.page = 1
this.getStockList().then(() => { this.getStockList().then(() => {

View File

@@ -1,7 +1,10 @@
import { defineConfig } from 'vite' import { defineConfig, loadEnv } from 'vite'
import uni from '@dcloudio/vite-plugin-uni' import uni from '@dcloudio/vite-plugin-uni'
export default defineConfig({ export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd())
return {
plugins: [ plugins: [
uni() uni()
], ],
@@ -10,5 +13,10 @@ export default defineConfig({
rollupOptions: { rollupOptions: {
input: './index.html' input: './index.html'
} }
},
define: {
'import.meta.env.VITE_API_BASE_URL': JSON.stringify(env.VITE_API_BASE_URL || 'https://sales.violin-work.online/api/v1'),
'import.meta.env.VITE_H5_BASE_URL': JSON.stringify(env.VITE_H5_BASE_URL || 'https://sales.violin-work.online')
}
} }
}) })