Commit ee3383dc by chenwq

feat: 添加客户来源选择功能并优化默认索引

1 parent d2410622
......@@ -259,6 +259,7 @@ Page({
packageList: [],
baseConfigData: {},
showSource: false,
sourceDefaultIndex: 0,
Sourcecolumns: [
{
type: SALES_TYPE.PRE_SALES,
......@@ -3228,8 +3229,18 @@ Page({
// return latestDate.formattedDate(); // 或返回时间戳 latestTimestamp
},
toSelectCustomerSource() {
const { Sourcecolumns = [], orderObj = {} } = this.data
const salesType = orderObj.customer?.salesType
const sourceDefaultIndex = Sourcecolumns.findIndex(
item => String(item.type) === String(salesType)
)
const selectedIndex = sourceDefaultIndex >= 0 ? sourceDefaultIndex : 0
this.setData({
showSource: true
showSource: true,
sourceDefaultIndex: selectedIndex
}, () => {
const picker = this.selectComponent?.('#customerSourcePicker')
picker?.setColumnIndex?.(0, selectedIndex)?.catch?.(() => {})
})
},
onChangeSource(e) {
......
......@@ -124,8 +124,11 @@ value="{{ orderObj.remark }}"
<gl-cell
border
label="客户来源"
value="{{ filter.getSalesTypeName(Sourcecolumns, orderObj.customer.salesType) }}"
valueAlign="right"
value="{{ filter.getSalesTypeName(Sourcecolumns, orderObj.customer.salesType) }}"
haveArrow
placeholder="点击选择"
bindclick="toSelectCustomerSource"
/>
<gl-cell border label="性别" value="{{ orderObj.customer.customerSex == 1 ? '男' : (orderObj.customer.customerSex == 2 ? '女' : '') }}" valueAlign="right" labelWidth="var(--fontSize140)" />
<gl-cell border valueAlign="right" label="手机号" required="{{ filter.isIncludesItem(requiredList ,'customerPhone') }}" value="{{ orderObj.customer.customerPhone }}" labelWidth="var(--fontSize140)" />
......@@ -816,11 +819,13 @@ value="{{ orderObj.remark }}"
/>
<van-popup show="{{ showSource }}" position="bottom" bind:close="onCloseSource">
<van-picker
id="customerSourcePicker"
show-toolbar
title="客户来源"
bind:cancel="onCloseSource"
columns="{{ Sourcecolumns }}"
value-key="name"
default-index="{{ sourceDefaultIndex }}"
bind:confirm="onChangeSource"
/>
</van-popup>
......
......@@ -34,6 +34,7 @@ function createPage(pageConfig, lowPriceFlag) {
const currentGoods = [{ goodsCode: 'CURRENT' }]
let profileEchoCustomerId
let routeCount = 0
const sourcePickerCalls = []
const page = {
_isLowPriceCreateOrder: Number(lowPriceFlag) === 1,
isLowPriceOrder: pageConfig.isLowPriceOrder,
......@@ -66,6 +67,15 @@ function createPage(pageConfig, lowPriceFlag) {
Object.assign(this.data, patch)
callback?.()
},
selectComponent(selector) {
if (selector !== '#customerSourcePicker') return null
return {
setColumnIndex(columnIndex, optionIndex) {
sourcePickerCalls.push([columnIndex, optionIndex])
return Promise.resolve()
}
}
},
async echoCustomerProfileIfNeeded(detail) {
profileEchoCustomerId = detail?.customer?.customerId
},
......@@ -80,7 +90,8 @@ function createPage(pageConfig, lowPriceFlag) {
currentGoods,
page,
getProfileEchoCustomerId: () => profileEchoCustomerId,
getRouteCount: () => routeCount
getRouteCount: () => routeCount,
getSourcePickerCalls: () => sourcePickerCalls
}
}
......@@ -113,16 +124,24 @@ describe('createOrder customer profile import', () => {
it('low-price profile selection keeps current goods and payment fields', async () => {
const pageConfig = await loadPageConfig()
const context = createPage(pageConfig, 1)
const selectedProfile = structuredClone(selectedRecord)
selectedProfile.customer.salesType = context.page.data.Sourcecolumns[2].type
await pageConfig.chooseCustomerInfo.call(context.page, {
detail: structuredClone(selectedRecord)
detail: selectedProfile
})
assert.equal(context.page.data.orderObj.customer.customerId, 2)
assert.equal(context.page.data.orderObj.customer.customerName, '新客户')
assert.equal(context.page.data.orderObj.customer.customerSex, 1)
assert.equal(context.page.data.orderObj.customer.experienceFlag, 'N')
assert.equal(context.page.data.orderObj.customer.salesType, 0)
assert.equal(
context.page.data.orderObj.customer.salesType,
selectedProfile.customer.salesType
)
pageConfig.toSelectCustomerSource.call(context.page)
assert.equal(context.page.data.sourceDefaultIndex, 2)
assert.deepEqual(context.getSourcePickerCalls(), [[0, 2]])
assert.equal(context.page.data.orderObj.remark, '新客户备注')
assert.equal(context.page.data.currentWordNumber, 5)
assert.equal(context.page.data.orderObj.orderCode, 'ARCHIVE-ORDER-001')
......
......@@ -34,6 +34,11 @@ describe('createOrder customer information template', () => {
assert.doesNotMatch(customerSection, /请通过客户档案选择/)
assert.match(customerSection, /label="客户来源"/)
assert.match(customerSection, /value="\{\{ filter\.getSalesTypeName\(Sourcecolumns, orderObj\.customer\.salesType\) \}\}"/)
assert.match(
customerSection,
/label="客户来源"[\s\S]*bindclick="toSelectCustomerSource"/
)
assert.match(template, /default-index="\{\{ sourceDefaultIndex \}\}"/)
assert.match(customerSection, /label="性别"/)
assert.match(customerSection, /orderObj\.customer\.customerSex == 1 \? '男' : \(orderObj\.customer\.customerSex == 2 \? '女' : ''\)/)
assert.match(customerSection, /label="手机号"/)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!