1. 程式人生 > >vue methods裡面函式之間的呼叫

vue methods裡面函式之間的呼叫

 //優惠券領取
        code(CouponCode, Id) {
            var data = new URLSearchParams();
            data.append('PValue', this.parseUrl(window.location.href).p || '');
            data.append('CouponCode', CouponCode);
            data.append('Id', Id);
            var _that = this;
            axios.post(codeUrl, data)
                .then(function (response) {
                    const data = response.data;
                    if (data.Data.Code == 200) {
                        layerApp.open({
                            content: data.Data.Message,
                            skin: 'msg'
                            , time: 3000
                        });
                    }
                    else if (data.Code == 299) {
                        _that.ifAPPLogin(data.Data.LoginRedirectUrl)
                    }
                    else {
                        layerApp.open({
                            content: data.Data.Message,
                            skin: 'msg'
                            , time: 3000
                        });
                    }
                }).finally((res) => {
                })
                .catch(function (error) {
                    console.warn(error)
                });
        },
        //登入
        ifAPPLogin(redirectUrl) {
            var customer = this.ShowCus();
            var url = window.location.href;
            url = url.replace(/\&/g, '&');
            switch (customer) {
                case "wap":
                    layerApp.open({
                        content: "請用萬里行賬號登入",
                        btn: "確定",
                        yes: () => {
                            layerApp.closeAll();
                            window.location.href = "http://m.ceair.com/mobile/user/user!loginOtherPage.shtml?channel=712&redirectUrl=" + redirectUrl;
                        }
                    });
                    break;
                case "Android":
                    Login.clickOnLogin(url, this.ShareTitle, "ffp_login");
                    break;
                case "IOS":
                    clickOnLogin(url, this.ShareTitle, "ffp_login");
                    break;
                case "WP":
                    external.notify("clickOnLogin?" + url + "&" + this.ShareTitle + "&ffp_login");
                    break;
            }
        },
        //判斷客戶端型別
        ShowCus() {
            var u = navigator.userAgent,
                w = window.location.href,
                t = this.parseUrl(w);
            if (!app.isInApp()) {
                return "wap";
            }
            if (u.match(/Android/i) != null) { //android裝置
                return "Android";
            } else if (u.match(/iPhone|iPod/i) != null) { //IOS
                return "IOS";
            } else {
                return "WP";
            }
        },
        //取p值
        parseUrl(url) {
            var pattern = /(\w+)=([^\#&]*)/ig,
                parames = {};
            url = url || window.location.href;
            url.replace(pattern, function (attr, key, value) {
                parames[key] = decodeURI(value);
            });
            return parames;
        }