Commit 757affd1 by 李伟康

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

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