Commit 86069986 by 李伟康

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

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