|
|
|
|
import { makeAutoObservable, runInAction } from "mobx"
|
|
|
|
|
import { create } from 'zustand'
|
|
|
|
|
import { fetchJSON, postForm } from '@/utils/request'
|
|
|
|
|
import { HT_HOST } from "@/config"
|
|
|
|
|
import { prepareUrl } from '@/utils/commons'
|
|
|
|
|
import { useStorage } from '@/hooks/useStorage'
|
|
|
|
|
|
|
|
|
|
export const fetchCityList = async (travelAgencyId, reservationId) => {
|
|
|
|
|
const { errcode, Result } = await fetchJSON(
|
|
|
|
|
`${HT_HOST}/service-cusservice/PTGetCityGuide`,
|
|
|
|
|
{ VEI_SN: travelAgencyId, GRI_SN: reservationId, LGC: 1 })
|
|
|
|
|
return errcode !== 0 ? {} : Result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const fetchPlanDetail = async (travelAgencyId, reservationId) => {
|
|
|
|
|
const json = await fetchJSON(
|
|
|
|
|
`${HT_HOST}/service-cusservice/GetPlanInfo`,
|
|
|
|
|
{ VEI_SN: travelAgencyId, GRI_SN: reservationId })
|
|
|
|
|
|
|
|
|
|
if (json.errcode == 0) {
|
|
|
|
|
return {
|
|
|
|
|
planDetail: json.PlanDetail[0],
|
|
|
|
|
planChangeList: json.PlanChange??[]
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const fetchAttachList = async (reservationId) => {
|
|
|
|
|
|
|
|
|
|
const { errcode, result } = await fetchJSON(
|
|
|
|
|
`${HT_HOST}/service-fileServer/PlanChangeFileList`,
|
|
|
|
|
{ GRI_SN: reservationId })
|
|
|
|
|
return errcode !== 0 ? {} : result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const useReservationStore = create((set, get) => ({
|
|
|
|
|
|
|
|
|
|
cityList: [],
|
|
|
|
|
|
|
|
|
|
selectedReservation: null,
|
|
|
|
|
selectedConfirmation: null,
|
|
|
|
|
arrivalDateRange: [],
|
|
|
|
|
referenceNo: '',
|
|
|
|
|
|
|
|
|
|
reservationList: [],
|
|
|
|
|
|
|
|
|
|
reservationDetail: {
|
|
|
|
|
referenceNumber: '', arrivalDate: '', tourGuide: ''
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
reservationPage: {
|
|
|
|
|
current: 1,
|
|
|
|
|
size: 10,
|
|
|
|
|
total: 0
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
confirmationList: [
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
getCityListByReservationId: async (reservationId) => {
|
|
|
|
|
const { travelAgencyId } = useStorage()
|
|
|
|
|
set(() => ({
|
|
|
|
|
cityList: []
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
const cityListJson = await fetchCityList(travelAgencyId, reservationId)
|
|
|
|
|
const mapCityList = cityListJson.map((data) => {
|
|
|
|
|
return {
|
|
|
|
|
key: data.CII_SN,
|
|
|
|
|
cityId: data.CII_SN,
|
|
|
|
|
cityName: data.CityName,
|
|
|
|
|
tourGuideId: data.TGI_SN,
|
|
|
|
|
tourGuide: data.GuideName
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
set(() => ({
|
|
|
|
|
cityList: mapCityList
|
|
|
|
|
}))
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
selectReservation: (reservation) => {
|
|
|
|
|
set(() => ({
|
|
|
|
|
selectedReservation: reservation
|
|
|
|
|
}))
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
selectConfirmation: (confirmation) => {
|
|
|
|
|
set(() => ({
|
|
|
|
|
selectedConfirmation: confirmation
|
|
|
|
|
}))
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
fetchReservationList: (formVal, current=1) => {
|
|
|
|
|
const { travelAgencyId } = useStorage()
|
|
|
|
|
const { reservationPage } = get()
|
|
|
|
|
// 设置为 0,后端会重新计算总数,当跳转第 X 页时可用原来的总数。
|
|
|
|
|
const totalNum = current == 1 ? 0 : reservationPage.total;
|
|
|
|
|
const fetchUrl = prepareUrl(HT_HOST + '/service-cusservice/GetPlanSearchList')
|
|
|
|
|
.append('VEI_SN', travelAgencyId)
|
|
|
|
|
.append('GroupNo', formVal.referenceNo)
|
|
|
|
|
.append('DateStart', formVal.startdate)
|
|
|
|
|
.append('DateEnd', formVal.enddate)
|
|
|
|
|
.append('NotConfirm', '')//status)// Todo: 待解决
|
|
|
|
|
.append('TotalNum', totalNum)
|
|
|
|
|
.append('PageSize', reservationPage.size)
|
|
|
|
|
.append('PageIndex', current)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
return fetchJSON(fetchUrl)
|
|
|
|
|
.then(json => {
|
|
|
|
|
if (json.errcode == 0) {
|
|
|
|
|
const mapReservationList = (json?.Result??[]).map((data, index) => {
|
|
|
|
|
return {
|
|
|
|
|
key: data.vas_gri_sn,
|
|
|
|
|
reservationId: data.vas_gri_sn,
|
|
|
|
|
referenceNumber: data.GriName,
|
|
|
|
|
arrivalDate: data.GetGDate,
|
|
|
|
|
pax: data.PersonNum,
|
|
|
|
|
status: data.GState,
|
|
|
|
|
reservationDate: data.SendDate,
|
|
|
|
|
guide: data.Guide
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
set((state) => ({
|
|
|
|
|
reservationList: mapReservationList,
|
|
|
|
|
reservationPage: {
|
|
|
|
|
...
|
|
|
|
|
state.reservationPage,
|
|
|
|
|
current: current,
|
|
|
|
|
total: (json?.Result??[{RsTotal: 0}])[0].RsTotal
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(json.errmsg + ': ' + json.errcode);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
fetchAllGuideList: () => {
|
|
|
|
|
const { userId, travelAgencyId } = useStorage()
|
|
|
|
|
const fetchUrl = prepareUrl(HT_HOST + '/service-cusservice/PTGetGuideList')
|
|
|
|
|
.append('VEI_SN', travelAgencyId)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
return fetchJSON(fetchUrl)
|
|
|
|
|
.then(json => {
|
|
|
|
|
if (json.errcode == 0) {
|
|
|
|
|
const guideList = (json?.Result??[]).map((data, index) => {
|
|
|
|
|
return {
|
|
|
|
|
guideId: data.TGI_SN,
|
|
|
|
|
guideName: data.TGI2_Name,
|
|
|
|
|
mobileNo: data.TGI_Mobile
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return guideList;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(json.errmsg + ': ' + json.errcode);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getReservationDetail: async (travelAgencyId, reservationId) => {
|
|
|
|
|
const { planDetail, planChangeList } = await fetchPlanDetail(travelAgencyId, reservationId)
|
|
|
|
|
const attachListJson = await fetchAttachList(reservationId)
|
|
|
|
|
|
|
|
|
|
const mapConfirmationList = planChangeList.map((data) => {
|
|
|
|
|
const filterAttchList = attachListJson.filter(attch => {
|
|
|
|
|
return attch.PCI_SN === data.PCI_SN;
|
|
|
|
|
});
|
|
|
|
|
return {
|
|
|
|
|
key: data.PCI_SN,
|
|
|
|
|
PCI_Changetext: data.PCI_Changetext,
|
|
|
|
|
PCI_SendDate: data.PCI_SendDate,
|
|
|
|
|
ConfirmPerson: data.ConfirmPerson,
|
|
|
|
|
PCI_ConfirmText: data.PCI_ConfirmText,
|
|
|
|
|
PCI_ConfirmDate: data.PCI_ConfirmDate,
|
|
|
|
|
VAS_SN: data.PCI_VAS_SN,
|
|
|
|
|
attachmentList: filterAttchList
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
set(() => ({
|
|
|
|
|
reservationDetail: {
|
|
|
|
|
referenceNumber: planDetail.GRI_Name,
|
|
|
|
|
tourGuide: planDetail.Guide,
|
|
|
|
|
arrivalDate: planDetail.eoi_getdate,
|
|
|
|
|
reservationId: reservationId
|
|
|
|
|
},
|
|
|
|
|
confirmationList: mapConfirmationList
|
|
|
|
|
}))
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submitConfirmation: (userId, travelAgencyId, confirmText) => {
|
|
|
|
|
const { selectedConfirmation, getReservationDetail, reservationDetail } = get()
|
|
|
|
|
const formData = new FormData()
|
|
|
|
|
formData.append('PCI_SN', selectedConfirmation.key)
|
|
|
|
|
formData.append('OPSN', userId)
|
|
|
|
|
formData.append('ConfirmText', confirmText)
|
|
|
|
|
formData.append('VAS_SN', selectedConfirmation.VAS_SN)
|
|
|
|
|
|
|
|
|
|
const postUrl = HT_HOST + '/service-cusservice/PTConfirmPlanChange'
|
|
|
|
|
|
|
|
|
|
return postForm(postUrl, formData)
|
|
|
|
|
.then(json => {
|
|
|
|
|
if (json.errcode == 0 && json.Result.length == 1) {
|
|
|
|
|
// this.fetchReservation(this.reservationDetail.reservationId);
|
|
|
|
|
getReservationDetail(travelAgencyId, reservationDetail.reservationId)
|
|
|
|
|
return json
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
export default useReservationStore
|
|
|
|
|
|
|
|
|
|
export class Reservation {
|
|
|
|
|
|
|
|
|
|
constructor(root) {
|
|
|
|
|
makeAutoObservable(this, { rootStore: false });
|
|
|
|
|
this.root = root;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateReservationGuide() {
|
|
|
|
|
const fetchUrl = prepareUrl(HT_HOST + '/service-cusservice/PTGetCityGuide')
|
|
|
|
|
.append('VEI_SN', this.root.authStore.login.travelAgencyId)
|
|
|
|
|
.append('GRI_SN', this.selectedReservation.reservationId)
|
|
|
|
|
.append('LGC', 1)
|
|
|
|
|
.append("token", this.root.authStore.login.token)
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
return fetchJSON(fetchUrl)
|
|
|
|
|
.then(json => {
|
|
|
|
|
if (json.errcode == 0) {
|
|
|
|
|
const reservationGuide = (json?.Result??[]).filter((data) => {
|
|
|
|
|
return data.TGI_SN != 0;
|
|
|
|
|
}).map((data) => {
|
|
|
|
|
return data.GuideName;
|
|
|
|
|
}).join(',');
|
|
|
|
|
runInAction(() => {
|
|
|
|
|
this.selectedReservation.guide = reservationGuide;
|
|
|
|
|
});
|
|
|
|
|
return reservationGuide;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(json.errmsg + ': ' + json.errcode);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setupCityGuide(cityId, guideId) {
|
|
|
|
|
let formData = new FormData();
|
|
|
|
|
formData.append('GRI_SN', this.selectedReservation.reservationId);
|
|
|
|
|
formData.append('VEI_SN', this.root.authStore.login.travelAgencyId);
|
|
|
|
|
formData.append('TGI_SN', guideId);
|
|
|
|
|
formData.append('CII_SN', cityId);
|
|
|
|
|
formData.append('GetDate', this.selectedReservation.reservationDate);
|
|
|
|
|
formData.append('LMI_SN', this.root.authStore.login.userId);
|
|
|
|
|
formData.append("token", this.root.authStore.login.token);
|
|
|
|
|
const postUrl = HT_HOST + '/service-cusservice/PTAddGuide';
|
|
|
|
|
|
|
|
|
|
return postForm(postUrl, formData)
|
|
|
|
|
.then(json => {
|
|
|
|
|
if (json.errcode != 0) {
|
|
|
|
|
throw new Error(json.errmsg + ': ' + json.errcode);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updatePropertyValue(name, value) {
|
|
|
|
|
runInAction(() => {
|
|
|
|
|
this[name] = value;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cityList = [];
|
|
|
|
|
|
|
|
|
|
selectedReservation = null;
|
|
|
|
|
selectedConfirmation = null;
|
|
|
|
|
arrivalDateRange = [];
|
|
|
|
|
referenceNo = '';
|
|
|
|
|
|
|
|
|
|
reservationList = [];
|
|
|
|
|
|
|
|
|
|
reservationDetail = {
|
|
|
|
|
referenceNumber: '', arrivalDate: '', tourGuide: ''
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
reservationPage = {
|
|
|
|
|
current: 1,
|
|
|
|
|
size: 10,
|
|
|
|
|
total: 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
confirmationList = [
|
|
|
|
|
];
|
|
|
|
|
}
|