import { useBasicSettingStore } from '@/stores/basicsetting'
import api from '@/utils/api'

export const getBasicConfig = async (tag = 'item_bottom') => {
  const basicSettingStore = useBasicSettingStore()
  if (basicSettingStore[tag]) {
    return basicSettingStore[tag]
  } else {
    try {
      const res = await api.get('/auto/config')
      if (res.code === 200) {
        basicSettingStore.setItemBottom(res.data.item_bottom)
        basicSettingStore.setAllowanceBottom(res.data.allowance_bottom)
        basicSettingStore.setAllowanceInvoice(res.data.allowance_invoice)
        basicSettingStore.setAllowanceInsuranc(res.data.allowance_insuranc)
        basicSettingStore.setBuyContract(res.data.buy_contract)
        return basicSettingStore[tag]
      } else {
        return null
      }
    } catch (error) {
      console.error('获取失败:', error);
      return null
    }
  }

}