Commit 88aa996b by 张立顺

fix 员工弹框

1 parent e2bf6d76
...@@ -12,9 +12,9 @@ alwaysApply: false ...@@ -12,9 +12,9 @@ alwaysApply: false
| 层 | 路径 | 职责 | | 层 | 路径 | 职责 |
|----|------|------| |----|------|------|
| UI | `tabWorkOrder/pages/createOrder/components/merchant-staff-picker/` | 纯展示,事件上报 | | UI | `tabWorkOrder/pages/createOrder/components/merchant-staff-picker/` | show 时自拉数,交互在组件内;confirm/cancel 事件上报 |
| 服务 | `services/merchantStaffSelection.js` + `.helpers.js` | API、字段映射、「系统」兜底 | | 服务 | `services/merchantStaffSelection.js` + `.helpers.js` | API、字段映射、「系统」兜底 |
| 编排 | `createOrder.js` | setData、清礼券、重载商品 | | 编排 | `createOrder.js` | 扁平 `staffPickerBox`/`staffPickerMode` 打开、confirm 写 orderObj、清礼券、重载商品 |
三种模式 `STAFF_MODE`:`sales` / `conversion` / `delivery`,字段映射见 `merchantStaffSelection.helpers.js` 中 `MODE_CONFIG`。 三种模式 `STAFF_MODE`:`sales` / `conversion` / `delivery`,字段映射见 `merchantStaffSelection.helpers.js` 中 `MODE_CONFIG`。
...@@ -32,7 +32,7 @@ alwaysApply: false ...@@ -32,7 +32,7 @@ alwaysApply: false
- **搜索中**(`keyWord` 非空)不注入,显示「暂无数据」 - **搜索中**(`keyWord` 非空)不注入,显示「暂无数据」
- `userId === -1` 时弹窗须回显「系统」(`shouldEchoSystemStaff`) - `userId === -1` 时弹窗须回显「系统」(`shouldEchoSystemStaff`)
- `useSystemStaffFallback === true` 时 `openStaffPicker` 自动 `onStaffPickerConfirm` - `useSystemStaffFallback === true` 时可在 `loadPickerData` 成功后自动 confirm(当前未实现,onLoad 靠 `resolveDefaultSelection` 预填)
逻辑变更先改 `merchantStaffSelection.helpers.js`,再改 `.js` 与页面。 逻辑变更先改 `merchantStaffSelection.helpers.js`,再改 `.js` 与页面。
...@@ -63,7 +63,7 @@ alwaysApply: false ...@@ -63,7 +63,7 @@ alwaysApply: false
## 改动检查清单 ## 改动检查清单
- [ ] 员工逻辑在 service 层,组件无 API / 无 getPageInstance - [ ] 员工拉数/交互在 picker 组件 + service 层,页面无嵌套 `staffPicker.*`、无 getPageInstance
- [ ] 礼券清空走 `orderCouponEffects`,三处调用保持一致 - [ ] 礼券清空走 `orderCouponEffects`,三处调用保持一致
- [ ] 导出函数与页面编排方法补 JSDoc - [ ] 导出函数与页面编排方法补 JSDoc
- [ ] 纯函数补/更新 `tabWorkOrder/pages/createOrder/tests/*.test.mjs` - [ ] 纯函数补/更新 `tabWorkOrder/pages/createOrder/tests/*.test.mjs`
...@@ -44,7 +44,6 @@ Component({ ...@@ -44,7 +44,6 @@ Component({
} }
}, },
attached() { attached() {
// console.log(wx.$util.isFullSucreen(), 'wx.$util.isFullSucreen()')
this.setData({ this.setData({
isFullSucreen: wx.$util.isFullSucreen(true) isFullSucreen: wx.$util.isFullSucreen(true)
}) })
......
...@@ -18,7 +18,7 @@ export const appId = "wx570d9331f9ace0bd"; ...@@ -18,7 +18,7 @@ export const appId = "wx570d9331f9ace0bd";
* 4预发布 * 4预发布
* 5cdptest * 5cdptest
*/ */
let index = 2; let index = 3;
const accountInfo = wx.getAccountInfoSync(); const accountInfo = wx.getAccountInfoSync();
const systemInfo = wx.getSystemInfoSync(); const systemInfo = wx.getSystemInfoSync();
const envName = accountInfo.miniProgram.envVersion; const envName = accountInfo.miniProgram.envVersion;
......
/** /**
* @file 员工选择弹窗 — 纯展示组件(createOrder 专用) * @file 员工选择弹窗 — createOrder 专用
* *
* 不调 API、不读写页面 orderObj;由页面传入列表与选中态,通过事件上报交互。 * show 为 true 时在 observer 内拉数;页面仅传扁平 staffPickerBox + staffPickerMode。
* * 事件:confirm { merchant, staff, mode };cancel
* 事件契约:
* - confirm:{ merchant, staff } 用户点击确认
* - cancel:关闭弹窗
* - merchantchange:{ merchantId, merchant } 切换门店
* - staffchange:{ staffId, staff, index } 切换员工
* - search:{ keyword } 姓名搜索(销售/交付模式)
* - togglemore:展开/收起门店列表
*/ */
import {
STAFF_MODE,
fetchStaff,
getModeConfig,
getPickerLabels,
hasStaffConflict,
loadStaffPicker,
updateMerchantSelection,
updateStaffSelection
} from '../../services/merchantStaffSelection'
Component({ Component({
properties: { properties: {
/** 是否显示弹窗 */ /** 是否显示;为 true 时在 observer 内异步拉数(先开弹层再加载) */
show: { show: {
type: Boolean, type: Boolean,
value: false value: false,
observer(n) {
if (n) {
this.setData({ keyWord: '' })
this.loadPickerData()
}
}
}, },
popupTitle: String, /** sales | conversion | delivery */
merchantTitle: String, mode: {
staffTitle: String, type: String,
merchantList: { value: ''
type: Array,
value: []
}, },
staffList: { orderObj: {
type: Array, type: Object,
value: [] value: {}
}, },
searchEnabled: { userInfo: {
type: Boolean, type: Object,
value: false value: {}
}, },
keyWord: { pointsMultiRole: {
type: String, type: String,
value: '' value: ''
}, },
moreMerchant: { orderCreateType: {
type: Boolean, type: String,
value: false value: ''
} }
}, },
data: {
popupTitle: '',
merchantTitle: '',
staffTitle: '',
merchantList: [],
staffList: [],
keyWord: '',
moreMerchant: false,
searchEnabled: false
},
methods: { methods: {
/**
* show=true 时加载门店与员工;失败 toast 并通知页面关闭
*/
async loadPickerData() {
const { mode, orderObj, userInfo, pointsMultiRole, orderCreateType } =
this.properties
if (!mode) return
const labels = getPickerLabels(mode, pointsMultiRole)
const config = getModeConfig(mode)
this.setData({
popupTitle: labels.popupTitle,
merchantTitle: labels.merchantTitle,
staffTitle: labels.staffTitle,
searchEnabled: config.searchEnabled,
merchantList: [],
staffList: [],
moreMerchant: false
})
try {
const result = await loadStaffPicker(mode, {
orderObj,
userInfo,
orderCreateType,
keyWord: ''
})
this.setData({
merchantList: result.merchantList,
staffList: result.staffList,
moreMerchant: result.moreMerchant
})
} catch (e) {
wx.$util.showToast(e?.message || '加载失败')
this.triggerEvent('cancel')
}
},
onToggleMoreMerchant() { onToggleMoreMerchant() {
this.triggerEvent('togglemore') this.setData({
moreMerchant: !this.data.moreMerchant
})
}, },
onMerchantTap(e) {
/** 切换门店后组件内重新拉员工列表 */
async onMerchantTap(e) {
const { item } = e.currentTarget.dataset const { item } = e.currentTarget.dataset
this.triggerEvent('merchantchange', { const merchantId = item?.merchantId
merchantId: item.merchantId, const mode = this.properties.mode
merchant: item const { merchantList, keyWord } = this.data
if (!merchantId) return
const active = merchantList.find(m => m.active)
if (active?.merchantId == merchantId) return
const updatedList = updateMerchantSelection(merchantList, merchantId)
this.setData({
merchantList: updatedList,
staffList: []
}) })
try {
const config = getModeConfig(mode)
const staffResult = await fetchStaff(mode, merchantId, {
orderObj: {
...this.properties.orderObj,
[config.merchantIdField]: merchantId,
[config.merchantNameField]: item.merchantName || '',
[config.staffIdField]: '',
[config.staffNameField]: ''
}, },
merchantList: updatedList,
orderCreateType: this.properties.orderCreateType,
keyWord
})
this.setData({
staffList: staffResult.staffList
})
} catch (err) {
wx.$util.showToast(err?.message || '加载员工失败')
}
},
/** 选择员工;sales/delivery 与对端角色互斥时 toast */
onStaffTap(e) { onStaffTap(e) {
const { item, index } = e.currentTarget.dataset const { item } = e.currentTarget.dataset
this.triggerEvent('staffchange', { const mode = this.properties.mode
staffId: item.uuid, if (hasStaffConflict(mode, this.properties.orderObj, item?.uuid)) {
staff: item, wx.$util.showToast(getModeConfig(mode).conflictMessage)
index return
}
this.setData({
staffList: updateStaffSelection(this.data.staffList, item.uuid)
}) })
}, },
onSearch(e) {
this.triggerEvent('search', { /** 按姓名搜索员工 */
keyword: e.detail.value || '' async onSearch(e) {
const keyword = e.detail.value || ''
const mode = this.properties.mode
const merchantId = (this.data.merchantList || []).find(m => m.active)
?.merchantId
if (!merchantId) return
this.setData({ keyWord: keyword })
try {
const staffResult = await fetchStaff(mode, merchantId, {
orderObj: this.properties.orderObj,
merchantList: this.data.merchantList,
orderCreateType: this.properties.orderCreateType,
keyWord: keyword
}) })
this.setData({
staffList: staffResult.staffList
})
} catch (err) {
wx.$util.showToast(err?.message || '搜索失败')
}
}, },
onConfirm() { onConfirm() {
const mode = this.properties.mode
const { merchantTitle, staffTitle, merchantList, staffList } = this.data
const merchant = const merchant =
(this.data.merchantList || []).find(item => item.active) || merchantList.find(m => m.active) || merchantList[0]
this.data.merchantList?.[0] const staff = staffList.find(s => s.active)
const staff = (this.data.staffList || []).find(item => item.active)
this.triggerEvent('confirm', { merchant, staff }) if (!staff) {
wx.$util.showToast(staffTitle)
return
}
if (
(mode === STAFF_MODE.SALES || mode === STAFF_MODE.DELIVERY) &&
!merchant
) {
wx.$util.showToast(merchantTitle || '请选择合作门店')
return
}
this.triggerEvent('confirm', { merchant, staff, mode })
}, },
onCancel() { onCancel() {
this.triggerEvent('cancel') this.triggerEvent('cancel')
} }
......
<popup <popup
show="{{show}}" show="{{show}}"
data-form="btn"
bindconfirm="onConfirm" bindconfirm="onConfirm"
bind:cancel="onCancel" bind:cancel="onCancel"
title="{{popupTitle}}" title="{{popupTitle}}"
......
...@@ -9,24 +9,15 @@ import { ...@@ -9,24 +9,15 @@ import {
import { SubmitContext } from './submitStrategy' import { SubmitContext } from './submitStrategy'
import { RouteContext } from './routeStrategy' import { RouteContext } from './routeStrategy'
import { import {
STAFF_MODE,
buildOrderPatch,
fetchStaff,
getModeConfig,
getPickerLabels,
getSelectedMerchant,
getSelectedStaff,
hasStaffConflict,
loadStaffPicker,
resolveDefaultSelection,
updateMerchantSelection,
updateStaffSelection
} from './services/merchantStaffSelection'
import {
clearOrderCouponFields, clearOrderCouponFields,
resetCouponComponent resetCouponComponent
} from './services/orderCouponEffects' } from './services/orderCouponEffects'
import { import {
STAFF_MODE,
buildOrderPatch,
resolveDefaultSelection
} from './services/merchantStaffSelection'
import {
PAY_TYPE, PAY_TYPE,
PAY_TYPE_MAP, PAY_TYPE_MAP,
ORDER_SOURCE, ORDER_SOURCE,
...@@ -207,20 +198,8 @@ Page({ ...@@ -207,20 +198,8 @@ Page({
skuGoodsData: {}, //多规格商品数据 skuGoodsData: {}, //多规格商品数据
vinValid: true, vinValid: true,
createAllGoodsFlag: 1, // 当前门店是否能创建全部类型订单 0-否 1-是 createAllGoodsFlag: 1, // 当前门店是否能创建全部类型订单 0-否 1-是
staffPicker: { staffPickerBox: false,
visible: false, staffPickerMode: ''
mode: '',
merchantTitle: '',
staffTitle: '',
popupTitle: '',
merchantList: [],
staffList: [],
selectedMerchantId: '',
selectedStaffId: '',
keyWord: '',
searchEnabled: false,
moreMerchant: false
}
}, },
onCloseOrderType() { onCloseOrderType() {
this.setData({ orderTypeBox: false }) this.setData({ orderTypeBox: false })
...@@ -539,7 +518,10 @@ Page({ ...@@ -539,7 +518,10 @@ Page({
let { showName, staffMode, positionnnum: positionNum } = let { showName, staffMode, positionnnum: positionNum } =
e.currentTarget.dataset || e.detail e.currentTarget.dataset || e.detail
if (staffMode) { if (staffMode) {
return this.openStaffPicker(staffMode) return this.setData({
staffPickerBox: true,
staffPickerMode: staffMode
})
} }
if (showName == 'orderTypeBox' && createAllGoodsFlag == 0) return if (showName == 'orderTypeBox' && createAllGoodsFlag == 0) return
if (showName == 'showSceneSelect') { if (showName == 'showSceneSelect') {
...@@ -637,179 +619,17 @@ Page({ ...@@ -637,179 +619,17 @@ Page({
}) })
} }
}, },
// --- 员工选择(merchant-staff-picker 编排)---
/**
* 打开员工/门店选择弹窗,按 mode 拉取列表。
* sales 且 useSystemStaffFallback 时自动确认(对齐旧版 defaultChecked)。
* @param {import('./services/merchantStaffSelection.helpers').StaffMode} mode
*/
async openStaffPicker(mode) {
const { orderObj, userInfo, pointsMultiRole, orderCreateType } = this.data
const labels = getPickerLabels(mode, pointsMultiRole)
const config = getModeConfig(mode)
this.setData({
'staffPicker.visible': true,
'staffPicker.mode': mode,
'staffPicker.keyWord': '',
'staffPicker.merchantTitle': labels.merchantTitle,
'staffPicker.staffTitle': labels.staffTitle,
'staffPicker.popupTitle': labels.popupTitle,
'staffPicker.searchEnabled': config.searchEnabled
})
try {
wx.$util.showLoading('加载中...')
const result = await loadStaffPicker(mode, {
orderObj,
userInfo,
orderCreateType,
keyWord: ''
})
wx.$util.hideLoading()
this.setData(
{
'staffPicker.merchantList': result.merchantList,
'staffPicker.staffList': result.staffList,
'staffPicker.moreMerchant': result.moreMerchant,
'staffPicker.selectedMerchantId': result.selectedMerchantId,
'staffPicker.selectedStaffId': result.selectedStaffId
},
() => {
if (
mode === STAFF_MODE.SALES &&
result.useSystemStaffFallback &&
getSelectedStaff(result.staffList)?.uuid == -1
) {
this.onStaffPickerConfirm({
detail: {
merchant: getSelectedMerchant(result.merchantList),
staff: getSelectedStaff(result.staffList)
}
})
}
}
)
} catch (e) {
wx.$util.hideLoading()
wx.$util.showToast(e?.message || '加载失败')
}
},
/** 关闭员工选择弹窗 */ /** 关闭员工选择弹窗 */
onStaffPickerCancel() { onStaffPickerCancel() {
this.setData({ this.setData({ staffPickerBox: false })
'staffPicker.visible': false,
'staffPicker.keyWord': ''
})
},
/** 展开/收起超过 3 个的门店列表 */
onStaffPickerToggleMore() {
this.setData({
'staffPicker.moreMerchant': !this.data.staffPicker.moreMerchant
})
},
/** 切换门店后重新拉取员工列表 */
async onStaffPickerMerchantChange(e) {
const { merchantId, merchant } = e.detail
const { staffPicker, orderObj, orderCreateType } = this.data
if (!merchantId || staffPicker.selectedMerchantId == merchantId) return
const config = getModeConfig(staffPicker.mode)
const merchantList = updateMerchantSelection(
staffPicker.merchantList,
merchantId
)
this.setData({
'staffPicker.merchantList': merchantList,
'staffPicker.selectedMerchantId': merchantId,
'staffPicker.staffList': [],
'staffPicker.selectedStaffId': ''
})
try {
wx.$util.showLoading('切换中...')
const staffResult = await fetchStaff(staffPicker.mode, merchantId, {
orderObj: {
...orderObj,
[config.merchantIdField]: merchantId,
[config.merchantNameField]: merchant?.merchantName || '',
[config.staffIdField]: '',
[config.staffNameField]: ''
},
merchantList,
orderCreateType,
keyWord: staffPicker.keyWord
})
wx.$util.hideLoading()
this.setData({
'staffPicker.staffList': staffResult.staffList,
'staffPicker.selectedStaffId': staffResult.selectedStaffId
})
} catch (err) {
wx.$util.hideLoading()
wx.$util.showToast(err?.message || '加载员工失败')
}
},
/** 选择员工;sales/delivery 与对端角色互斥时 toast 拦截 */
onStaffPickerStaffChange(e) {
const { staffId } = e.detail
const { staffPicker, orderObj } = this.data
if (hasStaffConflict(staffPicker.mode, orderObj, staffId)) {
wx.$util.showToast(getModeConfig(staffPicker.mode).conflictMessage)
return
}
this.setData({
'staffPicker.staffList': updateStaffSelection(
staffPicker.staffList,
staffId
),
'staffPicker.selectedStaffId': staffId
})
},
/** 按姓名搜索员工(仅 searchEnabled 模式) */
async onStaffPickerSearch(e) {
const keyword = e.detail.keyword || ''
const { staffPicker, orderObj, orderCreateType } = this.data
const merchantId = staffPicker.selectedMerchantId
if (!merchantId) return
this.setData({ 'staffPicker.keyWord': keyword })
try {
const staffResult = await fetchStaff(staffPicker.mode, merchantId, {
orderObj,
merchantList: staffPicker.merchantList,
orderCreateType,
keyWord: keyword
})
this.setData({
'staffPicker.staffList': staffResult.staffList,
'staffPicker.selectedStaffId': staffResult.selectedStaffId
})
} catch (err) {
wx.$util.showToast(err?.message || '搜索失败')
}
}, },
/** /**
* 确认员工选择:写入 orderObj。 * 确认员工选择:写入 orderObj;sales 模式清空礼券与商品并重载列表
* sales 模式会清空礼券与商品,并在已选场景时重载商品列表。 * @param {WechatMiniprogram.CustomEvent} e
*/ */
onStaffPickerConfirm(e) { onStaffPickerConfirm(e) {
const { merchant, staff } = e.detail const { merchant, staff, mode } = e.detail
const { staffPicker, orderObj, goodsList } = this.data const { orderObj, goodsList } = this.data
const mode = staffPicker.mode
if (!staff) {
wx.$util.showToast(staffPicker.staffTitle)
return
}
if (
(mode === STAFF_MODE.SALES || mode === STAFF_MODE.DELIVERY) &&
!merchant
) {
wx.$util.showToast(staffPicker.merchantTitle || '请选择合作门店')
return
}
const patch = buildOrderPatch(mode, merchant, staff) const patch = buildOrderPatch(mode, merchant, staff)
const nextOrderObj = { ...orderObj, ...patch } const nextOrderObj = { ...orderObj, ...patch }
let nextGoodsList = goodsList let nextGoodsList = goodsList
...@@ -841,12 +661,11 @@ Page({ ...@@ -841,12 +661,11 @@ Page({
this.setData({ this.setData({
orderObj: nextOrderObj, orderObj: nextOrderObj,
goodsList: nextGoodsList, goodsList: nextGoodsList,
'staffPicker.visible': false, staffPickerBox: false
'staffPicker.keyWord': ''
}) })
}, },
/** /**
* onLoad 预填销售顾问:上一单同店或单门店「系统」兜底。 * onLoad 预填销售顾问:上一单同店或单门店「系统」兜底
* @see resolveDefaultSelection * @see resolveDefaultSelection
*/ */
async prefillLastSeller() { async prefillLastSeller() {
......
...@@ -802,21 +802,15 @@ value="{{ orderObj.remark }}" ...@@ -802,21 +802,15 @@ value="{{ orderObj.remark }}"
title="请选择交易参考号" title="请选择交易参考号"
/> />
<merchant-staff-picker <merchant-staff-picker
show="{{ staffPicker.visible }}" wx:if="{{ staffPickerBox }}"
popup-title="{{ staffPicker.popupTitle }}" show="{{ staffPickerBox }}"
merchant-title="{{ staffPicker.merchantTitle }}" mode="{{ staffPickerMode }}"
staff-title="{{ staffPicker.staffTitle }}" orderObj="{{ orderObj }}"
merchant-list="{{ staffPicker.merchantList }}" userInfo="{{ userInfo }}"
staff-list="{{ staffPicker.staffList }}" pointsMultiRole="{{ pointsMultiRole }}"
search-enabled="{{ staffPicker.searchEnabled }}" orderCreateType="{{ orderCreateType }}"
key-word="{{ staffPicker.keyWord }}"
more-merchant="{{ staffPicker.moreMerchant }}"
bind:confirm="onStaffPickerConfirm" bind:confirm="onStaffPickerConfirm"
bind:cancel="onStaffPickerCancel" bind:cancel="onStaffPickerCancel"
bind:merchantchange="onStaffPickerMerchantChange"
bind:staffchange="onStaffPickerStaffChange"
bind:search="onStaffPickerSearch"
bind:togglemore="onStaffPickerToggleMore"
/> />
<sub-shop-merchant <sub-shop-merchant
show="{{ subShopMerchantBox }}" show="{{ subShopMerchantBox }}"
......
/** /**
* @file createOrder 员工选择 — 纯函数层(无 API、无页面副作用) * @file createOrder 员工选择 — 纯函数层(无 API、无页面副作用)
* *
* 架构:merchant-staff-picker(UI)→ merchantStaffSelection.js(API)→ 本文件(映射/兜底) * 架构:merchant-staff-picker(UI,show 时自拉数)→ merchantStaffSelection.js(API)→ 本文件(映射/兜底)
* *
* 三种模式与 orderObj 字段: * 三种模式与 orderObj 字段:
* - sales:merchantId/merchantName + userId/employeeName(销售顾问/录单员) * - sales:merchantId/merchantName + userId/employeeName(销售顾问/录单员)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!