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