ad_details_page.dart 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. import 'dart:convert';
  2. import 'package:bbyyy/beans/ad_bean_entity.dart';
  3. import 'package:bbyyy/beans/goods_bean_entity.dart';
  4. import 'package:bbyyy/beans/my_shop_bean_entity.dart';
  5. import 'package:bbyyy/beans/smart_order_bean_entity.dart';
  6. import 'package:bbyyy/https/MyDio.dart';
  7. import 'package:bbyyy/https/url.dart';
  8. import 'package:bbyyy/my_tools/AsperctRaioImage.dart';
  9. import 'package:bbyyy/my_tools/const.dart';
  10. import 'package:bbyyy/my_tools/dims.dart';
  11. import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
  12. import 'package:bbyyy/my_tools/my_colors.dart';
  13. import 'package:bbyyy/my_tools/my_cookie.dart';
  14. import 'package:bbyyy/my_tools/my_tools.dart';
  15. import 'package:bbyyy/my_tools/my_views.dart';
  16. import 'package:bbyyy/paegs/gang_page/gang_in_page/gang_in_page.dart';
  17. import 'package:bbyyy/paegs/mine_page/advertising_page/new_ad_page.dart';
  18. import 'package:bbyyy/paegs/product_details_page/product_details_page.dart';
  19. import 'package:flutter/cupertino.dart';
  20. import 'package:flutter/material.dart';
  21. import '../../paegs/pay_page/pay_page.dart';
  22. class AdDetailsPage extends StatefulWidget {
  23. AdBeanDataData data;
  24. bool canBeModified;
  25. AdDetailsPage(this.data, {this.canBeModified = false});
  26. @override
  27. _AdDetailsPageState createState() => _AdDetailsPageState();
  28. }
  29. class _AdDetailsPageState extends State<AdDetailsPage> {
  30. @override
  31. Widget build(BuildContext context) {
  32. print(json.encode(widget.data));
  33. return Scaffold(
  34. body: Column(
  35. children: [
  36. MyViews().myAppBar('广告详情', context, [
  37. widget.canBeModified
  38. ? GestureDetector(
  39. onTap: () {
  40. MyTools().toPage(context, NewAdPage(widget.data), (then) {
  41. if (then is bool) {
  42. if (!then) {
  43. Navigator.pop(context);
  44. }
  45. }
  46. });
  47. },
  48. behavior: HitTestBehavior.translucent,
  49. child: Container(
  50. padding:
  51. EdgeInsets.symmetric(vertical: 8, horizontal: 16),
  52. child: Icon(Icons.more_horiz),
  53. ),
  54. )
  55. : Container()
  56. ]),
  57. Container(
  58. height: 10,
  59. color: MyColors.cF7F7F7,
  60. ),
  61. Expanded(
  62. child: SingleChildScrollView(
  63. child: Column(
  64. children: [
  65. MyViews().netImg(
  66. imgURL(widget.data.coverPath), 314, double.infinity,
  67. placeholder: 'images/svg/goodsDefImg.svg'),
  68. Container(
  69. color: Colors.white,
  70. width: double.infinity,
  71. padding: EdgeInsets.fromLTRB(15, 15, 15, 18),
  72. child: Column(
  73. children: [
  74. Container(
  75. margin: EdgeInsets.only(bottom: 11),
  76. child: Text(
  77. '${widget.data.title}',
  78. style: TextStyle(
  79. color: MyColors.c333333,
  80. fontSize: 15,
  81. height: 1.4),
  82. ),
  83. ),
  84. ],
  85. crossAxisAlignment: CrossAxisAlignment.start,
  86. ),
  87. ),
  88. Container(
  89. color: Colors.white,
  90. child: Column(
  91. children: [
  92. MyViews().myText('广告描述', MyColors.c333333, 14),
  93. Container(
  94. child: MyViews().myText('${widget.data.description}',
  95. MyColors.c666666, 12),
  96. margin: EdgeInsets.only(top: 5),
  97. )
  98. ],
  99. crossAxisAlignment: CrossAxisAlignment.start,
  100. ),
  101. alignment: Alignment.centerLeft,
  102. padding: EdgeInsets.symmetric(horizontal: 14, vertical: 12),
  103. margin: EdgeInsets.only(top: 5),
  104. ),
  105. Container(
  106. color: Colors.white,
  107. child: MyViews().myText('广告详情', MyColors.c333333, 14),
  108. alignment: Alignment.centerLeft,
  109. margin: EdgeInsets.only(top: 5, bottom: 2),
  110. padding: EdgeInsets.symmetric(horizontal: 14, vertical: 12),
  111. ),
  112. Column(
  113. children: images(),
  114. ),
  115. Container(
  116. height: 10,
  117. )
  118. ],
  119. ),
  120. ),
  121. ),
  122. Visibility(
  123. visible: widget.data.linkId != 0 && !widget.canBeModified,
  124. child: SafeArea(
  125. top: false,
  126. child: Container(
  127. padding: EdgeInsets.symmetric(horizontal: 37),
  128. color: Colors.white,
  129. width: double.infinity,
  130. height: 60,
  131. child: Row(
  132. children: [
  133. Expanded(
  134. child: GestureDetector(
  135. onTap: () {
  136. if (widget.data.linkType == 0) {
  137. //进入店铺
  138. enterAShop();
  139. } else {
  140. //进入商品
  141. enterTheProduct();
  142. }
  143. },
  144. behavior: HitTestBehavior.translucent,
  145. child: Container(
  146. decoration: BoxDecoration(
  147. borderRadius: BorderRadius.circular(20),
  148. color: MyColors.cFF4233),
  149. height: 40,
  150. child: MyViews().myText(
  151. widget.data.linkType == 0 ? '查看货帮' : '查看货品',
  152. Colors.white,
  153. 14),
  154. alignment: Alignment.center),
  155. ),
  156. )
  157. ],
  158. ),
  159. ),
  160. ),
  161. ),
  162. Visibility(
  163. visible: !widget.data.paid && widget.canBeModified,
  164. child: SafeArea(
  165. top: false,
  166. child: Container(
  167. padding: EdgeInsets.symmetric(horizontal: 37),
  168. color: Colors.white,
  169. width: double.infinity,
  170. height: 60,
  171. child: Row(
  172. children: [
  173. Expanded(
  174. child: GestureDetector(
  175. onTap: () {
  176. //支付广告订单
  177. payForInsertionOrder();
  178. },
  179. behavior: HitTestBehavior.translucent,
  180. child: Container(
  181. decoration: BoxDecoration(
  182. borderRadius: BorderRadius.circular(20),
  183. color: MyColors.cFF4233),
  184. height: 40,
  185. child: MyViews().myText('立即支付', Colors.white, 14),
  186. alignment: Alignment.center),
  187. ),
  188. )
  189. ],
  190. ),
  191. ),
  192. ),
  193. )
  194. ],
  195. ),
  196. );
  197. }
  198. images() {
  199. List<Widget> imgs = [];
  200. widget.data.pictures.split(',').forEach((element) {
  201. imgs.add(AsperctRaioImage.network(imgURL(element),
  202. builder: (context, snapshot, url) {
  203. return MyViews().netImg(
  204. imgURL(element),
  205. (snapshot.data.height.toDouble() / 5) /
  206. (snapshot.data.width.toDouble() / 5) *
  207. MediaQuery.of(context).size.width,
  208. MediaQuery.of(context).size.width,
  209. placeholder: 'images/svg/goodsDefImg.svg');
  210. }));
  211. });
  212. return imgs;
  213. }
  214. void enterAShop() {
  215. MyDio().query({
  216. "key": "shop_user",
  217. "filters": {
  218. "conditions": ["id==${widget.data.linkId}"],
  219. },
  220. "dims": shopUserDims,
  221. "paging": [1, 1],
  222. "order_by": ["shop_name,DESC"]
  223. }, (response, hasError) {
  224. if (!hasError) {
  225. MyShopBeanEntity entity =
  226. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  227. MyTools()
  228. .toPage(context, GangInPage(entity.data.data[0], null), (then) {});
  229. }
  230. }, (error) {});
  231. }
  232. void enterTheProduct() {
  233. MyDio().query({
  234. "key": "commodity",
  235. "filters": {
  236. "conditions": ["id == ${widget.data.linkId}"]
  237. },
  238. "dims": commodityDims,
  239. "paging": [1, 1]
  240. }, (response, hasError) {
  241. if (!hasError) {
  242. GoodsBeanEntity entity =
  243. GoodsBeanEntity().fromJson(json.decode(response.data.toString()));
  244. MyTools().toPage(
  245. context, ProductDetailsPage(entity.data.data[0]), (then) {});
  246. }
  247. }, (error) {});
  248. }
  249. void payForInsertionOrder() {
  250. MyDio().query({
  251. 'key': 'order',
  252. "filters": {
  253. "conditions": [
  254. "commodity_id == ${widget.data.id}",
  255. "type == $orderTypeAdvertise"
  256. ]
  257. },
  258. "dims": orderDims,
  259. "paging": [1, 1]
  260. }, (response, hasError) {
  261. if (!hasError) {
  262. SmartOrderBeanEntity entity = SmartOrderBeanEntity()
  263. .fromJson(json.decode(response.data.toString()));
  264. showPayOrder(entity.data.data[0]);
  265. }
  266. }, (error) {});
  267. }
  268. void showPayOrder(SmartOrderBeanDataData order) {
  269. EasyLoading.instance
  270. ..contentPadding = EdgeInsets.symmetric(horizontal: 0, vertical: 12)
  271. ..alignment = Alignment.bottomCenter
  272. ..loadingStyle = EasyLoadingStyle.light
  273. ..contentMargin = EdgeInsets.fromLTRB(20, 20, 20, 65);
  274. double price = order.amount;
  275. EasyLoading.show(
  276. indicator: Material(
  277. color: Colors.white,
  278. child: Column(
  279. children: [
  280. Container(
  281. margin: EdgeInsets.symmetric(horizontal: 12),
  282. child: Row(
  283. children: [
  284. Container(
  285. child: Image.asset(
  286. 'images/app_logo.png',
  287. height: 27,
  288. width: 27,
  289. ),
  290. margin: EdgeInsets.only(right: 8),
  291. height: 45,
  292. width: 45,
  293. decoration: BoxDecoration(
  294. border: Border.all(color: MyColors.cEBEBEB, width: 1)),
  295. alignment: Alignment.center,
  296. ),
  297. Expanded(
  298. child: Container(
  299. height: 45,
  300. child: Column(
  301. children: [
  302. MyViews().myText('广告费', MyColors.c333333, 13),
  303. Row(
  304. children: [
  305. MyViews().myText('¥${price.toStringAsFixed(2)}',
  306. MyColors.cFF4233, 12),
  307. ],
  308. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  309. )
  310. ],
  311. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  312. crossAxisAlignment: CrossAxisAlignment.start,
  313. ),
  314. ),
  315. ),
  316. ],
  317. ),
  318. ),
  319. Container(
  320. height: 0.5,
  321. color: MyColors.cE7E7E7,
  322. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  323. ),
  324. Container(
  325. margin: EdgeInsets.symmetric(horizontal: 12),
  326. child: Row(
  327. children: [
  328. MyViews().myText('卖家信息:', MyColors.c333333, 13),
  329. Row(
  330. children: [
  331. Container(
  332. margin: EdgeInsets.only(right: 5),
  333. child: ClipRRect(
  334. child: Image.asset(
  335. 'images/app_logo.png',
  336. height: 23,
  337. width: 23,
  338. ),
  339. borderRadius: BorderRadius.circular(11.5),
  340. ),
  341. ),
  342. MyViews().myText('$appName', MyColors.c333333, 13),
  343. ],
  344. )
  345. ],
  346. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  347. ),
  348. ),
  349. Container(
  350. height: 0.5,
  351. color: MyColors.cE7E7E7,
  352. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  353. ),
  354. Container(
  355. margin: EdgeInsets.symmetric(horizontal: 12),
  356. child: Row(
  357. children: [
  358. MyViews().myText('买家信息:', MyColors.c333333, 13),
  359. Row(
  360. children: [
  361. Container(
  362. margin: EdgeInsets.only(right: 5),
  363. child: ClipRRect(
  364. child: MyViews().netImg(
  365. imgURL(MyCookie().userBean.picture), 23, 23),
  366. borderRadius: BorderRadius.circular(11.5),
  367. ),
  368. ),
  369. MyViews().myText(
  370. '${MyCookie().userBean.name}(${MyCookie().userBean.uid})',
  371. MyColors.c333333,
  372. 13),
  373. ],
  374. )
  375. ],
  376. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  377. ),
  378. ),
  379. Container(
  380. height: 0.5,
  381. color: MyColors.cE7E7E7,
  382. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  383. ),
  384. Container(
  385. margin: EdgeInsets.symmetric(horizontal: 12),
  386. child: Row(
  387. children: [
  388. MyViews().myText('下单时间:', MyColors.c333333, 13),
  389. MyViews().myText(
  390. '${DateTime.now().toString().substring(0, 19)}',
  391. MyColors.c333333,
  392. 13)
  393. ],
  394. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  395. ),
  396. ),
  397. Container(
  398. height: 0.5,
  399. color: MyColors.cE7E7E7,
  400. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  401. ),
  402. Container(
  403. margin: EdgeInsets.symmetric(horizontal: 20),
  404. child: Row(
  405. children: [
  406. Expanded(
  407. child: GestureDetector(
  408. onTap: () {
  409. EasyLoading.dismiss();
  410. },
  411. behavior: HitTestBehavior.translucent,
  412. child: Container(
  413. decoration: BoxDecoration(
  414. borderRadius: BorderRadius.only(
  415. topLeft: Radius.circular(20),
  416. bottomLeft: Radius.circular(20),
  417. ),
  418. border: Border.all(
  419. color: MyColors.cFF4233, width: 1)),
  420. height: 40,
  421. child: MyViews().myText('稍后支付', MyColors.cFF4233, 14),
  422. alignment: Alignment.center),
  423. ),
  424. ),
  425. Expanded(
  426. child: GestureDetector(
  427. onTap: () {
  428. MyTools().toPage(context,
  429. PayPage(order.uid, false, price), (then) {});
  430. // getUserWalletBalance((re, hE) {
  431. // if (!hE) {
  432. // UserBalanceEntity balance = UserBalanceEntity()
  433. // .fromJson(json.decode(re.data.toString()));
  434. // if (balance.data >= price) {
  435. // payOrder(payWayWallet, order.uid, (re, hE) {
  436. // if (!hE) {
  437. // showToast('支付成功');
  438. // EventBus().emit('payAnOrder');
  439. // }
  440. // }, (e) {}, context);
  441. // } else {
  442. // payOrder(payWayAliPay, order.uid, (re, hE) {
  443. // if (!hE) {
  444. // PayByAlipayBeanEntity entity =
  445. // PayByAlipayBeanEntity().fromJson(
  446. // json.decode(re.data.toString()));
  447. // EventBus().on('alipayPaymentCallback', (arg) {
  448. // EventBus().off('alipayPaymentCallback');
  449. // EasyLoading.dismiss();
  450. // showToast('支付成功');
  451. // EventBus().emit('reNoPayOrder');
  452. // });
  453. // print(entity.data);
  454. // EasyLoading.instance
  455. // ..contentPadding = EdgeInsets.symmetric(
  456. // horizontal: 20, vertical: 12)
  457. // ..alignment = Alignment.center
  458. // ..loadingStyle = EasyLoadingStyle.light
  459. // ..contentMargin = EdgeInsets.all(20);
  460. // EasyLoading.show();
  461. // aliPay(entity.data).then((value) {
  462. // print(json.encode(value));
  463. // AlipayResultBeanEntity e =
  464. // AlipayResultBeanEntity().fromJson(
  465. // json.decode(json.encode(value)));
  466. // try {
  467. // int r = int.parse(e.resultStatus);
  468. // if (r == 9000) {
  469. // showToast('支付成功');
  470. // } else {
  471. // showToast(aliPayResultStatus(r));
  472. // resetOrder(order.uid);
  473. // }
  474. // } catch (e) {
  475. // EasyLoading.dismiss();
  476. // }
  477. // });
  478. // // EventBus().emit('payAnOrder');
  479. // }
  480. // }, (e) {}, context);
  481. // // showToast('积分余额不足');
  482. // }
  483. // }
  484. // }, (e) {}, context);
  485. },
  486. behavior: HitTestBehavior.translucent,
  487. child: Container(
  488. decoration: BoxDecoration(
  489. borderRadius: BorderRadius.only(
  490. topRight: Radius.circular(20),
  491. bottomRight: Radius.circular(20),
  492. ),
  493. color: MyColors.cFF4233),
  494. height: 40,
  495. child: MyViews().myText('立即支付', Colors.white, 14),
  496. alignment: Alignment.center),
  497. ),
  498. )
  499. ],
  500. ),
  501. )
  502. ],
  503. ),
  504. ),
  505. );
  506. }
  507. }