Commit 42b6286e by 李伟康

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

- 在dailyNewspaper组件中添加ReportStatus属性传递到子组件
- 将itemShow计算方法移至mixins中统一管理
- 修复保存草稿时的日志信息显示问题
- 优化子表单数据处理逻辑并增强错误处理
- 在门店日报详情页面添加文本换行支持
- 修改门店日报索引页面的条件判断逻辑以使用新的状态传递
1 parent 3c45a3f3
......@@ -161,6 +161,7 @@ export default {
.label,
.value {
width: calc(50% - #{toRpx(16)});
word-break: break-all;
}
.label {
color: #999999;
......
......@@ -159,6 +159,7 @@ export default {
.label,
.value {
width: calc(50% - #{toRpx(16)});
word-break: break-all;
}
.label {
......
<template>
<view class="report-content ">
<view :class="['report-component',{'opacity':showNegotiationList}]">
<template v-if="!isToday || reportStatus() == 1">
<template v-if="!isToday || ReportStatus == 1">
<Detail :templateData="templateData" />
</template>
<template v-else>
......
......@@ -25,7 +25,7 @@
<view class="detail-right">
<component :ref="`ref-${componentName}`" :is="componentName" :templateData="templateData"
:currentDate="currentDate" @changeComponent="changeComponent" @submitReport="submitReport"
@saveReportStatus="saveReportStatus" />
@saveReportStatus="saveReportStatus" :ReportStatus="reportStatus" />
</view>
</view>
<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 utils from '@/utils/utils'
export default {
inject: ['sceneType', 'userInfo', 'templateType', 'dailyReportRecordId', 'reportStatus'],
data() {
return {
dayjs,
nowDate: dayjs().format('YYYY-MM-DD'),
nowDate: dayjs().format('YYYY-MM-DD')
}
},
props: {
currentDate: String,
templateData: {
type: Array,
default: () => ([])
}
default: () => []
},
ReportStatus: null
},
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() {
return this.currentDate == this.nowDate
},
......@@ -31,15 +57,14 @@ export default {
reportDate: currentDate,
staffUuid: uuid,
staffName: name,
dailyReportSource: 2,//1:生意助手员工版小程序,2:平板电脑
dailyReportSource: 2, //1:生意助手员工版小程序,2:平板电脑
templateType: templateType()
}
if (dailyReportRecordId()) params.dailyReportRecordId = dailyReportRecordId()
return params
},
},
watch: {
}
},
watch: {},
methods: {
async saveReport(res) {
try {
......@@ -50,68 +75,41 @@ export default {
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
})
}
})
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)
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 })
} else uni.showToast({ title: '操作失败', icon: 'none', mask: true })
console.log(data)
} catch (error) {
uni.hideLoading()
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) {
try {
......@@ -124,62 +122,62 @@ export default {
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.forEach(i => {
i.show = this.itemShow(i, e, c)
let hasShow = Object.prototype.hasOwnProperty.call(i, 'show'),
show = hasShow ? i.show : true
if (i.required && show) {
if ((i.value === null || i.value === '' || i.value === undefined)) throw `${e.label}第${cIndex + 1}行${i.label}不能为空`
if (i.type == 'phoneInput') {// 验证手机号
if (!phoneRegex.test(i.value)) throw `${e.label}第${cIndex + 1}行${i.label}格式不正确`
if (e.children && e.children.length)
e.children.map((c, cIndex) => {
let isArray = Array.isArray(c)
if (isArray) {
childrenValue.push({
[e.key]: {}
})
c.forEach(i => {
i.show = this.itemShow(i, e, c)
let hasShow = Object.prototype.hasOwnProperty.call(i, 'show'),
show = hasShow ? i.show : true
if (i.required && show) {
if (i.value === null || i.value === '' || i.value === undefined) throw `${e.label}第${cIndex + 1}行${i.label}不能为空`
if (i.type == 'phoneInput') {
// 验证手机号
if (!phoneRegex.test(i.value)) throw `${e.label}第${cIndex + 1}行${i.label}格式不正确`
}
}
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
})
} else {
if (e.show && c.required) {
if (c.value == null || c.value === '' || c.value == undefined) throw `${e.label}:${c.label}不能为空`
if (c.type == 'phoneInput') {
// 验证手机号
if (!phoneRegex.test(c.value)) throw `${e.label}:${c.label}格式不正确`
}
}
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
})
} else {
if (e.show && c.required) {
if (c.value == null || c.value === '' || c.value == undefined) throw `${e.label}:${c.label}不能为空`
if (c.type == 'phoneInput') {// 验证手机号
if (!phoneRegex.test(c.value)) throw `${e.label}:${c.label}格式不正确`
}
}
}
})
})
e.childrenValue = childrenValue
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 (e.value == null || e.value == undefined || e.value === '') throw `${e.label}不能为空`
if (e.type == 'phoneInput') {
// 验证手机号
if (!phoneRegex.test(e.value)) throw `${e.label}格式不正确`
}
}
if (e.type == 'subform') delete e.children
})
console.log('提交日报', list)
reportParams.jsonContent = JSON.stringify(list)
reportParams.requestJson = JSON.stringify(requestJson)
console.log(reportParams)
console.log('提交日报', reportParams)
uni.hideLoading()
this.$emit('submitReport', reportParams)
} catch (error) {
uni.hideLoading()
uni.showToast({ title: error, icon: 'none', mask: true })
}
},
}
}
}
\ No newline at end of file
}
......@@ -627,6 +627,10 @@ function resolveStorageFieldValue(field = {}, fieldValue) {
if (value === undefined || value == null || (Array.isArray(value) && !value.length)) {
return { value: undefined, storageType: 'JSON' }
}
const names = field.value.split('/')
value.forEach((item,index) => {
item.name = names[index]
})
return { value, storageType: 'JSON' }
}
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!