Commit 9324eef0 by 张立顺

feat 日报新增搜索功能

1 parent 64a92b2e
......@@ -7,7 +7,10 @@
const { fetchFieldOptions } = require('../../api/fieldOptionsService.js')
const { coerceMultipleSelectValue } = require('../../form-engine/multiple-select-value.js')
const { normalizeOptionRecord } = require('../../form-engine/field-submit-value.js')
const { shouldRefreshOptionsOnPopup } = require('../../utils/field-options-popup.js')
const {
shouldRefreshOptionsOnPopup,
isEmployeeListPickerSearchable
} = require('../../utils/field-options-popup.js')
const {
buildUpgradeIconUrl,
FORM_FIELD_ARROW_ICON
......@@ -45,6 +48,8 @@ Component({
showPicker: false,
pickerOptions: [],
loadingOptions: false,
pickerSearchable: false,
searchKeyword: '',
arrowIconUrl: ''
},
......@@ -174,7 +179,8 @@ Component({
staffUuid: ctx.staffUuid,
reportDate: ctx.reportDate,
reportType: ctx.reportType || 'store',
sceneType: ctx.sceneType
sceneType: ctx.sceneType,
name: this.data.searchKeyword || ''
}
},
......@@ -224,17 +230,21 @@ Component({
async onTap() {
if (this.data.disabled) return
const field = this.data.field || {}
const pickerSearchable = isEmployeeListPickerSearchable(field.optionsKey)
this.setData({ searchKeyword: '', pickerSearchable })
let options = this.data.pickerOptions
if (this.data.field?.optionsKey) {
if (field?.optionsKey) {
options = await this.loadOptions({
useCache: !shouldRefreshOptionsOnPopup(this.data.field)
useCache: !shouldRefreshOptionsOnPopup(field)
})
} else {
options = this.getStaticOptions()
this.setData({ pickerOptions: options })
}
if (!options.length) {
if (!options.length && !pickerSearchable) {
return wx.$util?.showToast?.('暂无可选项')
}
......@@ -242,6 +252,13 @@ Component({
this.setData({ showPicker: true })
},
/** 弹框内搜索:带 name 重拉员工列表(对齐 Merchant-Seles) */
async onPickerSearch(e) {
const searchKeyword = e.detail?.value || ''
this.setData({ searchKeyword })
await this.loadOptions({ useCache: false })
},
buildSubmitValues(selectedValues = []) {
const options = this.data.pickerOptions.length
? this.data.pickerOptions
......@@ -264,13 +281,13 @@ Component({
onPickerConfirm(e) {
const rawValue = e.detail?.value || []
const value = this.buildSubmitValues(rawValue)
this.setData({ showPicker: false })
this.setData({ showPicker: false, searchKeyword: '' })
this.updateDisplayLabel(this.data.field, value)
this.triggerEvent('change', this.buildChangeDetail(value))
},
onPickerCancel() {
this.setData({ showPicker: false })
this.setData({ showPicker: false, searchKeyword: '' })
}
}
})
......@@ -17,6 +17,9 @@
options="{{ pickerOptions }}"
value="{{ pickerValueIds }}"
loading="{{ loadingOptions }}"
searchable="{{ pickerSearchable }}"
search-keyword="{{ searchKeyword }}"
bind:search="onPickerSearch"
bind:confirm="onPickerConfirm"
bind:cancel="onPickerCancel"
/>
......@@ -13,7 +13,10 @@ const {
isOrderListField,
resolveCarBrandTypeFlagFromField
} = require('../../utils/order-list-params.js')
const { shouldRefreshOptionsOnPopup } = require('../../utils/field-options-popup.js')
const {
shouldRefreshOptionsOnPopup,
isEmployeeListPickerSearchable
} = require('../../utils/field-options-popup.js')
const {
buildUpgradeIconUrl,
FORM_FIELD_ARROW_ICON
......@@ -141,9 +144,9 @@ Component({
return this.data.field?.options?.length ? this.data.field.options : []
},
/** 4sStaffList(推荐人 / 交付专员)弹框启用服务端姓名搜索 */
/** storeStaffList / 4sStaffList 弹框启用服务端姓名搜索(门店驻店人员、洽谈驻店人员、销售/交付专员) */
isStaffPickerSearchable(field = this.data.field) {
return field?.optionsKey === '4sStaffList'
return isEmployeeListPickerSearchable(field?.optionsKey)
},
/** 组装 optionsKey 远程拉取参数(merchantId、reportDate、saleDate 等) */
......@@ -303,7 +306,7 @@ Component({
})
},
/** 弹框内搜索:带 name 重拉 4sStaffList(对齐 Merchant-Seles) */
/** 弹框内搜索:带 name 重拉员工列表(对齐 Merchant-Seles) */
async onPickerSearch(e) {
const searchKeyword = e.detail?.value || ''
this.setData({ searchKeyword })
......
......@@ -79,7 +79,7 @@ const subformDataList = buildAppSubformDataListFromJsonContent(jsonContent)
| optionsKey | Mock | Real |
|------------|------|------|
| `storeStaffList` | [`mock-field-options.js`](../fixtures/mock-field-options.js) | `dj.api.smartcarlife.employee.onTheJob.getByMerchantId`([`api.getEmployeeList`](../../api/api.js))。**打开弹框时 `useCache=false`,每次重新拉取** |
| `storeStaffList` | [`mock-field-options.js`](../fixtures/mock-field-options.js) | `dj.api.smartcarlife.employee.onTheJob.getByMerchantId`([`api.getEmployeeList`](../../api/api.js))。**打开弹框时 `useCache=false`,每次重新拉取**;弹框内 `search-input` 搜索时带 `name` 重拉(服务端筛选) |
| `4sStaffList` | mock fixture | 同上(对齐精品新建工单交付专员 `Merchant-Seles type=3`)。**打开弹框时 `useCache=false`,每次重新拉取**;弹框内 `search-input` 搜索时带 `name` 重拉(服务端筛选) |
| `orderList` | mock fixture(含 `raw` 供 completeFun) | `api.getGoodsOrderOutputValueList` → `dj.api.smartcarlife.goodsOrder.product.outputValue.list`(`sellerUserId`=staffUuid;**carBrandTypeFlag** 优先读 schema `field.reqParams.carBrandTypeFlag`(与 App 一致),缺失时由 subform `brandId` 推导;**saleDate** 仅行内 F3-*-12(与 App 一致,不用 reportDate);**不传** `baseGoodsCodeList`;选项 label 为 orderCode,option 含 `raw` 供 completeFun。**打开弹框时 `useCache=false`,每次重新拉取**。详见 [negotiation-template-features.md](./negotiation-template-features.md)) |
......@@ -94,7 +94,7 @@ const subformDataList = buildAppSubformDataListFromJsonContent(jsonContent)
- **适用字段**:
- `storeStaffList`:驻店「今日驻店人员」;门店日报 `F2-1`(`multipleSelect`);洽谈明细驻店人员(`select`)
- `4sStaffList`:门店日报「交付专员」(`select`,如 `F2-9-1`);洽谈明细「推荐人」等同类字段
- **搜索(仅 `4sStaffList`)**:`form-picker-popup` 顶部 `search-input`,确认后 `getEmployeeList` 增加 `name` 参数(对齐 `Merchant-Seles`);无匹配显示「暂无数据」
- **搜索(`storeStaffList` / `4sStaffList`)**:`form-picker-popup` 顶部 `search-input`,确认后 `getEmployeeList` 增加 `name` 参数(对齐 `Merchant-Seles`);无匹配显示「暂无数据」
驻店/门店 [`apiSwitch.js`](../config/apiSwitch.js) 中 `STAFF_DAILY_API_SWITCH` / `STORE_DAILY_API_SWITCH` 的 `fieldOptions` 已为 `'real'`;洽谈 `NEGOTIATION_DAILY_API_SWITCH.fieldOptions` 同为 `'real'`。
......
......@@ -6,7 +6,7 @@ import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const { shouldRefreshOptionsOnPopup } = require('../utils/field-options-popup.js')
const { shouldRefreshOptionsOnPopup, isEmployeeListPickerSearchable } = require('../utils/field-options-popup.js')
describe('field-options-popup', () => {
it('IT-FIELD-OPT-008: shouldRefreshOptionsOnPopup for remote select keys', () => {
......@@ -16,4 +16,11 @@ describe('field-options-popup', () => {
assert.equal(shouldRefreshOptionsOnPopup({ optionsKey: 'unknownKey' }), false)
assert.equal(shouldRefreshOptionsOnPopup({}), false)
})
it('IT-FIELD-OPT-008c: isEmployeeListPickerSearchable for staff list keys', () => {
assert.equal(isEmployeeListPickerSearchable('storeStaffList'), true)
assert.equal(isEmployeeListPickerSearchable('4sStaffList'), true)
assert.equal(isEmployeeListPickerSearchable('orderList'), false)
assert.equal(isEmployeeListPickerSearchable(''), false)
})
})
......@@ -212,6 +212,33 @@ describe('fieldOptionsAdapters', () => {
assert.deepEqual(res.data, [{ label: '张三', value: 'u-8', id: 'u-8', name: '张三' }])
})
it('IT-FIELD-OPT-008b: storeStaffList passes name with yqMerchantId for popup search', async () => {
STAFF_DAILY_API_SWITCH.fieldOptions = 'real'
let captured = null
__setEmployeeListApi({
getEmployeeList: async params => {
captured = params
return {
code: 0,
message: 'ok',
data: [{ staffName: '驻店张', uuid: 'u-9' }]
}
}
})
const res = await fetchFieldOptionsAdapter({
optionsKey: 'storeStaffList',
reportType: 'store',
merchantId: 'shop-4s',
yqMerchantId: 'yq-park',
name: '张'
})
assert.deepEqual(captured, { merchantId: 'yq-park', name: '张' })
assert.equal(res.code, 0)
assert.deepEqual(res.data, [{ label: '驻店张', value: 'u-9', id: 'u-9', name: '驻店张' }])
})
it('IT-FIELD-OPT-007: storeStaffList uses yqMerchantId over merchantId (all pages)', async () => {
STAFF_DAILY_API_SWITCH.fieldOptions = 'real'
let captured = null
......
......@@ -6,6 +6,9 @@
/** 打开弹框时需重新拉取的 optionsKey(orderList / 员工列表) */
const REFRESH_ON_POPUP_OPTIONS_KEYS = new Set(['orderList', 'storeStaffList', '4sStaffList'])
/** 弹框内支持服务端姓名搜索的员工 optionsKey(对齐 Merchant-Seles) */
const SEARCHABLE_EMPLOYEE_OPTIONS_KEYS = new Set(['storeStaffList', '4sStaffList'])
/**
* 打开选择弹框时是否 bypass fieldOptionsService 缓存(每次重新请求接口)
* @param {Object} [field={}] schema 字段,含 optionsKey
......@@ -15,7 +18,18 @@ function shouldRefreshOptionsOnPopup(field = {}) {
return REFRESH_ON_POPUP_OPTIONS_KEYS.has(field?.optionsKey)
}
/**
* 员工列表弹框是否展示 search-input(getEmployeeList 带 name 服务端筛选)
* @param {string} [optionsKey='']
* @returns {boolean}
*/
function isEmployeeListPickerSearchable(optionsKey = '') {
return SEARCHABLE_EMPLOYEE_OPTIONS_KEYS.has(optionsKey)
}
module.exports = {
REFRESH_ON_POPUP_OPTIONS_KEYS,
shouldRefreshOptionsOnPopup
SEARCHABLE_EMPLOYEE_OPTIONS_KEYS,
shouldRefreshOptionsOnPopup,
isEmployeeListPickerSearchable
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!