ad_details_page.dart 20 KB

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