Commit 86069986 by 李伟康

refactor(storeDailyReport): 优化日报编辑提交逻辑,新增冲突检查功能

1. 调整Edit组件按钮事件绑定,拆分保存上报逻辑
2. 新增表单重复值校验和上报前的数据冲突处理
3. 重构mixins中的提交保存方法,简化调用流程
4. 新增checkReportDetail事件处理多用户编辑冲突
1 parent 95f7f0f6
......@@ -53,8 +53,8 @@
v-if="!saveBtn">编辑
</view>
<template v-else>
<view :class="['btn default-btn', { w100: !showPushBtn }]" @click="$emit('saveReport', list)">保存</view>
<view class="btn" @click="$emit('submitReport', list)" v-if="showPushBtn">上报数据</view>
<view :class="['btn default-btn', { w100: !showPushBtn }]" @click="save">保存</view>
<view class="btn" @click="$emit('submitReport')" v-if="showPushBtn">上报数据</view>
</template>
</Footer>
</view>
......@@ -256,6 +256,9 @@ export default {
if (this.list[index].value == null || this.list[index].value == '' || this.list[index].value == undefined) {
if (res) this.$set(this.list[index], 'value', res.pendingCount)
}
},
save(){
this.$emit('checkReportDetail', this.list)
}
}
}
......
......@@ -7,7 +7,7 @@
<template v-else>
<Edit :templateData="templateData" @showNegotiationList="changeComponent(true)" @saveReport="saveReport"
@submitReport="submitReport" :reportDate="currentDate" :ReportStatus="ReportStatus"
@getSaveBtnStatus="saveBtnStatus = $event" :SubmissionStatus="SubmissionStatus" :isToday="isToday" />
@getSaveBtnStatus="saveBtnStatus = $event" :SubmissionStatus="SubmissionStatus" :isToday="isToday" @checkReportDetail="$emit('checkReportDetail', $event)" />
</template>
</view>
......
......@@ -104,20 +104,21 @@ export default {
* @param parent 父级数据
*/
open(data, c_index, index, parent) {
let _data = utils.deepClone(data) || {}
const hasCommonElement = (arrA, arrB) => {
arrA = arrA.map(item => String(item))
arrB = arrB.map(item => String(item))
return arrA.some(i => arrB.includes(i))
}
data.forEach(item => {
_data.forEach(item => {
if (item.type == 'select' && !item.optionsKey) {
item.options = item.options.filter(i => i.baseSceneCode && i.baseSceneCode?.length ? hasCommonElement(i.baseSceneCode, this.STORE_BASE_SCENE_CODE) : true)
}
})
data.$sceneCodes = this.STORE_BASE_SCENE_CODE
data.$brandIds = this.CAR_BRAND_ID || []
_data.$sceneCodes = this.STORE_BASE_SCENE_CODE
_data.$brandIds = this.CAR_BRAND_ID || []
this.data = utils.deepClone(data) || {}
this.data = _data || {}
this.c_index = c_index || 0
this.index = index || 0
this.parent = utils.deepClone(parent) || {}
......
......@@ -26,7 +26,8 @@
<component :ref="`ref-${componentName}`" :is="componentName" :templateData="templateData"
:currentDate="currentDate" @changeComponent="changeComponent" @submitReport="submitReport"
@saveReportStatus="saveReportStatus" :ReportStatus="reportStatus" @maxLengthError="maxLengthError"
:SubmissionStatus="submissionStatus" :submissionDate="submissionDate" />
:SubmissionStatus="submissionStatus" :submissionDate="submissionDate"
@checkReportDetail="checkReportDetail" />
</view>
</view>
<NoticePopup ref="notice" :title="noticeObj.title" :text="noticeObj.text" :type="noticeObj.type || 'success'"
......@@ -327,14 +328,38 @@ export default {
this.noticeObj = noticeObj
this.$refs.notice.open()
},
async checkReportDetail(list) {
let flag = this.dailyReportRecordId
if (!flag) flag = await this.getReportDetail(true)
let componentRef = this.$refs[`ref-${this.componentName}`]
if (flag) {
this.openNotice(
{
title: '数据已被他人更新',
text: '在你编辑期间,其他用户已完成保存操作。若直接保存,将覆盖对方的最新修改。',
buttons: {
cancelText: '取消',
confirmText: '直接保存'
}
},
false,
_ => {
componentRef.saveReport(list)
}
)
} else componentRef.saveReport(list)
},
async getReportDetail(getDailyReportRecordId = false) {
this.reportStatus = ''
this.dailyReportRecordId = ''
this.submissionDate = ''
console.log(getDailyReportRecordId)
if (!getDailyReportRecordId) {
this.reportStatus = ''
this.dailyReportRecordId = ''
this.submissionDate = ''
}
uni.showLoading({ title: '加载中...', mask: true })
try {
const { uuid, shopMerchantId } = this.userInfo,
nowDate = dayjs().format('YYYY-MM-DD'),
{ templateType, currentDate, SCENE_TYPE: sceneType } = this,
data = await uni.$api.dailyTemplateApi.getReportDetail({
merchantId: shopMerchantId,
......@@ -346,9 +371,9 @@ export default {
if (data) {
uni.hideLoading()
this.dailyReportRecordId = data.id
if (getDailyReportRecordId) return Promise.resolve(data.id)
else {
this.dailyReportRecordId = data.id
this.reportStatus = data.reportStatus
let templateData = JSON.parse(data.jsonContent || '[]')
templateData.forEach(e => {
......@@ -379,15 +404,10 @@ export default {
this.submissionDate = data.submissionDate
}
} else {
// if (this.templateType == 1) {
if (getDailyReportRecordId) return Promise.resolve('')
let lastDay = dayjs().subtract(30, 'day')
if (lastDay.isBefore(dayjs(currentDate), 'day')) this.getDailyTemplate()
else uni.hideLoading()
// } else {
// if (nowDate == currentDate) this.getDailyTemplate()
// else uni.hideLoading()
// }
}
} catch (error) {
uni.showToast({ title: error, icon: 'none', mask: true })
......@@ -411,12 +431,12 @@ export default {
this.assignTitle = val.title
this.assignIcon = val.icon
},
async submitReport(reportParams, skip) {
async submitReport(skip) {
if (this.templateType == 2 && !skip) {
uni.hideLoading()
this.noticeObj = {
title: '确定上报数据?',
text: '请确认驻店人员在当前场景下已完成所有个人的驻店日报及洽谈明细。门店日报上报后,将立即发送相关门店经营统计数据到指定消息群。',
text: '请确认已记录今日所有非成交客户信息,并确保成交客户已完成录单。门店日报上报后,将立即发送相关门店经营统计数据到指定消息群。',
type: 'warning',
buttons: [
{
......@@ -431,7 +451,7 @@ export default {
text: '确定',
type: 'primary',
callback: _ => {
this.submitReport(reportParams, true)
this.submitReport(true)
}
}
]
......@@ -441,15 +461,12 @@ export default {
}
this.$refs.notice.close()
uni.showLoading({ title: '提交中...', mask: true })
const saveData = await uni.$api.dailyTemplateApi.saveDraft(reportParams)
if (saveData) {
const { dailyReportRecordId } = this,
data = await uni.$api.dailyTemplateApi.submitReport({ dailyReportRecordId })
uni.hideLoading()
if (data) {
uni.showToast({ title: '操作成功', icon: 'success', mask: true })
this.saveReportStatus(data)
} else uni.showToast({ title: '操作失败', icon: 'none', mask: true })
const { dailyReportRecordId } = this,
data = await uni.$api.dailyTemplateApi.submitReport({ dailyReportRecordId })
uni.hideLoading()
if (data) {
uni.showToast({ title: '操作成功', icon: 'success', mask: true })
this.saveReportStatus(data)
} else uni.showToast({ title: '操作失败', icon: 'none', mask: true })
},
......
......@@ -83,7 +83,7 @@ export default {
console.log(error)
}
},
async saveReport(res, isPush = false) {
async saveReport(res) {
try {
const phoneRegex = /^1[3456789]\d{9}$/
uni.showLoading({ title: '提交中...', mask: true })
......@@ -93,7 +93,27 @@ export default {
let requestJson = buildAppNormalizedListsFromJsonContent(jsonContent)
list.map(e => {
let childrenValue = []
if (e.children && e.children.length)
if (e.children && e.children.length) {
if (e.validateDuplicates && e.validateDuplicates.length) {
e.validateDuplicates.forEach(key => {
const seen = new Map()
const duplicateRows = []
let label = ''
e.children.forEach((row, rowIndex) => {
const field = row.find(j => j.key === key)
if (field && field.label) label = field.label
if (field && field.value) {
if (seen.has(field.value)) {
duplicateRows.push(rowIndex + 1)
} else {
seen.set(field.value, true)
}
}
})
if (duplicateRows.length) throw `第${duplicateRows.join(',')}行${label}重复`
})
}
e.children.map((c, cIndex) => {
let isArray = Array.isArray(c)
if (isArray) {
......@@ -129,6 +149,7 @@ export default {
}
}
})
}
e.childrenValue = childrenValue
if (e.show && e.required && e.type != 'subform') {
if (e.value == null || e.value == undefined || e.value === '') throw `${e.label}不能为空`
......@@ -157,7 +178,6 @@ export default {
reportParams.requestJson = JSON.stringify(requestJson)
console.log('提交日报', reportParams)
uni.hideLoading()
if (isPush) return Promise.resolve(reportParams)
const data = await uni.$api.dailyTemplateApi.saveDraft(reportParams)
uni.hideLoading()
if (data) {
......@@ -170,9 +190,8 @@ export default {
uni.showToast({ title: error, icon: 'none', mask: true })
}
},
async submitReport(res) {
let reportParams = await this.saveReport(res, true)
this.$emit('submitReport', reportParams)
async submitReport() {
this.$emit('submitReport')
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!