home_page.dart 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  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()
  682. .fromJson(json.decode(response.data.toString()));
  683. commodityCategoryBeanData = entity.data;
  684. tabs.clear();
  685. tabs.add('全部');
  686. commodityCategoryBeanData.forEach((element) {
  687. tabs.insert(1, element.name);
  688. });
  689. if (selectedIndex > tabs.length - 1) {
  690. selectedIndex = 0;
  691. }
  692. setState(() {});
  693. } catch (e) {
  694. tabs.clear();
  695. tabs.add('全部');
  696. if (selectedIndex > tabs.length - 1) {
  697. selectedIndex = 0;
  698. }
  699. }
  700. } else {
  701. return commodityCategoryBeanData;
  702. }
  703. }, (error) {
  704. return commodityCategoryBeanData;
  705. });
  706. }
  707. findAStore() {
  708. MyDio().query({
  709. "key": "shop_user",
  710. "filters": {
  711. "or": true,
  712. "conditions": [
  713. "role!=$shopUserOwner",
  714. "user_uid==${MyCookie().getUID()}",
  715. "review_state==1"
  716. ],
  717. "filters": [
  718. {
  719. "conditions": [
  720. "role==$shopUserOwner",
  721. "user_uid==${MyCookie().getUID()}"
  722. ]
  723. }
  724. ]
  725. },
  726. "dims": shopUserDims,
  727. "paging": [1, 20000]
  728. }, (response, hasError) {
  729. if (!hasError) {
  730. MyShopBeanEntity entity =
  731. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  732. shops = entity.data.data;
  733. var shopUID = [];
  734. shops.forEach((element) {
  735. shopUID.add(element.shopUid);
  736. });
  737. getGoods(shopUID);
  738. }
  739. }, (error) {});
  740. }
  741. queryAd() {
  742. if (page == 1) {
  743. data.clear();
  744. puShop.clear();
  745. }
  746. if (pageIndex == 1) {
  747. data.addAll(container);
  748. } else {
  749. puShop.addAll(container);
  750. if(MyCookie().location!=null){
  751. puShop.forEach((element) {
  752. try{
  753. if(element is StoreBeanDataData&&element.longitude != 0 ){
  754. element.distance = balanceDisplay(AMapTools.distanceBetween(LatLng(element.latitude, element.longitude), LatLng(MyCookie().location.latitude, MyCookie().location.longitude)) / 1000);
  755. print('element.distance------${element.distance}');
  756. }
  757. }catch(e){
  758. print('element.distance------$e');
  759. }
  760. });
  761. puShop.sort((e1,e2){
  762. if(e1 is StoreBeanDataData&&e1.distance!=null&&e2 is StoreBeanDataData&&e2.distance!=null){
  763. return e1.distance.compareTo(e2.distance);
  764. }else if(e1 is StoreBeanDataData&&e1.distance==null&&e2 is StoreBeanDataData&&e2.distance!=null){
  765. return 1;
  766. }else if(e1 is StoreBeanDataData&&e1.distance!=null&&e2 is StoreBeanDataData&&e2.distance==null){
  767. return -1;
  768. }else{
  769. return 0;
  770. }
  771. });
  772. }else{
  773. EventBus().on('getLocation', (arg) {
  774. puShop.forEach((element) {
  775. try{
  776. if(element is StoreBeanDataData&&element.longitude != 0 ){
  777. element.distance = balanceDisplay(AMapTools.distanceBetween(LatLng(element.latitude, element.longitude), LatLng(MyCookie().location.latitude, MyCookie().location.longitude)) / 1000);
  778. print('element.distance------${element.distance}');
  779. }
  780. }catch(e){
  781. print('element.distance------$e');
  782. }
  783. });
  784. puShop.sort((e1,e2){
  785. if(e1 is StoreBeanDataData&&e1.distance!=null&&e2 is StoreBeanDataData&&e2.distance!=null){
  786. return e1.distance.compareTo(e2.distance);
  787. }else if(e1 is StoreBeanDataData&&e1.distance==null&&e2 is StoreBeanDataData&&e2.distance!=null){
  788. return 1;
  789. }else if(e1 is StoreBeanDataData&&e1.distance!=null&&e2 is StoreBeanDataData&&e2.distance==null){
  790. return -1;
  791. }else{
  792. return 0;
  793. }
  794. });
  795. });
  796. }
  797. }
  798. setState(() {});
  799. endRe(_reController);
  800. return;
  801. // int count = 5;
  802. // MyDio().query({
  803. // "key": "ad",
  804. // "filters": {
  805. // "conditions": ['on_show == true']
  806. // },
  807. // "dims": adDims,
  808. // "order_by": ["id,desc", "no,desc"],
  809. // "paging": [page, count]
  810. // }, (response, hasError) {
  811. // if (!hasError) {
  812. // AdBeanEntity entity =
  813. // AdBeanEntity().fromJson(json.decode(response.data.toString()));
  814. // container.addAll(entity.data.data);
  815. // container.shuffle();
  816. // }
  817. // if (page == 1) {
  818. // data.clear();
  819. // puShop.clear();
  820. // }
  821. // if (pageIndex == 1) {
  822. // data.addAll(container);
  823. // } else {
  824. // puShop.addAll(container);
  825. // }
  826. // setState(() {});
  827. // endRe(_reController);
  828. // }, (error) {
  829. // if (page == 1) {
  830. // data.clear();
  831. // }
  832. // data.addAll(container);
  833. // setState(() {});
  834. // endRe(_reController);
  835. // });
  836. }
  837. void checkPublicStores() {
  838. var conditions = ['private==false', 'state == $shopStateNormal'];
  839. if (selectedIndex != 0) {
  840. conditions.add("category == ${tabs[selectedIndex]}");
  841. }
  842. if (_description.text.isNotEmpty) {
  843. conditions.add('name LIKE ${_description.text.toString()}');
  844. }
  845. if (MyCookie().location == null && province == null) {
  846. conditions.add('province == 四川省');
  847. conditions.add('city == 成都市');
  848. } else {
  849. if (province != null) {
  850. conditions.add('province == $province');
  851. conditions.add('city == $city');
  852. } else if (MyCookie().location != null) {
  853. conditions.add('province == ${MyCookie().location.province}');
  854. conditions.add('city == ${MyCookie().location.city}');
  855. }
  856. }
  857. MyDio().query({
  858. "key": "shop",
  859. "filters": {"conditions": conditions},
  860. "dims": shopDims,
  861. "order_by": ["id,desc", "no,desc"],
  862. "paging": [page, 20]
  863. }, (response, hasError) {
  864. if (!hasError) {
  865. StoreBeanEntity entity =
  866. StoreBeanEntity().fromJson(json.decode(response.data.toString()));
  867. container.clear();
  868. container.addAll(entity.data.data);
  869. }
  870. queryAd();
  871. }, (error) {
  872. queryAd();
  873. });
  874. }
  875. void storeType() {
  876. List<CommodityCategoryBeanData> commodityCategoryBeanData = [];
  877. MyDio().query({
  878. "key": "shop_category",
  879. "filters": {},
  880. "dims": [
  881. "name",
  882. ]
  883. }, (response, hasError) {
  884. if (!hasError) {
  885. try {
  886. CommodityCategoryBeanEntity entity = CommodityCategoryBeanEntity()
  887. .fromJson(json.decode(response.data.toString()));
  888. commodityCategoryBeanData = entity.data;
  889. tabs.clear();
  890. tabs.add('全部');
  891. commodityCategoryBeanData.forEach((element) {
  892. tabs.insert(1, element.name);
  893. });
  894. setState(() {});
  895. } catch (e) {
  896. tabs.clear();
  897. tabs.add('全部');
  898. if (selectedIndex > tabs.length - 1) {
  899. selectedIndex = 0;
  900. }
  901. setState(() {});
  902. }
  903. }
  904. }, (error) {});
  905. }
  906. void addressSelection() {
  907. StateSetter ss;
  908. showModalBottomSheet(
  909. context: context,
  910. builder: (context) => BottomSheet(
  911. onClosing: () {},
  912. builder: (context) => Container(
  913. height: 350,
  914. child: Column(
  915. children: [
  916. StatefulBuilder(
  917. builder: (c, s) {
  918. ss = s;
  919. return Container(
  920. height: 40,
  921. color: Colors.white,
  922. padding: EdgeInsets.symmetric(horizontal: 15),
  923. child: Row(
  924. children: [
  925. Row(
  926. children: [
  927. Text(
  928. '定位到: ',
  929. style: TextStyle(
  930. color: MyColors.cFF4233, fontSize: 14),
  931. ),
  932. Text(
  933. _address == null
  934. ? '北京市 北京市'
  935. : '${_address.currentProvince.province} ${_address.currentCity.city}',
  936. style: TextStyle(
  937. color: MyColors.cFF4233, fontSize: 14),
  938. ),
  939. ],
  940. ),
  941. GestureDetector(
  942. child: Container(
  943. height: 40,
  944. width: 60,
  945. alignment: Alignment.center,
  946. child: Text(
  947. '确定',
  948. style: TextStyle(
  949. color: MyColors.cFF4233, fontSize: 16),
  950. ),
  951. ),
  952. onTap: () {
  953. if (_address == null) {
  954. province = '北京市';
  955. city = '北京市';
  956. setState(() {});
  957. _reController.requestRefresh();
  958. _address = null;
  959. Navigator.pop(context);
  960. } else {
  961. province = _address.currentProvince.province;
  962. city = _address.currentCity.city;
  963. setState(() {});
  964. _reController.requestRefresh();
  965. _address = null;
  966. Navigator.pop(context);
  967. }
  968. },
  969. behavior: HitTestBehavior.translucent,
  970. ),
  971. ],
  972. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  973. ),
  974. );
  975. },
  976. ),
  977. GestureDetector(
  978. onTap: () {
  979. if (MyCookie().location != null) {
  980. province = MyCookie().location.province;
  981. city = MyCookie().location.city;
  982. setState(() {});
  983. _reController.requestRefresh();
  984. _address = null;
  985. Navigator.pop(context);
  986. }
  987. },
  988. behavior: HitTestBehavior.translucent,
  989. child: Container(
  990. height: 60,
  991. color: Colors.white,
  992. padding: EdgeInsets.symmetric(horizontal: 20),
  993. child: Row(
  994. children: [
  995. Text(
  996. '当前定位:',
  997. style: TextStyle(color: MyColors.c333333, fontSize: 16),
  998. ),
  999. Text(
  1000. MyCookie().location != null
  1001. ? '${MyCookie().location.province} ${MyCookie().location.city}'
  1002. : '请开启定位权限',
  1003. style: TextStyle(color: MyColors.c333333, fontSize: 16),
  1004. )
  1005. ],
  1006. ),
  1007. ),
  1008. ),
  1009. Container(
  1010. height: 250.0,
  1011. child: AddressPicker(
  1012. style: TextStyle(color: Colors.black, fontSize: 17),
  1013. mode: AddressPickerMode.provinceAndCity,
  1014. onSelectedAddressChanged: (address) {
  1015. _address = address;
  1016. ss(() {});
  1017. },
  1018. ),
  1019. ),
  1020. ],
  1021. ),
  1022. ),
  1023. ),
  1024. );
  1025. }
  1026. }
  1027. class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
  1028. _SliverAppBarDelegate({
  1029. @required this.minHeight,
  1030. @required this.maxHeight,
  1031. @required this.child,
  1032. });
  1033. final double minHeight;
  1034. final double maxHeight;
  1035. final Widget child;
  1036. @override
  1037. double get minExtent => minHeight;
  1038. @override
  1039. double get maxExtent => max(maxHeight, minHeight);
  1040. @override
  1041. Widget build(
  1042. BuildContext context, double shrinkOffset, bool overlapsContent) {
  1043. return new SizedBox.expand(child: child);
  1044. }
  1045. @override
  1046. bool shouldRebuild(_SliverAppBarDelegate oldDelegate) {
  1047. return maxHeight != oldDelegate.maxHeight ||
  1048. minHeight != oldDelegate.minHeight ||
  1049. child != oldDelegate.child;
  1050. }
  1051. }