home_page.dart 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'dart:math';
  4. import 'package:address_picker/address_picker.dart';
  5. import 'package:amap_flutter_base/amap_flutter_base.dart';
  6. import 'package:bbyyy/beans/commodity_category_bean_entity.dart';
  7. import 'package:bbyyy/beans/goods_bean_entity.dart';
  8. import 'package:bbyyy/beans/home_carousel_bean_entity.dart';
  9. import 'package:bbyyy/beans/my_shop_bean_entity.dart';
  10. import 'package:bbyyy/beans/store_bean_entity.dart';
  11. import 'package:bbyyy/https/MyDio.dart';
  12. import 'package:bbyyy/https/my_request.dart';
  13. import 'package:bbyyy/https/url.dart';
  14. import 'package:bbyyy/my_tools/const.dart';
  15. import 'package:bbyyy/my_tools/dims.dart';
  16. import 'package:bbyyy/my_tools/event_bus.dart';
  17. import 'package:bbyyy/my_tools/my_colors.dart';
  18. import 'package:bbyyy/my_tools/my_cookie.dart';
  19. import 'package:bbyyy/my_tools/my_tools.dart';
  20. import 'package:bbyyy/my_tools/my_views.dart';
  21. import 'package:bbyyy/my_tools/providers.dart';
  22. import 'package:bbyyy/paegs/gang_page/gang_in_page/scan_page/scan_page.dart';
  23. import 'package:bbyyy/paegs/home_page/qr_code_payment/new_qr_code_payment_page.dart';
  24. import 'package:bbyyy/paegs/home_page/qr_code_payment/qr_code_payment_page.dart';
  25. import 'package:bbyyy/paegs/home_page/recommended_today_page.dart';
  26. import 'package:bbyyy/paegs/root_page/root_page_view.dart';
  27. import 'package:flutter/cupertino.dart';
  28. import 'package:flutter/material.dart';
  29. import 'package:flutter_svg/flutter_svg.dart';
  30. import 'package:flutter_swiper/flutter_swiper.dart';
  31. import 'package:get/get.dart';
  32. import 'package:provider/src/provider.dart';
  33. import 'package:pull_to_refresh/pull_to_refresh.dart';
  34. class HomePage extends StatefulWidget {
  35. @override
  36. _HomePageState createState() => _HomePageState();
  37. }
  38. class _HomePageState extends State<HomePage>
  39. with AutomaticKeepAliveClientMixin {
  40. var data = [];
  41. var container = [];
  42. var puShop = [];
  43. var imgs = ['images/banner1.png', 'images/banner2.png', 'images/banner3.png'];
  44. var netImgs = [];
  45. int selectedIndex = 0;
  46. var tabs = ['全部'];
  47. var types = ['货帮', '货品'];
  48. List<DropdownMenuItem<String>> sortItems = [];
  49. int typeIndex = 1;
  50. List<MyShopBeanDataData> shops = [];
  51. ScrollController _controller = ScrollController();
  52. double maxH;
  53. double minH = 164;
  54. double H = 0;
  55. bool showInput = false;
  56. TextEditingController _description = TextEditingController();
  57. FocusNode _descriptionFocus = FocusNode();
  58. RefreshController _reController = RefreshController(initialRefresh: true);
  59. int page = 1;
  60. int pageIndex = 0;
  61. bool showS = false;
  62. String province;
  63. String city;
  64. Address _address;
  65. @override
  66. void initState() {
  67. super.initState();
  68. EventBus().on('commodity_category', (arg) {
  69. setState(() {});
  70. });
  71. EventBus().on('uploadGoods', (arg) {
  72. _reController.requestRefresh();
  73. });
  74. EventBus().on('toTop', (arg) {
  75. _controller.animateTo(0.0,
  76. duration: Duration(milliseconds: 200), curve: Curves.easeIn);
  77. });
  78. EventBus().on('homeCarousel', (arg) {
  79. if (arg is HomeCarouselBeanEntity) {
  80. arg.data.forEach((element) {
  81. netImgs.add(element.path);
  82. });
  83. setState(() {});
  84. }
  85. });
  86. EventBus().on('商品变动', (arg) {
  87. _reController.requestRefresh();
  88. });
  89. EventBus().on('getLocation', (arg) {
  90. if (MyCookie().location.province == '四川省' &&
  91. MyCookie().location.city == '成都市') {
  92. return;
  93. }
  94. _reController.requestRefresh();
  95. setState(() {});
  96. });
  97. _controller.addListener(() {
  98. setState(() {
  99. if (_controller.offset == 0) {
  100. RootPageView().toTop = false;
  101. EventBus().emit('ChangePage');
  102. } else {
  103. RootPageView().toTop = true;
  104. EventBus().emit('ChangePage');
  105. }
  106. H = maxH - _controller.offset;
  107. if (H < minH) {
  108. H = minH;
  109. } else if (H > maxH) {
  110. H = maxH;
  111. }
  112. });
  113. });
  114. types.forEach((element) {
  115. sortItems.add(DropdownMenuItem(
  116. child: Text(
  117. element,
  118. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  119. ),
  120. value: element,
  121. ));
  122. });
  123. _descriptionFocus.addListener(() {
  124. if (_descriptionFocus.hasFocus) {
  125. } else {
  126. if (_description.text.isEmpty) {
  127. showInput = false;
  128. }
  129. }
  130. });
  131. // homeCarousel();
  132. }
  133. @override
  134. void dispose() {
  135. // TODO: implement dispose
  136. super.dispose();
  137. EventBus().off('commodity_category');
  138. EventBus().off('uploadGoods');
  139. EventBus().off('toTop');
  140. EventBus().off('homeCarousel');
  141. EventBus().off('商品变动');
  142. EventBus().off('getLocation');
  143. }
  144. @override
  145. Widget build(BuildContext context) {
  146. maxH = MediaQuery.of(context).size.width * (520 / 750);
  147. minH = MediaQuery.of(context).padding.top + 64;
  148. if (H == 0) {
  149. H = maxH;
  150. }
  151. return GestureDetector(
  152. onTap: () {
  153. MyTools().hideKeyboard(context);
  154. },
  155. behavior: HitTestBehavior.translucent,
  156. child: Scaffold(
  157. resizeToAvoidBottomInset: false,
  158. body: SmartRefresher(
  159. controller: _reController,
  160. onRefresh: onRefresh,
  161. onLoading: onLoading,
  162. enablePullDown: true,
  163. enablePullUp: true,
  164. child: CustomScrollView(
  165. slivers: [
  166. carouselAndSearch(context),
  167. // recommendedToday(),
  168. storeCategory(),
  169. shopList()
  170. ],
  171. ),
  172. ),
  173. ),
  174. );
  175. }
  176. Widget shopList() {
  177. return SliverList(
  178. delegate: SliverChildBuilderDelegate(
  179. (c, index) {
  180. return MyViews().pubShopItem(puShop[index], context);
  181. },
  182. childCount: puShop.length,
  183. ));
  184. }
  185. Widget storeCategory() {
  186. return SliverPersistentHeader(
  187. pinned: true, //是否固定在顶部
  188. floating: false,
  189. delegate: _SliverAppBarDelegate(
  190. minHeight: 54,
  191. maxHeight: 54,
  192. child: Column(
  193. children: [
  194. Container(
  195. color: Colors.white,
  196. height: 53,
  197. child: ListView.builder(
  198. padding: EdgeInsets.only(left: 12, right: 12),
  199. itemBuilder: (c, index) {
  200. return GestureDetector(
  201. onTap: () {
  202. setState(() {
  203. selectedIndex = index;
  204. _reController.requestRefresh();
  205. });
  206. },
  207. behavior: HitTestBehavior.translucent,
  208. child: Container(
  209. padding:
  210. EdgeInsets.only(right: 15, left: 15, bottom: 9),
  211. child: Column(
  212. children: [
  213. Text(
  214. tabs[index],
  215. style: TextStyle(
  216. color: index == selectedIndex
  217. ? MyColors.cFF4233
  218. : MyColors.c666666,
  219. fontSize: 14),
  220. ),
  221. Container(
  222. height: 10,
  223. child: Visibility(
  224. child: SvgPicture.asset('images/svg/tab.svg'),
  225. visible: index == selectedIndex,
  226. ),
  227. )
  228. ],
  229. mainAxisAlignment: MainAxisAlignment.end,
  230. ),
  231. height: 53,
  232. ),
  233. );
  234. },
  235. itemCount: tabs.length,
  236. scrollDirection: Axis.horizontal,
  237. ),
  238. ),
  239. Container(
  240. height: 1,
  241. color: MyColors.cf2f2f2,
  242. ),
  243. ],
  244. )));
  245. }
  246. Widget recommendedToday() {
  247. return SliverToBoxAdapter(
  248. child: Column(
  249. children: [
  250. Container(
  251. padding: EdgeInsets.only(left: 16, right: 10),
  252. height: 54,
  253. child: Row(
  254. children: [
  255. Text(
  256. '梆梆今日折扣',
  257. style: TextStyle(color: MyColors.c333333, fontSize: 14),
  258. ),
  259. GestureDetector(
  260. onTap: () {
  261. MyTools()
  262. .toPage(context, RecommendedTodayPage(), (then) {});
  263. },
  264. behavior: HitTestBehavior.translucent,
  265. child: Row(
  266. children: [
  267. Text(
  268. '查看更多',
  269. style: TextStyle(color: MyColors.c666666, fontSize: 12),
  270. ),
  271. Icon(
  272. Icons.chevron_right,
  273. color: MyColors.c666666,
  274. )
  275. ],
  276. ),
  277. )
  278. ],
  279. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  280. ),
  281. ),
  282. Container(
  283. height: 1,
  284. color: MyColors.cf2f2f2,
  285. ),
  286. Container(
  287. height: 168,
  288. child: ListView.builder(
  289. padding: EdgeInsets.symmetric(horizontal: 16, vertical: 15),
  290. itemBuilder: (c, index) {
  291. return Container(
  292. margin: EdgeInsets.only(right: 10),
  293. height: 138,
  294. width: 100,
  295. padding: EdgeInsets.all(5),
  296. decoration: BoxDecoration(
  297. boxShadow: [
  298. BoxShadow(
  299. color: MyColors.c7FE1E1E1,
  300. blurRadius: 5.0,
  301. ),
  302. ],
  303. color: Colors.white,
  304. borderRadius: BorderRadius.circular(4),
  305. ),
  306. child: Column(
  307. children: [
  308. MyViews().netImg('', 90, 90,
  309. placeholder: 'images/svg/goodsDefImg.svg'),
  310. Text(
  311. '8.9元充10元话费',
  312. style: TextStyle(color: MyColors.c333333, fontSize: 11),
  313. maxLines: 1,
  314. overflow: TextOverflow.ellipsis,
  315. softWrap: true,
  316. ),
  317. Row(
  318. children: [
  319. Text(
  320. '¥8.90',
  321. style: TextStyle(
  322. color: MyColors.cFF4233,
  323. fontSize: 13,
  324. fontWeight: FontWeight.bold),
  325. maxLines: 1,
  326. overflow: TextOverflow.ellipsis,
  327. softWrap: true,
  328. ),
  329. Container(
  330. decoration: BoxDecoration(
  331. border:
  332. Border.all(color: MyColors.cFF4233, width: 1),
  333. borderRadius: BorderRadius.circular(7),
  334. ),
  335. height: 14,
  336. width: 30,
  337. child: Text(
  338. '详情',
  339. style: TextStyle(
  340. color: MyColors.cFF4233, fontSize: 9),
  341. ),
  342. alignment: Alignment.center,
  343. )
  344. ],
  345. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  346. )
  347. ],
  348. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  349. crossAxisAlignment: CrossAxisAlignment.start,
  350. ),
  351. );
  352. },
  353. itemCount: 10,
  354. scrollDirection: Axis.horizontal,
  355. ),
  356. ),
  357. ],
  358. ),
  359. );
  360. }
  361. Widget carouselAndSearch(BuildContext context) {
  362. return SliverPersistentHeader(
  363. pinned: true,
  364. floating: false,
  365. delegate: _SliverAppBarDelegate(
  366. minHeight: minH,
  367. maxHeight: maxH,
  368. child: Stack(
  369. children: [
  370. Swiper(
  371. itemBuilder: (BuildContext context, int index) {
  372. return netImgs.length == 0
  373. ? GestureDetector(
  374. onTap: () {
  375. // EventBus().emit('showRP');
  376. },
  377. child: Image.asset(
  378. "${imgs[index]}",
  379. fit: BoxFit.cover,
  380. ),
  381. )
  382. : MyViews().netImg(imgURL(netImgs[index]), H,
  383. MediaQuery.of(context).size.width,
  384. placeholder: 'images/svg/goodsDefImg.svg');
  385. },
  386. itemCount: netImgs.length == 0 ? imgs.length : netImgs.length,
  387. viewportFraction: 1,
  388. scale: 1,
  389. autoplay: true,
  390. ),
  391. SafeArea(
  392. bottom: false,
  393. child: Stack(
  394. children: [
  395. Positioned(
  396. left: 0,
  397. child: Container(
  398. padding: EdgeInsets.only(left: 10, right: 10, top: 12),
  399. child: GestureDetector(
  400. onTap: () {
  401. addressSelection();
  402. },
  403. behavior: HitTestBehavior.translucent,
  404. child: Container(
  405. padding: EdgeInsets.only(left: 11, right: 14),
  406. decoration: BoxDecoration(
  407. boxShadow: [
  408. BoxShadow(
  409. color: MyColors.c7FE1E1E1,
  410. blurRadius: 5.0,
  411. ),
  412. ],
  413. color: Colors.white,
  414. borderRadius: BorderRadius.circular(20)),
  415. child: Row(
  416. children: [
  417. Icon(
  418. Icons.location_on_rounded,
  419. color: MyColors.c333333,
  420. size: 20,
  421. ),
  422. Text(
  423. province == null
  424. ? MyCookie().location != null
  425. ? MyCookie().location.city
  426. : '成都市'
  427. : city,
  428. style: TextStyle(
  429. color: MyColors.c333333,
  430. fontSize: 12,
  431. fontWeight: FontWeight.bold),
  432. ),
  433. ],
  434. ),
  435. height: 40,
  436. alignment: Alignment.center,
  437. ),
  438. ),
  439. alignment: Alignment.center,
  440. ),
  441. ),
  442. Positioned(
  443. top: 0,
  444. right: 50,
  445. child: Container(
  446. padding: EdgeInsets.only(left: 10, right: 10, top: 12),
  447. child: GestureDetector(
  448. onTap: () {
  449. showS = !showS;
  450. if (!showS) {
  451. _description.clear();
  452. }
  453. setState(() {});
  454. },
  455. behavior: HitTestBehavior.translucent,
  456. child: AnimatedContainer(
  457. height: 40,
  458. width: !showS
  459. ? 40
  460. : MediaQuery.of(context).size.width - 70,
  461. child: Row(
  462. children: [
  463. SvgPicture.asset(
  464. showS
  465. ? 'images/svg/箭头.svg'
  466. : 'images/svg/搜索.svg',
  467. height: 15,
  468. width: 15,
  469. color: MyColors.cFF4233,
  470. ),
  471. Visibility(
  472. visible: showS,
  473. child: Expanded(
  474. child: TextField(
  475. controller: _description,
  476. cursorColor: MyColors.cFF4233,
  477. cursorWidth: 1.0,
  478. onTap: () {},
  479. decoration: InputDecoration(
  480. border: InputBorder.none,
  481. disabledBorder: InputBorder.none,
  482. enabledBorder: InputBorder.none,
  483. focusedBorder: InputBorder.none,
  484. isDense: true,
  485. hintText: '请输入...',
  486. hintStyle: TextStyle(
  487. color: MyColors.c999999,
  488. fontSize: 16),
  489. contentPadding:
  490. const EdgeInsets.fromLTRB(
  491. 14, 4.5, 8, 4.5),
  492. ),
  493. maxLines: 1,
  494. style: TextStyle(
  495. color: MyColors.c333333,
  496. fontSize: 16,
  497. height: 1.3,
  498. letterSpacing: 0.2),
  499. keyboardType: TextInputType.text,
  500. onChanged: (t) {
  501. setState(() {});
  502. },
  503. ),
  504. ),
  505. ),
  506. Visibility(
  507. visible:
  508. showS && _description.text.isNotEmpty,
  509. child: GestureDetector(
  510. onTap: () {
  511. MyTools().hideKeyboard(context);
  512. _reController.requestRefresh();
  513. },
  514. behavior: HitTestBehavior.translucent,
  515. child: Container(
  516. child: MyViews()
  517. .myText('搜索', Colors.white, 13),
  518. decoration: BoxDecoration(
  519. color: MyColors.cFF4233,
  520. borderRadius: BorderRadius.circular(20),
  521. ),
  522. height: 40,
  523. width: 80,
  524. alignment: Alignment.center,
  525. ),
  526. ),
  527. )
  528. ],
  529. mainAxisAlignment: MainAxisAlignment.center,
  530. ),
  531. alignment: !showS
  532. ? Alignment.center
  533. : Alignment.centerLeft,
  534. padding: EdgeInsets.only(left: !showS ? 0 : 12),
  535. decoration: BoxDecoration(
  536. borderRadius:
  537. BorderRadius.all(Radius.circular(20)),
  538. color: Colors.white,
  539. ),
  540. duration: Duration(milliseconds: 200),
  541. ),
  542. ),
  543. alignment: Alignment.centerRight,
  544. ),
  545. ),
  546. Positioned(
  547. top: 0,
  548. right: 0,
  549. child: GestureDetector(
  550. onTap: () {
  551. MyTools().toPage(context, ScanPage(), (then) {
  552. if (then is String) {
  553. if (then.isNotEmpty && then != null) {
  554. Timer(Duration(milliseconds: 200), () {
  555. if (then.contains(
  556. 'https://bby.banghuo.net/pay.html?shop_uid=')) {
  557. } else {
  558. showToast('暂不支持该二维码');
  559. return;
  560. }
  561. MyTools().hideKeyboard(context);
  562. int shopUid = int.parse(then.split('=')[1]);
  563. print(shopUid);
  564. MyTools().toPage(context, NewPayToTheGangPage(shopUid,orderTypeOfflinePay), (then){});
  565. });
  566. }
  567. }
  568. });
  569. },
  570. behavior: HitTestBehavior.translucent,
  571. child: Container(
  572. margin: EdgeInsets.only(left: 10, right: 10, top: 12),
  573. height: 40,
  574. width: 40,
  575. child: SvgPicture.asset(
  576. 'images/svg/扫一扫_icon.svg',
  577. color: MyColors.cFF4233,
  578. height: 18,
  579. width: 18,
  580. ),
  581. alignment: Alignment.center,
  582. decoration: BoxDecoration(
  583. borderRadius: BorderRadius.circular(20),
  584. color: Colors.white),
  585. ),
  586. ),
  587. )
  588. ],
  589. ),
  590. ),
  591. ],
  592. )),
  593. );
  594. }
  595. @override
  596. // TODO: implement wantKeepAlive
  597. bool get wantKeepAlive => true;
  598. void getGoods(List<dynamic> shopUID) {
  599. var qData;
  600. if (shopUID.length == 0) {
  601. var conditions = ["public == true", "on_sale == true"];
  602. if (selectedIndex != 0) {
  603. conditions.add("category == ${tabs[selectedIndex]}");
  604. }
  605. if (_description.text.isNotEmpty) {
  606. conditions.add('title LIKE ${_description.text.toString()}');
  607. }
  608. qData = {
  609. "key": "commodity",
  610. "filters": {"conditions": conditions},
  611. "dims": commodityDims,
  612. "order_by": ["id,desc", "no,desc"],
  613. "paging": [page, 20]
  614. };
  615. } else {
  616. var conditions = ["shop_uid in $shopUID", "on_sale == true"];
  617. var conditions2 = ["public == true", "on_sale == true"];
  618. if (selectedIndex != 0) {
  619. conditions.add("category == ${tabs[selectedIndex]}");
  620. conditions2.add("category == ${tabs[selectedIndex]}");
  621. }
  622. if (_description.text.isNotEmpty) {
  623. conditions.add('title LIKE ${_description.text.toString()}');
  624. conditions2.add('title LIKE ${_description.text.toString()}');
  625. }
  626. qData = {
  627. "key": "commodity",
  628. "filters": {
  629. "or": true,
  630. "conditions": conditions,
  631. "filters": [
  632. {"conditions": conditions2}
  633. ]
  634. },
  635. "order_by": ["id,desc", "no,desc"],
  636. "dims": commodityDims,
  637. "paging": [page, 20]
  638. };
  639. }
  640. MyDio().query(qData, (response, hasError) {
  641. if (!hasError) {
  642. GoodsBeanEntity entity =
  643. GoodsBeanEntity.fromJson(json.decode(response.data.toString()));
  644. container.clear();
  645. container.addAll(entity.data.data);
  646. }
  647. queryAd();
  648. }, (error) {
  649. queryAd();
  650. });
  651. }
  652. void onRefresh() {
  653. page = 1;
  654. if (pageIndex == 1) {
  655. initTabs();
  656. findAStore();
  657. } else {
  658. storeType();
  659. checkPublicStores();
  660. }
  661. }
  662. void onLoading() {
  663. page++;
  664. if (pageIndex == 1) {
  665. findAStore();
  666. } else {
  667. checkPublicStores();
  668. }
  669. }
  670. Future<void> initTabs() async {
  671. List<CommodityCategoryBeanData> commodityCategoryBeanData = [];
  672. MyDio().query({
  673. "key": "commodity_category",
  674. "filters": {},
  675. "dims": [
  676. "name",
  677. ]
  678. }, (response, hasError) {
  679. if (!hasError) {
  680. try {
  681. CommodityCategoryBeanEntity entity = CommodityCategoryBeanEntity.fromJson(json.decode(response.data.toString()));
  682. commodityCategoryBeanData = entity.data;
  683. tabs.clear();
  684. tabs.add('全部');
  685. commodityCategoryBeanData.forEach((element) {
  686. tabs.insert(1, element.name);
  687. });
  688. if (selectedIndex > tabs.length - 1) {
  689. selectedIndex = 0;
  690. }
  691. setState(() {});
  692. } catch (e) {
  693. tabs.clear();
  694. tabs.add('全部');
  695. if (selectedIndex > tabs.length - 1) {
  696. selectedIndex = 0;
  697. }
  698. }
  699. } else {
  700. return commodityCategoryBeanData;
  701. }
  702. }, (error) {
  703. return commodityCategoryBeanData;
  704. });
  705. }
  706. findAStore() {
  707. MyDio().query({
  708. "key": "shop_user",
  709. "filters": {
  710. "or": true,
  711. "conditions": [
  712. "role!=$shopUserOwner",
  713. "user_uid==${MyCookie().getUID()}",
  714. "review_state==1"
  715. ],
  716. "filters": [
  717. {
  718. "conditions": [
  719. "role==$shopUserOwner",
  720. "user_uid==${MyCookie().getUID()}"
  721. ]
  722. }
  723. ]
  724. },
  725. "dims": shopUserDims,
  726. "paging": [1, 20000]
  727. }, (response, hasError) {
  728. if (!hasError) {
  729. MyShopBeanEntity entity =
  730. MyShopBeanEntity.fromJson(json.decode(response.data.toString()));
  731. shops = entity.data.data;
  732. var shopUID = [];
  733. shops.forEach((element) {
  734. shopUID.add(element.shopUid);
  735. });
  736. getGoods(shopUID);
  737. }
  738. }, (error) {});
  739. }
  740. queryAd() {
  741. if (page == 1) {
  742. data.clear();
  743. puShop.clear();
  744. }
  745. if (pageIndex == 1) {
  746. data.addAll(container);
  747. } else {
  748. puShop.addAll(container);
  749. if(MyCookie().location!=null){
  750. puShop.forEach((element) {
  751. try{
  752. if(element is StoreBeanDataData&&element.longitude != 0 ){
  753. element.distance = balanceDisplay(AMapTools.distanceBetween(LatLng(element.latitude, element.longitude), LatLng(MyCookie().location.latitude, MyCookie().location.longitude)) / 1000);
  754. // print('element.distance------${element.distance}');
  755. }
  756. }catch(e){
  757. // print('element.distance------$e');
  758. }
  759. });
  760. puShop.sort((e1,e2){
  761. if(e1 is StoreBeanDataData&&e1.distance!=null&&e2 is StoreBeanDataData&&e2.distance!=null){
  762. return e1.distance.compareTo(e2.distance);
  763. }else if(e1 is StoreBeanDataData&&e1.distance==null&&e2 is StoreBeanDataData&&e2.distance!=null){
  764. return 1;
  765. }else if(e1 is StoreBeanDataData&&e1.distance!=null&&e2 is StoreBeanDataData&&e2.distance==null){
  766. return -1;
  767. }else{
  768. return 0;
  769. }
  770. });
  771. }else{
  772. EventBus().on('getLocation', (arg) {
  773. puShop.forEach((element) {
  774. try{
  775. if(element is StoreBeanDataData&&element.longitude != 0 ){
  776. element.distance = balanceDisplay(AMapTools.distanceBetween(LatLng(element.latitude, element.longitude), LatLng(MyCookie().location.latitude, MyCookie().location.longitude)) / 1000);
  777. // print('element.distance------${element.distance}');
  778. }
  779. }catch(e){
  780. // print('element.distance------$e');
  781. }
  782. });
  783. puShop.sort((e1,e2){
  784. if(e1 is StoreBeanDataData&&e1.distance!=null&&e2 is StoreBeanDataData&&e2.distance!=null){
  785. return e1.distance.compareTo(e2.distance);
  786. }else if(e1 is StoreBeanDataData&&e1.distance==null&&e2 is StoreBeanDataData&&e2.distance!=null){
  787. return 1;
  788. }else if(e1 is StoreBeanDataData&&e1.distance!=null&&e2 is StoreBeanDataData&&e2.distance==null){
  789. return -1;
  790. }else{
  791. return 0;
  792. }
  793. });
  794. });
  795. }
  796. }
  797. setState(() {});
  798. endRe(_reController);
  799. return;
  800. // int count = 5;
  801. // MyDio().query({
  802. // "key": "ad",
  803. // "filters": {
  804. // "conditions": ['on_show == true']
  805. // },
  806. // "dims": adDims,
  807. // "order_by": ["id,desc", "no,desc"],
  808. // "paging": [page, count]
  809. // }, (response, hasError) {
  810. // if (!hasError) {
  811. // AdBeanEntity entity =
  812. // AdBeanEntity.fromJson(json.decode(response.data.toString()));
  813. // container.addAll(entity.data.data);
  814. // container.shuffle();
  815. // }
  816. // if (page == 1) {
  817. // data.clear();
  818. // puShop.clear();
  819. // }
  820. // if (pageIndex == 1) {
  821. // data.addAll(container);
  822. // } else {
  823. // puShop.addAll(container);
  824. // }
  825. // setState(() {});
  826. // endRe(_reController);
  827. // }, (error) {
  828. // if (page == 1) {
  829. // data.clear();
  830. // }
  831. // data.addAll(container);
  832. // setState(() {});
  833. // endRe(_reController);
  834. // });
  835. }
  836. void checkPublicStores() {
  837. var conditions = ['private==false', 'state == $shopStateNormal'];
  838. if (selectedIndex != 0) {
  839. conditions.add("category == ${tabs[selectedIndex]}");
  840. }
  841. if (_description.text.isNotEmpty) {
  842. conditions.add('name LIKE ${_description.text.toString()}');
  843. }
  844. if (MyCookie().location == null && province == null) {
  845. conditions.add('province == 四川省');
  846. conditions.add('city == 成都市');
  847. } else {
  848. if (province != null) {
  849. conditions.add('province == $province');
  850. conditions.add('city == $city');
  851. } else if (MyCookie().location != null) {
  852. conditions.add('province == ${MyCookie().location.province}');
  853. conditions.add('city == ${MyCookie().location.city}');
  854. }
  855. }
  856. MyDio().query({
  857. "key": "shop",
  858. "filters": {"conditions": conditions},
  859. "dims": shopDims,
  860. "order_by": ["id,desc", "no,desc"],
  861. "paging": [page, 20]
  862. }, (response, hasError) {
  863. if (!hasError) {
  864. StoreBeanEntity entity =
  865. StoreBeanEntity.fromJson(json.decode(response.data.toString()));
  866. container.clear();
  867. container.addAll(entity.data.data);
  868. }
  869. queryAd();
  870. }, (error) {
  871. queryAd();
  872. });
  873. }
  874. void storeType() {
  875. List<CommodityCategoryBeanData> commodityCategoryBeanData = [];
  876. MyDio().query({
  877. "key": "shop_category",
  878. "filters": {},
  879. "dims": [
  880. "name",
  881. ]
  882. }, (response, hasError) {
  883. if (!hasError) {
  884. try {
  885. CommodityCategoryBeanEntity entity = CommodityCategoryBeanEntity.fromJson(json.decode(response.data.toString()));
  886. commodityCategoryBeanData = entity.data;
  887. tabs.clear();
  888. tabs.add('全部');
  889. commodityCategoryBeanData.forEach((element) {
  890. tabs.insert(1, element.name);
  891. });
  892. setState(() {});
  893. } catch (e) {
  894. tabs.clear();
  895. tabs.add('全部');
  896. if (selectedIndex > tabs.length - 1) {
  897. selectedIndex = 0;
  898. }
  899. setState(() {});
  900. }
  901. }
  902. }, (error) {});
  903. }
  904. void addressSelection() {
  905. StateSetter ss;
  906. showModalBottomSheet(
  907. context: context,
  908. builder: (context) => BottomSheet(
  909. onClosing: () {},
  910. builder: (context) => Container(
  911. height: 350,
  912. child: Column(
  913. children: [
  914. StatefulBuilder(
  915. builder: (c, s) {
  916. ss = s;
  917. return Container(
  918. height: 40,
  919. color: Colors.white,
  920. padding: EdgeInsets.symmetric(horizontal: 15),
  921. child: Row(
  922. children: [
  923. Row(
  924. children: [
  925. Text(
  926. '定位到: ',
  927. style: TextStyle(
  928. color: MyColors.cFF4233, fontSize: 14),
  929. ),
  930. Text(
  931. _address == null
  932. ? '北京市 北京市'
  933. : '${_address.currentProvince.province} ${_address.currentCity.city}',
  934. style: TextStyle(
  935. color: MyColors.cFF4233, fontSize: 14),
  936. ),
  937. ],
  938. ),
  939. GestureDetector(
  940. child: Container(
  941. height: 40,
  942. width: 60,
  943. alignment: Alignment.center,
  944. child: Text(
  945. '确定',
  946. style: TextStyle(
  947. color: MyColors.cFF4233, fontSize: 16),
  948. ),
  949. ),
  950. onTap: () {
  951. if (_address == null) {
  952. province = '北京市';
  953. city = '北京市';
  954. setState(() {});
  955. _reController.requestRefresh();
  956. _address = null;
  957. Navigator.pop(context);
  958. } else {
  959. province = _address.currentProvince.province;
  960. city = _address.currentCity.city;
  961. setState(() {});
  962. _reController.requestRefresh();
  963. _address = null;
  964. Navigator.pop(context);
  965. }
  966. },
  967. behavior: HitTestBehavior.translucent,
  968. ),
  969. ],
  970. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  971. ),
  972. );
  973. },
  974. ),
  975. GestureDetector(
  976. onTap: () {
  977. if (MyCookie().location != null) {
  978. province = MyCookie().location.province;
  979. city = MyCookie().location.city;
  980. setState(() {});
  981. _reController.requestRefresh();
  982. _address = null;
  983. Navigator.pop(context);
  984. }
  985. },
  986. behavior: HitTestBehavior.translucent,
  987. child: Container(
  988. height: 60,
  989. color: Colors.white,
  990. padding: EdgeInsets.symmetric(horizontal: 20),
  991. child: Row(
  992. children: [
  993. Text(
  994. '当前定位:',
  995. style: TextStyle(color: MyColors.c333333, fontSize: 16),
  996. ),
  997. Text(
  998. MyCookie().location != null
  999. ? '${MyCookie().location.province} ${MyCookie().location.city}'
  1000. : '请开启定位权限',
  1001. style: TextStyle(color: MyColors.c333333, fontSize: 16),
  1002. )
  1003. ],
  1004. ),
  1005. ),
  1006. ),
  1007. Container(
  1008. height: 250.0,
  1009. child: AddressPicker(
  1010. style: TextStyle(color: Colors.black, fontSize: 17),
  1011. mode: AddressPickerMode.provinceAndCity,
  1012. onSelectedAddressChanged: (address) {
  1013. _address = address;
  1014. ss(() {});
  1015. },
  1016. ),
  1017. ),
  1018. ],
  1019. ),
  1020. ),
  1021. ),
  1022. );
  1023. }
  1024. }
  1025. class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
  1026. _SliverAppBarDelegate({
  1027. @required this.minHeight,
  1028. @required this.maxHeight,
  1029. @required this.child,
  1030. });
  1031. final double minHeight;
  1032. final double maxHeight;
  1033. final Widget child;
  1034. @override
  1035. double get minExtent => minHeight;
  1036. @override
  1037. double get maxExtent => max(maxHeight, minHeight);
  1038. @override
  1039. Widget build(
  1040. BuildContext context, double shrinkOffset, bool overlapsContent) {
  1041. return new SizedBox.expand(child: child);
  1042. }
  1043. @override
  1044. bool shouldRebuild(_SliverAppBarDelegate oldDelegate) {
  1045. return maxHeight != oldDelegate.maxHeight ||
  1046. minHeight != oldDelegate.minHeight ||
  1047. child != oldDelegate.child;
  1048. }
  1049. }