Commit 904dbc39 by 李伟康

feat(dailyNewspaper): 完善日报功能中的子表单处理逻辑

- 引入utils工具类用于深拷贝操作
- 优化模板数据处理,支持子表单字段值的正确解析和赋值
- 新增subform.js文件,提供完整的动态表单数据处理工具函数
- 修改保存和提交方法,增加子表单数据转换和验证逻辑
- 更新组件间数据传递方式,确保子表单数据正确同步
- 增加字段显示条件控制,支持动态显示隐藏逻辑
- 完善popup组件回调处理,支持订单等关联数据自动填充
1 parent 536cb79c
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
:tableIndex="index" :tableIndex="index"
hasFooter hasFooter
@clickAdd="addItem(index)" @clickAdd="addItem(index)"
:maxLength="i.rules.maxLength"
> >
<template v-slot:customCell="{row, colIndex}"> <template v-slot:customCell="{row, colIndex}">
{{ formatValue(row[colIndex].value) }} {{ formatValue(row[colIndex].value) }}
...@@ -109,11 +110,11 @@ export default { ...@@ -109,11 +110,11 @@ export default {
this.list[index].children.splice(c_index, 1) this.list[index].children.splice(c_index, 1)
}, },
addItem (index) { addItem (index) {
let { templateData } = this let { templateData } = this,
parent = this.list[index]
this.list[index].children.push(templateData[index].origin_children) this.list[index].children.push(templateData[index].origin_children)
let data = this.list[index].children[this.list[index].children.length - 1], let data = this.list[index].children[this.list[index].children.length - 1],
c_index = this.list[index].children.length - 1, c_index = this.list[index].children.length - 1
parent = this.list[index]
this.$refs.editForm.open(data, c_index, index, parent) this.$refs.editForm.open(data, c_index, index, parent)
}, },
confirm (data, c_index, index) { confirm (data, c_index, index) {
......
...@@ -154,11 +154,13 @@ export default { ...@@ -154,11 +154,13 @@ export default {
this.$refs.editForm.open(row, rowIndex, index, parent) this.$refs.editForm.open(row, rowIndex, index, parent)
}, },
delItem (c_index, index) { delItem (c_index, index) {
console.log(this.list[index].children)
console.log(c_index, index)
this.list[index].children.splice(c_index, 1) this.list[index].children.splice(c_index, 1)
}, },
addItem (index) { addItem (index) {
let { templateData } = this let { templateData } = this
this.list[index].children.push(templateData[index].children[0]) this.list[index].children.push(templateData[index].origin_children)
let data = this.list[index].children[this.list[index].children.length - 1], let data = this.list[index].children[this.list[index].children.length - 1],
c_index = this.list[index].children.length - 1, c_index = this.list[index].children.length - 1,
parent = this.list[index] parent = this.list[index]
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
:class="['item flex', { active: checkActive(i) }]" :class="['item flex', { active: checkActive(i) }]"
> >
<view class="sprite-icon icon-tag-checked"></view> <view class="sprite-icon icon-tag-checked"></view>
{{ i.productName }} {{ i.orderCode }}
</view> </view>
</template> </template>
</view> </view>
...@@ -34,7 +34,7 @@ export default { ...@@ -34,7 +34,7 @@ export default {
}, },
methods: { methods: {
async getList (searchValue, search) { async getList (searchValue, search) {
const { userInfo, params, data } = this, const { userInfo, params, data, reqParams } = this,
{ cacheData } = params { cacheData } = params
this.currentId = '' this.currentId = ''
if (!search && cacheData && cacheData.length) { if (!search && cacheData && cacheData.length) {
...@@ -43,12 +43,11 @@ export default { ...@@ -43,12 +43,11 @@ export default {
} }
this.componentLoading(params) this.componentLoading(params)
console.log(data) console.log(data)
const { shopMerchantId,uuid } = userInfo, const { shopMerchantId, uuid } = userInfo,
apiParams = { apiParams = {
merchantId: shopMerchantId, merchantId: shopMerchantId,
sellerUserId: uuid, sellerUserId: uuid,
carBrandTypeFlag: '', ...reqParams
saleDate: ''
} }
const res = await uni.$api.dailyTemplateApi.getGoodsOrderList(apiParams) const res = await uni.$api.dailyTemplateApi.getGoodsOrderList(apiParams)
this.updateParams(params, res || []) this.updateParams(params, res || [])
...@@ -63,20 +62,6 @@ export default { ...@@ -63,20 +62,6 @@ export default {
this.list = list this.list = list
this.$emit('onComplete') this.$emit('onComplete')
}, },
originalDataSearch (searchValue) {
if (!searchValue) this.searchStatus = false
else {
searchValue = searchValue.toUpperCase()
let { list } = this,
orderList = JSON.parse(JSON.stringify(list)),
arr = []
orderList.map(e => {
if (e.staffName && e.staffName.toUpperCase().indexOf(searchValue) != -1) arr.push(e)
})
this.searchList = arr
this.searchStatus = true
}
},
choose (i) { choose (i) {
this.currentId = i.orderCode this.currentId = i.orderCode
this.$emit('choose', i) this.$emit('choose', i)
......
...@@ -16,6 +16,7 @@ export default { ...@@ -16,6 +16,7 @@ export default {
dataKey: String, dataKey: String,
isDefeatOrder: Boolean, isDefeatOrder: Boolean,
positionTypeList: Array, positionTypeList: Array,
reqParams: Object,
}, },
computed: { computed: {
listData () { listData () {
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
:params.sync="componentObject[popupType]" :params.sync="componentObject[popupType]"
:data="data" :data="data"
:dataKey="dataKey" :dataKey="dataKey"
:reqParams="reqParams"
ref="componentRef" ref="componentRef"
@choose="chooseContent = $event" @choose="chooseContent = $event"
@onComplete="componentObject[popupType].loadComplete = true" @onComplete="componentObject[popupType].loadComplete = true"
...@@ -97,8 +98,9 @@ import EmployeeList from './components/EmployeeList.vue' ...@@ -97,8 +98,9 @@ import EmployeeList from './components/EmployeeList.vue'
import CarModelList from './components/CarModelList.vue' import CarModelList from './components/CarModelList.vue'
import OrderList from './components/OrderList.vue' import OrderList from './components/OrderList.vue'
import DateTime from './components/DateTime.vue' import DateTime from './components/DateTime.vue'
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import utils from '@/utils/utils'
export default { export default {
components: { components: {
Popup, Popup,
...@@ -146,7 +148,9 @@ export default { ...@@ -146,7 +148,9 @@ export default {
popupType: 0, popupType: 0,
itemIndex: null, itemIndex: null,
calendarData: '', calendarData: '',
popupTitle: '' popupTitle: '',
list: [],
reqParams:{}
} }
}, },
...@@ -190,12 +194,22 @@ export default { ...@@ -190,12 +194,22 @@ export default {
} }
}) })
}, },
open (data, popupType, index) { open (data, popupType, index, list) {
this.reqParams = {}
this.popupTitle = data.label || '' this.popupTitle = data.label || ''
this.data = data this.data = utils.deepClone(data)
this.dataKey = data.key this.dataKey = data.key
this.popupType = popupType this.popupType = popupType
this.itemIndex = index this.itemIndex = index
if (data.reqParams) {
let reqParamsFun = data.reqParamsFun || [],
reqParams = utils.deepClone(data.reqParams)
reqParamsFun.map(e => {
let fun = eval(`(function(list) { return ${data.reqParams[e]}; })`)
reqParams[e] = fun(list)
})
this.reqParams = reqParams
}
/**6 日历弹窗 */ /**6 日历弹窗 */
if (popupType == 6) { if (popupType == 6) {
this.calendarData = data.value || dayjs().format('YYYY-MM-DD') this.calendarData = data.value || dayjs().format('YYYY-MM-DD')
...@@ -240,7 +254,6 @@ export default { ...@@ -240,7 +254,6 @@ export default {
}, },
confirm (autoClose) { confirm (autoClose) {
try { try {
let { chooseContent, popupType, componentObject, itemIndex } = this let { chooseContent, popupType, componentObject, itemIndex } = this
if (popupType == 5) { if (popupType == 5) {
chooseContent = this.componentRef().getResult() chooseContent = this.componentRef().getResult()
......
...@@ -167,11 +167,15 @@ export default { ...@@ -167,11 +167,15 @@ export default {
let item = data.find(i => i.key == key) let item = data.find(i => i.key == key)
if (item) value.push(item.value || null) if (item) value.push(item.value || null)
}) })
return func(...value) let show = func(...value)
item.show = show
return show
} else { } else {
item.show = true
return true return true
} }
} else { } else {
item.show = true
return true return true
} }
}, },
...@@ -182,8 +186,9 @@ export default { ...@@ -182,8 +186,9 @@ export default {
this.$set(this.data[index], 'value', val) this.$set(this.data[index], 'value', val)
}, },
openSelect (item, type, index) { openSelect (item, type, index) {
let list = this.data || []
this.currentItem = item this.currentItem = item
this.$refs.dailyPopup.open(item, type, index) this.$refs.dailyPopup.open(item, type, index, list)
}, },
onScanSuccess (val, index) { onScanSuccess (val, index) {
this.$set(this.data[index], 'value', val) this.$set(this.data[index], 'value', val)
...@@ -199,6 +204,19 @@ export default { ...@@ -199,6 +204,19 @@ export default {
const { vehicleBrandName, vehicleSubBrandName, vehicleSeriesName, vehicleShapeName } = chooseContent const { vehicleBrandName, vehicleSubBrandName, vehicleSeriesName, vehicleShapeName } = chooseContent
this.$set(this.data[itemIndex], 'value', `${vehicleBrandName}-${vehicleSubBrandName}-${vehicleSeriesName}-${vehicleShapeName}`) this.$set(this.data[itemIndex], 'value', `${vehicleBrandName}-${vehicleSubBrandName}-${vehicleSeriesName}-${vehicleShapeName}`)
this.$set(this.data[itemIndex], this.data[itemIndex].key, chooseContent) this.$set(this.data[itemIndex], this.data[itemIndex].key, chooseContent)
} else if (popupType == 4) {
this.$set(this.data[itemIndex], 'value', chooseContent.orderCode)
let completeFun = this.data[itemIndex].completeFun
if (completeFun) {
let { keys, resultKeys } = completeFun
keys.map((key, index) => {
let ind = this.data.findIndex(i => i.key == key),
val = chooseContent[resultKeys[index]]
this.$set(this.data[ind], 'value', val != null ? val : '-')
})
}
} else { } else {
this.$set(this.data[itemIndex], 'value', chooseContent.staffName) this.$set(this.data[itemIndex], 'value', chooseContent.staffName)
this.$set(this.data[itemIndex], this.data[itemIndex].key, chooseContent.uuid) this.$set(this.data[itemIndex], this.data[itemIndex].key, chooseContent.uuid)
......
...@@ -306,6 +306,10 @@ export default { ...@@ -306,6 +306,10 @@ export default {
if (!isNaN(numValue) && numValue > max) { if (!isNaN(numValue) && numValue > max) {
filtered = String(max); filtered = String(max);
} }
// 如果超出最小值,限制为最小值
if (!isNaN(numValue) && numValue < min) {
filtered = String(min);
}
this.$set(this.item, 'value', filtered) this.$set(this.item, 'value', filtered)
this.$emit('onInput', filtered) this.$emit('onInput', filtered)
this.$nextTick(() => { this.$nextTick(() => {
......
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
<view <view
class="footer-row" class="footer-row"
:style="{width:tableWidth}" :style="{width:tableWidth}"
v-if="maxLength && tableData.length < maxLength"
> >
<view <view
class="add" class="add"
...@@ -133,6 +134,10 @@ export default { ...@@ -133,6 +134,10 @@ export default {
type: Number, type: Number,
default: 0 default: 0
}, },
maxLength: {
type: Number,
default: 20
},
}, },
data () { data () {
return { return {
...@@ -159,9 +164,6 @@ export default { ...@@ -159,9 +164,6 @@ export default {
mounted () { mounted () {
}, },
methods: { methods: {
handleScroll (e) {
// 滚动事件处理
},
handleRowClick (row, rowIndex) { handleRowClick (row, rowIndex) {
this.$emit('rowClick', row, rowIndex, this.tableIndex) this.$emit('rowClick', row, rowIndex, this.tableIndex)
}, },
......
...@@ -67,6 +67,8 @@ import StaffDailyReport from './StaffDailyReport/index.vue' ...@@ -67,6 +67,8 @@ import StaffDailyReport from './StaffDailyReport/index.vue'
import StoreDailyReport from './StoreDailyReport/index.vue' import StoreDailyReport from './StoreDailyReport/index.vue'
import NegotiationDetail from './NegotiationDetail/index.vue' import NegotiationDetail from './NegotiationDetail/index.vue'
import EditNegotiationDetail from './NegotiationDetail/edit.vue' import EditNegotiationDetail from './NegotiationDetail/edit.vue'
import utils from '@/utils/utils'
export default { export default {
components: { components: {
NoticePopup, NoticePopup,
...@@ -96,7 +98,7 @@ export default { ...@@ -96,7 +98,7 @@ export default {
templateData: [], templateData: [],
assignTitle: '', assignTitle: '',
assignIcon: '', assignIcon: '',
dailyReportRecordId:'' dailyReportRecordId: ''
} }
}, },
computed: { computed: {
...@@ -240,8 +242,8 @@ export default { ...@@ -240,8 +242,8 @@ export default {
} }
else return item.baseSceneCode?.length ? hasCommonElement(item.baseSceneCode, BASE_SCENE_CODE) : true else return item.baseSceneCode?.length ? hasCommonElement(item.baseSceneCode, BASE_SCENE_CODE) : true
}) })
templateData.map(e =>{ templateData.map(e => {
if(e.children && e.type == 'subform') e.origin_children = e.children[0] if (e.children && e.type == 'subform') e.origin_children = e.children[0]
}) })
console.log(templateData) console.log(templateData)
this.templateData = templateData this.templateData = templateData
...@@ -268,8 +270,30 @@ export default { ...@@ -268,8 +270,30 @@ export default {
}) })
if (data) { if (data) {
this.dailyReportRecordId = data.id this.dailyReportRecordId = data.id
this.templateData = JSON.parse(data.jsonContent || '[]') let templateData = JSON.parse(data.jsonContent || '[]')
console.log(this.templateData) templateData.forEach(e => {
if (e.childrenValue && e.childrenValue.length > 0) {
const children = e.childrenValue.map(c => {
// 每次循环创建新的深拷贝,避免引用共享问题
const originChildren = utils.deepClone(e.origin_children)
originChildren.forEach(item => {
const key = item.key
const val = c[e.key]?.[key]
if (typeof val === 'string') {
item.value = val
} else if (val) {
item.value = val.text
item[key] = val.value
}
})
return originChildren
})
e.children = children
}
})
console.log(templateData)
this.templateData = templateData
} }
else { else {
if (nowDate == currentDate) this.getDailyTemplate() if (nowDate == currentDate) this.getDailyTemplate()
......
import dayjs from "dayjs" import dayjs from "dayjs"
import { buildAppNormalizedListsFromJsonContent } from './subform'
import utils from '@/utils/utils'
export default { export default {
inject: ['sceneType', 'userInfo', 'templateType', 'dailyReportRecordId'], inject: ['sceneType', 'userInfo', 'templateType', 'dailyReportRecordId'],
data () { data () {
...@@ -37,11 +41,35 @@ export default { ...@@ -37,11 +41,35 @@ export default {
watch: { watch: {
}, },
methods: { methods: {
async saveReport (list) { async saveReport (res) {
try { try {
let { reportParams } = this let { reportParams } = this,
console.log('保存日报', reportParams) list = utils.deepClone(res)
reportParams.jsonContent = JSON.stringify(list) 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
})
}
})
e.childrenValue = childrenValue
delete e.children
})
let jsonContent = JSON.stringify(list)
reportParams.jsonContent = jsonContent
console.log(reportParams)
const data = await uni.$api.dailyTemplateApi.saveDraft(reportParams) const data = await uni.$api.dailyTemplateApi.saveDraft(reportParams)
console.log(data) console.log(data)
} catch (error) { } catch (error) {
...@@ -50,24 +78,44 @@ export default { ...@@ -50,24 +78,44 @@ export default {
}, },
async submitReport (list) { async submitReport (res) {
try { try {
let { reportParams } = this let { reportParams } = this,
console.log('提交日报', reportParams) list = utils.deepClone(res)
console.log(list) console.log('提交日报', list)
let jsonContent = JSON.stringify(list)
let { fieldDataList, subformDataList } = buildAppNormalizedListsFromJsonContent(jsonContent)
list.map(e => { list.map(e => {
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({
[e.key]: {}
})
c.map(i => { c.map(i => {
if(i.required && (i.value == null || i.value == undefined)) throw `${e.label}第${cIndex+1}项${i.label}不能为空` if (i.required && i.show && (i.value == null || i.value == undefined)) 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 { } else {
if(c.required && (c.value == null || c.value == undefined)) throw `${e.label}${c.label}不能为空` if (c.required && (c.value == null || c.value == undefined)) throw `${e.label}${c.label}不能为空`
} }
}) })
e.childrenValue = childrenValue
delete e.children
}) })
console.log('提交日报', list)
reportParams.jsonContent = JSON.stringify(list) reportParams.jsonContent = JSON.stringify(list)
reportParams.fieldDataList = fieldDataList
reportParams.subformDataList = subformDataList
console.log(reportParams)
const data = await uni.$api.dailyTemplateApi.submitReport(reportParams) const data = await uni.$api.dailyTemplateApi.submitReport(reportParams)
console.log(data) console.log(data)
} catch (error) { } catch (error) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!