product_details_page.dart 17 KB

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