From 7f04acaccb246bff94e9458960f7914cabc96f46 Mon Sep 17 00:00:00 2001 From: wurong <953969641@qq.com> Date: Mon, 26 Aug 2024 12:20:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=97=E9=93=BA=E5=85=85=E5=80=BC=EF=BC=9A?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=B2=A1=E6=9C=89=E6=95=B0=E6=8D=AE=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E6=97=B6=EF=BC=8C=E5=BA=94=E5=B1=95=E7=A4=BA=E6=96=87?= =?UTF-8?q?=E5=AD=97=E2=80=9C=E6=B2=A1=E6=9C=89=E6=89=BE=E5=88=B0=E7=9B=B8?= =?UTF-8?q?=E5=BA=94=E7=9A=84=E9=97=A8=E5=BA=97=EF=BC=8C=E8=AF=95=E8=AF=95?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E7=9A=84=E6=90=9C=E7=B4=A2=E2=80=9D;=20?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85html=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9B=20=E7=82=B9=E5=8D=95=E9=A1=B5?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=BC=93=E5=AD=98=E5=A4=84=E7=90=86=EF=BC=9B?= =?UTF-8?q?=20=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=A4=84=E7=90=86=20=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=BC=93=E5=AD=98=E5=A4=84=E7=90=86=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/home/home_page.dart | 13 +++++++-- lib/mine/mine_shop_page.dart | 2 +- lib/store/shop_details_page.dart | 22 +++++++++++++-- lib/store/store_order.dart | 23 ++++++++++++--- lib/store/store_view/store_order_list.dart | 33 ++++++++++++++++------ 5 files changed, 75 insertions(+), 18 deletions(-) diff --git a/lib/home/home_page.dart b/lib/home/home_page.dart index ef10a954..6d0b0e76 100644 --- a/lib/home/home_page.dart +++ b/lib/home/home_page.dart @@ -94,7 +94,6 @@ class HomePageState extends State with AutomaticKeepAliveClientMixin { @override void initState() { super.initState(); - eventBus.on().listen((event) { if (event.type < 3) { setState(() {}); @@ -169,6 +168,9 @@ class HomePageState extends State with AutomaticKeepAliveClientMixin { if (baseData != null && baseData.isSuccess) { bannerData = baseData.data.records; // if (bannerData.length > 0) swiperController.move(0, animation: false); + SharedPreferences.getInstance().then((value) { + value.setString("bannerData", jsonEncode(bannerData)); + }); } } finally { addLoadCount(); @@ -260,7 +262,9 @@ class HomePageState extends State with AutomaticKeepAliveClientMixin { "state": 1 }; BaseData> pageGoods = - await apiService.creditGoods(param).catchError((onError) {}); + await apiService.creditGoods(param).catchError((onError) { + debugPrint("error${onError}"); + }); if (pageGoods != null && pageGoods.isSuccess) { goods = pageGoods.data.list; } @@ -358,6 +362,11 @@ class HomePageState extends State with AutomaticKeepAliveClientMixin { context: context, token: value.getString("token"), ); + if (value.getString("bannerData") != null) { + bannerData = jsonDecode(value.getString("bannerData")).map((i) => BannerData.fromJson(i as Map)) + .toList(); + setState(() {}); + } } dioErrorType = null; if (isFirstIn) queryActivity(); diff --git a/lib/mine/mine_shop_page.dart b/lib/mine/mine_shop_page.dart index 3a496fd4..67e1017c 100644 --- a/lib/mine/mine_shop_page.dart +++ b/lib/mine/mine_shop_page.dart @@ -177,7 +177,7 @@ class _MineShopPage extends State with WidgetsBindingObserver{ : NoDataView( src: "assets/image/icon_empty.webp", isShowBtn: false, - text: "还没有会员卡~", + text: "没有找到相应的门店,试试其他的搜索~", fontSize: 16.sp, margin: EdgeInsets.only(top: 120.h), )), diff --git a/lib/store/shop_details_page.dart b/lib/store/shop_details_page.dart index 8c1d3a57..af7c01d2 100644 --- a/lib/store/shop_details_page.dart +++ b/lib/store/shop_details_page.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -115,13 +117,18 @@ class _ShopDetailsPage extends State { queryStoreInfo() async { EasyLoading.show( status: S.current.zhengzaijiazai, maskType: EasyLoadingMaskType.black); - SharedPreferences value = await SharedPreferences.getInstance(); - if (apiService == null) + if (apiService == null){ + SharedPreferences value = await SharedPreferences.getInstance(); apiService = ApiService( Dio(), context: context, token: value.getString("token"), ); + if (value.getString("miNiDetail${id}") != null) { + miNiDetail = MiNiDetail.fromJson(jsonDecode(value.getString('miNiDetail${id}'))); + setState(() {}); + } + } BaseData baseData = await apiService.queryStoreInfo(storeId).catchError((error) { debugPrint(error); @@ -186,6 +193,11 @@ class _ShopDetailsPage extends State { selectSkus.add(element.attrValueList[0].attrValue); }); }); + SharedPreferences.getInstance().then( + (value) => { + value.setString('miNiDetail${id}', jsonEncode(baseData.data)), + }, + ); EasyLoading.dismiss(); refreshController.refreshCompleted(); } else { @@ -686,10 +698,14 @@ class _ShopDetailsPage extends State { style: { 'body': Style( backgroundColor: Colors.white, - padding: EdgeInsets.all(0), + padding: EdgeInsets.symmetric(horizontal:12.w), + fontSize: FontSize(14.sp), + lineHeight: LineHeight.rem(1.5), margin: EdgeInsets.all(0)), 'p': Style( margin: EdgeInsets.all(0), + fontSize: FontSize(14.sp), + lineHeight: LineHeight.rem(1.5), padding: EdgeInsets.all(0), ), }, diff --git a/lib/store/store_order.dart b/lib/store/store_order.dart index 9b04c52e..79956e0b 100644 --- a/lib/store/store_order.dart +++ b/lib/store/store_order.dart @@ -76,7 +76,7 @@ class _StoreOrderPage extends State @override void initState() { super.initState(); - + _onRefresh(); tableId = widget.arguments["tableId"] ?? 0; tenant = widget.arguments["tenant"]; storeId = widget.arguments["id"]; @@ -90,9 +90,19 @@ class _StoreOrderPage extends State vsync: this, ); - SharedPreferences.getInstance().then((value) { - minLogin(value); - }); + // SharedPreferences.getInstance().then((value) { + // minLogin(value); + // }); + + } + + _onRefresh() async{ + SharedPreferences value = await SharedPreferences.getInstance(); + if (value.getString("storeInfo_${storeId}") != null) { + storeInfo = StoreInfo.fromJson(jsonDecode(value.getString('storeInfo_${storeId}'))); + setState(() {}); + } + minLogin(value); } /// 小程序登录 @@ -205,6 +215,11 @@ class _StoreOrderPage extends State if (mounted) { setState(() {}); } + SharedPreferences.getInstance().then( + (value) => { + value.setString('storeInfo_${storeId}', jsonEncode(baseData.data)), + }, + ); } } diff --git a/lib/store/store_view/store_order_list.dart b/lib/store/store_view/store_order_list.dart index 8a9190ce..85d2cb27 100644 --- a/lib/store/store_view/store_order_list.dart +++ b/lib/store/store_view/store_order_list.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; @@ -65,6 +67,7 @@ class _StoreOrderListPage extends State { @override void initState() { super.initState(); + _onRefresh(); controller.addListener(() { _viewportDimension = controller.position.viewportDimension; for (int i = 0; i < appletProducts.length; i++) { @@ -79,19 +82,29 @@ class _StoreOrderListPage extends State { } } }); + + } + + _onRefresh() async { + if (minService == null) { + SharedPreferences value = await SharedPreferences.getInstance(); + minService = MinApiService(Dio(), + context: context, + token: widget.minToken, + tenant: widget.tenant, + storeId: widget.arguments["id"], + showLoading: true); + if (value.getString("appletProducts_${widget.arguments["id"]}") != null) { + appletProducts = jsonDecode(value.getString("appletProducts_${widget.arguments["id"]}")).map((i) => FindMiNiGroupList.fromJson(i as Map)) + .toList(); + setState(() {}); + } + } appletGoods(); } ///小程序查询分组及商品列表 appletGoods() async { - SharedPreferences value = await SharedPreferences.getInstance(); - minService = MinApiService(Dio(), - context: context, - token: widget.minToken, - tenant: widget.tenant, - storeId: widget.arguments["id"], - showLoading: true); - BaseData> baseData = await minService.findMiNiGroupList({ "id": widget.arguments["id"], @@ -105,6 +118,9 @@ class _StoreOrderListPage extends State { // refreshController.refreshCompleted(); setState(() { appletProducts = baseData.data ?? []; + SharedPreferences.getInstance().then((value) { + value.setString("appletProducts_${widget.arguments["id"]}", jsonEncode(appletProducts)); + }); // productListBeans.clear(); // if (appletProducts.length > 0) // productListBeans.addAll(appletProducts[isSelected].productList); @@ -115,6 +131,7 @@ class _StoreOrderListPage extends State { goodsIndex += element.height; }); }); + } else { // refreshController.refreshFailed(); }