代码优化
This commit is contained in:
@ -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 {
|
||||||
|
|||||||
@ -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')) {
|
// 按顺序构建 qty key:qty01~qty12,qtyN1~qtyN3
|
||||||
dataList.value.push({'qty': objPng[k]})
|
const qtyKeys = [
|
||||||
}
|
...Array.from({length: 12}, (_, i) => 'qty' + String(i+1).padStart(2,'0')),
|
||||||
}
|
'qtyN1', 'qtyN2', 'qtyN3'
|
||||||
let lngkeys = []
|
]
|
||||||
for(let k in objLng) {
|
const noteKeys = [
|
||||||
if (k.includes('qty')) {
|
...Array.from({length: 12}, (_, i) => 'note' + String(i+1).padStart(2,'0')),
|
||||||
lngkeys.push({lng: k, value : objLng[k]})
|
'noteN1', 'noteN2', 'noteN3'
|
||||||
}
|
]
|
||||||
}
|
const monthLabels = [
|
||||||
lngkeys.forEach((i,idx)=> {
|
...Array.from({length: 12}, (_, i) => (i+1)+'月'),
|
||||||
dataList.value[idx].lng = i.value
|
'次年1月', '次年2月', '次年3月'
|
||||||
dataList.value[idx].note = noteKeys[idx].value
|
]
|
||||||
})
|
|
||||||
let totalObj = {month: '合计'}
|
qtyKeys.forEach((k, idx) => {
|
||||||
dataList.value.splice(12,0,totalObj)
|
dataList.value.push({
|
||||||
dataList.value.forEach((v,idx)=> {
|
month: monthLabels[idx],
|
||||||
|
qty: objPng[k] ?? null,
|
||||||
if (idx<12) {
|
lng: objLng[k] ?? null,
|
||||||
v.month = (idx+1)+'月'
|
note: data[noteKeys[idx]] ?? null,
|
||||||
}
|
})
|
||||||
if (idx>12) {
|
|
||||||
let a = null
|
|
||||||
if (idx==13)a=1
|
|
||||||
if (idx==14)a=2
|
|
||||||
if (idx==15)a=3
|
|
||||||
v.month = '次年'+a+'月'
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 在第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
|
||||||
|
|||||||
Reference in New Issue
Block a user