YSShopView.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_easyrefresh/easy_refresh.dart';
  4. import 'package:shared_preferences/shared_preferences.dart';
  5. import 'package:ysairplane2/code/YSContractPlaneDetail.dart';
  6. import 'package:ysairplane2/code/YSShortDetail.dart';
  7. import 'package:ysairplane2/tools/YSNetWorking.dart';
  8. import 'package:ysairplane2/tools/YSTools.dart';
  9. import '../YSMarryPlane.dart';
  10. import '../YSSearchResult.dart';
  11. class YSShopView extends StatefulWidget {
  12. final Map shop;
  13. final String location;
  14. final type;
  15. const YSShopView({Key key, @required this.shop, @required this.location, @required this.type}) : super(key: key);
  16. @override
  17. _YSShopViewState createState() => _YSShopViewState();
  18. }
  19. class _YSShopViewState extends State<YSShopView> {
  20. @override
  21. Widget build(BuildContext context) {
  22. return GestureDetector(
  23. onTap: (){
  24. Navigator.of(context).push(
  25. CupertinoPageRoute(builder: (context){
  26. return YSShop(shop: widget.shop,location: widget.location,);
  27. })
  28. );
  29. },
  30. child: Container(
  31. margin: EdgeInsets.only(top: hsp(10)),
  32. padding: EdgeInsets.all(hsp(30)),
  33. color: Colors.white,
  34. child: LayoutBuilder(
  35. builder: (context,size){
  36. return Row(
  37. children: [
  38. Image.network(widget.shop['logo'],height: hsp(100),width: hsp(100),),
  39. Container(
  40. width: size.maxWidth-hsp(300),
  41. padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  42. child: Column(
  43. crossAxisAlignment: CrossAxisAlignment.start,
  44. children: [
  45. Text(widget.shop['name'],style: TextStyle(fontSize: zsp(30),
  46. color: Colors.black,fontWeight: FontWeight.bold),),
  47. Text(widget.shop['address']??'',style: TextStyle(fontSize: zsp(28),
  48. color: Colors.grey,height: 2),)
  49. ],
  50. ),
  51. ),
  52. Container(
  53. height: hsp(60),
  54. width: hsp(200),
  55. decoration: BoxDecoration(
  56. color: Colors.redAccent,
  57. borderRadius: BorderRadius.all(Radius.circular(50))
  58. ),
  59. alignment: Alignment.center,
  60. child: Text('进店逛逛',style: TextStyle(fontSize: zsp(26),color: Colors.white),),
  61. )
  62. ],
  63. );
  64. },
  65. ),
  66. ),
  67. );
  68. }
  69. }
  70. class YSShop extends StatefulWidget {
  71. final Map shop;
  72. final String location;
  73. final type;
  74. const YSShop({Key key, @required this.shop, @required this.location, @required this.type}) : super(key: key);
  75. @override
  76. _YSShopState createState() => _YSShopState();
  77. }
  78. class _YSShopState extends State<YSShop> {
  79. int _page = 1;
  80. List _dataArray = [];
  81. int _titleIndex = 0;
  82. List _titles = ['综合','评分','价钱','距离'];
  83. Map _msgDict;
  84. String _cityStr = '';
  85. @override
  86. void initState() {
  87. Future.delayed(Duration(seconds: 0)).then((value){
  88. _refreshData();
  89. });
  90. super.initState();
  91. }
  92. @override
  93. Widget build(BuildContext context) {
  94. return Scaffold(
  95. backgroundColor: Color(0xFFF1F2F3),
  96. body: SingleChildScrollView(
  97. padding: EdgeInsets.all(0),
  98. child: Stack(
  99. children: [
  100. Container(
  101. height: MediaQuery.of(context).padding.top+hsp(450),
  102. width: MediaQuery.of(context).size.width,
  103. child: _msgDict==null?Image(
  104. image: AssetImage('lib/images/home3.png'),
  105. fit: BoxFit.fill,
  106. ):ysImageLoad(
  107. imageUrl: '${_msgDict['background']}',
  108. fit: BoxFit.fill,
  109. height: MediaQuery.of(context).padding.top+hsp(450),
  110. width: MediaQuery.of(context).size.width,
  111. ),
  112. ),
  113. GestureDetector(
  114. onTap: (){
  115. Navigator.pop(context);
  116. },
  117. child: Container(
  118. margin: EdgeInsets.only(left: hsp(30),right: wsp(30),top: MediaQuery.of(context).padding.top+hsp(50)),
  119. child: Icon(Icons.arrow_back_ios,color: Colors.white,size: hsp(50),),
  120. ),
  121. ),
  122. GestureDetector(
  123. onTap: (){
  124. Navigator.of(context).push(
  125. CupertinoPageRoute(builder: (context){
  126. return YSSearchResult(type: widget.type,);
  127. })
  128. );
  129. },
  130. child : Container(
  131. margin: EdgeInsets.only(left: hsp(110),top: MediaQuery.of(context).padding.top+hsp(45)),
  132. width: MediaQuery.of(context).size.width-hsp(140),
  133. height: hsp(60),
  134. decoration: BoxDecoration(
  135. color: Colors.black.withOpacity(0.35),
  136. borderRadius: BorderRadius.all(Radius.circular(50))
  137. ),
  138. padding: EdgeInsets.only(left: wsp(30),right: wsp(30)),
  139. child: Row(
  140. children: [
  141. Row(
  142. children: [
  143. Text(_cityStr,style: TextStyle(fontSize: zsp(26),color: Colors.white),),
  144. Icon(Icons.keyboard_arrow_down,color: Colors.white.withOpacity(0.5),size: hsp(40),)
  145. ],
  146. ),
  147. Container(
  148. height: hsp(30),
  149. width: 0.5,
  150. margin: EdgeInsets.only(left: wsp(10),right: wsp(10)),
  151. color: Colors.white.withOpacity(0.2),
  152. ),
  153. Row(
  154. children: [
  155. Icon(Icons.search,color: Colors.white.withOpacity(0.5),size: hsp(50),),
  156. Text(' 搜索',style: TextStyle(fontSize: zsp(26),color: Colors.white.withOpacity(0.5)),),
  157. ],
  158. )
  159. ],
  160. ),
  161. ),
  162. ),
  163. if(_msgDict!=null)Container(
  164. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(260)),
  165. height: hsp(200),
  166. decoration: BoxDecoration(
  167. color: Colors.white,
  168. borderRadius: BorderRadius.only(topRight: Radius.circular(10),topLeft: Radius.circular(10))
  169. ),
  170. padding: EdgeInsets.only(left: hsp(30),right: hsp(30)),
  171. width: MediaQuery.of(context).size.width,
  172. child: Row(
  173. children: [
  174. Image.network(widget.shop['logo'],height: hsp(100),width: hsp(100),),
  175. Container(
  176. width: MediaQuery.of(context).size.width-hsp(220),
  177. padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  178. child: Column(
  179. crossAxisAlignment: CrossAxisAlignment.start,
  180. mainAxisSize: MainAxisSize.min,
  181. children: [
  182. Text(widget.shop['name'],style: TextStyle(fontSize: zsp(30),
  183. color: Colors.black,fontWeight: FontWeight.bold),),
  184. Text(widget.shop['address'],style: TextStyle(fontSize: zsp(28),
  185. color: Colors.grey,height: 2),)
  186. ],
  187. ),
  188. ),
  189. ],
  190. ),
  191. ),
  192. Container(
  193. margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+hsp(430)),
  194. height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-hsp(350),
  195. width: MediaQuery.of(context).size.width,
  196. color: Colors.white,
  197. child: Column(
  198. children: [
  199. Container(
  200. width: MediaQuery.of(context).size.width,
  201. height: hsp(80),
  202. child: ListView.builder(
  203. itemBuilder: (context,index){
  204. return GestureDetector(
  205. onTap: (){
  206. _titleIndex = index;
  207. _refreshData();
  208. },
  209. child: Container(
  210. height: hsp(80),
  211. width: MediaQuery.of(context).size.width/4,
  212. alignment: Alignment.center,
  213. child: Text('${_titles[index]}',style: TextStyle(fontSize: zsp(26),color: _titleIndex==index?Color(0xFF007AFF):Color(0xFF222222),fontWeight: _titleIndex==index?FontWeight.bold:FontWeight.normal),),
  214. ),
  215. );
  216. },
  217. itemCount: _titles.length,
  218. padding: EdgeInsets.all(0),
  219. scrollDirection: Axis.horizontal,
  220. ),
  221. ),
  222. Divider(height: 0.5,thickness: 0.5,color: Color(0xFFEEEEEE),),
  223. Container(
  224. width: MediaQuery.of(context).size.width,
  225. height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-hsp(510)-0.5,
  226. child: EasyRefresh(
  227. onRefresh: _refreshData,
  228. onLoad: _loadMoreData,
  229. header: TaurusHeader(
  230. ),
  231. footer: TaurusFooter(
  232. ),
  233. child: ListView.separated(
  234. itemBuilder: (context,index){
  235. Map item = _dataArray[index];
  236. return GestureDetector(
  237. behavior: HitTestBehavior.opaque,
  238. onTap: (){
  239. Navigator.of(context).push(
  240. CupertinoPageRoute(
  241. builder: (context){
  242. return item['type']==4||item['type']==5||item['type']==9?YSMarryPlane(
  243. marryId: item['id'],type: item['type']
  244. ):item['type']==6?YSShortDetail(
  245. shortId: item['id'],
  246. ):YSContractPlaneDetail(
  247. contractId: item['id'],
  248. isWhole: item['type'],
  249. );
  250. }
  251. )
  252. );
  253. },
  254. child: Container(
  255. padding: EdgeInsets.all(hsp(30)),
  256. child: Row(
  257. children: [
  258. Container(
  259. height: hsp(200),
  260. width: hsp(250),
  261. child: ysImageLoad(
  262. imageUrl: '${item['cover']}',
  263. fit: BoxFit.fill,
  264. height: hsp(200),
  265. width: hsp(250),
  266. ),
  267. margin: EdgeInsets.only(right: hsp(30)),
  268. ),
  269. Container(
  270. width: MediaQuery.of(context).size.width-hsp(340),
  271. height: hsp(200),
  272. child: Column(
  273. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  274. crossAxisAlignment: CrossAxisAlignment.start,
  275. children: [
  276. Text('${item['title']}',style: TextStyle(fontSize: zsp(30),color: Color(0xFF343434)),maxLines: 2,),
  277. Text('${item['companyName']}',style: TextStyle(fontSize: zsp(24),color: Color(0xFF9A9A9A)),),
  278. Row(
  279. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  280. children: [
  281. Text('${item['modelNum']}',style: TextStyle(fontSize: zsp(24),color: Color(0xFF9A9A9A)),),
  282. RichText(
  283. text: TextSpan(
  284. text: '¥',
  285. style: TextStyle(fontSize: zsp(24),color: Color(0xFFEB423B)),
  286. children: [
  287. TextSpan(
  288. text: '${item['discountPrice']}',
  289. style: TextStyle(fontSize: zsp(42),fontWeight: FontWeight.bold),
  290. ),
  291. TextSpan(
  292. text: '元起',
  293. style: TextStyle(fontSize: zsp(20)),
  294. )
  295. ]
  296. ),
  297. )
  298. ],
  299. )
  300. ],
  301. ),
  302. )
  303. ],
  304. ),
  305. ),
  306. );
  307. },
  308. separatorBuilder: (context,index){
  309. return Divider(height: 0.5,thickness: 0.5,color: Color(0xFFEEEEEE),);
  310. },
  311. itemCount: _dataArray.length,
  312. padding: EdgeInsets.all(0),
  313. ),
  314. ),
  315. ),
  316. ],
  317. ),
  318. ),
  319. ],
  320. ),
  321. ),
  322. );
  323. }
  324. Future<void> _refreshData() async{
  325. SharedPreferences preferences = await SharedPreferences.getInstance();
  326. _cityStr = preferences.getString('location');
  327. _page = 1;
  328. Map request = {};
  329. request['partnerId'] = widget.shop['partnerId'];
  330. request['pageNo'] = _page;
  331. request['type'] = 4-_titleIndex;
  332. request['location'] = widget.location;
  333. Map dict = await ysRequestHttp(context,type: requestType.get,
  334. api: '/app/applets/AirTour/partner_list',parameter: request,isLoading: false,isToken: true);
  335. if(dict!=null){
  336. _msgDict = dict['partnerHome'];
  337. _dataArray = dict['data']['resultList'];
  338. setState(() {});
  339. }
  340. }
  341. Future<void> _loadMoreData() async{
  342. _page++;
  343. Map request = {};
  344. request['partnerId'] = widget.shop['partnerId'];
  345. request['pageNo'] = _page;
  346. request['type'] = 4-_titleIndex;
  347. request['location'] = widget.location;
  348. Map dict = await ysRequestHttp(context,type: requestType.get,
  349. api: '/app/applets/AirTour/partner_list',parameter: request,isLoading: false,isToken: true);
  350. if(dict!=null){
  351. _dataArray.addAll(dict['data']['resultList']);
  352. setState(() {});
  353. }
  354. }
  355. }