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 = {}) => { ...@@ -79,21 +79,21 @@ const getDiscussionStaffList = async (data = {}) => {
}) })
} }
/** /**
日报草稿数据保存 日报保存
*/ */
const saveDraft = async (data = {}) => { const saveDraft = async (data = {}) => {
return http.post({ return http.post({
method: 'dj.api.smartcarlife.dailyReport.dynamic.draft.save', method: 'dj.api.smartcarlife.dailyReport.dynamic.save',
projectName: 'boutique', projectName: 'boutique',
...data ...data
}) })
} }
/** /**
日报数据提交 日报数据推送
*/ */
const submitReport = async (data = {}) => { const submitReport = async (data = {}) => {
return http.post({ return http.post({
method: 'dj.api.smartcarlife.dailyReport.dynamic.save', method: 'dj.api.smartcarlife.dailyReport.dynamic.data.push',
projectName: 'boutique', projectName: 'boutique',
...data ...data
}) })
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
<view class="footer"> <view class="footer">
<Footer> <Footer>
<view class="btn default-btn" @click="saveBtn = true" v-if="!saveBtn">编辑</view> <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> </Footer>
</view> </view>
</template> </template>
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
<view class="footer"> <view class="footer">
<Footer> <Footer>
<view class="btn default-btn" @click="saveBtn = true" v-if="!saveBtn">编辑</view> <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> </Footer>
</view> </view>
</template> </template>
......
...@@ -47,11 +47,11 @@ ...@@ -47,11 +47,11 @@
</view> </view>
<view class="footer"> <view class="footer">
<Footer> <Footer>
<view :class="['btn default-btn', { w50: !saveBtn }]" @click="$emit('showNegotiationList')">查看洽谈明细表汇总</view> <view :class="['btn default-btn', { w50: !saveBtn || !showPushBtn }]" @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="saveBtn = true" v-if="!saveBtn">编辑</view>
<template v-else> <template v-else>
<view class="btn default-btn" @click="$emit('saveReport', list)">保存</view> <view :class="['btn default-btn',{w50:!showPushBtn}]" @click="$emit('saveReport', list)">保存</view>
<view class="btn" @click="$emit('submitReport', list)">上报数据</view> <view class="btn" @click="$emit('submitReport', list )" v-if="showPushBtn">上报数据</view>
</template> </template>
</Footer> </Footer>
</view> </view>
...@@ -82,7 +82,9 @@ export default { ...@@ -82,7 +82,9 @@ export default {
default: () => [] default: () => []
}, },
reportDate: String, reportDate: String,
ReportStatus: null ReportStatus: null,
isToday:Boolean,
SubmissionStatus:null
}, },
data() { data() {
return { return {
...@@ -91,6 +93,11 @@ export default { ...@@ -91,6 +93,11 @@ export default {
saveBtn: true saveBtn: true
} }
}, },
computed: {
showPushBtn(){
return this.SubmissionStatus != 1 && this.isToday
}
},
watch: { watch: {
templateData: { templateData: {
handler(val) { handler(val) {
......
...@@ -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" /> @getSaveBtnStatus="saveBtnStatus = $event" :SubmissionStatus="SubmissionStatus" :isToday="isToday" />
</template> </template>
</view> </view>
......
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
<view class="detail-right"> <view class="detail-right">
<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" />
</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'"
...@@ -56,7 +57,8 @@ export default { ...@@ -56,7 +57,8 @@ export default {
userInfo: this.userInfo, userInfo: this.userInfo,
templateType: () => this.templateType, templateType: () => this.templateType,
dailyReportRecordId: () => this.dailyReportRecordId, dailyReportRecordId: () => this.dailyReportRecordId,
reportStatus: () => this.reportStatus reportStatus: () => this.reportStatus,
submissionStatus: () => this.submissionStatus
} }
}, },
data() { data() {
...@@ -74,7 +76,8 @@ export default { ...@@ -74,7 +76,8 @@ export default {
assignTitle: '', assignTitle: '',
assignIcon: '', assignIcon: '',
dailyReportRecordId: '', dailyReportRecordId: '',
reportStatus: '' reportStatus: '',
submissionStatus: ''
} }
}, },
onBackPress(options) { onBackPress(options) {
...@@ -330,7 +333,8 @@ export default { ...@@ -330,7 +333,8 @@ export default {
this.noticeObj = noticeObj this.noticeObj = noticeObj
this.$refs.notice.open() this.$refs.notice.open()
}, },
async getReportDetail() { async getReportDetail(getDailyReportRecordId = false) {
console.log(getDailyReportRecordId)
this.reportStatus = '' this.reportStatus = ''
this.dailyReportRecordId = '' this.dailyReportRecordId = ''
uni.showLoading({ title: '加载中...', mask: true }) uni.showLoading({ title: '加载中...', mask: true })
...@@ -349,6 +353,8 @@ export default { ...@@ -349,6 +353,8 @@ export default {
if (data) { if (data) {
uni.hideLoading() uni.hideLoading()
this.dailyReportRecordId = data.id this.dailyReportRecordId = data.id
if (getDailyReportRecordId) return Promise.resolve(data.id)
else {
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 => {
...@@ -375,6 +381,10 @@ export default { ...@@ -375,6 +381,10 @@ export default {
} }
}) })
this.templateData = templateData this.templateData = templateData
this.submissionStatus = data.submissionStatus
}
} else { } else {
// if (this.templateType == 1) { // if (this.templateType == 1) {
let lastDay = dayjs().subtract(30, 'day') let lastDay = dayjs().subtract(30, 'day')
...@@ -438,12 +448,17 @@ export default { ...@@ -438,12 +448,17 @@ export default {
} }
this.$refs.notice.close() this.$refs.notice.close()
uni.showLoading({ title: '提交中...', mask: true }) uni.showLoading({ title: '提交中...', mask: true })
const data = await uni.$api.dailyTemplateApi.submitReport(reportParams) 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() uni.hideLoading()
if (data) { if (data) {
uni.showToast({ title: '操作成功', icon: 'success', mask: true }) uni.showToast({ title: '操作成功', icon: 'success', mask: true })
this.saveReportStatus(data) 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 })
}, },
saveReportStatus(data) { saveReportStatus(data) {
if (data) if (data)
......
...@@ -17,7 +17,8 @@ export default { ...@@ -17,7 +17,8 @@ export default {
type: Array, type: Array,
default: () => [] default: () => []
}, },
ReportStatus: null ReportStatus: null,
SubmissionStatus: null
}, },
computed: { computed: {
/**可编辑日期 */ /**可编辑日期 */
...@@ -31,7 +32,7 @@ export default { ...@@ -31,7 +32,7 @@ export default {
}, },
reportParams() { reportParams() {
let { shopMerchantId, shopMerchantName, uuid, name, merchantId, merchantName } = this.userInfo, let { shopMerchantId, shopMerchantName, uuid, name, merchantId, merchantName } = this.userInfo,
{ currentDate, templateType, dailyReportRecordId, sceneType } = this, { currentDate, templateType, dailyReportRecordId, sceneType, SubmissionStatus } = this,
params = { params = {
merchantId: shopMerchantId, merchantId: shopMerchantId,
merchantName: shopMerchantName, merchantName: shopMerchantName,
...@@ -42,8 +43,11 @@ export default { ...@@ -42,8 +43,11 @@ export default {
templateType: templateType(), templateType: templateType(),
yqMerchantId: merchantId, yqMerchantId: merchantId,
yqMerchantName: merchantName, 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() if (dailyReportRecordId()) params.dailyReportRecordId = dailyReportRecordId()
return params return params
} }
...@@ -76,52 +80,52 @@ export default { ...@@ -76,52 +80,52 @@ export default {
console.log(error) console.log(error)
} }
}, },
async saveReport(res) { // async saveReport(res) {
try { // try {
uni.showLoading({ title: '提交中...', mask: true }) // uni.showLoading({ title: '提交中...', mask: true })
let { reportParams } = this, // let { reportParams } = this,
list = utils.deepClone(res) // list = utils.deepClone(res)
let jsonContent = JSON.stringify(list) // let jsonContent = JSON.stringify(list)
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)
e.children.map((c, cIndex) => { // e.children.map((c, cIndex) => {
let isArray = Array.isArray(c) // let isArray = Array.isArray(c)
if (isArray) { // if (isArray) {
childrenValue.push({ // childrenValue.push({
[e.key]: {} // [e.key]: {}
}) // })
c.map(i => { // c.map(i => {
let value = i.value // let value = i.value
if (i[i.key]) // if (i[i.key])
childrenValue[cIndex][e.key][i.key] = { // childrenValue[cIndex][e.key][i.key] = {
text: value, // text: value,
value: i[i.key] // value: i[i.key]
} // }
else childrenValue[cIndex][e.key][i.key] = value // else childrenValue[cIndex][e.key][i.key] = value
}) // })
} // }
}) // })
e.childrenValue = childrenValue // e.childrenValue = childrenValue
if (e.type == 'subform') delete e.children // if (e.type == 'subform') delete e.children
}) // })
reportParams.jsonContent = JSON.stringify(list) // reportParams.jsonContent = JSON.stringify(list)
reportParams.requestJson = JSON.stringify(requestJson) // reportParams.requestJson = JSON.stringify(requestJson)
console.log('保存草稿', reportParams) // console.log('保存草稿', 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) {
uni.showToast({ title: '操作成功', icon: 'success', mask: true }) // uni.showToast({ title: '操作成功', icon: 'success', mask: true })
this.$emit('saveReportStatus', data) // this.$emit('saveReportStatus', data)
} else uni.showToast({ title: '操作失败', icon: 'none', mask: true }) // } else uni.showToast({ title: '操作失败', icon: 'none', mask: true })
console.log(data) // console.log(data)
} catch (error) { // } catch (error) {
uni.hideLoading() // uni.hideLoading()
uni.showToast({ title: error, icon: 'none', mask: true }) // uni.showToast({ title: error, icon: 'none', mask: true })
} // }
}, // },
async submitReport(res) { async saveReport(res, isPush = false) {
try { try {
const phoneRegex = /^1[3456789]\d{9}$/ const phoneRegex = /^1[3456789]\d{9}$/
uni.showLoading({ title: '提交中...', mask: true }) uni.showLoading({ title: '提交中...', mask: true })
...@@ -194,11 +198,24 @@ export default { ...@@ -194,11 +198,24 @@ export default {
reportParams.requestJson = JSON.stringify(requestJson) reportParams.requestJson = JSON.stringify(requestJson)
console.log('提交日报', reportParams) console.log('提交日报', reportParams)
uni.hideLoading() 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) { } catch (error) {
uni.hideLoading() uni.hideLoading()
uni.showToast({ title: error, icon: 'none', mask: true }) 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!