Commit 42b6286e by 李伟康

feat(dailyNewspaper): 添加报表状态传递功能并优化组件显示逻辑

- 在dailyNewspaper组件中添加ReportStatus属性传递到子组件
- 将itemShow计算方法移至mixins中统一管理
- 修复保存草稿时的日志信息显示问题
- 优化子表单数据处理逻辑并增强错误处理
- 在门店日报详情页面添加文本换行支持
- 修改门店日报索引页面的条件判断逻辑以使用新的状态传递
1 parent 3c45a3f3
...@@ -161,6 +161,7 @@ export default { ...@@ -161,6 +161,7 @@ export default {
.label, .label,
.value { .value {
width: calc(50% - #{toRpx(16)}); width: calc(50% - #{toRpx(16)});
word-break: break-all;
} }
.label { .label {
color: #999999; color: #999999;
......
...@@ -159,6 +159,7 @@ export default { ...@@ -159,6 +159,7 @@ export default {
.label, .label,
.value { .value {
width: calc(50% - #{toRpx(16)}); width: calc(50% - #{toRpx(16)});
word-break: break-all;
} }
.label { .label {
......
<template> <template>
<view class="report-content "> <view class="report-content ">
<view :class="['report-component',{'opacity':showNegotiationList}]"> <view :class="['report-component',{'opacity':showNegotiationList}]">
<template v-if="!isToday || reportStatus() == 1"> <template v-if="!isToday || ReportStatus == 1">
<Detail :templateData="templateData" /> <Detail :templateData="templateData" />
</template> </template>
<template v-else> <template v-else>
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
<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" /> @saveReportStatus="saveReportStatus" :ReportStatus="reportStatus" />
</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'"
......
import dayjs from "dayjs" import dayjs from 'dayjs'
import { buildAppNormalizedListsFromJsonContent } from './subform' import { buildAppNormalizedListsFromJsonContent } from './subform'
import utils from '@/utils/utils' 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')
} }
}, },
props: { props: {
currentDate: String, currentDate: String,
templateData: { templateData: {
type: Array, type: Array,
default: () => ([]) default: () => []
} },
ReportStatus: null
}, },
computed: { computed: {
itemShow(item, parent, data) {
try {
let childrenShowRules = parent.childrenShowRules || null
if (childrenShowRules) {
if (Object.keys(childrenShowRules).includes(item.key)) {
let { keys, result } = childrenShowRules[item.key],
params = keys.map((i, index) => `val${index + 1}`),
// 将 new Function 改为 eval 方式
func = eval(`(function(${params.join(',')}) { return ${result}; })`),
value = []
keys.map(key => {
let item = data.find(i => i.key == key)
if (item) value.push(item.value || null)
})
let show = func(...value)
return show
} else {
return true
}
} else {
return true
}
} catch (error) {
console.log(error)
}
},
isToday() { isToday() {
return this.currentDate == this.nowDate return this.currentDate == this.nowDate
}, },
...@@ -31,15 +57,14 @@ export default { ...@@ -31,15 +57,14 @@ export default {
reportDate: currentDate, reportDate: currentDate,
staffUuid: uuid, staffUuid: uuid,
staffName: name, staffName: name,
dailyReportSource: 2,//1:生意助手员工版小程序,2:平板电脑 dailyReportSource: 2, //1:生意助手员工版小程序,2:平板电脑
templateType: templateType() templateType: templateType()
} }
if (dailyReportRecordId()) params.dailyReportRecordId = dailyReportRecordId() if (dailyReportRecordId()) params.dailyReportRecordId = dailyReportRecordId()
return params return params
}
}, },
}, watch: {},
watch: {
},
methods: { methods: {
async saveReport(res) { async saveReport(res) {
try { try {
...@@ -50,7 +75,8 @@ export default { ...@@ -50,7 +75,8 @@ 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) e.children.map((c, cIndex) => { if (e.children && e.children.length)
e.children.map((c, cIndex) => {
let isArray = Array.isArray(c) let isArray = Array.isArray(c)
if (isArray) { if (isArray) {
childrenValue.push({ childrenValue.push({
...@@ -58,13 +84,13 @@ export default { ...@@ -58,13 +84,13 @@ export default {
}) })
c.map(i => { c.map(i => {
let value = i.value let value = i.value
if (i[i.key]) childrenValue[cIndex][e.key][i.key] = { if (i[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
...@@ -72,46 +98,18 @@ export default { ...@@ -72,46 +98,18 @@ export default {
}) })
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 })
} }
},
itemShow(item, parent, data) {
try {
let childrenShowRules = parent.childrenShowRules || null
if (childrenShowRules) {
if (Object.keys(childrenShowRules).includes(item.key)) {
let { keys, result } = childrenShowRules[item.key],
params = keys.map((i, index) => `val${index + 1}`),
// 将 new Function 改为 eval 方式
func = eval(`(function(${params.join(',')}) { return ${result}; })`),
value = []
keys.map(key => {
let item = data.find(i => i.key == key)
if (item) value.push(item.value || null)
})
let show = func(...value)
return show
} else {
return true
}
} else {
return true
}
} catch (error) {
console.log(error)
}
}, },
submitReport(res) { submitReport(res) {
try { try {
...@@ -124,8 +122,8 @@ export default { ...@@ -124,8 +122,8 @@ 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) e.children.map((c, cIndex) => { if (e.children && e.children.length)
e.children.map((c, cIndex) => {
let isArray = Array.isArray(c) let isArray = Array.isArray(c)
if (isArray) { if (isArray) {
childrenValue.push({ childrenValue.push({
...@@ -136,23 +134,25 @@ export default { ...@@ -136,23 +134,25 @@ export default {
let hasShow = Object.prototype.hasOwnProperty.call(i, 'show'), let hasShow = Object.prototype.hasOwnProperty.call(i, 'show'),
show = hasShow ? i.show : true show = hasShow ? i.show : true
if (i.required && show) { if (i.required && show) {
if ((i.value === null || i.value === '' || i.value === undefined)) throw `${e.label}第${cIndex + 1}行${i.label}不能为空` if (i.value === null || i.value === '' || i.value === undefined) throw `${e.label}第${cIndex + 1}行${i.label}不能为空`
if (i.type == 'phoneInput') {// 验证手机号 if (i.type == 'phoneInput') {
// 验证手机号
if (!phoneRegex.test(i.value)) throw `${e.label}第${cIndex + 1}行${i.label}格式不正确` if (!phoneRegex.test(i.value)) throw `${e.label}第${cIndex + 1}行${i.label}格式不正确`
} }
} }
let value = i.value let value = i.value
if (i[i.key]) childrenValue[cIndex][e.key][i.key] = { if (i[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
}) })
} else { } else {
if (e.show && c.required) { if (e.show && c.required) {
if (c.value == null || c.value === '' || c.value == undefined) throw `${e.label}:${c.label}不能为空` if (c.value == null || c.value === '' || c.value == undefined) throw `${e.label}:${c.label}不能为空`
if (c.type == 'phoneInput') {// 验证手机号 if (c.type == 'phoneInput') {
// 验证手机号
if (!phoneRegex.test(c.value)) throw `${e.label}:${c.label}格式不正确` if (!phoneRegex.test(c.value)) throw `${e.label}:${c.label}格式不正确`
} }
} }
...@@ -160,26 +160,24 @@ export default { ...@@ -160,26 +160,24 @@ 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}不能为空`
if (e.type == 'phoneInput') {// 验证手机号 if (e.type == 'phoneInput') {
// 验证手机号
if (!phoneRegex.test(e.value)) throw `${e.label}格式不正确` if (!phoneRegex.test(e.value)) throw `${e.label}格式不正确`
} }
} }
if (e.type == 'subform') delete e.children if (e.type == 'subform') delete e.children
}) })
console.log('提交日报', list)
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)
uni.hideLoading() uni.hideLoading()
this.$emit('submitReport', reportParams) 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 })
} }
},
} }
}
} }
...@@ -627,6 +627,10 @@ function resolveStorageFieldValue(field = {}, fieldValue) { ...@@ -627,6 +627,10 @@ function resolveStorageFieldValue(field = {}, fieldValue) {
if (value === undefined || value == null || (Array.isArray(value) && !value.length)) { if (value === undefined || value == null || (Array.isArray(value) && !value.length)) {
return { value: undefined, storageType: 'JSON' } return { value: undefined, storageType: 'JSON' }
} }
const names = field.value.split('/')
value.forEach((item,index) => {
item.name = names[index]
})
return { value, storageType: 'JSON' } return { value, storageType: 'JSON' }
} }
if (field.type === 'carBrandSelect') { if (field.type === 'carBrandSelect') {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!