Commit 04d23d73 by 张立顺

fix 驻店日报bug

1 parent c14387d2
{
"projectname": "%E7%B2%BE%E5%93%81%E5%8D%87%E7%BA%A7",
"compileType": "miniprogram",
"libVersion": "3.13.1",
"packOptions": {
"ignore": [
{
"value": ".vscode",
"type": "folder"
},
{
"value": "docs",
"type": "folder"
},
{
"value": "packageDynamicForm/tests",
"type": "folder"
},
{
"value": "packageDynamicForm/test",
"type": "folder"
},
{
"value": "packageDynamicForm/scripts",
"type": "folder"
},
{
"value": "packageDynamicForm/docs",
"type": "folder"
},
{
"value": "packageDynamicForm/README.md",
"type": "file"
},
{
"value": "packageDynamicForm/fixtures/schema-staff-daily-full.json",
"type": "file"
},
{
"value": "packageDynamicForm/fixtures/mock-store-detail-jsonContent.json",
"type": "file"
},
{
"value": "packageEquity/tests",
"type": "folder"
},
{
"value": "tabIndex/tests",
"type": "folder"
},
{
"value": "packageEquity/docs",
"type": "folder"
},
{
"value": "cdn-upload",
"type": "folder"
}
],
"include": []
},
"setting": {
"urlCheck": false,
"coverView": true,
"es6": true,
"postcss": true,
"minified": true,
"enhance": true,
"showShadowRootInWxmlPanel": true,
"packNpmRelationList": [
{
"packageJsonPath": "./package.json",
"miniprogramNpmDistDir": "./"
},
{
"packageJsonPath": "./packageUsedCar/package.json",
"miniprogramNpmDistDir": "./packageUsedCar/"
}
],
"ignoreUploadUnusedFiles": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"useCompilerPlugins": [
"sass"
],
"ignoreDevUnusedFiles": false,
"minifyWXML": true,
"compileWorklet": false,
"uglifyFileName": false,
"uploadWithSourceMap": false,
"packNpmManually": true,
"minifyWXSS": true,
"localPlugins": false,
"disableUseStrict": false,
"condition": false,
"swc": false,
"disableSWC": true
},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
},
"appid": "wx4e697bcf4954ceef",
"simulatorPluginLibVersion": {}
{
"projectname": "%E7%B2%BE%E5%93%81%E5%8D%87%E7%BA%A7",
"compileType": "miniprogram",
"libVersion": "3.13.1",
"packOptions": {
"ignore": [
{
"value": ".vscode",
"type": "folder"
},
{
"value": "docs",
"type": "folder"
},
{
"value": "packageDynamicForm/tests",
"type": "folder"
},
{
"value": "packageDynamicForm/test",
"type": "folder"
},
{
"value": "packageDynamicForm/scripts",
"type": "folder"
},
{
"value": "packageDynamicForm/docs",
"type": "folder"
},
{
"value": "packageDynamicForm/README.md",
"type": "file"
},
{
"value": "packageDynamicForm/fixtures/schema-staff-daily-full.json",
"type": "file"
},
{
"value": "packageDynamicForm/fixtures/mock-store-detail-jsonContent.json",
"type": "file"
},
{
"value": "packageEquity/tests",
"type": "folder"
},
{
"value": "tabIndex/tests",
"type": "folder"
},
{
"value": "packageEquity/docs",
"type": "folder"
},
{
"value": "cdn-upload",
"type": "folder"
}
],
"include": []
},
"setting": {
"urlCheck": false,
"coverView": true,
"es6": true,
"postcss": true,
"minified": true,
"enhance": true,
"showShadowRootInWxmlPanel": true,
"packNpmRelationList": [
{
"packageJsonPath": "./package.json",
"miniprogramNpmDistDir": "./"
},
{
"packageJsonPath": "./packageUsedCar/package.json",
"miniprogramNpmDistDir": "./packageUsedCar/"
}
],
"ignoreUploadUnusedFiles": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"useCompilerPlugins": [
"sass"
],
"ignoreDevUnusedFiles": false,
"minifyWXML": true,
"compileWorklet": false,
"uglifyFileName": false,
"uploadWithSourceMap": false,
"packNpmManually": true,
"minifyWXSS": true,
"localPlugins": false,
"disableUseStrict": false,
"condition": false,
"swc": false,
"disableSWC": true
},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
},
"appid": "wx4e697bcf4954ceef",
"simulatorPluginLibVersion": {}
}
\ No newline at end of file
......@@ -87,7 +87,8 @@ Page({
sideAfterRearGearArr: [], // 后档
otherGoodsArr: [],
customerInfoBox: false,
baseConfigData: {}
baseConfigData: {},
vinValid: true
},
async prefillLastSeller() {
const { orderObj } = this.data
......@@ -221,26 +222,35 @@ Page({
let { selectCustomIndex } = this.data
let propCustomer = `notUpgradeOrderList[${selectCustomIndex}].customer`
let prop = `notUpgradeOrderList[${selectCustomIndex}]`
this.setData({
[propCustomer]: {
customerName: detail.customer.customerName,
customerSex: detail.customer.customerSex,
customerPhone: detail.customer.customerPhone,
const standNo = detail.customer.standNo || ''
this.setData(
{
[propCustomer]: {
customerName: detail.customer.customerName,
customerSex: detail.customer.customerSex,
customerPhone: detail.customer.customerPhone,
carBrandId: detail.customer.carBrandId,
carBrand: detail.customer.carBrand,
carChildsBrandId: detail.customer.carChildsBrandId,
carChildsBrandName: detail.customer.carChildsBrandName,
carSeriesId: detail.customer.carSeriesId,
carSeriesName: detail.customer.carSeriesName,
standNo: detail.customer.standNo,
plateNumber: detail.customer.plateNumber,
experienceFlag: detail.customer.experienceFlag || 'Y'
carBrandId: detail.customer.carBrandId,
carBrand: detail.customer.carBrand,
carChildsBrandId: detail.customer.carChildsBrandId,
carChildsBrandName: detail.customer.carChildsBrandName,
carSeriesId: detail.customer.carSeriesId,
carSeriesName: detail.customer.carSeriesName,
standNo: detail.customer.standNo,
plateNumber: detail.customer.plateNumber,
experienceFlag: detail.customer.experienceFlag || 'Y'
},
[prop + '.customerCouponCode']: detail.customerCoupon?.customerCouponCode,
[prop + '.customerCouponId']: detail?.customerCouponId, // 客户券id
customerInfoBox: false
},
[prop + '.customerCouponCode']: detail.customerCoupon?.customerCouponCode,
[prop + '.customerCouponId']: detail?.customerCouponId, // 客户券id
customerInfoBox: false
})
() => {
// 档案带入 17 位车架号时走与 OCR 相同的校验链路,避免提交误拦
if (standNo.length === 17) {
this.handleVinInput(standNo, true, 'standNo', selectCustomIndex)
}
}
)
},
onCustomerInfoCancel() {
this.setData({ customerInfoBox: false })
......
......@@ -717,7 +717,7 @@
<car-brands
show="{{ carBrandBox }}"
bindconfirm="chooseCar"
carSeriesId="{{ notUpgradeOrderList[selectCustomIndex].carSeriesId || '' }}"
carSeriesId="{{ notUpgradeOrderList[selectCustomIndex].customer.carSeriesId || '' }}"
merchantId="{{ orderObj.merchantId || undefined }}"
/>
<merchant-seles
......
import { IMG_URL } from '../../../utils/imageBase.js'
import { IMG_URL } from '../../../utils/imageBase.js'
// tabWorkOrder/pages/staffDaily/staffDaily.js
var util = require('~/utils/timeFormat/time-utils.js')
import dayjs from 'dayjs'
......@@ -13,6 +13,15 @@ import {
import api from '../../api'
import comApi from '~/api/api'
import { setConfigInfo } from '~/store/index'
const {
isStaffCountInconsistent,
findInconsistentBrandField,
hasExistingInputErrors,
buildStaffCountInconsistencyMessage,
buildBrandFieldInconsistencyMessage,
buildBrandCheckWarningLines,
STAFF_DAILY_FIELD_KEYS
} = require('../upgradeStaffDaily/services/dailyReportInconsistency.helpers.js')
let toastList = {
deliveryCount: '新车交付数不能为空',
// filmToShopCount: '到店流量数(太阳膜)不能为空',
......@@ -33,7 +42,7 @@ Page({
//apply-shared页面可以影响组件
styleIsolation: 'apply-shared'
},
data: {
data: {
IMG_URL,
pickerdateList: [
{
......@@ -253,7 +262,12 @@ Page({
inputPlaceholder: '自动填入系统数据'
}
],
tabIndex: 0
tabIndex: 0,
alertModal: {
show: false,
title: '',
lines: []
}
},
tabClick(e) {
let { index } = e.detail
......@@ -683,6 +697,11 @@ Page({
wx.$util.showToast('必填不能为空')
return false //必填校验没过
}
wx.hideKeyboard?.()
if (!wx.$hasPermission?.canSkipValidation?.(userInfo)) {
const blocked = await this.blockSubmitIfInconsistent()
if (blocked) return false
}
orderObj.isAdmin = role == 'super' ? true : false
orderObj.oprBy = orderObj.staffUuid
orderObj.sceneType = 0
......@@ -779,25 +798,132 @@ Page({
lastWeek() {
this.changeWeek(-1)
},
/**
* 展示单行不一致预警,返回 Promise 在用户确认后 resolve
* @param {object} params
* @param {string} params.title
* @param {string} params.content
* @param {Function} [params.onConfirm]
* @returns {Promise<void>}
*/
showInconsistencyModal({ title, content, onConfirm }) {
return new Promise(resolve => {
wx.showModal({
title,
content,
showCancel: false,
confirmText: '知道了',
confirmColor: '#347BFF',
success: () => {
onConfirm?.()
resolve()
}
})
})
},
/**
* 展示多行警示预警(PC 端按品牌换行)
* @param {object} params
* @param {string} params.title
* @param {string[]} params.lines
* @returns {Promise<boolean>}
*/
showAlertModal({ title, lines }) {
return new Promise(resolve => {
this._alertModalResolve = resolve
this.setData({
alertModal: {
show: true,
title: title || '警示预警',
lines: lines || []
}
})
})
},
/** 关闭多行警示预警弹层(components/modal didClickBtn) */
onAlertModalConfirm() {
this.setData({ 'alertModal.show': false })
const resolve = this._alertModalResolve
this._alertModalResolve = null
resolve?.(true)
},
/**
* 提交前拦截与上一位驻店人员填写不一致(避免 PC blur+click 竞态导致误提交)
* @returns {Promise<boolean>} true 表示应阻止提交
*/
async blockSubmitIfInconsistent() {
const {
orderObj,
userInfo,
carBandList,
hwObjArray,
hwOhterObjArray,
otherObjArray
} = this.data
const canSkipValidation = userInfo =>
wx.$hasPermission?.canSkipValidation?.(userInfo)
if (hasExistingInputErrors({ orderObj, carBandList })) {
return true
}
const fieldMeta = [...hwObjArray, ...hwOhterObjArray, ...otherObjArray]
if (isStaffCountInconsistent(orderObj, userInfo, canSkipValidation)) {
await this.showInconsistencyModal({
title: '预警提示',
content: buildStaffCountInconsistencyMessage(orderObj),
onConfirm: () => {
this.setData({ 'orderObj.staffCountError': true })
}
})
return true
}
const inconsistent = findInconsistentBrandField({
carBandList,
orderObj,
userInfo,
fieldMeta,
canSkipValidation,
fieldKeys: STAFF_DAILY_FIELD_KEYS
})
if (inconsistent) {
await this.showInconsistencyModal({
title: '预警提示',
content: buildBrandFieldInconsistencyMessage({
label: inconsistent.label,
orderObj
}),
onConfirm: () => {
this.setData({
tabIndex: inconsistent.index,
[`carBandList[${inconsistent.index}].${inconsistent.name}inputError`]: true
})
}
})
return true
}
return false
},
checkValueStaffCount(e) {
let that = this
let { orderObj, userInfo } = this.data
if (
this.isNotEmpty(orderObj.recordStaffCount) &&
this.isNotEmpty(orderObj.staffCount) &&
orderObj.recordStaffCount != orderObj.staffCount &&
orderObj.lastStaffUuid &&
userInfo.uuid != orderObj.lastStaffUuid &&
!wx.$hasPermission?.canSkipValidation?.(userInfo) // 超管和区域运维跳过校验提示
// true
) {
const canSkipValidation = userInfo =>
wx.$hasPermission?.canSkipValidation?.(userInfo)
if (isStaffCountInconsistent(orderObj, userInfo, canSkipValidation)) {
wx.showModal({
title: '预警提示',
content: `今日驻店人数与 ${orderObj.lastStaffName} 提交不一致,再次确认!不一致提交日报时,今日驻店人数将被清空。`,
content: buildStaffCountInconsistencyMessage(orderObj),
showCancel: false,
confirmText: '知道了',
confirmColor: '#347BFF',
success(res) {
success() {
that.setData({
[`orderObj.staffCountError`]: true
})
......@@ -821,12 +947,9 @@ Page({
return false
}
// 根据车型做对应的文字处理
let context = ''
let showModal = false
const warningLines = buildBrandCheckWarningLines(data)
const templateType = params.templateType || TEMPLATE_TYPE.SINGLE
// 权益延保模板(2) 同时有 realEquityToShopCount 和 extendedWarrantyToShopCount,标红时两个都标红
const touchCountErrorKeys = templateType === TEMPLATE_TYPE.EQUITY_EXTENDED
? ['realEquityToShopCountinputError', 'extendedWarrantyToShopCountinputError']
: templateType === TEMPLATE_TYPE.GUANGLIAN
......@@ -835,10 +958,8 @@ Page({
data.forEach(item => {
if (!item.isCheckPass) {
showModal = true
carBandList.forEach(el => {
if (el.brandType == item.brandType) {
context += `【${item.brandName}】 店端总未触客数+门店售前触客数与当月实际交车数不符,差异值${item.differenceValue},请相关驻店销售对齐核销再次提交\t\n`
el.deliveryCountinputError = true
touchCountErrorKeys.forEach(key => { el[key] = true })
el.notDeliveryCountinputError = true
......@@ -850,24 +971,14 @@ Page({
this.setData({
carBandList
})
console.log(showModal, 'showModal')
if (showModal) {
// 将 showModal 转换为 Promise,以便等待用户关闭模态框
return new Promise(resolve => {
wx.showModal({
title: '警示预警',
content: context,
showCancel: false,
confirmText: '知道了',
confirmColor: '#347BFF',
success: () => {
resolve(true)
}
})
})
} else {
return false
if (warningLines.length) {
return this.showAlertModal({
title: '警示预警',
lines: warningLines
}).then(() => true)
}
return false
} catch (error) {
console.error('dailyReportCheck error:', error)
return false
......
......@@ -708,4 +708,22 @@ page .isFullSucreen {
.con:nth-child(n+3) {
margin-top: 16rpx;
}
}
.daily-alert-body {
max-height: 480rpx;
padding: 0 48rpx 24rpx;
box-sizing: border-box;
}
.daily-alert-line {
font-size: 28rpx;
line-height: 44rpx;
color: #292d33;
margin-bottom: 24rpx;
word-break: break-all;
}
.daily-alert-line:last-child {
margin-bottom: 0;
}
\ No newline at end of file
......@@ -437,11 +437,11 @@
<block wx:if="{{ filter.isIncludesItem(weeklyList, orderObj.reportDate) && role != 'other' }}">
<view class="confirm text-center" wx:if="{{ !isEditReport }}" bindtap="editReport">编辑</view>
<block wx:else>
<view class="confirm text-center" bindtap="submit">保存</view>
<view class="confirm text-center" catchtap="submit">保存</view>
<view class="save text-center" bindtap="cancelReport">取消</view>
</block>
</block>
<view wx:else class="confirm text-center" bindtap="submit">提交</view>
<view wx:else class="confirm text-center" catchtap="submit">提交</view>
</view>
</view>
</view>
......@@ -464,4 +464,23 @@
bindconfirm="changePromble"
bindcancel="closeSlectItemPopup"
bindclick="click"
/>
\ No newline at end of file
/>
<modal
id="dailyAlertModal"
show="{{ alertModal.show }}"
custom="{{ true }}"
tabTitleShow="{{ false }}"
title="{{ alertModal.title }}"
btns="{{ ['知道了'] }}"
btnBorder="{{ true }}"
maskEnable="{{ false }}"
binddidClickBtn="onAlertModalConfirm"
>
<scroll-view scroll-y class="daily-alert-body">
<view
class="daily-alert-line"
wx:for="{{ alertModal.lines }}"
wx:key="index"
>{{ item }}</view>
</scroll-view>
</modal>
\ No newline at end of file
/**
* @file 驻店/权益日报一致性校验 — 纯函数(无 setData、无 wx API)
*
* staffDaily(权益)与 upgradeStaffDaily(轻改)共用;字段列表因模板不同而区分。
*/
/** 轻改驻店日报(upgradeStaffDaily)与上一位比对的品牌字段 */
const UPGRADE_STAFF_DAILY_FIELD_KEYS = [
'deliveryCount',
'notDeliveryCount',
'equityToShopCount',
'waitInviteCount',
'customerLossCount',
'issueCouponCount'
]
/** 权益日报(staffDaily)与上一位比对的品牌字段 */
const STAFF_DAILY_FIELD_KEYS = [
'deliveryCount',
'notDeliveryCount',
'extendedWarrantyToShopCount',
'realEquityToShopCount',
'waitInviteCount',
'customerLossCount'
]
/** @deprecated 使用 UPGRADE_STAFF_DAILY_FIELD_KEYS */
const BRAND_INCONSISTENCY_FIELD_KEYS = UPGRADE_STAFF_DAILY_FIELD_KEYS
/**
* @param {*} value
* @returns {boolean}
*/
function isNotEmpty(value) {
return (
value !== null &&
value !== undefined &&
value !== '' &&
!(Array.isArray(value) && value.length === 0)
)
}
/**
* 当前用户是否需做「与上一位驻店人员」一致性校验
* @param {object} orderObj
* @param {object} userInfo
* @param {(userInfo: object) => boolean} [canSkipValidation]
* @returns {boolean}
*/
function shouldValidateInconsistency(orderObj, userInfo, canSkipValidation) {
return (
!!orderObj?.lastStaffUuid &&
userInfo?.uuid != orderObj.lastStaffUuid &&
!canSkipValidation?.(userInfo)
)
}
/**
* 今日驻店人数是否与上一位驻店人员提交不一致
* @param {object} orderObj
* @param {object} userInfo
* @param {(userInfo: object) => boolean} [canSkipValidation]
* @returns {boolean}
*/
function isStaffCountInconsistent(orderObj, userInfo, canSkipValidation) {
if (!shouldValidateInconsistency(orderObj, userInfo, canSkipValidation)) {
return false
}
return (
isNotEmpty(orderObj.recordStaffCount) &&
isNotEmpty(orderObj.staffCount) &&
orderObj.recordStaffCount != orderObj.staffCount
)
}
/**
* @param {Array<{ key?: string, label?: string }>} fieldMeta
* @returns {Record<string, string>}
*/
function getFieldLabelMap(fieldMeta) {
const map = {}
;(fieldMeta || []).forEach(item => {
if (item?.key && item?.label) {
map[item.key] = item.label
}
})
return map
}
/**
* 查找第一个与上一位驻店人员不一致的品牌字段
* @param {object} params
* @param {Array<object>} params.carBandList
* @param {object} params.orderObj
* @param {object} params.userInfo
* @param {Array<{ key?: string, label?: string }>} params.fieldMeta
* @param {(userInfo: object) => boolean} [params.canSkipValidation]
* @param {string[]} [params.fieldKeys]
* @returns {{ index: number, name: string, label: string } | null}
*/
function findInconsistentBrandField({
carBandList,
orderObj,
userInfo,
fieldMeta,
canSkipValidation,
fieldKeys = UPGRADE_STAFF_DAILY_FIELD_KEYS
}) {
if (!shouldValidateInconsistency(orderObj, userInfo, canSkipValidation)) {
return null
}
const labelMap = getFieldLabelMap(fieldMeta)
for (let index = 0; index < (carBandList || []).length; index++) {
const item = carBandList[index]
for (const name of fieldKeys) {
const checkName = `${name}Record`
const recordValue = item[checkName]
const filledValue = item[name]
if (
isNotEmpty(filledValue) &&
isNotEmpty(recordValue) &&
recordValue != filledValue
) {
return {
index,
name,
label: labelMap[name] || name
}
}
}
}
return null
}
/**
* 是否已有 blur 阶段标记的预警错误(用户忽略预警再次点提交时拦截)
* @param {object} params
* @param {object} params.orderObj
* @param {Array<object>} params.carBandList
* @returns {boolean}
*/
function hasExistingInputErrors({ orderObj, carBandList }) {
if (orderObj?.staffCountError) {
return true
}
for (const item of carBandList || []) {
for (const key of Object.keys(item)) {
if (key.endsWith('inputError') && item[key]) {
return true
}
}
}
return false
}
/**
* @param {object} orderObj
* @returns {string}
*/
function buildStaffCountInconsistencyMessage(orderObj) {
return `今日驻店人数与 ${orderObj.lastStaffName} 提交不一致,再次确认!不一致提交日报时,今日驻店人数将被清空。`
}
/**
* @param {object} params
* @param {string} params.label
* @param {object} params.orderObj
* @returns {string}
*/
function buildBrandFieldInconsistencyMessage({ label, orderObj }) {
return `${label}与 ${orderObj.lastStaffName} 提交不一致,再次确认!不一致提交日报时,${label}将被清空。`
}
/**
* 将 dailyReportCheck 失败项转为按品牌分行的警示文案(PC 端自定义弹层展示)
* @param {Array<{ isCheckPass?: boolean, brandName?: string, differenceValue?: * }>} failedItems
* @returns {string[]}
*/
function buildBrandCheckWarningLines(failedItems) {
return (failedItems || [])
.filter(item => !item.isCheckPass)
.map(
item =>
`【${item.brandName}】店端总未触客数+门店售前触客数与当月实际交车数不符,差异值${item.differenceValue},请相关驻店销售对齐核销再次提交`
)
}
module.exports = {
BRAND_INCONSISTENCY_FIELD_KEYS,
UPGRADE_STAFF_DAILY_FIELD_KEYS,
STAFF_DAILY_FIELD_KEYS,
isStaffCountInconsistent,
findInconsistentBrandField,
hasExistingInputErrors,
buildStaffCountInconsistencyMessage,
buildBrandFieldInconsistencyMessage,
buildBrandCheckWarningLines
}
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const {
isStaffCountInconsistent,
findInconsistentBrandField,
hasExistingInputErrors,
buildBrandCheckWarningLines
} = require('../services/dailyReportInconsistency.helpers.js')
const userInfo = { uuid: 'user-b' }
const orderObjBase = {
lastStaffUuid: 'user-a',
lastStaffName: '张三',
recordStaffCount: 3
}
const fieldMeta = [{ key: 'deliveryCount', label: '店端实际交车数' }]
describe('dailyReportInconsistency.helpers', () => {
it('isStaffCountInconsistent returns true when staff count differs', () => {
assert.equal(
isStaffCountInconsistent(
{ ...orderObjBase, staffCount: 5 },
userInfo,
() => false
),
true
)
})
it('isStaffCountInconsistent returns false when can skip validation', () => {
assert.equal(
isStaffCountInconsistent(
{ ...orderObjBase, staffCount: 5 },
userInfo,
() => true
),
false
)
})
it('findInconsistentBrandField finds first mismatched field', () => {
const result = findInconsistentBrandField({
carBandList: [{ deliveryCount: 2, deliveryCountRecord: 1 }],
orderObj: orderObjBase,
userInfo,
fieldMeta,
canSkipValidation: () => false
})
assert.deepEqual(result, {
index: 0,
name: 'deliveryCount',
label: '店端实际交车数'
})
})
it('hasExistingInputErrors detects staffCountError and inputError flags', () => {
assert.equal(
hasExistingInputErrors({
orderObj: { staffCountError: true },
carBandList: []
}),
true
)
assert.equal(
hasExistingInputErrors({
orderObj: {},
carBandList: [{ deliveryCountinputError: true }]
}),
true
)
assert.equal(
hasExistingInputErrors({
orderObj: {},
carBandList: [{ deliveryCount: 1 }]
}),
false
)
})
it('buildBrandCheckWarningLines returns one line per failed brand', () => {
const lines = buildBrandCheckWarningLines([
{ isCheckPass: true, brandName: '问界' },
{ isCheckPass: false, brandName: '鸿蒙', differenceValue: 2 }
])
assert.equal(lines.length, 1)
assert.match(lines[0], /【鸿蒙】/)
assert.match(lines[0], /差异值2/)
})
it('findInconsistentBrandField uses staffDaily field keys', () => {
const { STAFF_DAILY_FIELD_KEYS, findInconsistentBrandField } = require(
'../services/dailyReportInconsistency.helpers.js'
)
assert.ok(STAFF_DAILY_FIELD_KEYS.includes('extendedWarrantyToShopCount'))
const result = findInconsistentBrandField({
carBandList: [
{ extendedWarrantyToShopCount: 2, extendedWarrantyToShopCountRecord: 1 }
],
orderObj: orderObjBase,
userInfo,
fieldMeta: [{ key: 'extendedWarrantyToShopCount', label: '延保到店流量' }],
canSkipValidation: () => false,
fieldKeys: STAFF_DAILY_FIELD_KEYS
})
assert.equal(result?.name, 'extendedWarrantyToShopCount')
})
})
import { IMG_URL } from '../../../utils/imageBase.js'
import { IMG_URL } from '../../../utils/imageBase.js'
// tabWorkOrder/pages/staffDaily/staffDaily.js
var util = require('~/utils/timeFormat/time-utils.js')
import dayjs from 'dayjs'
......@@ -12,6 +12,14 @@ import api from '../../api'
import apiCon from '~/api/api'
import { getYQInfo } from '~/store/index'
import comApi from '~/api/api'
const {
isStaffCountInconsistent,
findInconsistentBrandField,
hasExistingInputErrors,
buildStaffCountInconsistencyMessage,
buildBrandFieldInconsistencyMessage,
buildBrandCheckWarningLines
} = require('./services/dailyReportInconsistency.helpers.js')
let toastList = {
deliveryCount: '新车交付数不能为空',
// filmToShopCount: '到店流量数(太阳膜)不能为空',
......@@ -31,7 +39,7 @@ Page({
styleIsolation: 'apply-shared'
},
data: {
data: {
IMG_URL,
tabList: ['全部', '待跟进', '已升级', '战败'],
tabIndex: 0,
......@@ -277,7 +285,12 @@ Page({
// disabled: true,
// inputPlaceholder: '自动填入系统数据'
// }
]
],
alertModal: {
show: false,
title: '',
lines: []
}
},
tabClick(e) {
let { index } = e.detail
......@@ -609,6 +622,11 @@ Page({
wx.$util.showToast('必填不能为空')
return false //必填校验没过
}
wx.hideKeyboard?.()
if (!wx.$hasPermission?.canSkipValidation?.(userInfo)) {
const blocked = await this.blockSubmitIfInconsistent()
if (blocked) return false
}
orderObj.isAdmin = role == 'super' ? true : false
orderObj.oprBy = orderObj.staffUuid
orderObj.sceneType = 1
......@@ -699,25 +717,131 @@ Page({
this.getStaffReport()
this.getStaffDailyReportDetailWeeklyList()
},
/**
* 展示单行不一致预警,返回 Promise 在用户确认后 resolve
* @param {object} params
* @param {string} params.title
* @param {string} params.content
* @param {Function} [params.onConfirm]
* @returns {Promise<void>}
*/
showInconsistencyModal({ title, content, onConfirm }) {
return new Promise(resolve => {
wx.showModal({
title,
content,
showCancel: false,
confirmText: '知道了',
confirmColor: '#347BFF',
success: () => {
onConfirm?.()
resolve()
}
})
})
},
/**
* 展示多行警示预警(PC 端按品牌换行)
* @param {object} params
* @param {string} params.title
* @param {string[]} params.lines
* @returns {Promise<boolean>}
*/
showAlertModal({ title, lines }) {
return new Promise(resolve => {
this._alertModalResolve = resolve
this.setData({
alertModal: {
show: true,
title: title || '警示预警',
lines: lines || []
}
})
})
},
/** 关闭多行警示预警弹层(components/modal didClickBtn) */
onAlertModalConfirm() {
this.setData({ 'alertModal.show': false })
const resolve = this._alertModalResolve
this._alertModalResolve = null
resolve?.(true)
},
/**
* 提交前拦截与上一位驻店人员填写不一致(避免 PC blur+click 竞态导致误提交)
* @returns {Promise<boolean>} true 表示应阻止提交
*/
async blockSubmitIfInconsistent() {
const {
orderObj,
userInfo,
carBandList,
hwObjArray,
hwOhterObjArray,
otherObjArray
} = this.data
const canSkipValidation = userInfo =>
wx.$hasPermission?.canSkipValidation?.(userInfo)
if (hasExistingInputErrors({ orderObj, carBandList })) {
return true
}
const fieldMeta = [...hwObjArray, ...hwOhterObjArray, ...otherObjArray]
if (isStaffCountInconsistent(orderObj, userInfo, canSkipValidation)) {
await this.showInconsistencyModal({
title: '预警提示',
content: buildStaffCountInconsistencyMessage(orderObj),
onConfirm: () => {
this.setData({ 'orderObj.staffCountError': true })
}
})
return true
}
const inconsistent = findInconsistentBrandField({
carBandList,
orderObj,
userInfo,
fieldMeta,
canSkipValidation
})
if (inconsistent) {
await this.showInconsistencyModal({
title: '预警提示',
content: buildBrandFieldInconsistencyMessage({
label: inconsistent.label,
orderObj
}),
onConfirm: () => {
this.setData({
tabIndex: inconsistent.index,
[`carBandList[${inconsistent.index}].${inconsistent.name}inputError`]: true
})
}
})
return true
}
return false
},
checkValueStaffCount(e) {
let that = this
let { orderObj, userInfo } = this.data
if (
this.isNotEmpty(orderObj.recordStaffCount) &&
this.isNotEmpty(orderObj.staffCount) &&
orderObj.recordStaffCount != orderObj.staffCount &&
orderObj.lastStaffUuid &&
userInfo.uuid != orderObj.lastStaffUuid &&
!wx.$hasPermission?.canSkipValidation?.(userInfo) // 超管和区域运维跳过校验提示
// true
) {
const canSkipValidation = userInfo =>
wx.$hasPermission?.canSkipValidation?.(userInfo)
if (isStaffCountInconsistent(orderObj, userInfo, canSkipValidation)) {
wx.showModal({
title: '预警提示',
content: `今日驻店人数与 ${orderObj.lastStaffName} 提交不一致,再次确认!不一致提交日报时,今日驻店人数将被清空。`,
content: buildStaffCountInconsistencyMessage(orderObj),
showCancel: false,
confirmText: '知道了',
confirmColor: '#347BFF',
success(res) {
success() {
that.setData({
[`orderObj.staffCountError`]: true
})
......@@ -741,20 +865,12 @@ Page({
return false
}
// 根据车型做对应的文字处理
let context = ''
let showModal = false
const warningLines = buildBrandCheckWarningLines(data)
data.forEach(item => {
if (!item.isCheckPass) {
showModal = true
carBandList.forEach(el => {
if (el.brandType == item.brandType) {
let bandType = {
0: '问界',
1: '鸿蒙'
}
context += `【${item.brandName}】 店端总未触客数+门店售前触客数与当月实际交车数不符,差异值${item.differenceValue},请相关驻店销售对齐核销再次提交\t\n`
el.deliveryCountinputError = true
el.equityToShopCountinputError = true
el.notDeliveryCountinputError = true
......@@ -767,23 +883,13 @@ Page({
carBandList
})
if (showModal) {
// 将 showModal 转换为 Promise,以便等待用户关闭模态框
return new Promise(resolve => {
wx.showModal({
title: '警示预警',
content: context,
showCancel: false,
confirmText: '知道了',
confirmColor: '#347BFF',
success: () => {
resolve(true)
}
})
})
} else {
return false
if (warningLines.length) {
return this.showAlertModal({
title: '警示预警',
lines: warningLines
}).then(() => true)
}
return false
} catch (error) {
console.error('dailyReportCheck error:', error)
return false
......
......@@ -675,4 +675,22 @@ page .isFullSucreen {
font-size: 28rpx;
}
}
}
.daily-alert-body {
max-height: 480rpx;
padding: 0 48rpx 24rpx;
box-sizing: border-box;
}
.daily-alert-line {
font-size: 28rpx;
line-height: 44rpx;
color: #292d33;
margin-bottom: 24rpx;
word-break: break-all;
}
.daily-alert-line:last-child {
margin-bottom: 0;
}
\ No newline at end of file
......@@ -227,11 +227,11 @@
<block wx:if="{{ filter.filterDisabled(role, weeklyList, orderObj.reportDate, false, orderObj.isDateWithin7Days) && role != 'other' }}">
<view class="confirm text-center" wx:if="{{ !isEditReport }}" bindtap="editReport">编辑</view>
<block wx:else>
<view class="confirm text-center" bindtap="submit">保存</view>
<view class="confirm text-center" catchtap="submit">保存</view>
<view class="save text-center" bindtap="cancelReport">取消</view>
</block>
</block>
<view wx:else class="confirm text-center" bindtap="submit">提交</view>
<view wx:else class="confirm text-center" catchtap="submit">提交</view>
</view>
</view>
</view>
......@@ -254,4 +254,23 @@
bindconfirm="changePromble"
bindcancel="closeSlectItemPopup"
bindclick="click"
/>
\ No newline at end of file
/>
<modal
id="dailyAlertModal"
show="{{ alertModal.show }}"
custom="{{ true }}"
tabTitleShow="{{ false }}"
title="{{ alertModal.title }}"
btns="{{ ['知道了'] }}"
btnBorder="{{ true }}"
maskEnable="{{ false }}"
binddidClickBtn="onAlertModalConfirm"
>
<scroll-view scroll-y class="daily-alert-body">
<view
class="daily-alert-line"
wx:for="{{ alertModal.lines }}"
wx:key="index"
>{{ item }}</view>
</scroll-view>
</modal>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!