sh_real_name_system_web/src/utils/getCommonData.js

65 lines
1.9 KiB
JavaScript
Raw Normal View History

import store from '@/store'
import {
getCompanySelectListAPI,
getMainProjectListAllAPI,
getSubCompanySelectListAPI,
getLotProjectSelectListAPI,
} from '@/api/common'
// 获取公司下拉列表
export async function getCompanySelectListCommonFun() {
const { companySelectList } = store.state.common
// 先判断store中有没有 如果没有则直接调接口 如果有则取store中的数据
if (companySelectList.length > 0) {
return companySelectList
}
const res = await getCompanySelectListAPI()
if (res.code === 200) {
store.commit('SET_COMPANY_SELECT_LIST', res.rows)
return res.rows
}
return []
}
// 获取总包工程下拉列表
export async function getMainProjectListCommonFun() {
const { mainProjectList } = store.state.common
if (mainProjectList.length > 0) {
return mainProjectList
}
const res = await getMainProjectListAllAPI()
if (res.code === 200) {
store.commit('SET_MAIN_PROJECT_LIST', res.rows)
return res.rows
}
return []
}
// 获取分公司下拉列表
export async function getSubCompanySelectListCommonFun() {
const { subCompanySelectList } = store.state.common
if (subCompanySelectList.length > 0) {
return subCompanySelectList
}
const res = await getSubCompanySelectListAPI()
if (res.code === 200) {
store.commit('SET_SUB_COMPANY_SELECT_LIST', res.rows)
return res.rows
}
return []
}
// 获取标段工程下拉列表
export async function getLotProjectSelectListCommonFun() {
const { lotProjectSelectList } = store.state.common
if (lotProjectSelectList.length > 0) {
return lotProjectSelectList
}
const res = await getLotProjectSelectListAPI()
if (res.code === 200) {
store.commit('SET_LOT_PROJECT_SELECT_LIST', res.rows)
return res.rows
}
return []
}