home_page.dart 39 KB

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