回溯点:保存注册预约客户流程修复进度
This commit is contained in:
@@ -6,6 +6,8 @@ Page({
|
||||
customers: [],
|
||||
loadError: '',
|
||||
createModalVisible: false,
|
||||
duplicateModalVisible: false,
|
||||
duplicateCustomers: [],
|
||||
creating: false,
|
||||
createForm: {
|
||||
nickname: '',
|
||||
@@ -60,6 +62,17 @@ Page({
|
||||
this.setData({ createModalVisible: false })
|
||||
},
|
||||
|
||||
closeDuplicateModal() {
|
||||
this.setData({ duplicateModalVisible: false })
|
||||
},
|
||||
|
||||
selectDuplicateCustomer(event) {
|
||||
const customerId = event.currentTarget.dataset.id
|
||||
if (!customerId) return
|
||||
this.setData({ duplicateModalVisible: false })
|
||||
this.openDetail({ currentTarget: { dataset: { id: customerId } } })
|
||||
},
|
||||
|
||||
stopTap() {
|
||||
},
|
||||
|
||||
@@ -94,12 +107,37 @@ Page({
|
||||
}
|
||||
this.setData({ creating: true })
|
||||
try {
|
||||
const matches = await customersApi.matchExactIdentity(nickname, wechatId || undefined, phone || undefined)
|
||||
if (Array.isArray(matches) && matches.length) {
|
||||
this.setData({
|
||||
createModalVisible: false,
|
||||
duplicateCustomers: matches.map(item => ({
|
||||
id: item.id,
|
||||
name: item.name || item.nickname || nickname,
|
||||
phone: item.phone || '未填写手机号'
|
||||
})),
|
||||
duplicateModalVisible: true
|
||||
})
|
||||
return
|
||||
}
|
||||
await customersApi.create({ nickname, wechatId: wechatId || undefined, phone: phone || undefined })
|
||||
wx.showToast({ title: '客户已新增', icon: 'success' })
|
||||
this.resetCreateForm()
|
||||
this.setData({ createModalVisible: false })
|
||||
await this.loadCustomers()
|
||||
} catch (error) {
|
||||
if (/客户已存在|重复|相同/.test(String(error.message || ''))) {
|
||||
try {
|
||||
const matches = await customersApi.matchExactIdentity(nickname, wechatId || undefined, phone || undefined)
|
||||
if (Array.isArray(matches) && matches.length) {
|
||||
this.setData({ createModalVisible: false, duplicateCustomers: matches.map(item => ({ id: item.id, name: item.name || item.nickname || nickname, phone: item.phone || '未填写手机号' })), duplicateModalVisible: true })
|
||||
return
|
||||
}
|
||||
} catch (lookupError) {
|
||||
wx.showToast({ title: lookupError.message || '客户重复,请重新查询已有客户', icon: 'none' })
|
||||
return
|
||||
}
|
||||
}
|
||||
wx.showToast({ title: error.message || '新增失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ creating: false })
|
||||
|
||||
@@ -31,6 +31,7 @@ async function run() {
|
||||
global.wx.showToast = options => { toast = options.title }
|
||||
customersApi.create = async value => { submitted = value }
|
||||
customersApi.list = async () => ({ list: [] })
|
||||
customersApi.matchExactIdentity = async () => []
|
||||
|
||||
page.setData({ 'createForm.nickname': '小周', 'createForm.wechatId': 'wx_zhou' })
|
||||
await page.submitCustomer()
|
||||
@@ -41,6 +42,23 @@ async function run() {
|
||||
await page.submitCustomer()
|
||||
assert.strictEqual(submitted, undefined)
|
||||
assert.strictEqual(toast, '请填写客户姓名')
|
||||
|
||||
let lookedUp
|
||||
customersApi.matchExactIdentity = async (...args) => {
|
||||
lookedUp = args
|
||||
return [{ id: '29', name: '小周', phone: '13800138000' }]
|
||||
}
|
||||
const duplicatePage = {
|
||||
...definition,
|
||||
data: JSON.parse(JSON.stringify(definition.data)),
|
||||
setData(values) { Object.assign(this.data, values) }
|
||||
}
|
||||
duplicatePage.data.createForm = { nickname: '小周', wechatId: 'wx-zhou', phone: '13800138000' }
|
||||
await definition.submitCustomer.call(duplicatePage)
|
||||
assert.deepStrictEqual(lookedUp, ['小周', 'wx-zhou', '13800138000'])
|
||||
assert.strictEqual(duplicatePage.data.duplicateModalVisible, true)
|
||||
assert.deepStrictEqual(duplicatePage.data.duplicateCustomers, [{ id: '29', name: '小周', phone: '13800138000' }])
|
||||
assert.strictEqual(submitted, undefined)
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
|
||||
@@ -45,4 +45,12 @@
|
||||
<button class="primary-btn modal-submit" loading="{{creating}}" bindtap="submitCustomer">保存客户</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{duplicateModalVisible}}" class="modal-mask" bindtap="closeDuplicateModal">
|
||||
<view class="customer-modal duplicate-modal" catchtap="stopTap">
|
||||
<view class="modal-head"><view><text class="modal-title">客户已存在</text><text class="duplicate-hint">姓名、微信号和手机号完全一致</text></view><view class="modal-close" bindtap="closeDuplicateModal">×</view></view>
|
||||
<view class="duplicate-list"><view wx:for="{{duplicateCustomers}}" wx:key="id" class="duplicate-customer" data-id="{{item.id}}" bindtap="selectDuplicateCustomer"><view><text class="duplicate-name">{{item.name}}</text><text class="duplicate-phone">{{item.phone}}</text></view><text class="arrow">›</text></view></view>
|
||||
<button class="secondary-btn duplicate-cancel" bindtap="closeDuplicateModal">返回修改资料</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -147,3 +147,12 @@
|
||||
.modal-submit {
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
|
||||
.duplicate-modal { max-height: 76vh; overflow: hidden; }
|
||||
.duplicate-hint { display: block; margin-top: 7rpx; color: #7a8981; font-size: 21rpx; font-weight: 400; }
|
||||
.duplicate-list { max-height: 48vh; overflow-y: auto; }
|
||||
.duplicate-customer { display: flex; align-items: center; justify-content: space-between; min-height: 86rpx; border-bottom: 1rpx solid #e8eee9; }
|
||||
.duplicate-name,.duplicate-phone { display: block; }
|
||||
.duplicate-name { color: #26342d; font-size: 25rpx; font-weight: 700; }
|
||||
.duplicate-phone { margin-top: 6rpx; color: #77867e; font-size: 21rpx; }
|
||||
.duplicate-cancel { margin-top: 20rpx; background: #eaf3ed; color: #397055; }
|
||||
|
||||
Reference in New Issue
Block a user