public SearchViewModel()
        {
            SearchHistoryList = new ObservableCollection <string>();

            //InitSearchPage();

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

                if (string.IsNullOrEmpty(str))
                {
                    CrossToastPopUp.Current.ShowToastWarning("请输入关键词", ToastLength.Short);
                }
                else
                {
                    if (!SearchHistoryList.Contains(str))
                    {
                        SearchedItem searchedItem = new SearchedItem
                        {
                            createTime     = DateTime.UtcNow.ToString(),
                            searchedString = str
                        };
                        await LocalDatabaseHelper <SearchedItem> .InsertOrReplaceAsync(searchedItem);
                    }

                    ProductListPage productListPage = new ProductListPage(str);
                    SearchString = "";
                    await Application.Current.MainPage.Navigation.PushAsync(productListPage);
                }
            }, (str) => { return(true); });

            ClearCommand = new Command(async() =>
            {
                bool action = await Application.Current.MainPage.DisplayAlert("确认", "删除所有搜索历史?", "确认", "取消");
                if (action)
                {
                    await localDatabaseService.DeleteAllSearchedItem();
                    InitSearchPage();
                }
            }, () => { return(true); });
        }
        private async void InitHomePage()
        {
            try
            {
                if (!Tools.IsNetConnective())
                {
                    CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Long);
                    return;
                }

                string result1 = await RestSharpHelper <string> .GetAsyncWithoutDeserialization("/goods/home");

                if (!string.IsNullOrWhiteSpace(result1))
                {
                    HomeContentRD homeContentRD = JsonConvert.DeserializeObject <HomeContentRD>(result1);
                    HotProductList = homeContentRD.result[1].panelContents.ToList();


                    await LocalDatabaseHelper <HomePanelContent> .InsertByList(HotProductList);
                }
                else
                {
                    HotProductList = await LocalDatabaseHelper <HomePanelContent> .GetAllItems();
                }

                string result2 = await RestSharpHelper <string> .GetAsyncWithoutDeserialization("/goods/SearchAllItemCat");

                if (!string.IsNullOrWhiteSpace(result2))
                {
                    CategoryRD categoryRD = JsonConvert.DeserializeObject <CategoryRD>(result2);

                    List <Category> temp = new List <Category>();
                    foreach (var item in categoryRD.result)
                    {
                        if (!item.isParent)
                        {
                            temp.Add(item);
                        }
                    }
                    await LocalDatabaseHelper <Category> .InsertByList(categoryRD.result);

                    CatList = temp.GetRange(0, 10);
                }
                else
                {
                    List <Category> temp = new List <Category>();
                    List <Category> localCategoryList = await LocalDatabaseHelper <Category> .GetAllItems();

                    foreach (var item in localCategoryList)
                    {
                        if (!item.isParent)
                        {
                            temp.Add(item);
                        }
                    }
                    CatList = temp.GetRange(0, 10);
                }

                //RestSharpService _restSharpService = new RestSharpService();
                //HomeContentRD homeContentRD = await RestSharpService.GetHomeContent();
                //CategoryRD categoryRD = await RestSharpService.GetCategories();

                //CarouselList = homeContentRD.result[0].panelContents.ToList<HomePanelContent>();
                //HotProductList = homeContentRD.result[1].panelContents.ToList<HomePanelContent>();
                //OfficialChoiceList = homeContentRD.result[2].panelContents.ToList<HomePanelContent>();
                //GoodBrandList = homeContentRD.result[3].panelContents.ToList<HomePanelContent>();
                //BrandChoiceList = homeContentRD.result[4].panelContents.ToList<HomePanelContent>();

                CarouselList = new List <HomePanelContent>
                {
                    new HomePanelContent
                    {
                        picUrl  = "sanye.png",
                        fullUrl = "http://www.sanecn.com/"
                    },
                    new HomePanelContent
                    {
                        picUrl  = "bianselong.jpg",
                        fullUrl = "http://www.cdbsljs.com/"
                    },
                    new HomePanelContent
                    {
                        picUrl  = "jiabei.jpg",
                        fullUrl = "http://www.cdbsljs.com/"
                    }
                };

                //List<Category> temp = new List<Category>();
                //foreach (var item in categoryRD.result)
                //{
                //    if (!item.isParent)
                //    {
                //        temp.Add(item);
                //    }
                //}
                //CatList = temp.GetRange(0, 10);
            }
            catch (Exception)
            {
                throw;
            }
        }