解决方案:使用promise
getUdfList() {
return new Promise((resolve, reject) => {
request({
method: 'GET',
url: '/v1/api/md/tmUdField/list',
params: { ...this.pageParams }
})
.then((res) => {
resolve(res)
})
.catch((e) => {
reject(e)
console.log('err', e)
})
})
},
getOptions() {
this.getUdfList().then((res) => {
let newData = []
res.data.records.forEach((item) => {
newData.push({
type: 'UD',
fieldName: item.unit == '' ? item.fieldName : `${item.fieldName}(${item.unit})`,
noUnitName: item.fieldName,
unit: item.unit,
objType: item.objectType
})
})
this.siteUdfList = newData.filter((item) => {
return item.objType == 'SITE_INFO'
})
this.operUdfList = newData.filter((item) => {
return item.objType == 'OPERATION_STEP_INFO'
})
this.partUdfList = newData.filter((item) => {
return item.objType == 'PART_INFO'
})
request({
method: 'GET',
url: this.selectUrl,
params: { ...this.pageParams, ...this.selectParams }
})
.then((res) => {
const cascaderData = res.data
if (cascaderData?.length > 0) {
cascaderData.map((item) => {
item.fields.forEach((e) => {
e.type = 'FIXED'
})
if (item.objectType == '节点信息') {
item.fields.push(...this.siteUdfList)
}
if (item.objectType == '运作环节信息') {
item.fields.push(...this.operUdfList)
}
if (item.objectType == '零件信息') {
item.fields.push(...this.partUdfList)
}
if (item.objectType == '备库计划') {
this.actuaryMode == 'PERIODIC_MODE' ? (this.isDisabled = false) : (this.isDisabled = true)
return Object.assign(item, { disabled: this.isDisabled })
}
})
this.options = JSON.parse(JSON.stringify(cascaderData).replace(/objectType/g, 'fieldName'))
console.log('this.options', this.options)
}
})
.catch((e) => {
console.log('err', e)
})
})
}