From b8bbf215991637077b7d2af77f0653cf5c4acae4 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 28 Oct 2026 21:06:36 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=AE=A2=E6=88=B7=E5=95=86=E5=9F=8E):=20?= =?UTF-8?q?=E4=B8=8B=E5=8D=95=E5=AE=A2=E6=88=B7=E8=B4=A6=E5=8F=B7=E4=B8=8E?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=95=86=E5=9F=8E=E4=BA=8C=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 正常客户开户/停用/重置;order_customer 三重闸;mall-panel 商品、地址、下单;价格/客户由服务端推导;菜单与账户入口修复。 --- .../20261030-customer-self-service-mall.md | 87 ++++ ...0261089_customer_portal_order_customer.sql | 24 + miniprogram/components/mall-panel/index.js | 381 ++++++++++++++ miniprogram/components/mall-panel/index.json | 6 + miniprogram/components/mall-panel/index.wxml | 139 +++++ miniprogram/components/mall-panel/index.wxss | 481 ++++++++++++++++++ miniprogram/modules/registry.js | 8 + miniprogram/pages/home/home.js | 3 +- miniprogram/pages/home/home.json | 1 + miniprogram/pages/home/home.wxml | 6 + miniprogram/utils/constants.js | 2 + miniprogram/utils/request.js | 19 + .../modules/workflow/routes/customerRoutes.ts | 96 ++++ server/src/routes/mobile.ts | 2 + server/src/routes/mobile/mobileMallRoutes.ts | 129 +++++ server/src/routes/mobile/mobileShared.ts | 33 +- server/src/services/accountLoginService.ts | 12 +- server/src/services/customerMallService.ts | 374 ++++++++++++++ .../services/customerOrderAccountService.ts | 397 +++++++++++++++ .../src/services/customerSkuPriceService.ts | 19 - server/src/utils/customerStatus.ts | 5 + server/tests/customerOrderMall.test.ts | 55 ++ server/tests/customerSkuPriceEdit.test.ts | 2 - src/i18n/locales/en/customers.ts | 19 + src/i18n/locales/id/customers.ts | 19 + src/i18n/locales/zh-CN/customers.ts | 19 + src/pages/customers/CustomerManagement.tsx | 133 +++++ src/utils/menuLayout.ts | 1 + src/utils/menuLayoutCache.ts | 2 +- src/utils/workflowApi.ts | 32 ++ 30 files changed, 2481 insertions(+), 25 deletions(-) create mode 100644 docs/design/20261030-customer-self-service-mall.md create mode 100644 migrations/20261089_customer_portal_order_customer.sql create mode 100644 miniprogram/components/mall-panel/index.js create mode 100644 miniprogram/components/mall-panel/index.json create mode 100644 miniprogram/components/mall-panel/index.wxml create mode 100644 miniprogram/components/mall-panel/index.wxss create mode 100644 server/src/routes/mobile/mobileMallRoutes.ts create mode 100644 server/src/services/customerMallService.ts create mode 100644 server/src/services/customerOrderAccountService.ts create mode 100644 server/src/utils/customerStatus.ts create mode 100644 server/tests/customerOrderMall.test.ts diff --git a/docs/design/20261030-customer-self-service-mall.md b/docs/design/20261030-customer-self-service-mall.md new file mode 100644 index 0000000..9d18813 --- /dev/null +++ b/docs/design/20261030-customer-self-service-mall.md @@ -0,0 +1,87 @@ +# 客户自助商城(二期)— 下单客户与小程序商城 + +- 日期:2026-10-30 +- 参考:配送系统 `docs/design/20261028-customer-order-mall.md`、`customerOrderAccountService.ts`、`customerMallService.ts`、`miniprogram/components/mall-panel/` +- 状态:本地实现,未部署 + +## 1. 范围 + +1. 客户列表开通「下单客户」账号; +2. 小程序登录后进入「客户商城」,只展示该客户自己的 `customer_skus` 商品; +3. 选品、购物车、确认下单,复用既有录单/下单链路; +4. 账号停用/启用/重置密码。 + +**不在一期**:我的订单、售后、优惠券、二级页面。 + +## 2. 客户范围(硬性) + +只有**正常客户**可开通账号,以下一律排除: + +- `__RETAIL__`(散客录单); +- `__INDEPENDENT_INBOUND__`(独立进货); +- `source IN ('retail','independent_inbound','main_system')`; +- `customer_code LIKE 'MAIN\\_%'`(配送系统分配过来的客户); +- 客户状态非正常(沿用供应商可交易状态)。 + +服务端开户/账号列表/登录/商城四个入口都必须同一判据,不能只在前端隐藏按钮。 + +## 3. 身份与登录 + +- 角色:`order_customer`(下单客户),无 Web 业务权限码; +- 绑定表:复用 `customer_portal_users`,新增 `status int default 1`、`created_by uuid`、`updated_at timestamptz`; +- 登录三重闸: + 1. `customer_portal_users` 有绑定行; + 2. 绑定行 `status=1`; + 3. `public.user_roles` 有 `order_customer`。 +- 登录:手机号/登录名 + 密码;微信手机号快速登录可选;首次登录改密; +- 复用 `auth.users + profiles + user_roles + customer_portal_users` 同事务开户; +- 初始化密码:手机号后 6 位,否则 `123456`;开户返回默认密码供管理员转交; +- 历史绑定无 `order_customer` 角色 → 不自动升级;显式开户时补授角色; +- 停用/重置密码只作用于持有 `order_customer` 的行; +- 登录名/手机号冲突规则沿用供应商开户。 + +## 4. Web 客户列表 + +- 正常客户行操作菜单增加「开通登录账号」; +- 已开通显示账号状态; +- 弹窗收集手机号(可选)和登录账号(无手机号必填),可设初始密码; +- 账号管理:停用/启用、重置密码; +- 接口: + - POST `/customers/:customerCode/login-account` + - GET `/customers/login-accounts?codes=...` + - PATCH `/customers/login-accounts/:userId/status` + - POST `/customers/login-accounts/:userId/reset-password` + +## 5. 小程序商城 + +参考 `miniprogram/components/mall-panel/`: + +- 首页内嵌 `mall-panel`,不新增二级页面; +- 商品来自该客户 `customer_skus`,只返回 `is_listed=true` 且有价商品; +- 价格复用 `enrichOrderItemsWithPrices`,与录单同源; +- 双列商品卡、搜索、分类 chips、加购/减购、购物车悬浮条; +- 确认弹层:商品清单、逐行加工方式/备注、收货地址、配送日、整单备注; +- 下单接口不接受 `customer_code/branch_code/price/processing_owner`,由登录账号和客户档案推导; +- 复用 `submitMobileCustomerOrder` 的建单/分配/分拣/配送/成本链路; +- 配送日 `[明天, 明天+6]`,默认明天; +- 地址可编辑并保存,服务端未配置地理编码 key 时保存失败但已存地址可下单。 + +## 6. 接口(移动端) + +| 方法 | 路径 | +|---|---| +| GET | `/mobile/mall/bootstrap` | +| GET | `/mobile/mall/products?q=&category_code=` | +| PUT | `/mobile/mall/address` | +| POST | `/mobile/mall/orders` | + +## 7. 验收 + +1. 正常客户可开户;散客/独立进货/主系统客户服务端拒绝; +2. 账号可登录小程序,错误密码/停用/无角色拒绝; +3. 商城只显示自己的 `customer_skus`,不含其他客户/未上架/无价商品; +4. 下单后订单进入现有录单/分配链路,客户归属正确; +5. 价格与录单同源; +6. 客户端不能通过请求体越权指定 customer/branch/price; +7. 客户列表账号管理可用; +8. typecheck + 服务层/接口测试;不部署。 diff --git a/migrations/20261089_customer_portal_order_customer.sql b/migrations/20261089_customer_portal_order_customer.sql new file mode 100644 index 0000000..ea57ba9 --- /dev/null +++ b/migrations/20261089_customer_portal_order_customer.sql @@ -0,0 +1,24 @@ +-- 2026-10-30:客户自助商城二期:复用 customer_portal_users,新增状态/创建人/更新时间, +-- 并登记 order_customer 角色(不新增账号表)。 +DO $$ +DECLARE + sch text; +BEGIN + FOR sch IN + SELECT nspname FROM pg_namespace + WHERE nspname = 'tenant_template' OR nspname LIKE 'tenant\_%' + LOOP + IF EXISTS ( + SELECT 1 FROM information_schema.tables + WHERE table_schema = sch AND table_name = 'customer_portal_users' + ) THEN + EXECUTE format('ALTER TABLE %I.customer_portal_users ADD COLUMN IF NOT EXISTS status INT NOT NULL DEFAULT 1', sch); + EXECUTE format('ALTER TABLE %I.customer_portal_users ADD COLUMN IF NOT EXISTS created_by UUID', sch); + EXECUTE format('ALTER TABLE %I.customer_portal_users ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ', sch); + END IF; + END LOOP; +END $$; + +INSERT INTO public.role_definitions (role_code, role_name, is_builtin, sort_order) +VALUES ('order_customer', '下单客户', true, 900) +ON CONFLICT (role_code) DO NOTHING; diff --git a/miniprogram/components/mall-panel/index.js b/miniprogram/components/mall-panel/index.js new file mode 100644 index 0000000..ff34cb7 --- /dev/null +++ b/miniprogram/components/mall-panel/index.js @@ -0,0 +1,381 @@ +const { + fetchMallBootstrap, + fetchMallProducts, + submitMallOrder, + saveMallAddress, +} = require('../../utils/request'); +const { resolveSkuImageUrl } = require('../../utils/skuImage'); +const { PROCESSING_METHOD_OPTIONS } = require('../../utils/constants'); + +function money(value) { + return (Math.round((Number(value) || 0) * 100) / 100).toFixed(2); +} + +/** 统一在这里格式化:避免 WXML 里拼 null/单位、价格小数位不一致。 */ +function decorateProduct(item, qty) { + const price = Number(item.price) || 0; + const hasPrice = item.has_price === true || price > 0; + const spec = String(item.spec || '').trim(); + // 单位已在价格后缀(/斤)展示,这里只留规格,避免同名信息占两行(2026-10-30)。 + const metaText = spec; + return { + ...item, + price, + has_price: hasPrice, + price_text: hasPrice ? `¥${money(price)}` : '待报价', + meta_text: metaText, + image_src: resolveSkuImageUrl(item.image_url, item.sku_code), + qty, + // 下单弹层默认选中该客户商品库配置的加工方式(客户可改);加工方由后台决定。 + processing_method: String(item.processing_method || '').trim() || '原材料', + }; +} + +Component({ + options: { + addGlobalClass: true, + }, + + properties: { + embedded: { + type: Boolean, + value: false, + }, + }, + + data: { + loading: true, + error: '', + customer: {}, + // 收货地址:客户可直接编辑;失焦/下单前保存(服务端解析坐标并回写客户档案) + deliveryAddress: '', + savedAddress: '', + addressSaving: false, + deliveryDate: '', + dateMin: '', + dateMax: '', + query: '', + categoryFilter: '', + categories: [], + products: [], + // 加工方式选项(客户只选方式,仓内/供应商加工由管理员配置决定) + processingMethods: PROCESSING_METHOD_OPTIONS, + // sku_code → { sku_code, name, unit, price, quantity };与商品列表筛选解耦, + // 搜索/切分类重载商品时不丢已选数量。 + cart: {}, + cartCount: 0, + cartTotal: '0.00', + checkoutVisible: false, + checkoutItems: [], + submitting: false, + remark: '', + }, + + lifetimes: { + attached() { + this.bootstrap(); + }, + }, + + methods: { + async bootstrap() { + await this.loadBootstrap(); + if (!this.data.error) await this.loadProducts(); + }, + + async loadBootstrap() { + try { + const data = (await fetchMallBootstrap()) || {}; + const defaultAddress = String(data.default_address || '').trim(); + this.setData({ + loading: false, + error: '', + customer: data.customer || {}, + deliveryAddress: defaultAddress, + savedAddress: defaultAddress, + deliveryDate: String(data.delivery_date_min || ''), + dateMin: String(data.delivery_date_min || ''), + dateMax: String(data.delivery_date_max || ''), + }); + } catch (err) { + this.setData({ + loading: false, + error: (err && err.message) || '加载失败', + }); + } + }, + + async loadProducts() { + try { + // 空筛选不能传 undefined:wx.request 会把它序列化成字面量 "undefined", + // 服务端按关键词过滤后就会变成「暂无商品」。 + const params = {}; + if (this.data.query) params.q = this.data.query; + if (this.data.categoryFilter) params.category_code = this.data.categoryFilter; + const data = (await fetchMallProducts(params)) || {}; + const products = (Array.isArray(data.products) ? data.products : []).map((item) => + decorateProduct(item, Number((this.data.cart || {})[item.sku_code]?.quantity) || 0) + ); + const cart = { ...(this.data.cart || {}) }; + products.forEach((item) => { + if (!cart[item.sku_code]) return; + cart[item.sku_code] = { + ...cart[item.sku_code], + name: item.name, + unit: item.unit, + price: Number(item.price) || 0, + }; + }); + this.setData( + { + products, + categories: Array.isArray(data.categories) ? data.categories : [], + cart, + }, + () => this.recalc() + ); + } catch (err) { + this.setData({ error: (err && err.message) || '加载失败' }); + } + }, + + recalc() { + let cartCount = 0; + let cartTotal = 0; + Object.values(this.data.cart || {}).forEach((item) => { + const qty = Number(item.quantity) || 0; + if (qty <= 0) return; + cartCount += qty; + cartTotal += qty * (Number(item.price) || 0); + }); + this.setData({ cartCount, cartTotal: money(cartTotal) }); + }, + + onCardTap(e) { + const index = Number(e.currentTarget.dataset.index); + const product = this.data.products[index]; + if (!product) return; + if (!product.has_price) { + wx.showToast({ title: '待报价', icon: 'none' }); + return; + } + this.onQtyPlus(e); + }, + + onQtyPlus(e) { + const index = Number(e.currentTarget.dataset.index); + const product = this.data.products[index]; + if (!product || !product.has_price) return; + const quantity = (Number(product.qty) || 0) + 1; + const cart = { ...(this.data.cart || {}) }; + cart[product.sku_code] = { + sku_code: product.sku_code, + name: product.name, + unit: product.unit, + price: Number(product.price) || 0, + processing_method: + (cart[product.sku_code] || {}).processing_method || + product.processing_method || + '原材料', + remark: (cart[product.sku_code] || {}).remark || '', + quantity, + }; + this.setData( + { cart, [`products[${index}].qty`]: quantity }, + () => this.recalc() + ); + }, + + onQtyMinus(e) { + const index = Number(e.currentTarget.dataset.index); + const product = this.data.products[index]; + if (!product) return; + const quantity = Math.max(0, (Number(product.qty) || 0) - 1); + const cart = { ...(this.data.cart || {}) }; + if (quantity > 0) { + cart[product.sku_code] = { ...(cart[product.sku_code] || {}), quantity }; + } else { + delete cart[product.sku_code]; + } + this.setData( + { cart, [`products[${index}].qty`]: quantity }, + () => this.recalc() + ); + }, + + onQueryInput(e) { + const query = String((e && e.detail && e.detail.value) || ''); + this.setData({ query }); + if (this._queryTimer) clearTimeout(this._queryTimer); + this._queryTimer = setTimeout(() => { + this._queryTimer = null; + this.loadProducts(); + }, 400); + }, + + onCategoryTap(e) { + const code = String(e.currentTarget.dataset.code || '').trim(); + if (code === this.data.categoryFilter) return; + this.setData({ categoryFilter: code }, () => this.loadProducts()); + }, + + onDeliveryDateChange(e) { + this.setData({ deliveryDate: String((e && e.detail && e.detail.value) || '') }); + }, + + onAddressInput(e) { + this.setData({ + deliveryAddress: String((e && e.detail && e.detail.value) || '').slice(0, 200), + }); + }, + + /** 地址保存到客户档案(服务端必须能解析出坐标,否则返回 400) */ + async saveAddress() { + const address = String(this.data.deliveryAddress || '').trim(); + if (!address) { + wx.showToast({ title: '请填写收货地址', icon: 'none' }); + return false; + } + if (address === this.data.savedAddress) return true; + if (this._addressSavePromise) return this._addressSavePromise; + + this.setData({ addressSaving: true }); + this._addressSavePromise = (async () => { + try { + const data = (await saveMallAddress(address)) || {}; + const saved = String(data.address || address).trim(); + this.setData({ deliveryAddress: saved, savedAddress: saved }); + return true; + } catch (err) { + wx.showToast({ + title: (err && err.message) || '地址保存失败', + icon: 'none', + duration: 2500, + }); + return false; + } finally { + this.setData({ addressSaving: false }); + this._addressSavePromise = null; + } + })(); + return this._addressSavePromise; + }, + + onAddressBlur() { + if (String(this.data.deliveryAddress || '').trim() !== this.data.savedAddress) { + void this.saveAddress(); + } + }, + + /** 逐行加工方式(只改方式;仓内/供应商加工由管理员配置) */ + onItemMethodChange(e) { + const index = Number(e.currentTarget.dataset.index); + const pickIndex = Number(e.detail && e.detail.value) || 0; + const method = this.data.processingMethods[pickIndex] || '原材料'; + const checkoutItem = this.data.checkoutItems[index]; + if (!checkoutItem) return; + const cart = { ...(this.data.cart || {}) }; + if (cart[checkoutItem.sku_code]) { + cart[checkoutItem.sku_code] = { + ...cart[checkoutItem.sku_code], + processing_method: method, + }; + } + this.setData({ + cart, + [`checkoutItems[${index}].processing_method`]: method, + [`checkoutItems[${index}].methodIndex`]: pickIndex, + }); + }, + + /** 逐行备注 */ + onItemRemarkInput(e) { + const index = Number(e.currentTarget.dataset.index); + const remark = String((e.detail && e.detail.value) || '').slice(0, 200); + const checkoutItem = this.data.checkoutItems[index]; + if (!checkoutItem) return; + const cart = { ...(this.data.cart || {}) }; + if (cart[checkoutItem.sku_code]) { + cart[checkoutItem.sku_code] = { ...cart[checkoutItem.sku_code], remark }; + } + this.setData({ cart, [`checkoutItems[${index}].remark`]: remark }); + }, + + onRemarkInput(e) { + this.setData({ remark: String((e && e.detail && e.detail.value) || '') }); + }, + + openCheckout() { + if (!this.data.cartCount || this.data.submitting) return; + const checkoutItems = Object.values(this.data.cart || {}) + .filter((item) => Number(item.quantity) > 0) + .map((item) => { + const method = item.processing_method || '原材料'; + return { + ...item, + processing_method: method, + methodIndex: Math.max(0, this.data.processingMethods.indexOf(method)), + remark: item.remark || '', + amount: money((Number(item.quantity) || 0) * (Number(item.price) || 0)), + }; + }); + this.setData({ + checkoutVisible: true, + checkoutItems, + }); + }, + + closeCheckout() { + if (this.data.submitting) return; + this.setData({ checkoutVisible: false }); + }, + + noop() {}, + + async submitOrder() { + if (this.data.submitting) return; + const items = Object.values(this.data.cart || {}) + .filter((item) => Number(item.quantity) > 0) + .map((item) => ({ + sku_code: item.sku_code, + quantity: Number(item.quantity), + processing_method: item.processing_method || '原材料', + remark: item.remark || '', + })); + if (!items.length) { + this.setData({ checkoutVisible: false }); + return; + } + // 地址改过就先保存(服务端解析坐标并回写客户档案);失败则不下单 + const addressOk = await this.saveAddress(); + if (!addressOk) return; + this.setData({ submitting: true }); + try { + await submitMallOrder({ + items, + delivery_date: this.data.deliveryDate, + delivery_address: String(this.data.deliveryAddress || '').trim(), + remark: this.data.remark, + }); + this.setData({ + checkoutVisible: false, + submitting: false, + remark: '', + cart: {}, + checkoutItems: [], + products: this.data.products.map((item) => ({ ...item, qty: 0 })), + cartCount: 0, + cartTotal: '0.00', + }); + wx.showToast({ title: '下单成功', icon: 'success' }); + } catch (err) { + this.setData({ submitting: false }); + wx.showToast({ + title: (err && err.message) || '下单失败', + icon: 'none', + duration: 2500, + }); + } + }, + }, +}); diff --git a/miniprogram/components/mall-panel/index.json b/miniprogram/components/mall-panel/index.json new file mode 100644 index 0000000..fadd35e --- /dev/null +++ b/miniprogram/components/mall-panel/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "van-icon": "@vant/weapp/icon/index" + } +} diff --git a/miniprogram/components/mall-panel/index.wxml b/miniprogram/components/mall-panel/index.wxml new file mode 100644 index 0000000..e00ea54 --- /dev/null +++ b/miniprogram/components/mall-panel/index.wxml @@ -0,0 +1,139 @@ + + 加载中... + {{error}} + + + + + + + + 全部 + {{item.name}} + + + + + + + + {{item.qty}} + + {{item.name}} + {{item.meta_text}} + {{item.description}} + + {{item.price_text}}/{{item.unit}} + + − + {{item.qty}} + + + + + + + 暂无商品 + + + + + + + + {{cartCount}} + 合计 ¥{{cartTotal}} + + 去下单 + + + + + + + + 确认下单 + 取消 + + + + + + {{item.name}} + ×{{item.quantity}} + + + {{item.processing_method}} + + + ¥{{item.amount}} + + + + + + 收货地址 + + + + + 配送日 + {{deliveryDate}} + + + + 备注 + + + + + 取消 + 确认下单 + + + + + + diff --git a/miniprogram/components/mall-panel/index.wxss b/miniprogram/components/mall-panel/index.wxss new file mode 100644 index 0000000..8595081 --- /dev/null +++ b/miniprogram/components/mall-panel/index.wxss @@ -0,0 +1,481 @@ +.mall-panel { + padding: 0 24rpx 260rpx; +} + +.mall-panel.is-embedded { + padding-top: 16rpx; +} + +.mall-state { + padding: 60rpx 0; + text-align: center; + font-size: 26rpx; + color: #94a3b8; +} + +.mall-state--empty { + width: 100%; + padding: 120rpx 0; +} + +.mall-search { + padding: 0 0 16rpx; +} + +.mall-search-input { + width: 100%; + box-sizing: border-box; + height: 76rpx; + padding: 0 28rpx; + border-radius: 999rpx; + background: #ffffff; + border: 1rpx solid #e5e7eb; + font-size: 26rpx; +} + +.mall-cats { + white-space: nowrap; + padding-bottom: 16rpx; +} + +.mall-cat { + display: inline-block; + margin-right: 12rpx; + padding: 10rpx 24rpx; + border-radius: 999rpx; + background: #ffffff; + border: 1rpx solid #e5e7eb; + color: #475569; + font-size: 24rpx; + font-weight: 600; +} + +.mall-cat.is-active { + background: #047857; + border-color: #047857; + color: #ffffff; +} + +.mall-grid { + display: flex; + flex-wrap: wrap; + align-items: flex-start; + justify-content: space-between; + padding-top: 4rpx; +} + +.mall-card { + display: flex; + flex-direction: column; + width: calc(50% - 8rpx); + box-sizing: border-box; + margin-bottom: 12rpx; + padding: 12rpx; + border-radius: 16rpx; + background: #ffffff; + border: 1rpx solid #f1f5f9; +} + +.mall-thumb-wrap { + position: relative; + width: 100%; + height: 180rpx; + border-radius: 12rpx; + overflow: hidden; + background: #f1f5f9; +} + +.mall-thumb { + width: 100%; + height: 100%; + display: block; +} + +.mall-thumb--empty { + background: linear-gradient(135deg, #eef2f7 0%, #e2e8f0 100%); +} + +.mall-card-badge { + position: absolute; + top: 12rpx; + right: 12rpx; + min-width: 40rpx; + height: 40rpx; + padding: 0 10rpx; + box-sizing: border-box; + border-radius: 999rpx; + background: #059669; + color: #ffffff; + font-size: 22rpx; + font-weight: 700; + line-height: 40rpx; + text-align: center; +} + +.mall-name { + margin-top: 8rpx; + overflow: hidden; + text-overflow: ellipsis; + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 2; + font-size: 26rpx; + font-weight: 600; + line-height: 1.25; + color: #0f172a; +} + +.mall-meta { + margin-top: 2rpx; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-size: 20rpx; + color: #94a3b8; +} + +.mall-desc { + margin-top: 2rpx; + overflow: hidden; + text-overflow: ellipsis; + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 1; + font-size: 20rpx; + line-height: 1.3; + color: #64748b; +} + +.mall-card-foot { + display: flex; + align-items: center; + justify-content: space-between; + gap: 8rpx; + margin-top: 6rpx; + padding-top: 0; +} + +.mall-price { + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-size: 28rpx; + font-weight: 700; + color: #047857; +} + +.mall-price-unit { + margin-left: 2rpx; + font-size: 20rpx; + font-weight: 400; + color: #64748b; +} + +.mall-price.is-missing { + font-size: 24rpx; + color: #94a3b8; + font-weight: 500; +} + +.mall-step { + display: flex; + align-items: center; + gap: 8rpx; + flex-shrink: 0; +} + +.mall-step-btn { + width: 40rpx; + height: 40rpx; + border-radius: 999rpx; + display: flex; + align-items: center; + justify-content: center; + font-size: 26rpx; + line-height: 1; + color: #047857; + background: #ecfdf5; + border: 1rpx solid #a7f3d0; +} + +.mall-step-btn--add { + color: #ffffff; + background: #059669; + border-color: #059669; +} + +.mall-step-btn--add.is-disabled { + color: #9ca3af; + background: #f3f4f6; + border-color: #e5e7eb; +} + +.mall-step-qty { + min-width: 28rpx; + text-align: center; + font-size: 24rpx; + font-weight: 700; + color: #0f172a; +} + +.mall-bar { + position: fixed; + left: 24rpx; + right: 24rpx; + /* app-tab-bar 高约 116rpx + 安全区,购物车条必须浮在它上方 */ + bottom: calc(136rpx + env(safe-area-inset-bottom)); + z-index: 300; + display: flex; + align-items: center; + justify-content: space-between; + gap: 16rpx; + padding: 16rpx 20rpx 16rpx 24rpx; + border-radius: 999rpx; + background: rgba(15, 23, 42, 0.94); + box-shadow: 0 12rpx 30rpx rgba(15, 23, 42, 0.24); +} + +.mall-bar-left { + display: flex; + align-items: center; + gap: 12rpx; + min-width: 0; +} + +.mall-bar-badge { + min-width: 40rpx; + height: 40rpx; + padding: 0 10rpx; + box-sizing: border-box; + border-radius: 999rpx; + background: #10b981; + color: #ffffff; + font-size: 22rpx; + font-weight: 700; + line-height: 40rpx; + text-align: center; +} + +.mall-bar-total { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-size: 28rpx; + font-weight: 700; + color: #ffffff; +} + +.mall-bar-btn { + flex-shrink: 0; + padding: 12rpx 36rpx; + border-radius: 999rpx; + background: #10b981; + color: #ffffff; + font-size: 26rpx; + font-weight: 700; +} + +.mall-bar-btn.is-disabled { + background: rgba(255, 255, 255, 0.24); + color: rgba(255, 255, 255, 0.6); +} + +.mall-mask { + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + z-index: 1000; + display: flex; + align-items: flex-end; + background: rgba(9, 9, 11, 0.45); +} + +.mall-sheet { + width: 100%; + max-height: 86vh; + display: flex; + flex-direction: column; + box-sizing: border-box; + padding: 24rpx 28rpx calc(28rpx + env(safe-area-inset-bottom)); + border-radius: 28rpx 28rpx 0 0; + background: #ffffff; +} + +/* 整个弹层只有一个滚动区(头部与底部按钮固定),避免嵌套滚动条 */ +.mall-sheet-body { + flex: 1; + min-height: 0; + max-height: calc(86vh - 220rpx); +} + +.mall-sheet-head { + flex-shrink: 0; + display: flex; + align-items: center; + justify-content: space-between; + padding-bottom: 8rpx; +} + +.mall-sheet-title { + font-size: 30rpx; + font-weight: 700; + color: #0f172a; +} + +.mall-sheet-close { + padding: 8rpx 4rpx 8rpx 24rpx; + font-size: 26rpx; + color: #64748b; +} + +.mall-sheet-items { + margin: 8rpx 0 4rpx; + padding: 12rpx 20rpx; + border-radius: 16rpx; + background: #f8fafc; + box-sizing: border-box; +} + +.mall-sheet-item { + display: flex; + flex-direction: row; + align-items: center; + gap: 8rpx; + padding: 14rpx 0; + border-bottom: 1rpx solid #eef2f7; + font-size: 24rpx; + color: #334155; +} + +.mall-sheet-item:last-child { + border-bottom: none; +} + +.mall-sheet-item-name { + flex: 1 1 120rpx; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.mall-sheet-item-qty { + flex-shrink: 0; + color: #64748b; +} + +.mall-item-field { + height: 48rpx; + padding: 0 10rpx; + box-sizing: border-box; + border-radius: 10rpx; + background: #ffffff; + border: 1rpx solid #e2e8f0; + font-size: 22rpx; + color: #334155; +} + +.mall-item-method { + flex: none; + width: 140rpx; +} + +.mall-item-method .mall-item-field { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + line-height: 46rpx; +} + +.mall-sheet-item-amount { + flex-shrink: 0; + min-width: 96rpx; + text-align: right; + font-weight: 600; + color: #0f172a; +} + +.mall-item-remark { + flex: none; + width: 132rpx; +} + +.mall-field { + display: flex; + align-items: center; + justify-content: space-between; + gap: 20rpx; + padding: 20rpx 0; + border-bottom: 1rpx solid #f4f4f5; +} + +.mall-field--address { + flex-direction: column; + align-items: stretch; + gap: 8rpx; +} + +.mall-input--address { + width: 100%; + height: 64rpx; + padding: 0 16rpx; + box-sizing: border-box; + border-radius: 12rpx; + background: #f8fafc; + border: 1rpx solid #e2e8f0; + font-size: 24rpx; + color: #334155; + text-align: left; +} + +.mall-label { + flex-shrink: 0; + font-size: 26rpx; + color: #475569; +} + +.mall-value { + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-size: 26rpx; + color: #0f172a; + text-align: right; +} + +.mall-input { + flex: 1; + min-width: 0; + font-size: 26rpx; + text-align: right; +} + +.mall-sheet-actions { + flex-shrink: 0; + display: flex; + gap: 20rpx; + margin-top: 20rpx; +} + +.mall-btn { + flex: 1; + text-align: center; + padding: 22rpx 0; + border-radius: 999rpx; + font-size: 28rpx; + font-weight: 700; +} + +.mall-btn--ghost { + color: #475569; + background: #f4f4f5; +} + +.mall-btn--primary { + color: #ffffff; + background: #059669; +} diff --git a/miniprogram/modules/registry.js b/miniprogram/modules/registry.js index a10b1c7..c930467 100644 --- a/miniprogram/modules/registry.js +++ b/miniprogram/modules/registry.js @@ -217,6 +217,14 @@ const MOBILE_MODULES = [ handler: 'goProductTrace', homeEmbed: 'product-trace-panel', }, + { + id: 'mall', + title: '下单', + subtitle: '选购商品并下单', + page: '/pages/home/home', + roles: ['order_customer'], + homeEmbed: 'mall-panel', + }, ]; /** 首页合并展示时的稳定排序 */ diff --git a/miniprogram/pages/home/home.js b/miniprogram/pages/home/home.js index 7d962ae..2f32d14 100644 --- a/miniprogram/pages/home/home.js +++ b/miniprogram/pages/home/home.js @@ -39,6 +39,7 @@ const HOME_PANEL_SELECTORS = { 'admin-purchase': '#adminPurchaseHomePanel', 'prep-amend-review': '#prepAmendHomePanel', 'order-entry': '#orderEntryHomePanel', + mall: '#mallHomePanel', }; function pxToRpx(px, windowWidth) { @@ -136,7 +137,7 @@ function pickExclusiveHomeProgress(flags) { } function pickDefaultHomeModule(workspaceIds, workspaceMods) { - const order = [ + const order = ['mall', 'purchase', 'admin-purchase', 'delivery', diff --git a/miniprogram/pages/home/home.json b/miniprogram/pages/home/home.json index cd163ef..03ff256 100644 --- a/miniprogram/pages/home/home.json +++ b/miniprogram/pages/home/home.json @@ -23,6 +23,7 @@ "order-manage-panel": "/components/order-manage-panel/index", "admin-preparations-panel": "/components/admin-preparations-panel/index", "order-entry-panel": "/components/order-entry-panel/index", + "mall-panel": "/components/mall-panel/index", "van-icon": "@vant/weapp/icon/index", "van-tag": "@vant/weapp/tag/index", "van-button": "@vant/weapp/button/index", diff --git a/miniprogram/pages/home/home.wxml b/miniprogram/pages/home/home.wxml index 815ce87..e395634 100644 --- a/miniprogram/pages/home/home.wxml +++ b/miniprogram/pages/home/home.wxml @@ -432,6 +432,12 @@ id="orderEntryHomePanel" embedded="{{true}}" /> +