Commit 757affd1 by 李伟康

refactor(dailyNewspaper): 优化日报表单数据处理逻辑

- 统一函数声明语法格式
- 添加字段数据列表和子表单数据列表处理
- 修复子表单必填验证逻辑
- 为所有提示消息添加遮罩层
- 优化数据结构转换流程
1 parent b205b945
...@@ -400,7 +400,7 @@ export default { ...@@ -400,7 +400,7 @@ export default {
else uni.hideLoading() else uni.hideLoading()
} }
} catch (error) { } catch (error) {
uni.showToast({ title: error, icon: 'none' }) uni.showToast({ title: error, icon: 'none', mask: true })
} }
}, },
...@@ -454,10 +454,10 @@ export default { ...@@ -454,10 +454,10 @@ export default {
const data = await uni.$api.dailyTemplateApi.submitReport(reportParams) const data = await uni.$api.dailyTemplateApi.submitReport(reportParams)
uni.hideLoading() uni.hideLoading()
if (data) { if (data) {
uni.showToast({ title: '操作成功', icon: 'success' }) uni.showToast({ title: '操作成功', icon: 'success', mask: true })
this.saveReportStatus(data) this.saveReportStatus(data)
} }
else uni.showToast({ title: '操作失败', icon: 'none' }) else uni.showToast({ title: '操作失败', icon: 'none', mask: true })
}, },
saveReportStatus (data) { saveReportStatus (data) {
......
...@@ -5,7 +5,7 @@ import utils from '@/utils/utils' ...@@ -5,7 +5,7 @@ import utils from '@/utils/utils'
export default { export default {
inject: ['sceneType', 'userInfo', 'templateType', 'dailyReportRecordId', 'reportStatus'], inject: ['sceneType', 'userInfo', 'templateType', 'dailyReportRecordId', 'reportStatus'],
data () { data() {
return { return {
dayjs, dayjs,
nowDate: dayjs().format('YYYY-MM-DD'), nowDate: dayjs().format('YYYY-MM-DD'),
...@@ -19,10 +19,10 @@ export default { ...@@ -19,10 +19,10 @@ export default {
} }
}, },
computed: { computed: {
isToday () { isToday() {
return this.currentDate == this.nowDate return this.currentDate == this.nowDate
}, },
reportParams () { reportParams() {
let { shopMerchantId, shopMerchantName, uuid, name } = this.userInfo, let { shopMerchantId, shopMerchantName, uuid, name } = this.userInfo,
{ currentDate, templateType, dailyReportRecordId } = this, { currentDate, templateType, dailyReportRecordId } = this,
params = { params = {
...@@ -41,11 +41,13 @@ export default { ...@@ -41,11 +41,13 @@ export default {
watch: { watch: {
}, },
methods: { methods: {
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 { fieldDataList, subformDataList } = buildAppNormalizedListsFromJsonContent(jsonContent)
list.map(e => { list.map(e => {
let childrenValue = [] let childrenValue = []
if (e.children && e.children.length) e.children.map((c, cIndex) => { if (e.children && e.children.length) e.children.map((c, cIndex) => {
...@@ -68,24 +70,25 @@ export default { ...@@ -68,24 +70,25 @@ export default {
e.childrenValue = childrenValue e.childrenValue = childrenValue
if (e.type == 'subform') delete e.children if (e.type == 'subform') delete e.children
}) })
let jsonContent = JSON.stringify(list) reportParams.jsonContent = JSON.stringify(list)
reportParams.jsonContent = jsonContent reportParams.fieldDataList = fieldDataList
reportParams.subformDataList = subformDataList
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' }) uni.showToast({ title: '操作成功', icon: 'success', mask: true })
this.$emit('saveReportStatus', data) this.$emit('saveReportStatus', data)
} }
else uni.showToast({ title: '操作失败', icon: 'none' }) 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' }) uni.showToast({ title: error, icon: 'none', mask: true })
} }
}, },
itemShow (item, parent, data) { itemShow(item, parent, data) {
try { try {
let childrenShowRules = parent.childrenShowRules || null let childrenShowRules = parent.childrenShowRules || null
if (childrenShowRules) { if (childrenShowRules) {
...@@ -111,7 +114,7 @@ export default { ...@@ -111,7 +114,7 @@ export default {
console.log(error) console.log(error)
} }
}, },
submitReport (res) { submitReport(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 })
...@@ -157,7 +160,7 @@ export default { ...@@ -157,7 +160,7 @@ export default {
} }
}) })
e.childrenValue = childrenValue e.childrenValue = childrenValue
if (e.show && e.required) { 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}不能为空`
if (e.type == 'phoneInput') {// 验证手机号 if (e.type == 'phoneInput') {// 验证手机号
if (!phoneRegex.test(e.value)) throw `${e.label}格式不正确` if (!phoneRegex.test(e.value)) throw `${e.label}格式不正确`
...@@ -176,7 +179,7 @@ export default { ...@@ -176,7 +179,7 @@ export default {
this.$emit('submitReport', reportParams) this.$emit('submitReport', reportParams)
} catch (error) { } catch (error) {
uni.hideLoading() uni.hideLoading()
uni.showToast({ title: error, icon: 'none' }) uni.showToast({ title: error, icon: 'none', mask: true })
} }
}, },
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!