diff --git a/src/views/plan/PlanYearDemandHdr/components/createForm.vue b/src/views/plan/PlanYearDemandHdr/components/createForm.vue index 5818fc8..dcbb234 100644 --- a/src/views/plan/PlanYearDemandHdr/components/createForm.vue +++ b/src/views/plan/PlanYearDemandHdr/components/createForm.vue @@ -123,55 +123,38 @@ import Index from '/@/views/sys/error-log/index.vue'; try { const data = await getLngPlanYearDemandHdr(id); Object.assign(formState, data); - let noteKeys = [] - for (let i in data) { - if (i.includes('note') && i.length>4) { - noteKeys.push({note: i, value: data[i]}) - } - } - let arr = data?.lngPlanYearDemandList || []; - let objPng = {} - let objLng = {} - arr.forEach(v=> { - if (v.catCode == 'PNG') { - objPng = {...v} - } - if (v.catCode == 'LNG') { - objLng = {...v} - } - }) - for(let k in objPng) { - if (k.includes('qty')) { - dataList.value.push({'qty': objPng[k]}) - } - } - let lngkeys = [] - for(let k in objLng) { - if (k.includes('qty')) { - lngkeys.push({lng: k, value : objLng[k]}) - } - } - lngkeys.forEach((i,idx)=> { - dataList.value[idx].lng = i.value - dataList.value[idx].note = noteKeys[idx].value - }) - let totalObj = {month: '合计'} - dataList.value.splice(12,0,totalObj) - dataList.value.forEach((v,idx)=> { - - if (idx<12) { - v.month = (idx+1)+'月' - } - if (idx>12) { - let a = null - if (idx==13)a=1 - if (idx==14)a=2 - if (idx==15)a=3 - v.month = '次年'+a+'月' - } - }) + const arr = data?.lngPlanYearDemandList || []; + let objPng: any = {}; + let objLng: any = {}; + arr.forEach((v: any) => { + if (v.catCode == 'PNG') objPng = { ...v }; + if (v.catCode == 'LNG') objLng = { ...v }; + }); + + const qtyKeys = [ + ...Array.from({ length: 12 }, (_, i) => 'qty' + String(i + 1).padStart(2, '0')), + 'qtyN1', 'qtyN2', 'qtyN3', + ]; + const noteKeys = [ + ...Array.from({ length: 12 }, (_, i) => 'note' + String(i + 1).padStart(2, '0')), + 'noteN1', 'noteN2', 'noteN3', + ]; + const monthLabels = [ + ...Array.from({ length: 12 }, (_, i) => (i + 1) + '月'), + '次年1月', '次年2月', '次年3月', + ]; + + dataList.value = qtyKeys.map((k, idx) => ({ + month: monthLabels[idx], + qty: objPng[k] ?? null, + lng: objLng[k] ?? null, + note: data[noteKeys[idx]] ?? null, + })); + + dataList.value.splice(12, 0, { month: '合计' }); + setTimeout(() => { - numCount() + numCount(); }, 100); } finally { diff --git a/src/views/plan/PlanYearDemandHdrEc/components/createForm.vue b/src/views/plan/PlanYearDemandHdrEc/components/createForm.vue index b972a85..552af90 100644 --- a/src/views/plan/PlanYearDemandHdrEc/components/createForm.vue +++ b/src/views/plan/PlanYearDemandHdrEc/components/createForm.vue @@ -123,7 +123,7 @@ const pageType = ref(currentRoute.value.query?.type); const pageId = ref(currentRoute.value.query?.id) - const dataList = ref([]) + const dataList = ref([]) const curIdx = ref(null) const curIndex = ref(null) const spinning = ref(false); @@ -216,55 +216,42 @@ } const updateData = (data)=> { dataList.value = [] - let noteKeys = [] - for (let i in data) { - if (i.includes('note') && i.length>4) { - noteKeys.push({note: i, value: data[i]}) - } - } let arr = data?.lngPlanYearDemandList || []; - let objPng = {} - let objLng = {} + let objPng: any = {} + let objLng: any = {} arr.forEach(v=> { - if (v.catCode == 'PNG') { - objPng = {...v} - } - if (v.catCode == 'LNG') { - objLng = {...v} - } + if (v.catCode == 'PNG') objPng = {...v} + if (v.catCode == 'LNG') objLng = {...v} }) - for(let k in objPng) { - if (k.includes('qty')) { - dataList.value.push({'qty': objPng[k]}) - } - } - let lngkeys = [] - for(let k in objLng) { - if (k.includes('qty')) { - lngkeys.push({lng: k, value : objLng[k]}) - } - } - lngkeys.forEach((i,idx)=> { - dataList.value[idx].lng = i.value - dataList.value[idx].note = noteKeys[idx].value - }) - let totalObj = {month: '合计'} - dataList.value.splice(12,0,totalObj) - dataList.value.forEach((v,idx)=> { - - if (idx<12) { - v.month = (idx+1)+'月' - } - if (idx>12) { - let a = null - if (idx==13)a=1 - if (idx==14)a=2 - if (idx==15)a=3 - v.month = '次年'+a+'月' - } + + // 按顺序构建 qty key:qty01~qty12,qtyN1~qtyN3 + const qtyKeys = [ + ...Array.from({length: 12}, (_, i) => 'qty' + String(i+1).padStart(2,'0')), + 'qtyN1', 'qtyN2', 'qtyN3' + ] + const noteKeys = [ + ...Array.from({length: 12}, (_, i) => 'note' + String(i+1).padStart(2,'0')), + 'noteN1', 'noteN2', 'noteN3' + ] + const monthLabels = [ + ...Array.from({length: 12}, (_, i) => (i+1)+'月'), + '次年1月', '次年2月', '次年3月' + ] + + qtyKeys.forEach((k, idx) => { + dataList.value.push({ + month: monthLabels[idx], + qty: objPng[k] ?? null, + lng: objLng[k] ?? null, + note: data[noteKeys[idx]] ?? null, + }) }) + + // 在第12条后插入合计行 + dataList.value.splice(12, 0, {month: '合计'}) + setTimeout(() => { - numCount() + numCount(null) }, 500); } const numCount = (record) => { @@ -363,8 +350,8 @@ let k = '' let kn = '' if (idx<12) { - k = 'qty'+(idx<9 ? ('0'+(idx+1)) : idx+1) - kn = 'note'+(idx<9 ? ('0'+(idx+1)) : idx+1) + k = 'qty'+ String(idx+1).padStart(2,'0') + kn = 'note'+ String(idx+1).padStart(2,'0') } if (idx>12) { let a = null