product_details_page.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. import 'dart:convert';
  2. import 'package:bbyyy/beans/goods_bean_entity.dart';
  3. import 'package:bbyyy/beans/my_shop_bean_entity.dart';
  4. import 'package:bbyyy/https/MyDio.dart';
  5. import 'package:bbyyy/https/url.dart';
  6. import 'package:bbyyy/my_tools/AsperctRaioImage.dart';
  7. import 'package:bbyyy/my_tools/dims.dart';
  8. import 'package:bbyyy/my_tools/event_bus.dart';
  9. import 'package:bbyyy/my_tools/global.dart';
  10. import 'package:bbyyy/my_tools/my_colors.dart';
  11. import 'package:bbyyy/my_tools/my_cookie.dart';
  12. import 'package:bbyyy/my_tools/my_tools.dart';
  13. import 'package:bbyyy/my_tools/my_views.dart';
  14. import 'package:bbyyy/paegs/chat_page/chat_page.dart';
  15. import 'package:bbyyy/paegs/gang_page/gang_in_page/gang_in_page.dart';
  16. import 'package:bbyyy/paegs/place_an_order_page/place_an_order_page.dart';
  17. import 'package:flutter/cupertino.dart';
  18. import 'package:flutter/material.dart';
  19. class ProductDetailsPage extends StatefulWidget {
  20. GoodsBeanDataData data;
  21. ProductDetailsPage(this.data);
  22. @override
  23. _ProductDetailsPageState createState() => _ProductDetailsPageState();
  24. }
  25. class _ProductDetailsPageState extends State<ProductDetailsPage> {
  26. int statusIndex = 0;
  27. _ProductDetailsPageState();
  28. MyShopBeanDataData shop;
  29. @override
  30. void initState() {
  31. // TODO: implement initState
  32. super.initState();
  33. queryStoreInformation();
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. return Scaffold(
  38. backgroundColor: MyColors.cF7F7F7,
  39. body: Column(
  40. children: [
  41. MyViews().myAppBar(
  42. '商品详情',
  43. context,
  44. shop != null && shop.ownerUid == MyCookie().getUID()
  45. ? [
  46. GestureDetector(
  47. onTap: () {
  48. showSimpleDialog(
  49. '确认下架商品(${widget.data.title})', context, () {
  50. Navigator.pop(context);
  51. MyDio().update({
  52. 'key': 'commodity',
  53. 'values': {
  54. 'id': widget.data.id,
  55. 'on_sale': false,
  56. }
  57. }, (response, hasError) {
  58. if (!hasError) {
  59. showToast('已下架');
  60. Navigator.pop(context);
  61. EventBus().emit('商品变动');
  62. }
  63. }, (error) {});
  64. });
  65. },
  66. behavior: HitTestBehavior.translucent,
  67. child: Container(
  68. decoration: BoxDecoration(
  69. border:
  70. Border.all(color: MyColors.cFF4233, width: 1),
  71. borderRadius: BorderRadius.circular(12.5),
  72. ),
  73. height: 25,
  74. width: 50,
  75. child: MyViews().myText('下架', MyColors.cFF4233, 14),
  76. alignment: Alignment.center,
  77. ),
  78. ),
  79. GestureDetector(
  80. onTap: () {
  81. showSimpleDialog(
  82. '确认删除商品(${widget.data.title})', context, () {
  83. Navigator.pop(context);
  84. MyDio().del({
  85. 'key': 'commodity',
  86. 'ids': [widget.data.id]
  87. }, (response, hasError) {
  88. if (!hasError) {
  89. showToast('删除成功');
  90. Navigator.pop(context);
  91. EventBus().emit('商品变动');
  92. }
  93. }, (error) {});
  94. });
  95. },
  96. behavior: HitTestBehavior.translucent,
  97. child: Container(
  98. margin: EdgeInsets.symmetric(horizontal: 10),
  99. decoration: BoxDecoration(
  100. color: MyColors.cFF4233,
  101. borderRadius: BorderRadius.circular(12.5),
  102. ),
  103. height: 25,
  104. width: 50,
  105. child: MyViews().myText('删除', Colors.white, 14),
  106. alignment: Alignment.center,
  107. ),
  108. ),
  109. ]
  110. : []),
  111. Expanded(
  112. child: Stack(
  113. children: [
  114. SingleChildScrollView(
  115. child: Column(
  116. children: [
  117. MyViews().netImg(
  118. imgURL(widget.data.coverPath), 314, double.infinity,
  119. placeholder: 'images/svg/goodsDefImg.svg'),
  120. Container(
  121. color: Colors.white,
  122. padding: EdgeInsets.fromLTRB(15, 15, 15, 18),
  123. child: Column(
  124. children: [
  125. Container(
  126. margin: EdgeInsets.only(bottom: 11),
  127. child: Text(
  128. '${widget.data.title}',
  129. style: TextStyle(
  130. color: MyColors.c333333,
  131. fontSize: 15,
  132. height: 1.4),
  133. ),
  134. ),
  135. Row(
  136. children: [
  137. Row(
  138. children: [
  139. Text(
  140. '¥',
  141. style: TextStyle(
  142. color: MyColors.cFF4233,
  143. fontSize: 14,
  144. height: 1),
  145. ),
  146. Text(
  147. '${widget.data.price}',
  148. style: TextStyle(
  149. color: MyColors.cFF4233,
  150. fontSize: 20,
  151. height: 1),
  152. ),
  153. Container(
  154. width: 8,
  155. ),
  156. Text(
  157. '价格¥',
  158. style: TextStyle(
  159. color: MyColors.c999999,
  160. fontSize: 13,
  161. height: 1),
  162. ),
  163. Text(
  164. '${widget.data.originalPrice}',
  165. style: TextStyle(
  166. color: MyColors.c999999,
  167. fontSize: 13,
  168. decoration:
  169. TextDecoration.lineThrough,
  170. height: 1),
  171. ),
  172. ],
  173. crossAxisAlignment: CrossAxisAlignment.end,
  174. ),
  175. Text(
  176. '库存:${widget.data.stock}',
  177. style: TextStyle(
  178. color: MyColors.c666666, fontSize: 14),
  179. ),
  180. ],
  181. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  182. )
  183. ],
  184. crossAxisAlignment: CrossAxisAlignment.start,
  185. ),
  186. ),
  187. Container(
  188. color: Colors.white,
  189. child: Column(
  190. children: [
  191. MyViews().myText('商品描述', MyColors.c333333, 14),
  192. Container(
  193. child: MyViews().myText(
  194. '${widget.data.description}',
  195. MyColors.c666666,
  196. 12),
  197. margin: EdgeInsets.only(top: 5),
  198. )
  199. ],
  200. crossAxisAlignment: CrossAxisAlignment.start,
  201. ),
  202. alignment: Alignment.centerLeft,
  203. padding:
  204. EdgeInsets.symmetric(horizontal: 14, vertical: 12),
  205. margin: EdgeInsets.only(top: 5),
  206. ),
  207. Container(
  208. color: Colors.white,
  209. child: MyViews().myText('商品详情', MyColors.c333333, 14),
  210. alignment: Alignment.centerLeft,
  211. margin: EdgeInsets.only(top: 5, bottom: 2),
  212. padding:
  213. EdgeInsets.symmetric(horizontal: 14, vertical: 12),
  214. ),
  215. Column(
  216. children: images(),
  217. ),
  218. Container(
  219. height: 10,
  220. )
  221. ],
  222. ),
  223. ),
  224. GestureDetector(
  225. onTap: () {
  226. toGangPage();
  227. },
  228. behavior: HitTestBehavior.translucent,
  229. child: Container(
  230. decoration: BoxDecoration(
  231. borderRadius: BorderRadius.only(
  232. bottomRight: Radius.circular(21),
  233. bottomLeft: Radius.circular(21),
  234. ),
  235. color: Colors.white),
  236. height: 56,
  237. padding: EdgeInsets.only(left: 16, right: 14),
  238. child: Row(
  239. children: [
  240. ClipRRect(
  241. child: MyViews()
  242. .netImg(imgURL(widget.data.shopPic), 40, 40),
  243. borderRadius: BorderRadius.all(Radius.circular(20)),
  244. ),
  245. Expanded(
  246. child: Container(
  247. margin: EdgeInsets.only(left: 10),
  248. child: MyViews().myText(
  249. widget.data.shopName, MyColors.c333333, 15),
  250. ),
  251. ),
  252. Container(child: MyViews().myText('进店逛逛', Colors.white, 12),decoration: BoxDecoration(
  253. borderRadius: BorderRadius.circular(12),
  254. color: MyColors.cFF4233
  255. ),height: 24,width: 60,alignment: Alignment.center,),
  256. // Container(
  257. // decoration: BoxDecoration(
  258. // color: MyColors.cFFCD74,
  259. // borderRadius: BorderRadius.circular(10),
  260. // ),
  261. // child: Icon(
  262. // Icons.chevron_right,
  263. // color: Colors.white,
  264. // size: 20,
  265. // ),
  266. // height: 20,
  267. // width: 20,
  268. // alignment: Alignment.center,
  269. // )
  270. ],
  271. ),
  272. ),
  273. ),
  274. ],
  275. ),
  276. ),
  277. SafeArea(
  278. top: false,
  279. child: Container(
  280. padding: EdgeInsets.symmetric(horizontal: 37),
  281. color: Colors.white,
  282. width: double.infinity,
  283. height: 60,
  284. child: Row(
  285. children: [
  286. Expanded(
  287. child: GestureDetector(
  288. onTap: () {
  289. queryShopMembers();
  290. },
  291. behavior: HitTestBehavior.translucent,
  292. child: Container(
  293. decoration: BoxDecoration(
  294. borderRadius: BorderRadius.only(
  295. topLeft: Radius.circular(20),
  296. bottomLeft: Radius.circular(20),
  297. ),
  298. border: Border.all(
  299. color: MyColors.cFF4233, width: 1)),
  300. height: 40,
  301. child: MyViews().myText('联系卖家', MyColors.cFF4233, 14),
  302. alignment: Alignment.center),
  303. ),
  304. ),
  305. Expanded(
  306. child: GestureDetector(
  307. onTap: () {
  308. MyTools().toPage(
  309. context, PlaceAnOrderPage(widget.data), (then) {});
  310. },
  311. behavior: HitTestBehavior.translucent,
  312. child: Container(
  313. decoration: BoxDecoration(
  314. borderRadius: BorderRadius.only(
  315. topRight: Radius.circular(20),
  316. bottomRight: Radius.circular(20),
  317. ),
  318. color: MyColors.cFF4233),
  319. height: 40,
  320. child: MyViews().myText('立即下单', Colors.white, 14),
  321. alignment: Alignment.center),
  322. ),
  323. )
  324. ],
  325. ),
  326. ),
  327. )
  328. ],
  329. ),
  330. );
  331. }
  332. images() {
  333. List<Widget> imgs = [];
  334. widget.data.pictures.split(',').forEach((element) {
  335. imgs.add(AsperctRaioImage.network(imgURL(element),
  336. builder: (context, snapshot, url) {
  337. return MyViews().netImg(
  338. imgURL(element),
  339. (snapshot.data.height.toDouble() / 5) /
  340. (snapshot.data.width.toDouble() / 5) *
  341. MediaQuery.of(context).size.width,
  342. MediaQuery.of(context).size.width,
  343. placeholder: 'images/svg/goodsDefImg.svg');
  344. }));
  345. });
  346. return imgs;
  347. }
  348. List<MyShopBeanDataData> member = [];
  349. List<MyShopBeanDataData> helper = [];
  350. queryShopMembers() {
  351. MyShopBeanDataData chatWith = MyShopBeanDataData();
  352. chatWith.userName = widget.data.userName;
  353. chatWith.userUid = widget.data.userUid;
  354. chatWith.userPic = widget.data.userPic;
  355. MyTools().toPage(context, ChatPage(chatWith, widget.data), (then) {});
  356. // MyDio().query({
  357. // "key": "shop_user",
  358. // "filters": {
  359. // "conditions": ["shop_uid==${data.shopUid}", "review_state==1"]
  360. // },
  361. // "dims": shopUserDims,
  362. // "paging": [1, 2000]
  363. // }, (response, hasError) {
  364. // if (!hasError) {
  365. // MyShopBeanEntity entity =
  366. // MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  367. // member = entity.data.data;
  368. // helper.clear();
  369. // member.forEach((element) {
  370. // if (element.role == shopUserStaff) {
  371. // helper.add(element);
  372. // }
  373. // });
  374. // MyShopBeanDataData chatWith;
  375. //
  376. // if(helper.length==0){
  377. // chatWith = member[member.indexWhere((element) => element.role==shopUserOwner)];
  378. // }else{
  379. // chatWith = helper[Random().nextInt(helper.length)];
  380. // }
  381. // MyTools().toPage(context, ChatPage(chatWith,data), (then){});
  382. // }
  383. // }, (error) {});
  384. }
  385. void toGangPage() {
  386. navigatorKey.currentState
  387. .push(MaterialPageRoute(builder: (context) => GangInPage(shop, null)));
  388. }
  389. void queryStoreInformation() {
  390. MyDio().query({
  391. "key": "shop_user",
  392. "filters": {
  393. "conditions": ["shop_uid==${widget.data.shopUid}"]
  394. },
  395. "dims": shopUserDims,
  396. "paging": [1, 1],
  397. "order_by": ["shop_name,DESC"]
  398. }, (response, hasError) {
  399. if (!hasError) {
  400. MyShopBeanEntity entity =
  401. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  402. shop = entity.data.data[0];
  403. setState(() {});
  404. }
  405. }, (error) {});
  406. }
  407. }