new_ad_page.dart 50 KB

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