import { observable, action, runInAction } from "mobx";
import { fetchJSON } from '@/utils/request';
import { urlParams, HOST_NAME } from '@/utils/common';
import  * as Skeleton from '@/stores/Skeleton';

export class UserStore {
    @observable itinerary=Skeleton.itineraryList;
    @observable operation = Skeleton.operation;
    @observable orderDetail = Skeleton.orderDetail;
    constructor(appStore){
        this.appStore = appStore;
    }
    @action getItinerary(search){
        const userid = this.appStore.userid || urlParams(search).userid;
        const url = HOST_NAME + '/wechat-order/itinerary?userid='+userid;
        fetchJSON(url).then(json => {
            runInAction(() => {
                this.itinerary = json.itineraryList;
            })
        })
    }
    @action itineraryDetail(coli) {
        const url = HOST_NAME + '/wechat-order/detail/' + coli;
        fetchJSON(url).then(json => {
            runInAction(() => {
                this.orderDetail = json;
            })
        })
    }
    @action orderTrack(orderId) {
        const url = 'https://www.mycht.cn/webht.php/apps/trippestordersync/api/operation_detail?q=' + orderId
        fetchJSON(url).then(json => {
            runInAction(() => {
                this.operation = json;
            })
        })
    }
    @action paidCallback(outTradeNo) {
        const url = HOST_NAME + '/wechat-order/paid?outTradeNo=' + outTradeNo;
        fetchJSON(url).then(json => {
            runInAction(() => {
                this.orderDetail.paidQuote = json.paidQuote;
            })
        })
    }
}

export default UserStore;
