import { makeAutoObservable, runInAction, toJS } from 'mobx'; import * as req from '../utils/request'; import { isEmpty, sortBy, objectMapper } from '../utils/commons'; const modelMapper = { 'operator': { url: '/service-Analyse2/GetOperatorInfo', mapper: { op_id: [{ key: 'key' }, { key: 'value' }], cn_name: { key: 'label' }, en_name: { key: 'label_alias' }, }, }, 'country': { url: '/service-Analyse2/GetCountryInfo', mapper: { c_id: [{ key: 'key' }, { key: 'value' }], cn_name: { key: 'label' }, en_name: { key: 'label_alias' }, }, }, 'destination': { url: '/service-Analyse2/GetDestinationInfo/test', mapper: { id: [{ key: 'key' }, { key: 'value' }], cn_name: { key: 'label' }, en_name: { key: 'label_alias' }, }, }, 'vendor': { url: '/service-web/QueryData/GetVEIName', mapper: { CAV_VEI_SN: [{ key: 'key' }, { key: 'value' }], VEI2_CompanyBN: { key: 'label' }, }, }, 'creditcardbilltype': { url: '/service-web/QueryData/GetCreditCardBillType', mapper: { cb_billtype: [{ key: 'key' }, { key: 'value' }, { key: 'label' }], }, }, }; class DictData { constructor(appStore) { this.appStore = appStore; makeAutoObservable(this); } async fetchDictData(model = '', param={}) { const mkey = model.toLowerCase(); this[mkey] = { loading: true, dataSource: [] }; const json = await req.fetchJSON(modelMapper[mkey].url, param); if (json.errcode === 0) { runInAction(() => { this[mkey].loading = false; this[mkey].dataSource = objectMapper(json.result, modelMapper[mkey].mapper); // console.log({ loading: false, ...json }, model, 'DictData', toJS(this[mkey])); }); } return this[mkey]; } data = {}; operator = { loading: false, dataSource: [] }; country = { loading: false, dataSource: [] }; vendor = { loading: false, dataSource: [] }; creditcardbilltype = { loading: false, dataSource: [] }; } export default DictData;