new_ad_page.dart 48 KB

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