ttk-app-core
Version:
enterprise develop framework
92 lines (87 loc) • 2.69 kB
JavaScript
function sortBaseArchives(data){
const sortData = ['芒果','草莓', '橘子', '猕猴桃', '杨梅', '苹果']
const constant = {
'草莓': 'supplierId',
'苹果': 'inventoryId',
'芒果': 'customerId',
'猕猴桃': 'departmentId',
'橘子': 'projectId',
'杨梅': 'personId',
'自定义档案': true,
}
const arr = []
sortData.forEach((key) => {
if( data[key] ){
const value = data[key]
const arr2 = []
value.forEach(item => {
arr2.push({
label: item.name,
value: item.id
})
})
let item = {
name: key,
key: constant[key],
children: arr2
}
arr.push(item)
}
})
for( const [key, value] of Object.entries(data) ) {
if( constant[key] == true ) {
const zidingyiArr = value
for( const value of zidingyiArr.values() ){
const childrenArr = []
if( value.userDefineArchiveDataList ) {
for( const item of value.userDefineArchiveDataList.values() ) {
childrenArr.push({
label: item.name,
value: item.id
})
}
}
arr.push({
name: value.name,
key: value.calcName,
children: childrenArr
})
}
}
}
return arr
}
function changeToOption(data, label = 'label', key = 'value') {
return data.map(item => {
return {
label: item[label],
value: item[key].toString()
}
})
}
function sortSearchOption(data, mode, delKey) {
if (mode) {
for (const [key, value] of Object.entries(mode)) {
let val = data[key]
if (typeof value == 'string') {
data[value] = val
} else if (typeof value == 'object') {
for (const [index, item] of Object.entries(value)) {
data[index] = item(val)
}
}
delete data[key]
}
}
if (delKey) {
delKey.forEach(item => {
try {
delete data[item]
} catch (err) {
console.log(err)
}
})
}
return data
}
export { sortBaseArchives, changeToOption, sortSearchOption }