public AddToCartViewVM(ProductInfo productInfo)
        {
            Product     = productInfo;
            MallPrice   = Product.itemAttributeValues[0].mallPrice.ToString();
            MemberPrice = Product.itemAttributeValues[0].memberPrice.ToString();
            Index       = 0;

            //CusPriceVisible = GlobalVariables.LoggedUser.userType == "0";
            MemberPriceVisible = GlobalVariables.IsLogged;

            ProductNum = 1;

            AddToCartCommand = new Command(async() =>
            {
                if (GlobalVariables.IsLogged)
                {
                    AddToCartAsync();
                }
                await PopupNavigation.Instance.PopAsync();
            }, () => { return(true); });

            ToOrderCommand = new Command(async() =>
            {
                if (GlobalVariables.IsLogged)
                {
                    List <CartItemInfo> productList = new List <CartItemInfo>();

                    CartItemInfo cartItemInfo = new CartItemInfo();
                    Tools.AutoMapping <ProductInfo, CartItemInfo>(Product, cartItemInfo);
                    cartItemInfo.productNum       = 1;
                    cartItemInfo.productImg       = Product.productImageBig;
                    cartItemInfo.attributesValues = Product.itemAttributeValues[Index].attributeValue;

                    productList.Add(cartItemInfo);

                    OrderingPage orderingPage = new OrderingPage(productList);
                    await PopupNavigation.Instance.PopAsync();
                    await Application.Current.MainPage.Navigation.PushModalAsync(orderingPage);
                }
                else
                {
                    LoginPage loginPage = new LoginPage();
                    await PopupNavigation.Instance.PopAsync();
                    await Application.Current.MainPage.Navigation.PushModalAsync(loginPage);
                }
            }, () => { return(true); });

            SelectAttributeCommand = new Command(() =>
            {
                MallPrice   = Product.itemAttributeValues[Index].mallPrice.ToString();
                MemberPrice = Product.itemAttributeValues[Index].memberPrice.ToString();
            }, () => { return(true); });
        }
        public CartViewModel()
        {
            ItemList           = new List <CartItemInfo>();
            TotalSelectedPrice = "0";
            ItemNumber         = "0";
            CheckedNumber      = 0;
            //IsAllChecked = false;
            //AllCheckedButton_Color = Color.LightGray;

            InitCart();

            OrderCommand = new Command(() =>
            {
                List <CartItemInfo> productList = new List <CartItemInfo>();

                foreach (var item in ItemList)
                {
                    if (item.Checked)
                    {
                        productList.Add(item);
                    }
                }

                if (productList.Count == 0)
                {
                    CrossToastPopUp.Current.ShowToastError("没有选中商品", ToastLength.Long);
                }
                else
                {
                    OrderingPage orderingPage = new OrderingPage(productList);
                    Application.Current.MainPage.Navigation.PushModalAsync(orderingPage);
                }
            }, () => { return(true); });

            TwoTappedCommand = new Command <long>((id) =>
            {
                TwoTapped_TappedAsync(id);
            }, (id) => { return(true); });

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

            CheckedChangedCommand = new Command <long>((id) =>
            {
                /*
                 * foreach (var item in ItemList)
                 * {
                 *  if (item.productId == id)
                 *  {
                 *      item.Checked = !item.Checked;
                 *  }
                 * }*/

                OnCount();
            }, (id) => { return(true); });

            RefreshCommand = new Command(() =>
            {
                InitCart();
            }, () => { return(true); });
        }
Exemple #3
0
        public ProductDetailVM(string productId)
        {
            //CusPriceVisible = GlobalVariables.LoggedUser.userType == "0";
            MemberPriceVisible = GlobalVariables.IsLogged;
            VisitorVisible     = !MemberPriceVisible;

            Product         = new ProductInfo();
            StarSource      = "star_gray.png";
            IsCollected     = false;
            CusPriceVisible = false;

            BackCommand = new Command(() =>
            {
                Application.Current.MainPage.Navigation.PopModalAsync();
            }, () => { return(true); });

            AddToCartCommand = new Command(() =>
            {
                if (GlobalVariables.IsLogged)
                {
                    var page = new AddToCartView(Product);
                    PopupNavigation.Instance.PushAsync(page);
                }
                else
                {
                    LoginPage loginPage = new LoginPage();
                    Application.Current.MainPage.Navigation.PushModalAsync(loginPage);
                }
            }, () => { return(true); });

            BuyCommand = new Command(() =>
            {
                if (GlobalVariables.IsLogged)
                {
                    List <CartItemInfo> productList = new List <CartItemInfo>();

                    CartItemInfo cartItemInfo = new CartItemInfo();
                    Tools.AutoMapping <ProductInfo, CartItemInfo>(Product, cartItemInfo);
                    cartItemInfo.productNum = 1;
                    cartItemInfo.productImg = Product.productImageBig;

                    productList.Add(cartItemInfo);

                    OrderingPage orderingPage = new OrderingPage(productList);
                    Application.Current.MainPage.Navigation.PushModalAsync(orderingPage);
                }
                else
                {
                    LoginPage loginPage = new LoginPage();
                    Application.Current.MainPage.Navigation.PushModalAsync(loginPage);
                }
            }, () => { return(true); });

            ShareCommand = new Command(() =>
            {
                if (GlobalVariables.IsLogged)
                {
                    string para = "?productId=" + Product.productId + "&userId=" + GlobalVariables.LoggedUser.id;
                    MessagingCenter.Send(new object(), "Register");//首先进行注册,然后订阅注册的结果。
                    MessagingCenter.Send(new object(), "ShareToFriend", para);
                }
                else
                {
                    LoginPage loginPage = new LoginPage();
                    Application.Current.MainPage.Navigation.PushModalAsync(loginPage);
                }
            }, () => { return(true); });

            CallServiceCommand = new Command(() =>
            {
                try
                {
                    PhoneDialer.Open("18080961008");
                }
                catch (ArgumentNullException)
                {
                    // Number was null or white space
                    CrossToastPopUp.Current.ShowToastError("无联系方式", ToastLength.Short);
                }
                catch (FeatureNotSupportedException)
                {
                    // Phone Dialer is not supported on this device.
                    CrossToastPopUp.Current.ShowToastError("该设备不支持拨号", ToastLength.Short);
                }
                catch (Exception)
                {
                    // Other error has occurred.
                    CrossToastPopUp.Current.ShowToastError("出现其他错误", ToastLength.Short);
                }
            }, () => { return(true); });

            StarCommand = new Command(() =>
            {
                Collect();
            }, () => { return(true); });

            SpeakCommand = new Command(() =>
            {
                if (GlobalVariables.IsLogged)
                {
                    DependencyService.Get <ITextToSpeech>().Speak(Product.productName + " 市场价" + Product.mallPrice + "元 会员价" + Product.memberPrice + "元");
                }
                else
                {
                    DependencyService.Get <ITextToSpeech>().Speak(Product.productName + " 市场价" + Product.mallPrice + "元");
                }
            }, () => { return(true); });

            InitProductDetailPageAsync(productId);
        }