ad_details_page.dart 20 KB

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