import { makeAutoObservable, runInAction } from "mobx"; import { fetchJSON } from '@/utils/request'; import { HT_HOST } from "@/config"; import { prepareUrl } from '@/utils/commons'; class Reservation { constructor(root) { makeAutoObservable(this, { rootStore: false }); this.root = root; } fetchReservationList(current, referenceNo, fromDate, thruDate) { this.reservationPage.current = current; const fetchUrl = prepareUrl(HT_HOST + '/service-cusservice/GetPlanSearchList') .append('VEI_SN', this.root.authStore.login.travelAgencyId) .append('GroupNo', referenceNo) .append('DateStart', fromDate) .append('DateEnd', thruDate) .append('TotalNum', 0) .append('PageSize', this.reservationPage.size) .append('PageIndex', this.reservationPage.current) .build(); return fetchJSON(fetchUrl) .then(json => { runInAction(() => { if (json.errcode == 0) { this.reservationList = json.Result.map((data, index) => { return { key: data.vas_gri_sn, referenceId: data.vas_gri_sn, referenceNumber: data.GriName, arrivalDate: data.GetGDate, pax: data.PersonNum, status: data.GState, reservationDate: data.GetGDate, guide: data.Guide } }); this.reservationPage.total = json.Result[0].RsTotal; } else { throw new Error(json.errmsg + ': ' + json.errcode); } }); }); } fetchReservation(reservationId) { const fetchUrl = prepareUrl(HT_HOST + '/service-cusservice/GetPlanInfo') .append('VEI_SN', this.root.authStore.login.travelAgencyId) .append('GRI_SN', reservationId) .build(); return fetchJSON(fetchUrl) .then(json => { runInAction(() => { if (json.errcode == 0) { this.itineraryList = json.VendorTour.map((data, index) => { return { key: data.GRD_SN, day: data.GRD_OrderDate, placeTransport: data.GRD_Traffic, todayActivities: data.GRD_LandscapeWL, accommodation: data.GRD_Hotel, meals: data.GRD_Meal_L + data.GRD_Meal_S, } }); this.reservationDetail = { referenceNumber: json.PlanDetail[0].GRI_Name, tourGuide: json.PlanDetail[0].Guide, arrivalDate: json.PlanDetail[0].eoi_getdate }; this.meetAndGreet = { customerNames: json.JJPInfo[0].CustomerName, referenceNumber: json.JJPInfo[0].GroupName, pax: json.JJPInfo[0].Str_PersonNum }; this.customerNames = json.CusAndRequest[0].GCI_CustomerList; } else { throw new Error(json.errmsg + ': ' + json.errcode); } }); }); } fetchCityList(reservationId) { const fetchUrl = prepareUrl(HT_HOST + '/service-cusservice/PTGetCityGuide') .append('VEI_SN', this.root.authStore.login.travelAgencyId) .append('GRI_SN', reservationId) .append('LGC', 1) .build(); return fetchJSON(fetchUrl) .then(json => { runInAction(() => { if (json.errcode == 0) { this.cityList = json.Result.map((data, index) => { return { key: data.CII_SN, cityName: data.CityName, tourGuideId: data.TGI_SN, tourGuide: data.GuideName, } }); } else { throw new Error(json.errmsg + ': ' + json.errcode); } }); }); } cityList = []; reservationList = []; reservationDetail = { referenceNumber: '', arrivalDate: '', tourGuide: '' }; meetAndGreet = { referenceNumber: '', customerNames: '', pax: '' } reservationPage = { current: 1, size: 10, total: 0 } itineraryList = [ ]; customerNames = ''; } export default Reservation;