import request from '@/utils/request'
import { upcloud_base_strategy } from '@/config/serviceSettings'
import store from '../../../store'

let _business = null

export function getBusiness(val) {
  let resCodeData = 'wms_enterprise'
  if (val) resCodeData = val
  return new Promise((resolve, reject) => {
    if (_business) {
      resolve(_business)
      return
    }
    request({
      method: 'get',
      url: upcloud_base_strategy + '/registry/by-code',
      params: {
        regCode: resCodeData,
        warehouseId: store.getters.warehouse.warehouseId,
      },
    }).then((res) => {
      // debugger
      if (!res || !res.data) {
        _business = 'default'
        resolve('default')
      } else {
        _business = res.data.regValue
        resolve(res.data.regValue)
      }
    })
  })
}
