ad_details_page.dart 20 KB

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