ad_details_page.dart 20 KB

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