代码优化

This commit is contained in:
‘huanghaiixia’
2026-04-14 14:47:54 +08:00
parent 71febe07e5
commit 456fb753c7
2 changed files with 65 additions and 95 deletions

View File

@ -123,55 +123,38 @@ import Index from '/@/views/sys/error-log/index.vue';
try { try {
const data = await getLngPlanYearDemandHdr(id); const data = await getLngPlanYearDemandHdr(id);
Object.assign(formState, data); Object.assign(formState, data);
let noteKeys = [] const arr = data?.lngPlanYearDemandList || [];
for (let i in data) { let objPng: any = {};
if (i.includes('note') && i.length>4) { let objLng: any = {};
noteKeys.push({note: i, value: data[i]}) arr.forEach((v: any) => {
} if (v.catCode == 'PNG') objPng = { ...v };
} if (v.catCode == 'LNG') objLng = { ...v };
let arr = data?.lngPlanYearDemandList || []; });
let objPng = {}
let objLng = {} const qtyKeys = [
arr.forEach(v=> { ...Array.from({ length: 12 }, (_, i) => 'qty' + String(i + 1).padStart(2, '0')),
if (v.catCode == 'PNG') { 'qtyN1', 'qtyN2', 'qtyN3',
objPng = {...v} ];
} const noteKeys = [
if (v.catCode == 'LNG') { ...Array.from({ length: 12 }, (_, i) => 'note' + String(i + 1).padStart(2, '0')),
objLng = {...v} 'noteN1', 'noteN2', 'noteN3',
} ];
}) const monthLabels = [
for(let k in objPng) { ...Array.from({ length: 12 }, (_, i) => (i + 1) + '月'),
if (k.includes('qty')) { '次年1月', '次年2月', '次年3月',
dataList.value.push({'qty': objPng[k]}) ];
}
} dataList.value = qtyKeys.map((k, idx) => ({
let lngkeys = [] month: monthLabels[idx],
for(let k in objLng) { qty: objPng[k] ?? null,
if (k.includes('qty')) { lng: objLng[k] ?? null,
lngkeys.push({lng: k, value : objLng[k]}) note: data[noteKeys[idx]] ?? null,
} }));
}
lngkeys.forEach((i,idx)=> { dataList.value.splice(12, 0, { month: '合计' });
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+'月'
}
})
setTimeout(() => { setTimeout(() => {
numCount() numCount();
}, 100); }, 100);
} finally { } finally {

View File

@ -123,7 +123,7 @@
const pageType = ref(currentRoute.value.query?.type); const pageType = ref(currentRoute.value.query?.type);
const pageId = ref(currentRoute.value.query?.id) const pageId = ref(currentRoute.value.query?.id)
const dataList = ref([]) const dataList = ref<any[]>([])
const curIdx = ref(null) const curIdx = ref(null)
const curIndex = ref(null) const curIndex = ref(null)
const spinning = ref(false); const spinning = ref(false);
@ -216,55 +216,42 @@
} }
const updateData = (data)=> { const updateData = (data)=> {
dataList.value = [] 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 arr = data?.lngPlanYearDemandList || [];
let objPng = {} let objPng: any = {}
let objLng = {} let objLng: any = {}
arr.forEach(v=> { arr.forEach(v=> {
if (v.catCode == 'PNG') { if (v.catCode == 'PNG') objPng = {...v}
objPng = {...v} if (v.catCode == 'LNG') objLng = {...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) { // 按顺序构建 qty keyqty01~qty12qtyN1~qtyN3
v.month = (idx+1)+'月' const qtyKeys = [
} ...Array.from({length: 12}, (_, i) => 'qty' + String(i+1).padStart(2,'0')),
if (idx>12) { 'qtyN1', 'qtyN2', 'qtyN3'
let a = null ]
if (idx==13)a=1 const noteKeys = [
if (idx==14)a=2 ...Array.from({length: 12}, (_, i) => 'note' + String(i+1).padStart(2,'0')),
if (idx==15)a=3 'noteN1', 'noteN2', 'noteN3'
v.month = '次年'+a+'月' ]
} 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(() => { setTimeout(() => {
numCount() numCount(null)
}, 500); }, 500);
} }
const numCount = (record) => { const numCount = (record) => {
@ -363,8 +350,8 @@
let k = '' let k = ''
let kn = '' let kn = ''
if (idx<12) { if (idx<12) {
k = 'qty'+(idx<9 ? ('0'+(idx+1)) : idx+1) k = 'qty'+ String(idx+1).padStart(2,'0')
kn = 'note'+(idx<9 ? ('0'+(idx+1)) : idx+1) kn = 'note'+ String(idx+1).padStart(2,'0')
} }
if (idx>12) { if (idx>12) {
let a = null let a = null