new_ad_page.dart 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  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. ..loadingStyle = EasyLoadingStyle.light
  618. ..contentMargin = EdgeInsets.all(20);
  619. EasyLoading.show();
  620. print('uploadCover');
  621. if (cover == null) {
  622. uploadPictureOne();
  623. } else {
  624. upload(cover, (r, hE) {
  625. if (!hE) {
  626. UploadImageBeanEntity data =
  627. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  628. coverPath = data.data[0].path;
  629. uploadPictureOne();
  630. } else {
  631. EasyLoading.dismiss();
  632. }
  633. }, (e) {
  634. EasyLoading.dismiss();
  635. });
  636. }
  637. }
  638. void uploadPictureOne() {
  639. if (pictures[0] != null) {
  640. upload(pictures[0], (r, hE) {
  641. if (!hE) {
  642. UploadImageBeanEntity data =
  643. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  644. if (picturesPath == '') {
  645. picturesPath = data.data[0].path;
  646. } else {
  647. picturesPath = picturesPath + ',' + data.data[0].path;
  648. }
  649. uploadPictureTwo();
  650. } else {
  651. EasyLoading.dismiss();
  652. }
  653. }, (e) {
  654. EasyLoading.dismiss();
  655. });
  656. } else {
  657. if (p1 != '') {
  658. if (picturesPath == '') {
  659. picturesPath = p1;
  660. } else {
  661. picturesPath = picturesPath + ',' + p1;
  662. }
  663. }
  664. uploadPictureTwo();
  665. }
  666. }
  667. void uploadPictureTwo() {
  668. print('uploadPictureTwo');
  669. if (pictures[1] != null) {
  670. upload(pictures[1], (r, hE) {
  671. if (!hE) {
  672. UploadImageBeanEntity data =
  673. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  674. if (picturesPath == '') {
  675. picturesPath = data.data[0].path;
  676. } else {
  677. picturesPath = picturesPath + ',' + data.data[0].path;
  678. }
  679. uploadPictureThree();
  680. } else {
  681. EasyLoading.dismiss();
  682. }
  683. }, (e) {
  684. EasyLoading.dismiss();
  685. });
  686. } else {
  687. if (p2 != '') {
  688. if (picturesPath == '') {
  689. picturesPath = p2;
  690. } else {
  691. picturesPath = picturesPath + ',' + p2;
  692. }
  693. }
  694. uploadPictureThree();
  695. }
  696. }
  697. void uploadPictureThree() {
  698. print('uploadPictureThree');
  699. if (pictures[2] != null) {
  700. upload(pictures[2], (r, hE) {
  701. if (!hE) {
  702. UploadImageBeanEntity data =
  703. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  704. if (picturesPath == '') {
  705. picturesPath = data.data[0].path;
  706. } else {
  707. picturesPath = picturesPath + ',' + data.data[0].path;
  708. }
  709. if (widget.data != null) {
  710. updateAd();
  711. } else {
  712. saveAd();
  713. }
  714. } else {
  715. EasyLoading.dismiss();
  716. }
  717. }, (e) {
  718. EasyLoading.dismiss();
  719. });
  720. } else {
  721. if (p3 != '') {
  722. if (picturesPath == '') {
  723. picturesPath = p3;
  724. } else {
  725. picturesPath = picturesPath + ',' + p3;
  726. }
  727. }
  728. if (widget.data != null) {
  729. updateAd();
  730. } else {
  731. saveAd();
  732. }
  733. }
  734. }
  735. void showPayOrder(AnnualFeeOrderBeanEntity order) {
  736. EasyLoading.instance
  737. ..contentPadding = EdgeInsets.symmetric(horizontal: 0, vertical: 12)
  738. ..alignment = Alignment.bottomCenter
  739. ..loadingStyle = EasyLoadingStyle.light
  740. ..contentMargin = EdgeInsets.fromLTRB(20, 20, 20, 65);
  741. double price = NumUtil.multiply(
  742. int.parse(_days.text.toString()),
  743. pricing[pricing.indexWhere((element) => element.type == typeIndex)]
  744. .pricing);
  745. EasyLoading.show(
  746. indicator: Material(
  747. color: Colors.white,
  748. child: Column(
  749. children: [
  750. Container(
  751. margin: EdgeInsets.symmetric(horizontal: 12),
  752. child: Row(
  753. children: [
  754. Container(
  755. child: Image.asset(
  756. 'images/app_logo.png',
  757. height: 27,
  758. width: 27,
  759. ),
  760. margin: EdgeInsets.only(right: 8),
  761. height: 45,
  762. width: 45,
  763. decoration: BoxDecoration(
  764. border: Border.all(color: MyColors.cEBEBEB, width: 1)),
  765. alignment: Alignment.center,
  766. ),
  767. Expanded(
  768. child: Container(
  769. height: 45,
  770. child: Column(
  771. children: [
  772. MyViews().myText('广告费', MyColors.c333333, 13),
  773. Row(
  774. children: [
  775. MyViews().myText('¥${price.toStringAsFixed(2)}',
  776. MyColors.cFF4233, 12),
  777. ],
  778. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  779. )
  780. ],
  781. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  782. crossAxisAlignment: CrossAxisAlignment.start,
  783. ),
  784. ),
  785. ),
  786. ],
  787. ),
  788. ),
  789. Container(
  790. height: 0.5,
  791. color: MyColors.cE7E7E7,
  792. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  793. ),
  794. Container(
  795. margin: EdgeInsets.symmetric(horizontal: 12),
  796. child: Row(
  797. children: [
  798. MyViews().myText('卖家信息:', MyColors.c333333, 13),
  799. Row(
  800. children: [
  801. Container(
  802. margin: EdgeInsets.only(right: 5),
  803. child: ClipRRect(
  804. child: Image.asset(
  805. 'images/app_logo.png',
  806. height: 23,
  807. width: 23,
  808. ),
  809. borderRadius: BorderRadius.circular(11.5),
  810. ),
  811. ),
  812. MyViews().myText('$appName', MyColors.c333333, 13),
  813. ],
  814. )
  815. ],
  816. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  817. ),
  818. ),
  819. Container(
  820. height: 0.5,
  821. color: MyColors.cE7E7E7,
  822. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  823. ),
  824. Container(
  825. margin: EdgeInsets.symmetric(horizontal: 12),
  826. child: Row(
  827. children: [
  828. MyViews().myText('买家信息:', MyColors.c333333, 13),
  829. Row(
  830. children: [
  831. Container(
  832. margin: EdgeInsets.only(right: 5),
  833. child: ClipRRect(
  834. child: MyViews().netImg(
  835. imgURL(MyCookie().userBean.picture), 23, 23),
  836. borderRadius: BorderRadius.circular(11.5),
  837. ),
  838. ),
  839. MyViews().myText(
  840. '${MyCookie().userBean.name}(${MyCookie().userBean.uid})',
  841. MyColors.c333333,
  842. 13),
  843. ],
  844. )
  845. ],
  846. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  847. ),
  848. ),
  849. Container(
  850. height: 0.5,
  851. color: MyColors.cE7E7E7,
  852. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  853. ),
  854. Container(
  855. margin: EdgeInsets.symmetric(horizontal: 12),
  856. child: Row(
  857. children: [
  858. MyViews().myText('下单时间:', MyColors.c333333, 13),
  859. MyViews().myText(
  860. '${DateTime.now().toString().substring(0, 19)}',
  861. MyColors.c333333,
  862. 13)
  863. ],
  864. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  865. ),
  866. ),
  867. Container(
  868. height: 0.5,
  869. color: MyColors.cE7E7E7,
  870. margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11),
  871. ),
  872. Container(
  873. margin: EdgeInsets.symmetric(horizontal: 20),
  874. child: Row(
  875. children: [
  876. Expanded(
  877. child: GestureDetector(
  878. onTap: () {
  879. EasyLoading.dismiss();
  880. Navigator.pop(context, widget.data == null);
  881. },
  882. behavior: HitTestBehavior.translucent,
  883. child: Container(
  884. decoration: BoxDecoration(
  885. borderRadius: BorderRadius.only(
  886. topLeft: Radius.circular(20),
  887. bottomLeft: Radius.circular(20),
  888. ),
  889. border: Border.all(
  890. color: MyColors.cFF4233, width: 1)),
  891. height: 40,
  892. child: MyViews().myText('稍后支付', MyColors.cFF4233, 14),
  893. alignment: Alignment.center),
  894. ),
  895. ),
  896. Expanded(
  897. child: GestureDetector(
  898. onTap: () {
  899. getUserWalletBalance((re, hE) {
  900. if (!hE) {
  901. UserBalanceEntity balance = UserBalanceEntity()
  902. .fromJson(json.decode(re.data.toString()));
  903. if (balance.data >= price) {
  904. payOrder(payWayWallet, order.data.orderUid,
  905. (re, hE) {
  906. if (!hE) {
  907. showToast('支付成功');
  908. EventBus().emit('payAnOrder');
  909. Navigator.pop(context, widget.data == null);
  910. }
  911. }, (e) {}, context);
  912. } else {
  913. payOrder(payWayAliPay, order.data.orderUid,
  914. (re, hE) {
  915. if (!hE) {
  916. PayByAlipayBeanEntity entity =
  917. PayByAlipayBeanEntity().fromJson(
  918. json.decode(re.data.toString()));
  919. EventBus().on('alipayPaymentCallback', (arg) {
  920. EventBus().off('alipayPaymentCallback');
  921. EasyLoading.dismiss();
  922. showToast('支付成功');
  923. EventBus().emit('reNoPayOrder');
  924. Navigator.pop(context, widget.data == null);
  925. });
  926. print(entity.data);
  927. EasyLoading.instance
  928. ..contentPadding = EdgeInsets.symmetric(
  929. horizontal: 20, vertical: 12)
  930. ..alignment = Alignment.center
  931. ..loadingStyle = EasyLoadingStyle.light
  932. ..contentMargin = EdgeInsets.all(20);
  933. EasyLoading.show();
  934. aliPay(entity.data).then((value) {
  935. print(json.encode(value));
  936. AlipayResultBeanEntity e =
  937. AlipayResultBeanEntity().fromJson(
  938. json.decode(json.encode(value)));
  939. try {
  940. int r = int.parse(e.resultStatus);
  941. if (r == 9000) {
  942. showToast('支付成功');
  943. Navigator.pop(
  944. context, widget.data == null);
  945. } else {
  946. showToast(aliPayResultStatus(r));
  947. resetOrder(order.data.orderUid);
  948. }
  949. } catch (e) {
  950. EasyLoading.dismiss();
  951. }
  952. });
  953. // EventBus().emit('payAnOrder');
  954. }
  955. }, (e) {}, context);
  956. // showToast('积分余额不足');
  957. }
  958. }
  959. }, (e) {}, context);
  960. },
  961. behavior: HitTestBehavior.translucent,
  962. child: Container(
  963. decoration: BoxDecoration(
  964. borderRadius: BorderRadius.only(
  965. topRight: Radius.circular(20),
  966. bottomRight: Radius.circular(20),
  967. ),
  968. color: MyColors.cFF4233),
  969. height: 40,
  970. child: MyViews().myText('立即支付', Colors.white, 14),
  971. alignment: Alignment.center),
  972. ),
  973. )
  974. ],
  975. ),
  976. )
  977. ],
  978. ),
  979. ),
  980. );
  981. }
  982. String p1 = '';
  983. String p2 = '';
  984. String p3 = '';
  985. void initAd() {
  986. _title.text = widget.data.title;
  987. coverPath = widget.data.coverPath;
  988. typeIndex = widget.data.type;
  989. typeValue = typeIndex == 0 ? '店铺/商品部分广告' : '首页banner';
  990. startTime = widget.data.startDate;
  991. _days.text = widget.data.days.toString();
  992. _description.text = widget.data.description;
  993. widget.data.pictures.split(',').forEach((element) {
  994. if (p1 == '') {
  995. p1 = element;
  996. } else if (p2 == '') {
  997. p2 = element;
  998. } else if (p3 == '') {
  999. p3 = element;
  1000. }
  1001. });
  1002. if (widget.data.linkId == 0) {
  1003. associationType = -1;
  1004. } else {
  1005. associationType = widget.data.linkType;
  1006. }
  1007. setState(() {});
  1008. if (associationType != -1) {
  1009. if (associationType == 0) {
  1010. MyDio().query({
  1011. "key": "shop_user",
  1012. "filters": {
  1013. "conditions": ["id==${widget.data.linkId}"],
  1014. },
  1015. "dims": shopUserDims,
  1016. "paging": [1, 1],
  1017. "order_by": ["shop_name,DESC"]
  1018. }, (response, hasError) {
  1019. if (!hasError) {
  1020. MyShopBeanEntity entity = MyShopBeanEntity()
  1021. .fromJson(json.decode(response.data.toString()));
  1022. if (entity.data.data.length != 0) {
  1023. shop = entity.data.data[0];
  1024. setState(() {});
  1025. }
  1026. }
  1027. }, (error) {});
  1028. } else if (associationType == 1) {
  1029. MyDio().query({
  1030. "key": "commodity",
  1031. "filters": {
  1032. "conditions": ["id == ${widget.data.linkId}"]
  1033. },
  1034. "dims": commodityDims,
  1035. "paging": [1, 1]
  1036. }, (response, hasError) {
  1037. if (!hasError) {
  1038. GoodsBeanEntity entity = GoodsBeanEntity()
  1039. .fromJson(json.decode(response.data.toString()));
  1040. if (entity.data.data.length != 0) {
  1041. product = entity.data.data[0];
  1042. setState(() {});
  1043. }
  1044. }
  1045. }, (error) {});
  1046. }
  1047. }
  1048. }
  1049. getCover() {
  1050. if (cover == null && coverPath == '') {
  1051. return SvgPicture.asset(
  1052. 'images/svg/更换头像.svg',
  1053. height: 40,
  1054. width: 40,
  1055. );
  1056. } else if (cover != null) {
  1057. return ClipRRect(
  1058. child: Image.file(
  1059. cover,
  1060. height: 40,
  1061. width: 40,
  1062. ),
  1063. borderRadius: BorderRadius.circular(4),
  1064. );
  1065. } else if (coverPath != '') {
  1066. return ClipRRect(
  1067. child: MyViews().netImg(imgURL(coverPath), 40, 40),
  1068. borderRadius: BorderRadius.circular(4),
  1069. );
  1070. }
  1071. }
  1072. getP1() {
  1073. if (pictures[0] == null && p1 == '') {
  1074. return Container(
  1075. height: 102,
  1076. width: 102,
  1077. decoration: BoxDecoration(
  1078. color: MyColors.cF0F0F0,
  1079. borderRadius: BorderRadius.all(Radius.circular(4))),
  1080. child: Icon(
  1081. Icons.add,
  1082. color: MyColors.cB6B6B6,
  1083. size: 44,
  1084. ),
  1085. );
  1086. } else if (pictures[0] != null) {
  1087. return ClipRRect(
  1088. child: Image.file(
  1089. pictures[0],
  1090. height: 102,
  1091. width: 102,
  1092. fit: BoxFit.cover,
  1093. ),
  1094. borderRadius: BorderRadius.circular(4),
  1095. );
  1096. } else if (p1 != '') {
  1097. return ClipRRect(
  1098. child: MyViews().netImg(imgURL(p1), 102, 102),
  1099. borderRadius: BorderRadius.circular(4),
  1100. );
  1101. }
  1102. }
  1103. getP2() {
  1104. if (pictures[1] == null && p2 == '') {
  1105. return Container(
  1106. height: 102,
  1107. width: 102,
  1108. decoration: BoxDecoration(
  1109. color: MyColors.cF0F0F0,
  1110. borderRadius: BorderRadius.all(Radius.circular(4))),
  1111. child: Icon(
  1112. Icons.add,
  1113. color: MyColors.cB6B6B6,
  1114. size: 44,
  1115. ),
  1116. );
  1117. } else if (pictures[1] != null) {
  1118. return ClipRRect(
  1119. child: Image.file(
  1120. pictures[1],
  1121. height: 102,
  1122. width: 102,
  1123. fit: BoxFit.cover,
  1124. ),
  1125. borderRadius: BorderRadius.circular(4),
  1126. );
  1127. } else if (p2 != '') {
  1128. return ClipRRect(
  1129. child: MyViews().netImg(imgURL(p2), 102, 102),
  1130. borderRadius: BorderRadius.circular(4),
  1131. );
  1132. }
  1133. }
  1134. getP3() {
  1135. if (pictures[2] == null && p3 == '') {
  1136. return Container(
  1137. height: 102,
  1138. width: 102,
  1139. decoration: BoxDecoration(
  1140. color: MyColors.cF0F0F0,
  1141. borderRadius: BorderRadius.all(Radius.circular(4))),
  1142. child: Icon(
  1143. Icons.add,
  1144. color: MyColors.cB6B6B6,
  1145. size: 44,
  1146. ),
  1147. );
  1148. } else if (pictures[2] != null) {
  1149. return ClipRRect(
  1150. child: Image.file(
  1151. pictures[2],
  1152. height: 102,
  1153. width: 102,
  1154. fit: BoxFit.cover,
  1155. ),
  1156. borderRadius: BorderRadius.circular(4),
  1157. );
  1158. } else if (p3 != '') {
  1159. return ClipRRect(
  1160. child: MyViews().netImg(imgURL(p3), 102, 102),
  1161. borderRadius: BorderRadius.circular(4),
  1162. );
  1163. }
  1164. }
  1165. void updateAd() {
  1166. var values = {
  1167. "id": widget.data.id,
  1168. "title": _title.text.toString(),
  1169. "description": _description.text.toString(),
  1170. "cover_path": coverPath,
  1171. "pictures": picturesPath
  1172. };
  1173. if (associationType == 0 && shop != null) {
  1174. values['link_type'] = associationType;
  1175. values['link_id'] = shop.id;
  1176. }
  1177. if (associationType == 1 && product != null) {
  1178. values['link_type'] = associationType;
  1179. values['link_id'] = product.id;
  1180. }
  1181. MyDio().update({'key': 'ad', 'values': values}, (response, hasError) {
  1182. if (!hasError) {
  1183. widget.data.title = _title.text.toString();
  1184. widget.data.description = _description.text.toString();
  1185. widget.data.coverPath = coverPath;
  1186. widget.data.pictures = picturesPath;
  1187. AnnualFeeOrderBeanEntity entity = AnnualFeeOrderBeanEntity()
  1188. .fromJson(json.decode(response.data.toString()));
  1189. if (!widget.data.paid) {
  1190. showPayOrder(entity);
  1191. }else{
  1192. EasyLoading.dismiss();
  1193. Navigator.pop(context, widget.data == null);
  1194. }
  1195. }
  1196. }, (error) {});
  1197. }
  1198. void saveAd() {
  1199. var object = {
  1200. "type": typeValue == '店铺/商品部分广告' ? 0 : 1,
  1201. "start_date": startTime,
  1202. "days": int.parse(_days.text.toString()),
  1203. "user_uid": MyCookie().getUID(),
  1204. "user_name": MyCookie().getName(),
  1205. "user_pic": MyCookie().userBean.picture,
  1206. "title": _title.text.toString(),
  1207. "description": _description.text.toString(),
  1208. "cover_path": coverPath,
  1209. "pictures": picturesPath
  1210. };
  1211. if (associationType == 0 && shop != null) {
  1212. object['link_type'] = associationType;
  1213. object['link_id'] = shop.id;
  1214. }
  1215. if (associationType == 1 && product != null) {
  1216. object['link_type'] = associationType;
  1217. object['link_id'] = product.id;
  1218. }
  1219. MyDio().save({'key': 'ad', 'object': object}, (response, hasError) {
  1220. AnnualFeeOrderBeanEntity entity = AnnualFeeOrderBeanEntity()
  1221. .fromJson(json.decode(response.data.toString()));
  1222. showPayOrder(entity);
  1223. }, (error) {});
  1224. }
  1225. void deleteAD(AdBeanDataData ad) {
  1226. MyDio().del({
  1227. 'key': 'ad',
  1228. 'ids': [ad.id]
  1229. }, (response, hasError) {
  1230. Navigator.pop(context,widget.data==null);
  1231. }, (error) {});
  1232. }
  1233. }