home_page.dart 35 KB

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