new_ad_page.dart 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:bbyyy/beans/ad_bean_entity.dart';
  4. import 'package:bbyyy/beans/ad_pricing_bean_entity.dart';
  5. import 'package:bbyyy/beans/alipay_result_bean_entity.dart';
  6. import 'package:bbyyy/beans/annual_fee_order_bean_entity.dart';
  7. import 'package:bbyyy/beans/goods_bean_entity.dart';
  8. import 'package:bbyyy/beans/my_shop_bean_entity.dart';
  9. import 'package:bbyyy/beans/pay_by_alipay_bean_entity.dart';
  10. import 'package:bbyyy/beans/upload_image_bean_entity.dart';
  11. import 'package:bbyyy/beans/user_balance_entity.dart';
  12. import 'package:bbyyy/https/MyDio.dart';
  13. import 'package:bbyyy/https/my_request.dart';
  14. import 'package:bbyyy/https/url.dart';
  15. import 'package:bbyyy/my_tools/const.dart';
  16. import 'package:bbyyy/my_tools/dims.dart';
  17. import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
  18. import 'package:bbyyy/my_tools/event_bus.dart';
  19. import 'package:bbyyy/my_tools/my_colors.dart';
  20. import 'package:bbyyy/my_tools/my_cookie.dart';
  21. import 'package:bbyyy/my_tools/my_tools.dart';
  22. import 'package:bbyyy/my_tools/my_views.dart';
  23. import 'package:bbyyy/pay/pay_tools.dart';
  24. import 'package:flustars/flustars.dart';
  25. import 'package:flutter/cupertino.dart';
  26. import 'package:flutter/material.dart';
  27. import 'package:flutter/services.dart';
  28. import 'package:flutter_svg/svg.dart';
  29. import 'package:tobias/tobias.dart';
  30. import 'associated_store_page.dart';
  31. import 'related_products_page.dart';
  32. class NewAdPage extends StatefulWidget {
  33. AdBeanDataData data;
  34. NewAdPage(this.data);
  35. @override
  36. _NewAdPageState createState() => _NewAdPageState();
  37. }
  38. class _NewAdPageState extends State<NewAdPage> {
  39. TextEditingController _title = TextEditingController();
  40. TextEditingController _description = TextEditingController();
  41. TextEditingController _days = TextEditingController();
  42. List<DropdownMenuItem<String>> sortItems = [];
  43. List<AdPricingBeanData> pricing = [];
  44. String typeValue = '';
  45. int typeIndex = 0;
  46. File cover;
  47. String coverPath = '';
  48. String picturesPath = '';
  49. List<File> pictures = [null, null, null];
  50. int associationType = -1;
  51. String startTime = '请选择时间';
  52. DateTime startDate;
  53. MyShopBeanDataData shop;
  54. GoodsBeanDataData product;
  55. @override
  56. void initState() {
  57. // TODO: implement initState
  58. super.initState();
  59. Future.delayed(Duration.zero, () {
  60. advertisingPricing((re, hE) {
  61. if (!hE) {
  62. AdPricingBeanEntity entity =
  63. AdPricingBeanEntity().fromJson(json.decode(re.data.toString()));
  64. if (entity.data.isEmpty) {
  65. return;
  66. }
  67. pricing = entity.data;
  68. typeValue = entity.data[0].type == 0 ? '店铺/商品部分广告' : '首页banner';
  69. typeIndex = entity.data[0].type;
  70. entity.data.forEach((element) {
  71. sortItems.add(DropdownMenuItem(
  72. child: Container(
  73. child: Text(
  74. element.type == 0 ? '店铺/商品部分广告' : '首页banner',
  75. style: TextStyle(color: MyColors.c333333, fontSize: 15),
  76. textAlign: TextAlign.end,
  77. ),
  78. alignment: Alignment.centerRight,
  79. width: 150,
  80. ),
  81. value: element.type == 0 ? '店铺/商品部分广告' : '首页banner',
  82. ));
  83. });
  84. if (widget.data != null) {
  85. initAd();
  86. }
  87. setState(() {});
  88. }
  89. });
  90. });
  91. }
  92. @override
  93. Widget build(BuildContext context) {
  94. return GestureDetector(
  95. onTap: () {
  96. MyTools().hideKeyboard(context);
  97. },
  98. behavior: HitTestBehavior.translucent,
  99. child: Scaffold(
  100. backgroundColor: MyColors.cF7F7F7,
  101. body: Column(
  102. children: [
  103. MyViews().myAppBar('发布广告', context, []),
  104. Container(
  105. height: 10,
  106. color: MyColors.cF7F7F7,
  107. ),
  108. Expanded(
  109. child: SingleChildScrollView(
  110. child: Column(
  111. children: [
  112. Container(
  113. color: Colors.white,
  114. child: Column(
  115. children: [
  116. //广告标题
  117. Container(
  118. padding: EdgeInsets.all(16),
  119. child: aboutRow([
  120. MyViews().myText('广告标题', MyColors.c333333, 15),
  121. Expanded(
  122. child: Container(
  123. alignment: Alignment.centerRight,
  124. child: TextField(
  125. textAlign: TextAlign.end,
  126. controller: _title,
  127. cursorColor: MyColors.cFF4233,
  128. cursorWidth: 1.0,
  129. onTap: () {},
  130. decoration: InputDecoration(
  131. border: InputBorder.none,
  132. disabledBorder: InputBorder.none,
  133. enabledBorder: InputBorder.none,
  134. focusedBorder: InputBorder.none,
  135. isDense: true,
  136. hintText: '请输入',
  137. hintStyle: TextStyle(
  138. color: MyColors.c999999,
  139. fontSize: 15),
  140. contentPadding: const EdgeInsets.fromLTRB(
  141. 14, 4.5, 8, 4.5),
  142. ),
  143. maxLines: 1,
  144. style: TextStyle(
  145. color: MyColors.c333333,
  146. fontSize: 15,
  147. height: 1.3,
  148. letterSpacing: 0.2),
  149. keyboardType: TextInputType.text,
  150. onChanged: (t) {},
  151. ),
  152. ),
  153. ),
  154. ]),
  155. ),
  156. Container(
  157. height: 0.5,
  158. color: MyColors.cE7E7E7,
  159. margin: EdgeInsets.symmetric(horizontal: 16),
  160. ),
  161. //首页图片
  162. Container(
  163. padding: EdgeInsets.all(16),
  164. child: aboutRow([
  165. MyViews().myText('首页图片', MyColors.c333333, 15),
  166. GestureDetector(
  167. onTap: () async {
  168. cover = await selectImage();
  169. setState(() {});
  170. },
  171. behavior: HitTestBehavior.translucent,
  172. child: getCover(),
  173. )
  174. ]),
  175. ),
  176. Container(
  177. height: 0.5,
  178. color: MyColors.cE7E7E7,
  179. margin: EdgeInsets.symmetric(horizontal: 16),
  180. ),
  181. //广告类型
  182. Container(
  183. padding: EdgeInsets.symmetric(
  184. horizontal: 16,
  185. vertical:
  186. widget.data == null || !widget.data.paid
  187. ? 4
  188. : 16),
  189. child: aboutRow([
  190. MyViews().myText('广告类型', MyColors.c333333, 15),
  191. widget.data == null || !widget.data.paid
  192. ? DropdownButtonHideUnderline(
  193. child: DropdownButton(
  194. items: sortItems,
  195. onChanged: (value) {
  196. setState(() {
  197. typeValue = value;
  198. });
  199. },
  200. value: typeValue,
  201. ),
  202. )
  203. : MyViews()
  204. .myText(typeValue, MyColors.c333333, 15),
  205. ]),
  206. ),
  207. Container(
  208. height: 0.5,
  209. color: MyColors.cE7E7E7,
  210. margin: EdgeInsets.symmetric(horizontal: 16),
  211. ),
  212. //开始投放时间
  213. Container(
  214. padding: EdgeInsets.all(16),
  215. child: aboutRow([
  216. MyViews().myText('开始投放时间', MyColors.c333333, 15),
  217. GestureDetector(
  218. onTap: () async {
  219. if (widget.data == null ||
  220. !widget.data.paid) {
  221. var result = await showDatePicker(
  222. context: context,
  223. initialDate: DateTime.now(),
  224. firstDate: DateTime.now(),
  225. lastDate: DateTime.now()
  226. .add(Duration(days: 500)),
  227. );
  228. setState(() {
  229. startTime =
  230. result.toString().substring(0, 10);
  231. startDate = result;
  232. });
  233. }
  234. },
  235. behavior: HitTestBehavior.translucent,
  236. child: MyViews()
  237. .myText(startTime, MyColors.c333333, 15),
  238. ),
  239. ]),
  240. ),
  241. Container(
  242. height: 0.5,
  243. color: MyColors.cE7E7E7,
  244. margin: EdgeInsets.symmetric(horizontal: 16),
  245. ),
  246. //停止投放时间
  247. Container(
  248. padding: EdgeInsets.all(16),
  249. child: aboutRow([
  250. MyViews().myText('投放天数', MyColors.c333333, 15),
  251. Expanded(
  252. child: Container(
  253. alignment: Alignment.centerRight,
  254. child: TextField(
  255. enabled: widget.data == null ||
  256. !widget.data.paid,
  257. inputFormatters: [
  258. FilteringTextInputFormatter.allow(
  259. RegExp("[0-9]")),
  260. ],
  261. textAlign: TextAlign.end,
  262. controller: _days,
  263. cursorColor: MyColors.cFF4233,
  264. cursorWidth: 1.0,
  265. onTap: () {},
  266. decoration: InputDecoration(
  267. border: InputBorder.none,
  268. disabledBorder: InputBorder.none,
  269. enabledBorder: InputBorder.none,
  270. focusedBorder: InputBorder.none,
  271. isDense: true,
  272. hintText: '请输入天数',
  273. hintStyle: TextStyle(
  274. color: MyColors.c999999,
  275. fontSize: 15),
  276. contentPadding: const EdgeInsets.fromLTRB(
  277. 14, 4.5, 8, 4.5),
  278. ),
  279. maxLines: 1,
  280. style: TextStyle(
  281. color: MyColors.c333333,
  282. fontSize: 15,
  283. height: 1.3,
  284. letterSpacing: 0.2),
  285. keyboardType: TextInputType.number,
  286. onChanged: (t) {},
  287. ),
  288. ),
  289. ),
  290. ]),
  291. ),
  292. Container(
  293. height: 10,
  294. color: MyColors.cF7F7F7,
  295. ),
  296. //详情描述
  297. Container(
  298. padding: EdgeInsets.all(16),
  299. child: aboutRow([
  300. MyViews().myText('详情描述', MyColors.c333333, 15),
  301. ]),
  302. ),
  303. Container(
  304. margin: EdgeInsets.only(
  305. left: 15, right: 15, bottom: 15),
  306. constraints: BoxConstraints(minHeight: 86),
  307. decoration: BoxDecoration(
  308. border:
  309. Border.all(color: MyColors.cE7E7E7, width: 1),
  310. borderRadius: BorderRadius.all(
  311. Radius.circular(4),
  312. ),
  313. ),
  314. child: TextField(
  315. controller: _description,
  316. cursorColor: MyColors.cFF4233,
  317. maxLines: null,
  318. cursorWidth: 1.0,
  319. onTap: () {},
  320. decoration: InputDecoration(
  321. border: InputBorder.none,
  322. disabledBorder: InputBorder.none,
  323. enabledBorder: InputBorder.none,
  324. focusedBorder: InputBorder.none,
  325. isDense: true,
  326. hintText: '请输入',
  327. hintStyle: TextStyle(
  328. color: MyColors.c999999, fontSize: 14),
  329. contentPadding:
  330. const EdgeInsets.fromLTRB(14, 4.5, 8, 4.5),
  331. ),
  332. style: TextStyle(
  333. color: MyColors.c333333,
  334. fontSize: 14,
  335. height: 1.3,
  336. letterSpacing: 0.2),
  337. keyboardType: TextInputType.text,
  338. onChanged: (t) {},
  339. ),
  340. ),
  341. Container(
  342. height: 0.5,
  343. color: MyColors.cE7E7E7,
  344. margin: EdgeInsets.symmetric(horizontal: 16),
  345. ),
  346. //详情图片
  347. Container(
  348. padding: EdgeInsets.all(16),
  349. child: aboutRow([
  350. MyViews().myText('详情图片', MyColors.c333333, 15),
  351. ]),
  352. ),
  353. Container(
  354. margin: EdgeInsets.only(
  355. left: 15, right: 15, bottom: 17),
  356. child: Row(
  357. children: [
  358. GestureDetector(
  359. onTap: () async {
  360. pictures[0] =
  361. await selectImage(isCover: false);
  362. setState(() {});
  363. },
  364. behavior: HitTestBehavior.translucent,
  365. child: getP1(),
  366. ),
  367. GestureDetector(
  368. onTap: () async {
  369. pictures[1] =
  370. await selectImage(isCover: false);
  371. setState(() {});
  372. },
  373. behavior: HitTestBehavior.translucent,
  374. child: getP2(),
  375. ),
  376. GestureDetector(
  377. onTap: () async {
  378. pictures[2] =
  379. await selectImage(isCover: false);
  380. setState(() {});
  381. },
  382. behavior: HitTestBehavior.translucent,
  383. child: getP3(),
  384. ),
  385. ],
  386. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  387. ),
  388. ),
  389. Container(
  390. height: 10,
  391. color: MyColors.cF7F7F7,
  392. ),
  393. //广告关联类型
  394. Container(
  395. padding: EdgeInsets.symmetric(
  396. horizontal: 16, vertical: 4),
  397. child: aboutRow([
  398. MyViews().myText('广告关联类型', MyColors.c333333, 15),
  399. Row(
  400. children: [
  401. Checkbox(
  402. activeColor: MyColors.cFF4233,
  403. value: associationType == 0,
  404. onChanged: (v) {
  405. shop = null;
  406. product = null;
  407. setState(() {
  408. if (v) {
  409. associationType = 0;
  410. } else {
  411. associationType = -1;
  412. }
  413. });
  414. }),
  415. MyViews().myText('店铺', MyColors.c333333, 15),
  416. Checkbox(
  417. activeColor: MyColors.cFF4233,
  418. value: associationType == 1,
  419. onChanged: (v) {
  420. setState(() {
  421. if (v) {
  422. associationType = 1;
  423. } else {
  424. associationType = -1;
  425. }
  426. });
  427. }),
  428. MyViews().myText('商品', MyColors.c333333, 15),
  429. ],
  430. ),
  431. ]),
  432. ),
  433. //关联
  434. Visibility(
  435. visible: associationType != -1,
  436. child: Column(
  437. children: [
  438. Container(
  439. height: 0.5,
  440. color: MyColors.cE7E7E7,
  441. margin: EdgeInsets.symmetric(horizontal: 16),
  442. ),
  443. Container(
  444. padding: EdgeInsets.all(16),
  445. child: aboutRow([
  446. MyViews().myText(
  447. associationType == 0 ? '关联店铺' : '关联商品',
  448. MyColors.c333333,
  449. 15),
  450. GestureDetector(
  451. onTap: () {
  452. MyTools().hideKeyboard(context);
  453. MyTools().toPage(
  454. context,
  455. associationType == 0
  456. ? AssociatedStorePage()
  457. : RelatedProductsPage(),
  458. (then) {
  459. if (then is MyShopBeanDataData) {
  460. shop = then;
  461. setState(() {});
  462. }
  463. if (then is GoodsBeanDataData) {
  464. product = then;
  465. setState(() {});
  466. }
  467. });
  468. },
  469. behavior: HitTestBehavior.translucent,
  470. child: associatedView()),
  471. ]),
  472. ),
  473. ],
  474. ),
  475. ),
  476. Container(
  477. height: 10,
  478. color: MyColors.cF7F7F7,
  479. ),
  480. GestureDetector(
  481. onTap: () {
  482. uploadCover();
  483. },
  484. behavior: HitTestBehavior.translucent,
  485. child: Container(
  486. height: 50,
  487. child: MyViews().myText(
  488. widget.data == null ? '发 布' : '保 存',
  489. MyColors.cFF4233,
  490. 16),
  491. alignment: Alignment.center,
  492. ),
  493. ),
  494. Container(
  495. height: 50,
  496. color: MyColors.cF7F7F7,
  497. ),
  498. ],
  499. ),
  500. )
  501. ],
  502. ),
  503. ),
  504. ),
  505. ],
  506. ),
  507. ),
  508. );
  509. }
  510. Widget aboutRow(List<Widget> ws) {
  511. return Row(
  512. children: ws,
  513. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  514. );
  515. }
  516. associatedView() {
  517. if (associationType == 0) {
  518. if (shop == null) {
  519. return MyViews().myText('选择关联店铺', MyColors.c333333, 15);
  520. } else {
  521. return Row(
  522. children: [
  523. ClipRRect(
  524. child: MyViews().netImg(imgURL(shop.shopPic), 24, 24),
  525. borderRadius: BorderRadius.circular(12),
  526. ),
  527. Container(
  528. child: MyViews().myText(shop.shopName, MyColors.c333333, 15),
  529. margin: EdgeInsets.only(left: 8),
  530. )
  531. ],
  532. );
  533. }
  534. } else {
  535. if (product == null) {
  536. return MyViews().myText('选择关联商品', MyColors.c333333, 15);
  537. } else {
  538. return Row(
  539. children: [
  540. ClipRRect(
  541. child: MyViews().netImg(imgURL(product.coverPath), 24, 24),
  542. borderRadius: BorderRadius.circular(12),
  543. ),
  544. Container(
  545. child: MyViews().myText(product.title, MyColors.c333333, 15),
  546. margin: EdgeInsets.only(left: 8),
  547. )
  548. ],
  549. );
  550. }
  551. }
  552. }
  553. void uploadCover() {
  554. if (_title.text.isEmpty) {
  555. showToast('请填写标题');
  556. return;
  557. }
  558. if (cover == null && coverPath == '') {
  559. showToast('请选择首页图片');
  560. return;
  561. }
  562. if (startTime == '请选择时间') {
  563. showToast('请选择时间');
  564. return;
  565. }
  566. if (_days.text.isEmpty) {
  567. showToast('请填写投放天数');
  568. return;
  569. }
  570. if (_description.text.isEmpty) {
  571. showToast('请填写描述');
  572. return;
  573. }
  574. EasyLoading.instance
  575. ..contentPadding = EdgeInsets.symmetric(horizontal: 20, vertical: 12)
  576. ..alignment = Alignment.center
  577. ..contentMargin = EdgeInsets.all(20);
  578. EasyLoading.show();
  579. print('uploadCover');
  580. if (cover == null) {
  581. uploadPictureOne();
  582. } else {
  583. upload(cover, (r, hE) {
  584. if (!hE) {
  585. UploadImageBeanEntity data =
  586. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  587. coverPath = data.data[0].path;
  588. uploadPictureOne();
  589. } else {
  590. EasyLoading.dismiss();
  591. }
  592. }, (e) {
  593. EasyLoading.dismiss();
  594. });
  595. }
  596. }
  597. void uploadPictureOne() {
  598. if (pictures[0] != null) {
  599. upload(pictures[0], (r, hE) {
  600. if (!hE) {
  601. UploadImageBeanEntity data =
  602. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  603. if (picturesPath == '') {
  604. picturesPath = data.data[0].path;
  605. } else {
  606. picturesPath = picturesPath + ',' + data.data[0].path;
  607. }
  608. uploadPictureTwo();
  609. } else {
  610. EasyLoading.dismiss();
  611. }
  612. }, (e) {
  613. EasyLoading.dismiss();
  614. });
  615. } else {
  616. if (p1 != '') {
  617. if (picturesPath == '') {
  618. picturesPath = p1;
  619. } else {
  620. picturesPath = picturesPath + ',' + p1;
  621. }
  622. }
  623. uploadPictureTwo();
  624. }
  625. }
  626. void uploadPictureTwo() {
  627. print('uploadPictureTwo');
  628. if (pictures[1] != null) {
  629. upload(pictures[1], (r, hE) {
  630. if (!hE) {
  631. UploadImageBeanEntity data =
  632. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  633. if (picturesPath == '') {
  634. picturesPath = data.data[0].path;
  635. } else {
  636. picturesPath = picturesPath + ',' + data.data[0].path;
  637. }
  638. uploadPictureThree();
  639. } else {
  640. EasyLoading.dismiss();
  641. }
  642. }, (e) {
  643. EasyLoading.dismiss();
  644. });
  645. } else {
  646. if (p2 != '') {
  647. if (picturesPath == '') {
  648. picturesPath = p2;
  649. } else {
  650. picturesPath = picturesPath + ',' + p2;
  651. }
  652. }
  653. uploadPictureThree();
  654. }
  655. }
  656. void uploadPictureThree() {
  657. print('uploadPictureThree');
  658. if (pictures[2] != null) {
  659. upload(pictures[2], (r, hE) {
  660. if (!hE) {
  661. UploadImageBeanEntity data =
  662. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  663. if (picturesPath == '') {
  664. picturesPath = data.data[0].path;
  665. } else {
  666. picturesPath = picturesPath + ',' + data.data[0].path;
  667. }
  668. if (widget.data != null) {
  669. updateAd();
  670. } else {
  671. saveAd();
  672. }
  673. } else {
  674. EasyLoading.dismiss();
  675. }
  676. }, (e) {
  677. EasyLoading.dismiss();
  678. });
  679. } else {
  680. if (p3 != '') {
  681. if (picturesPath == '') {
  682. picturesPath = p3;
  683. } else {
  684. picturesPath = picturesPath + ',' + p3;
  685. }
  686. }
  687. if (widget.data != null) {
  688. updateAd();
  689. } else {
  690. saveAd();
  691. }
  692. }
  693. }
  694. void showPayOrder(AnnualFeeOrderBeanEntity order) {
  695. EasyLoading.instance
  696. ..contentPadding = EdgeInsets.symmetric(horizontal: 0, vertical: 12)
  697. ..alignment = Alignment.bottomCenter
  698. ..contentMargin = EdgeInsets.fromLTRB(20, 20, 20, 65);
  699. double price = NumUtil.multiply(
  700. int.parse(_days.text.toString()),
  701. pricing[pricing.indexWhere((element) => element.type == typeIndex)]
  702. .pricing);
  703. EasyLoading.show(
  704. indicator: Material(
  705. color: Colors.white,
  706. child: Column(
  707. children: [
  708. Container(
  709. margin: EdgeInsets.symmetric(horizontal: 12),
  710. child: Row(
  711. children: [
  712. Container(
  713. child: Image.asset(
  714. 'images/app_logo.png',
  715. height: 27,
  716. width: 27,
  717. ),
  718. margin: EdgeInsets.only(right: 8),
  719. height: 45,
  720. width: 45,
  721. decoration: BoxDecoration(
  722. border: Border.all(color: MyColors.cEBEBEB, width: 1)),
  723. alignment: Alignment.center,
  724. ),
  725. Expanded(
  726. child: Container(
  727. height: 45,
  728. child: Column(
  729. children: [
  730. MyViews().myText('广告费', MyColors.c333333, 13),
  731. Row(
  732. children: [
  733. MyViews().myText('¥${price.toStringAsFixed(2)}',
  734. MyColors.cFF4233, 12),
  735. ],
  736. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  737. )
  738. ],
  739. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  740. crossAxisAlignment: CrossAxisAlignment.start,
  741. ),
  742. ),
  743. ),
  744. ],
  745. ),
  746. ),
  747. Container(
  748. height: 0.5,
  749. color: MyColors.cE7E7E7,
  750. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  751. ),
  752. Container(
  753. margin: EdgeInsets.symmetric(horizontal: 12),
  754. child: Row(
  755. children: [
  756. MyViews().myText('卖家信息:', MyColors.c333333, 13),
  757. Row(
  758. children: [
  759. Container(
  760. margin: EdgeInsets.only(right: 5),
  761. child: ClipRRect(
  762. child: Image.asset(
  763. 'images/app_logo.png',
  764. height: 23,
  765. width: 23,
  766. ),
  767. borderRadius: BorderRadius.circular(11.5),
  768. ),
  769. ),
  770. MyViews().myText('$appName', MyColors.c333333, 13),
  771. ],
  772. )
  773. ],
  774. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  775. ),
  776. ),
  777. Container(
  778. height: 0.5,
  779. color: MyColors.cE7E7E7,
  780. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  781. ),
  782. Container(
  783. margin: EdgeInsets.symmetric(horizontal: 12),
  784. child: Row(
  785. children: [
  786. MyViews().myText('买家信息:', MyColors.c333333, 13),
  787. Row(
  788. children: [
  789. Container(
  790. margin: EdgeInsets.only(right: 5),
  791. child: ClipRRect(
  792. child: MyViews().netImg(
  793. imgURL(MyCookie().userBean.picture), 23, 23),
  794. borderRadius: BorderRadius.circular(11.5),
  795. ),
  796. ),
  797. MyViews().myText(
  798. '${MyCookie().userBean.name}(${MyCookie().userBean.uid})',
  799. MyColors.c333333,
  800. 13),
  801. ],
  802. )
  803. ],
  804. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  805. ),
  806. ),
  807. Container(
  808. height: 0.5,
  809. color: MyColors.cE7E7E7,
  810. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  811. ),
  812. Container(
  813. margin: EdgeInsets.symmetric(horizontal: 12),
  814. child: Row(
  815. children: [
  816. MyViews().myText('下单时间:', MyColors.c333333, 13),
  817. MyViews().myText(
  818. '${DateTime.now().toString().substring(0, 19)}',
  819. MyColors.c333333,
  820. 13)
  821. ],
  822. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  823. ),
  824. ),
  825. Container(
  826. height: 0.5,
  827. color: MyColors.cE7E7E7,
  828. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  829. ),
  830. Container(
  831. margin: EdgeInsets.symmetric(horizontal: 20),
  832. child: Row(
  833. children: [
  834. Expanded(
  835. child: GestureDetector(
  836. onTap: () {
  837. EasyLoading.dismiss();
  838. Navigator.pop(context, widget.data == null);
  839. },
  840. behavior: HitTestBehavior.translucent,
  841. child: Container(
  842. decoration: BoxDecoration(
  843. borderRadius: BorderRadius.only(
  844. topLeft: Radius.circular(20),
  845. bottomLeft: Radius.circular(20),
  846. ),
  847. border: Border.all(
  848. color: MyColors.cFF4233, width: 1)),
  849. height: 40,
  850. child: MyViews().myText('稍后支付', MyColors.cFF4233, 14),
  851. alignment: Alignment.center),
  852. ),
  853. ),
  854. Expanded(
  855. child: GestureDetector(
  856. onTap: () {
  857. getUserWalletBalance((re, hE) {
  858. if (!hE) {
  859. UserBalanceEntity balance = UserBalanceEntity()
  860. .fromJson(json.decode(re.data.toString()));
  861. if (balance.data >= price) {
  862. payOrder(payWayWallet, order.data.orderUid,
  863. (re, hE) {
  864. if (!hE) {
  865. showToast('支付成功');
  866. EventBus().emit('payAnOrder');
  867. Navigator.pop(context, widget.data == null);
  868. }
  869. }, (e) {}, context);
  870. } else {
  871. payOrder(payWayAliPay, order.data.orderUid,
  872. (re, hE) {
  873. if (!hE) {
  874. PayByAlipayBeanEntity entity =
  875. PayByAlipayBeanEntity().fromJson(
  876. json.decode(re.data.toString()));
  877. EventBus().on('alipayPaymentCallback', (arg) {
  878. EventBus().off('alipayPaymentCallback');
  879. EasyLoading.dismiss();
  880. showToast('支付成功');
  881. EventBus().emit('reNoPayOrder');
  882. Navigator.pop(context, widget.data == null);
  883. });
  884. print(entity.data);
  885. EasyLoading.instance
  886. ..contentPadding = EdgeInsets.symmetric(
  887. horizontal: 20, vertical: 12)
  888. ..alignment = Alignment.center
  889. ..contentMargin = EdgeInsets.all(20);
  890. EasyLoading.show();
  891. aliPay(entity.data).then((value) {
  892. print(json.encode(value));
  893. AlipayResultBeanEntity e =
  894. AlipayResultBeanEntity().fromJson(
  895. json.decode(json.encode(value)));
  896. try {
  897. int r = int.parse(e.resultStatus);
  898. if (r == 9000) {
  899. showToast('支付成功');
  900. Navigator.pop(
  901. context, widget.data == null);
  902. } else {
  903. showToast(aliPayResultStatus(r));
  904. resetOrder(order.data.orderUid);
  905. }
  906. } catch (e) {
  907. EasyLoading.dismiss();
  908. }
  909. });
  910. // EventBus().emit('payAnOrder');
  911. }
  912. }, (e) {}, context);
  913. // showToast('积分余额不足');
  914. }
  915. }
  916. }, (e) {}, context);
  917. },
  918. behavior: HitTestBehavior.translucent,
  919. child: Container(
  920. decoration: BoxDecoration(
  921. borderRadius: BorderRadius.only(
  922. topRight: Radius.circular(20),
  923. bottomRight: Radius.circular(20),
  924. ),
  925. color: MyColors.cFF4233),
  926. height: 40,
  927. child: MyViews().myText('立即支付', Colors.white, 14),
  928. alignment: Alignment.center),
  929. ),
  930. )
  931. ],
  932. ),
  933. )
  934. ],
  935. ),
  936. ),
  937. );
  938. }
  939. String p1 = '';
  940. String p2 = '';
  941. String p3 = '';
  942. void initAd() {
  943. _title.text = widget.data.title;
  944. coverPath = widget.data.coverPath;
  945. typeIndex = widget.data.type;
  946. typeValue = typeIndex == 0 ? '店铺/商品部分广告' : '首页banner';
  947. startTime = widget.data.startDate;
  948. _days.text = widget.data.days.toString();
  949. _description.text = widget.data.description;
  950. widget.data.pictures.split(',').forEach((element) {
  951. if (p1 == '') {
  952. p1 = element;
  953. } else if (p2 == '') {
  954. p2 = element;
  955. } else if (p3 == '') {
  956. p3 = element;
  957. }
  958. });
  959. if (widget.data.linkId == 0) {
  960. associationType = -1;
  961. } else {
  962. associationType = widget.data.linkType;
  963. }
  964. setState(() {});
  965. if (associationType != -1) {
  966. if (associationType == 0) {
  967. MyDio().query({
  968. "key": "shop_user",
  969. "filters": {
  970. "conditions": ["id==${widget.data.linkId}"],
  971. },
  972. "dims": shopUserDims,
  973. "paging": [1, 1],
  974. "order_by": ["shop_name,DESC"]
  975. }, (response, hasError) {
  976. if (!hasError) {
  977. MyShopBeanEntity entity = MyShopBeanEntity()
  978. .fromJson(json.decode(response.data.toString()));
  979. if (entity.data.data.length != 0) {
  980. shop = entity.data.data[0];
  981. setState(() {});
  982. }
  983. }
  984. }, (error) {});
  985. } else if (associationType == 1) {
  986. MyDio().query({
  987. "key": "commodity",
  988. "filters": {
  989. "conditions": ["id == ${widget.data.linkId}"]
  990. },
  991. "dims": commodityDims,
  992. "paging": [1, 1]
  993. }, (response, hasError) {
  994. if (!hasError) {
  995. GoodsBeanEntity entity = GoodsBeanEntity()
  996. .fromJson(json.decode(response.data.toString()));
  997. if (entity.data.data.length != 0) {
  998. product = entity.data.data[0];
  999. setState(() {});
  1000. }
  1001. }
  1002. }, (error) {});
  1003. }
  1004. }
  1005. }
  1006. getCover() {
  1007. if (cover == null && coverPath == '') {
  1008. return SvgPicture.asset(
  1009. 'images/svg/更换头像.svg',
  1010. height: 40,
  1011. width: 40,
  1012. );
  1013. } else if (cover != null) {
  1014. return ClipRRect(
  1015. child: Image.file(
  1016. cover,
  1017. height: 40,
  1018. width: 40,
  1019. ),
  1020. borderRadius: BorderRadius.circular(4),
  1021. );
  1022. } else if (coverPath != '') {
  1023. return ClipRRect(
  1024. child: MyViews().netImg(imgURL(coverPath), 40, 40),
  1025. borderRadius: BorderRadius.circular(4),
  1026. );
  1027. }
  1028. }
  1029. getP1() {
  1030. if (pictures[0] == null && p1 == '') {
  1031. return Container(
  1032. height: 102,
  1033. width: 102,
  1034. decoration: BoxDecoration(
  1035. color: MyColors.cF0F0F0,
  1036. borderRadius: BorderRadius.all(Radius.circular(4))),
  1037. child: Icon(
  1038. Icons.add,
  1039. color: MyColors.cB6B6B6,
  1040. size: 44,
  1041. ),
  1042. );
  1043. } else if (pictures[0] != null) {
  1044. return ClipRRect(
  1045. child: Image.file(
  1046. pictures[0],
  1047. height: 102,
  1048. width: 102,
  1049. fit: BoxFit.cover,
  1050. ),
  1051. borderRadius: BorderRadius.circular(4),
  1052. );
  1053. } else if (p1 != '') {
  1054. return ClipRRect(
  1055. child: MyViews().netImg(imgURL(p1), 102, 102),
  1056. borderRadius: BorderRadius.circular(4),
  1057. );
  1058. }
  1059. }
  1060. getP2() {
  1061. if (pictures[1] == null && p2 == '') {
  1062. return Container(
  1063. height: 102,
  1064. width: 102,
  1065. decoration: BoxDecoration(
  1066. color: MyColors.cF0F0F0,
  1067. borderRadius: BorderRadius.all(Radius.circular(4))),
  1068. child: Icon(
  1069. Icons.add,
  1070. color: MyColors.cB6B6B6,
  1071. size: 44,
  1072. ),
  1073. );
  1074. } else if (pictures[1] != null) {
  1075. return ClipRRect(
  1076. child: Image.file(
  1077. pictures[1],
  1078. height: 102,
  1079. width: 102,
  1080. fit: BoxFit.cover,
  1081. ),
  1082. borderRadius: BorderRadius.circular(4),
  1083. );
  1084. } else if (p2 != '') {
  1085. return ClipRRect(
  1086. child: MyViews().netImg(imgURL(p2), 102, 102),
  1087. borderRadius: BorderRadius.circular(4),
  1088. );
  1089. }
  1090. }
  1091. getP3() {
  1092. if (pictures[2] == null && p3 == '') {
  1093. return Container(
  1094. height: 102,
  1095. width: 102,
  1096. decoration: BoxDecoration(
  1097. color: MyColors.cF0F0F0,
  1098. borderRadius: BorderRadius.all(Radius.circular(4))),
  1099. child: Icon(
  1100. Icons.add,
  1101. color: MyColors.cB6B6B6,
  1102. size: 44,
  1103. ),
  1104. );
  1105. } else if (pictures[2] != null) {
  1106. return ClipRRect(
  1107. child: Image.file(
  1108. pictures[2],
  1109. height: 102,
  1110. width: 102,
  1111. fit: BoxFit.cover,
  1112. ),
  1113. borderRadius: BorderRadius.circular(4),
  1114. );
  1115. } else if (p3 != '') {
  1116. return ClipRRect(
  1117. child: MyViews().netImg(imgURL(p3), 102, 102),
  1118. borderRadius: BorderRadius.circular(4),
  1119. );
  1120. }
  1121. }
  1122. void updateAd() {
  1123. var values = {
  1124. "id": widget.data.id,
  1125. "title": _title.text.toString(),
  1126. "description": _description.text.toString(),
  1127. "cover_path": coverPath,
  1128. "pictures": picturesPath
  1129. };
  1130. if (associationType == 0 && shop != null) {
  1131. values['link_type'] = associationType;
  1132. values['link_id'] = shop.id;
  1133. }
  1134. if (associationType == 1 && product != null) {
  1135. values['link_type'] = associationType;
  1136. values['link_id'] = product.id;
  1137. }
  1138. MyDio().update({'key': 'ad', 'values': values}, (response, hasError) {
  1139. if (!hasError) {
  1140. widget.data.title = _title.text.toString();
  1141. widget.data.description = _description.text.toString();
  1142. widget.data.coverPath = coverPath;
  1143. widget.data.pictures = picturesPath;
  1144. AnnualFeeOrderBeanEntity entity = AnnualFeeOrderBeanEntity()
  1145. .fromJson(json.decode(response.data.toString()));
  1146. if (!widget.data.paid) {
  1147. showPayOrder(entity);
  1148. }
  1149. }
  1150. }, (error) {});
  1151. }
  1152. void saveAd() {
  1153. var object = {
  1154. "type": typeValue == '店铺/商品部分广告' ? 0 : 1,
  1155. "start_date": startTime,
  1156. "days": int.parse(_days.text.toString()),
  1157. "user_uid": MyCookie().getUID(),
  1158. "user_name": MyCookie().getName(),
  1159. "user_pic": MyCookie().userBean.picture,
  1160. "title": _title.text.toString(),
  1161. "description": _description.text.toString(),
  1162. "cover_path": coverPath,
  1163. "pictures": picturesPath
  1164. };
  1165. if (associationType == 0 && shop != null) {
  1166. object['link_type'] = associationType;
  1167. object['link_id'] = shop.id;
  1168. }
  1169. if (associationType == 1 && product != null) {
  1170. object['link_type'] = associationType;
  1171. object['link_id'] = product.id;
  1172. }
  1173. MyDio().save({'key': 'ad', 'object': object}, (response, hasError) {
  1174. AnnualFeeOrderBeanEntity entity = AnnualFeeOrderBeanEntity()
  1175. .fromJson(json.decode(response.data.toString()));
  1176. showPayOrder(entity);
  1177. }, (error) {});
  1178. }
  1179. }