Commit 2d0434c3 by 李伟康

fix(dailyNewspaper): 解决日报模板数据处理和显示问题

- 修复字符串和数字类型判断逻辑中的空格问题
- 添加缺失的 children 数组初始化检查
- 在提交报告后增加数据验证并处理失败情况
- 实现保存报告状态功能并在成功后更新列表
- 添加表单项显示规则控制方法
- 防止详情模式下表格行点击事件触发
- 优化代码格式和条件判断语法
1 parent 1170dd56
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<template v-for="(item, index) in list"> <template v-for="(item, index) in list">
<template v-if="item.type == 'group'"> <template v-if="item.type == 'group'">
<view <view
v-if="itemShow(item)"
class="group-box" class="group-box"
:key="`group-${index}`" :key="`group-${index}`"
> >
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
</template> </template>
<template v-else> <template v-else>
<view <view
v-if="itemShow(item)"
:class="['item',{ 'before-divider': isFollowedByGroup(index)},{'frist': index === 0}]" :class="['item',{ 'before-divider': isFollowedByGroup(index)},{'frist': index === 0}]"
:key="`item-${index}`" :key="`item-${index}`"
> >
...@@ -80,6 +82,31 @@ export default { ...@@ -80,6 +82,31 @@ export default {
}, },
methods: { methods: {
itemShow (i) {
if (i.rules) {
let { keys, result } = i.rules,
{ list } = this
if (keys && result) {
let params = keys.map((c, index) => `val${index + 1}`),
// 将 new Function 改为 eval 方式
func = eval(`(function(${params.join(',')}) { return ${result}; })`),
value = []
keys.map(key => {
let item = list.find(i => i.key == key)
if (item) value.push(item.value || null)
})
let show = func(...value)
i.show = show
return show
} else {
i.show = true
return true
}
} else {
i.show = true
return true
}
},
isFollowedByGroup(index) { isFollowedByGroup(index) {
const prevItem = this.list[index + 1]; const prevItem = this.list[index + 1];
return prevItem && prevItem.type === 'group'; return prevItem && prevItem.type === 'group';
......
...@@ -174,6 +174,7 @@ export default { ...@@ -174,6 +174,7 @@ export default {
return value !== null && value !== '' && value !== undefined ? value : '-' return value !== null && value !== '' && value !== undefined ? value : '-'
}, },
handleRowClick (row, rowIndex) { handleRowClick (row, rowIndex) {
if (this.isDetail) return
// 清除之前的定时器 // 清除之前的定时器
if (this.clickTimer) { if (this.clickTimer) {
clearTimeout(this.clickTimer) clearTimeout(this.clickTimer)
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
:currentDate="currentDate" :currentDate="currentDate"
@changeComponent="changeComponent" @changeComponent="changeComponent"
@submitReport="submitReport" @submitReport="submitReport"
@saveReportStatus="saveReportStatus"
/> />
</view> </view>
</view> </view>
...@@ -377,7 +378,7 @@ export default { ...@@ -377,7 +378,7 @@ export default {
const key = item.key const key = item.key
const val = c[e.key]?.[key] const val = c[e.key]?.[key]
if (['string','number'].includes(typeof val)) { if (['string', 'number'].includes(typeof val)) {
item.value = val item.value = val
} else if (val) { } else if (val) {
item.value = val.text item.value = val.text
...@@ -388,7 +389,7 @@ export default { ...@@ -388,7 +389,7 @@ export default {
}) })
e.children = children e.children = children
} else { } else {
if(!e.children) e.children = [] if (!e.children) e.children = []
} }
}) })
this.templateData = templateData this.templateData = templateData
...@@ -451,12 +452,19 @@ export default { ...@@ -451,12 +452,19 @@ export default {
uni.showLoading({ title: '提交中...', mask: true }) uni.showLoading({ title: '提交中...', mask: true })
const data = await uni.$api.dailyTemplateApi.submitReport(reportParams) const data = await uni.$api.dailyTemplateApi.submitReport(reportParams)
uni.hideLoading() uni.hideLoading()
uni.showToast({ title: '操作成功', icon: 'success' }) if (data) {
setTimeout(() => { uni.showToast({ title: '操作成功', icon: 'success' })
if (this.templateType == 2) this.getReportDetail() this.saveReportStatus(data)
}, 1500) }
}, else uni.showToast({ title: '操作失败', icon: 'none' })
},
saveReportStatus (data) {
if (data) setTimeout(() => {
this.getReportList()
this.getReportDetail()
}, 1.5e3)
}
} }
} }
</script> </script>
......
...@@ -73,7 +73,11 @@ export default { ...@@ -73,7 +73,11 @@ export default {
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()
uni.showToast({ title: '操作成功', icon: 'success' }) if (data) {
uni.showToast({ title: '操作成功', icon: 'success' })
this.$emit('saveReportStatus', data)
}
else uni.showToast({ title: '操作失败', icon: 'none' })
console.log(data) console.log(data)
} catch (error) { } catch (error) {
uni.hideLoading() uni.hideLoading()
...@@ -87,7 +91,7 @@ export default { ...@@ -87,7 +91,7 @@ export default {
if (childrenShowRules) { if (childrenShowRules) {
if (Object.keys(childrenShowRules).includes(item.key)) { if (Object.keys(childrenShowRules).includes(item.key)) {
let { keys, result } = childrenShowRules[item.key], let { keys, result } = childrenShowRules[item.key],
params = keys.map((i, index) => `val${index + 1}`), params = keys.map((i, index) => `val${index + 1}`),
// 将 new Function 改为 eval 方式 // 将 new Function 改为 eval 方式
func = eval(`(function(${params.join(',')}) { return ${result}; })`), func = eval(`(function(${params.join(',')}) { return ${result}; })`),
value = [] value = []
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!