예제 #1
0
        public HomeViewModel()
        {
            CarouselList   = new List <HomePanelContent>();
            CatList        = new List <Category>();
            HotProductList = new List <HomePanelContent>();

            MemberVisible = GlobalVariables.IsLogged;

            InitHomePage();

            //TimerCallback timerDelegate = new TimerCallback(Tick);
            //timer = new Timer(timerDelegate, null, 0, 5000); //5秒执行一次Tick方法

            CarouselTappedCommand = new Command <int>((position) =>
            {
                string url      = CarouselList[position].fullUrl;
                WebPage webPage = new WebPage(url);
                Application.Current.MainPage.Navigation.PushModalAsync(webPage);
            }, (position) => { return(true); });

            FindMoreCommand = new Command <int>((id) =>
            {
                foreach (var item in CatList)
                {
                    if (item.id == id)
                    {
                        ProductListPage productListPage = new ProductListPage(item);
                        Application.Current.MainPage.Navigation.PushModalAsync(productListPage);
                    }
                }
            }, (id) => { return(true); });

            SearchCommand = new Command(() =>
            {
                if (!Tools.IsNetConnective())
                {
                    CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Long);
                    return;
                }

                if (string.IsNullOrEmpty(SearchString))
                {
                    CrossToastPopUp.Current.ShowToastWarning("请输入关键词", ToastLength.Short);
                }
                else
                {
                    ProductListPage productListPage = new ProductListPage(SearchString);
                    SearchString = "";
                    Application.Current.MainPage.Navigation.PushModalAsync(productListPage);
                }
            }, () => { return(true); });

            NavigateCommand = new Command <string>((pageName) =>
            {
                Type type = Type.GetType(pageName);
                Page page = (Page)Activator.CreateInstance(type);
                Application.Current.MainPage.Navigation.PushModalAsync(page);
            }, (pageName) => { return(true); });

            ItemTapCommand = new Command <long>((id) =>
            {
                ProductDetailPage productDetailPage = new ProductDetailPage(id.ToString());
                Application.Current.MainPage.Navigation.PushModalAsync(productDetailPage);
            }, (id) => { return(true); });

            MoreCatCommand = new Command(() =>
            {
                FindMorePage findMorePage = new FindMorePage();
                Application.Current.MainPage.Navigation.PushModalAsync(findMorePage);
            }, () => { return(true); });
        }
예제 #2
0
        public HomeViewModel()
        {
            CarouselList   = new List <HomePanelContent>();
            CatList        = new List <Category>();
            HotProductList = new List <HomePanelContent>();

            MemberVisible = GlobalVariables.IsLogged;

            InitHomePage();

            CarouselTappedCommand = new Command <int>((position) =>
            {
                string url      = CarouselList[position].fullUrl;
                WebPage webPage = new WebPage(url);
                Application.Current.MainPage.Navigation.PushAsync(webPage);
            }, (position) => { return(true); });

            FindMoreCommand = new Command <int>((id) =>
            {
                foreach (var item in CatList)
                {
                    if (item.id == id)
                    {
                        ProductListPage productListPage = new ProductListPage(item);
                        Application.Current.MainPage.Navigation.PushAsync(productListPage);
                    }
                }
            }, (id) => { return(true); });

            SearchCommand = new Command(() =>
            {
                SearchPage searchPage = new SearchPage();
                Application.Current.MainPage.Navigation.PushAsync(searchPage);
            }, () => { return(true); });

            NavigateCommand = new Command <string>((pageName) =>
            {
                Type type = Type.GetType(pageName);
                Page page = (Page)Activator.CreateInstance(type);
                Application.Current.MainPage.Navigation.PushAsync(page);
            }, (pageName) => { return(true); });

            ItemTapCommand = new Command <long>((id) =>
            {
                ProductDetailPage productDetailPage = new ProductDetailPage(id.ToString());
                //NavigationPage navigationPage = new NavigationPage(productDetailPage);
                Application.Current.MainPage.Navigation.PushAsync(productDetailPage);
            }, (id) => { return(true); });

            MoreCatCommand = new Command(() =>
            {
                FindMorePage findMorePage = new FindMorePage();
                Application.Current.MainPage.Navigation.PushAsync(findMorePage);
            }, () => { return(true); });

            GetRebateCommand = new Command(() =>
            {
                try
                {
                    if (!string.IsNullOrWhiteSpace(PasteString))
                    {
                        string paras         = PasteString.Split('#')[2];
                        byte[] bytes         = Convert.FromBase64String(paras);
                        string decodedString = System.Text.Encoding.Default.GetString(bytes);

                        JObject json = JObject.Parse(decodedString);
                        ProductDetailPage productDetailPage = new ProductDetailPage(json["p"].ToString());
                        Application.Current.MainPage.Navigation.PushAsync(productDetailPage);
                    }
                }
                catch (Exception)
                {
                    CrossToastPopUp.Current.ShowToastError("出现错误。", ToastLength.Short);
                    throw;
                }
            }, () => { return(true); });
        }