Commit c63fd77d by 李伟康

fix(dailyReport): 修复日报保存和提交功能

- 修改API方法名称从draft.save到save和dynamic.save到data.push
- 添加submissionStatus状态管理和传递
- 重构提交流程先保存再推送数据
- 更新组件间数据传递和状态同步逻辑
- 调整页面组件参数传递和按钮显示控制
- 修复数据解析和状态更新相关问题
1 parent 1c03567a
......@@ -79,21 +79,21 @@ const getDiscussionStaffList = async (data = {}) => {
})
}
/**
日报草稿数据保存
日报保存
*/
const saveDraft = async (data = {}) => {
return http.post({
method: 'dj.api.smartcarlife.dailyReport.dynamic.draft.save',
method: 'dj.api.smartcarlife.dailyReport.dynamic.save',
projectName: 'boutique',
...data
})
}
/**
日报数据提交
日报数据推送
*/
const submitReport = async (data = {}) => {
return http.post({
method: 'dj.api.smartcarlife.dailyReport.dynamic.save',
method: 'dj.api.smartcarlife.dailyReport.dynamic.data.push',
projectName: 'boutique',
...data
})
......
......@@ -44,7 +44,7 @@
<view class="footer">
<Footer>
<view class="btn default-btn" @click="saveBtn = true" v-if="!saveBtn">编辑</view>
<view class="btn" @click="$emit('submitReport', list)" v-else>保存</view>
<view class="btn" @click="$emit('saveReport', list)" v-else>保存</view>
</Footer>
</view>
</template>
......
......@@ -41,7 +41,7 @@
<view class="footer">
<Footer>
<view class="btn default-btn" @click="saveBtn = true" v-if="!saveBtn">编辑</view>
<view class="btn" @click="$emit('submitReport', list)" v-else>保存</view>
<view class="btn" @click="$emit('saveReport', list)" v-else>保存</view>
</Footer>
</view>
</template>
......
......@@ -47,11 +47,11 @@
</view>
<view class="footer">
<Footer>
<view :class="['btn default-btn', { w50: !saveBtn }]" @click="$emit('showNegotiationList')">查看洽谈明细表汇总</view>
<view :class="['btn default-btn',{w50:!saveBtn}]" @click="saveBtn = true" v-if="!saveBtn">编辑</view>
<view :class="['btn default-btn', { w50: !saveBtn || !showPushBtn }]" @click="$emit('showNegotiationList')">查看洽谈明细表汇总</view>
<view :class="['btn default-btn',{w50:!saveBtn || !showPushBtn}]" @click="saveBtn = true" v-if="!saveBtn">编辑</view>
<template v-else>
<view class="btn default-btn" @click="$emit('saveReport', list)">保存</view>
<view class="btn" @click="$emit('submitReport', list)">上报数据</view>
<view :class="['btn default-btn',{w50:!showPushBtn}]" @click="$emit('saveReport', list)">保存</view>
<view class="btn" @click="$emit('submitReport', list )" v-if="showPushBtn">上报数据</view>
</template>
</Footer>
</view>
......@@ -82,7 +82,9 @@ export default {
default: () => []
},
reportDate: String,
ReportStatus: null
ReportStatus: null,
isToday:Boolean,
SubmissionStatus:null
},
data() {
return {
......@@ -91,6 +93,11 @@ export default {
saveBtn: true
}
},
computed: {
showPushBtn(){
return this.SubmissionStatus != 1 && this.isToday
}
},
watch: {
templateData: {
handler(val) {
......
......@@ -7,7 +7,7 @@
<template v-else>
<Edit :templateData="templateData" @showNegotiationList="changeComponent(true)" @saveReport="saveReport"
@submitReport="submitReport" :reportDate="currentDate" :ReportStatus="ReportStatus"
@getSaveBtnStatus="saveBtnStatus = $event" />
@getSaveBtnStatus="saveBtnStatus = $event" :SubmissionStatus="SubmissionStatus" :isToday="isToday" />
</template>
</view>
......
......@@ -25,7 +25,8 @@
<view class="detail-right">
<component :ref="`ref-${componentName}`" :is="componentName" :templateData="templateData"
:currentDate="currentDate" @changeComponent="changeComponent" @submitReport="submitReport"
@saveReportStatus="saveReportStatus" :ReportStatus="reportStatus" @maxLengthError="maxLengthError" />
@saveReportStatus="saveReportStatus" :ReportStatus="reportStatus" @maxLengthError="maxLengthError"
:SubmissionStatus="submissionStatus" />
</view>
</view>
<NoticePopup ref="notice" :title="noticeObj.title" :text="noticeObj.text" :type="noticeObj.type || 'success'"
......@@ -56,7 +57,8 @@ export default {
userInfo: this.userInfo,
templateType: () => this.templateType,
dailyReportRecordId: () => this.dailyReportRecordId,
reportStatus: () => this.reportStatus
reportStatus: () => this.reportStatus,
submissionStatus: () => this.submissionStatus
}
},
data() {
......@@ -74,7 +76,8 @@ export default {
assignTitle: '',
assignIcon: '',
dailyReportRecordId: '',
reportStatus: ''
reportStatus: '',
submissionStatus: ''
}
},
onBackPress(options) {
......@@ -283,8 +286,8 @@ export default {
// if (templateType != 1) {
// if (!componentRef.isToday) return false
// } else {
let lastDay = dayjs().subtract(30, 'day')
if (!lastDay.isBefore(dayjs(currentDate), 'day')) return false
let lastDay = dayjs().subtract(30, 'day')
if (!lastDay.isBefore(dayjs(currentDate), 'day')) return false
// }
return templateData.length ? componentRef.saveBtnStatus : false
......@@ -330,7 +333,8 @@ export default {
this.noticeObj = noticeObj
this.$refs.notice.open()
},
async getReportDetail() {
async getReportDetail(getDailyReportRecordId = false) {
console.log(getDailyReportRecordId)
this.reportStatus = ''
this.dailyReportRecordId = ''
uni.showLoading({ title: '加载中...', mask: true })
......@@ -349,37 +353,43 @@ export default {
if (data) {
uni.hideLoading()
this.dailyReportRecordId = data.id
this.reportStatus = data.reportStatus
let templateData = JSON.parse(data.jsonContent || '[]')
templateData.forEach(e => {
if (e.childrenValue && e.childrenValue.length > 0) {
const children = e.childrenValue.map(c => {
// 每次循环创建新的深拷贝,避免引用共享问题
const originChildren = utils.deepClone(e.origin_children)
originChildren.forEach(item => {
const key = item.key
const val = c[e.key]?.[key]
if (getDailyReportRecordId) return Promise.resolve(data.id)
else {
this.reportStatus = data.reportStatus
let templateData = JSON.parse(data.jsonContent || '[]')
templateData.forEach(e => {
if (e.childrenValue && e.childrenValue.length > 0) {
const children = e.childrenValue.map(c => {
// 每次循环创建新的深拷贝,避免引用共享问题
const originChildren = utils.deepClone(e.origin_children)
originChildren.forEach(item => {
const key = item.key
const val = c[e.key]?.[key]
if (['string', 'number'].includes(typeof val)) {
item.value = val
} else if (val) {
item.value = val.text
item[key] = val.value
}
if (['string', 'number'].includes(typeof val)) {
item.value = val
} else if (val) {
item.value = val.text
item[key] = val.value
}
})
return originChildren
})
return originChildren
})
e.children = children
} else {
if (!e.children) e.children = []
}
})
this.templateData = templateData
e.children = children
} else {
if (!e.children) e.children = []
}
})
this.templateData = templateData
this.submissionStatus = data.submissionStatus
}
} else {
// if (this.templateType == 1) {
let lastDay = dayjs().subtract(30, 'day')
if (lastDay.isBefore(dayjs(currentDate), 'day')) this.getDailyTemplate()
else uni.hideLoading()
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()
......@@ -438,12 +448,17 @@ export default {
}
this.$refs.notice.close()
uni.showLoading({ title: '提交中...', mask: true })
const data = await uni.$api.dailyTemplateApi.submitReport(reportParams)
uni.hideLoading()
if (data) {
uni.showToast({ title: '操作成功', icon: 'success', mask: true })
this.saveReportStatus(data)
const saveData = await uni.$api.dailyTemplateApi.saveDraft(reportParams)
if (saveData) {
const dailyReportRecordId = await this.getReportDetail(true),
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 })
} else uni.showToast({ title: '操作失败', icon: 'none', mask: true })
},
saveReportStatus(data) {
if (data)
......
......@@ -17,7 +17,8 @@ export default {
type: Array,
default: () => []
},
ReportStatus: null
ReportStatus: null,
SubmissionStatus: null
},
computed: {
/**可编辑日期 */
......@@ -31,7 +32,7 @@ export default {
},
reportParams() {
let { shopMerchantId, shopMerchantName, uuid, name, merchantId, merchantName } = this.userInfo,
{ currentDate, templateType, dailyReportRecordId, sceneType } = this,
{ currentDate, templateType, dailyReportRecordId, sceneType, SubmissionStatus } = this,
params = {
merchantId: shopMerchantId,
merchantName: shopMerchantName,
......@@ -42,8 +43,11 @@ export default {
templateType: templateType(),
yqMerchantId: merchantId,
yqMerchantName: merchantName,
sceneType
sceneType,
submissionDate: dayjs().format('YYYY-MM-DD HH:mm:ss')
}
if (!SubmissionStatus) params.submissionStatus = 2
else params.submissionStatus = SubmissionStatus
if (dailyReportRecordId()) params.dailyReportRecordId = dailyReportRecordId()
return params
}
......@@ -76,52 +80,52 @@ export default {
console.log(error)
}
},
async saveReport(res) {
try {
uni.showLoading({ title: '提交中...', mask: true })
let { reportParams } = this,
list = utils.deepClone(res)
let jsonContent = JSON.stringify(list)
let requestJson = buildAppNormalizedListsFromJsonContent(jsonContent)
list.map(e => {
let childrenValue = []
if (e.children && e.children.length)
e.children.map((c, cIndex) => {
let isArray = Array.isArray(c)
if (isArray) {
childrenValue.push({
[e.key]: {}
})
c.map(i => {
let value = i.value
if (i[i.key])
childrenValue[cIndex][e.key][i.key] = {
text: value,
value: i[i.key]
}
else childrenValue[cIndex][e.key][i.key] = value
})
}
})
e.childrenValue = childrenValue
if (e.type == 'subform') delete e.children
})
reportParams.jsonContent = JSON.stringify(list)
reportParams.requestJson = JSON.stringify(requestJson)
console.log('保存草稿', reportParams)
const data = await uni.$api.dailyTemplateApi.saveDraft(reportParams)
uni.hideLoading()
if (data) {
uni.showToast({ title: '操作成功', icon: 'success', mask: true })
this.$emit('saveReportStatus', data)
} else uni.showToast({ title: '操作失败', icon: 'none', mask: true })
console.log(data)
} catch (error) {
uni.hideLoading()
uni.showToast({ title: error, icon: 'none', mask: true })
}
},
async submitReport(res) {
// async saveReport(res) {
// try {
// uni.showLoading({ title: '提交中...', mask: true })
// let { reportParams } = this,
// list = utils.deepClone(res)
// let jsonContent = JSON.stringify(list)
// let requestJson = buildAppNormalizedListsFromJsonContent(jsonContent)
// list.map(e => {
// let childrenValue = []
// if (e.children && e.children.length)
// e.children.map((c, cIndex) => {
// let isArray = Array.isArray(c)
// if (isArray) {
// childrenValue.push({
// [e.key]: {}
// })
// c.map(i => {
// let value = i.value
// if (i[i.key])
// childrenValue[cIndex][e.key][i.key] = {
// text: value,
// value: i[i.key]
// }
// else childrenValue[cIndex][e.key][i.key] = value
// })
// }
// })
// e.childrenValue = childrenValue
// if (e.type == 'subform') delete e.children
// })
// reportParams.jsonContent = JSON.stringify(list)
// reportParams.requestJson = JSON.stringify(requestJson)
// console.log('保存草稿', reportParams)
// const data = await uni.$api.dailyTemplateApi.saveDraft(reportParams)
// uni.hideLoading()
// if (data) {
// uni.showToast({ title: '操作成功', icon: 'success', mask: true })
// this.$emit('saveReportStatus', data)
// } else uni.showToast({ title: '操作失败', icon: 'none', mask: true })
// console.log(data)
// } catch (error) {
// uni.hideLoading()
// uni.showToast({ title: error, icon: 'none', mask: true })
// }
// },
async saveReport(res, isPush = false) {
try {
const phoneRegex = /^1[3456789]\d{9}$/
uni.showLoading({ title: '提交中...', mask: true })
......@@ -194,11 +198,24 @@ export default {
reportParams.requestJson = JSON.stringify(requestJson)
console.log('提交日报', reportParams)
uni.hideLoading()
this.$emit('submitReport', reportParams)
if (isPush) return Promise.resolve(reportParams)
const data = await uni.$api.dailyTemplateApi.saveDraft(reportParams)
uni.hideLoading()
if (data) {
uni.showToast({ title: '操作成功', icon: 'success', mask: true })
this.$emit('saveReportStatus', data)
} else uni.showToast({ title: '操作失败', icon: 'none', mask: true })
// if (!isPush) {
// } else this.$emit('submitReport', reportParams)
} catch (error) {
uni.hideLoading()
uni.showToast({ title: error, icon: 'none', mask: true })
}
},
async submitReport(res) {
let reportParams = await this.saveReport(res, true)
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!