Commit 904dbc39 by 李伟康

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

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