new_ad_page.dart 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  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()
  1010. .fromJson(json.decode(response.data.toString()));
  1011. if (entity.data.data.length != 0) {
  1012. shop = entity.data.data[0];
  1013. setState(() {});
  1014. }
  1015. }
  1016. }, (error) {});
  1017. } else if (associationType == 1) {
  1018. MyDio().query({
  1019. "key": "commodity",
  1020. "filters": {
  1021. "conditions": ["id == ${widget.data.linkId}"]
  1022. },
  1023. "dims": commodityDims,
  1024. "paging": [1, 1]
  1025. }, (response, hasError) {
  1026. if (!hasError) {
  1027. GoodsBeanEntity entity = GoodsBeanEntity()
  1028. .fromJson(json.decode(response.data.toString()));
  1029. if (entity.data.data.length != 0) {
  1030. product = entity.data.data[0];
  1031. setState(() {});
  1032. }
  1033. }
  1034. }, (error) {});
  1035. }
  1036. }
  1037. }
  1038. getCover() {
  1039. if (cover == null && coverPath == '') {
  1040. return SvgPicture.asset(
  1041. 'images/svg/更换头像.svg',
  1042. height: 40,
  1043. width: 40,
  1044. );
  1045. } else if (cover != null) {
  1046. return ClipRRect(
  1047. child: Image.file(
  1048. cover,
  1049. height: 40,
  1050. width: 40,
  1051. ),
  1052. borderRadius: BorderRadius.circular(4),
  1053. );
  1054. } else if (coverPath != '') {
  1055. return ClipRRect(
  1056. child: MyViews().netImg(imgURL(coverPath), 40, 40),
  1057. borderRadius: BorderRadius.circular(4),
  1058. );
  1059. }
  1060. }
  1061. void updateAd() {
  1062. var values = {
  1063. "id": widget.data.id,
  1064. "title": _title.text.toString(),
  1065. "description": _description.text.toString(),
  1066. "cover_path": coverPath,
  1067. "pictures": picturesPath,
  1068. "mobile": _number.text.toString()
  1069. };
  1070. if (associationType == 0 && shop != null) {
  1071. values['link_type'] = associationType;
  1072. values['link_id'] = shop.id;
  1073. }
  1074. if (associationType == 1 && product != null) {
  1075. values['link_type'] = associationType;
  1076. values['link_id'] = product.id;
  1077. }
  1078. MyDio().update({'key': 'ad', 'values': values}, (response, hasError) {
  1079. if (!hasError) {
  1080. widget.data.title = _title.text.toString();
  1081. widget.data.description = _description.text.toString();
  1082. widget.data.coverPath = coverPath;
  1083. widget.data.pictures = picturesPath;
  1084. AnnualFeeOrderBeanEntity entity = AnnualFeeOrderBeanEntity()
  1085. .fromJson(json.decode(response.data.toString()));
  1086. if (!widget.data.paid) {
  1087. payForInsertionOrder();
  1088. } else {
  1089. EasyLoading.dismiss();
  1090. Navigator.pop(context, widget.data == null);
  1091. }
  1092. }
  1093. }, (error) {});
  1094. }
  1095. void saveAd() {
  1096. var object = {
  1097. "type": typeValue == '货帮/商品部分广告' ? 0 : 1,
  1098. "start_date": startTime,
  1099. "days": int.parse(_days.text.toString()),
  1100. "user_uid": MyCookie().getUID(),
  1101. "user_name": MyCookie().getName(),
  1102. "user_pic": MyCookie().userBean.picture,
  1103. "title": _title.text.toString(),
  1104. "description": _description.text.toString(),
  1105. "cover_path": coverPath,
  1106. "pictures": picturesPath,
  1107. "renewed": false,
  1108. "mobile": _number.text.toString()
  1109. };
  1110. if (associationType == 0 && shop != null) {
  1111. object['link_type'] = associationType;
  1112. object['link_id'] = shop.id;
  1113. }
  1114. if (associationType == 1 && product != null) {
  1115. object['link_type'] = associationType;
  1116. object['link_id'] = product.id;
  1117. }
  1118. MyDio().save({'key': 'ad', 'object': object}, (response, hasError) {
  1119. if (!hasError) {
  1120. AnnualFeeOrderBeanEntity entity = AnnualFeeOrderBeanEntity()
  1121. .fromJson(json.decode(response.data.toString()));
  1122. showPayOrder(entity);
  1123. }
  1124. }, (error) {});
  1125. }
  1126. void deleteAD(AdBeanDataData ad) {
  1127. MyDio().del({
  1128. 'key': 'ad',
  1129. 'ids': [ad.id]
  1130. }, (response, hasError) {
  1131. Navigator.pop(context, widget.data == null);
  1132. }, (error) {});
  1133. }
  1134. void payForInsertionOrder() {
  1135. MyDio().query({
  1136. 'key': 'order',
  1137. "filters": {
  1138. "conditions": [
  1139. "commodity_id == ${widget.data.id}",
  1140. "type == $orderTypeAdvertise"
  1141. ]
  1142. },
  1143. "dims": orderDims,
  1144. "paging": [1, 1]
  1145. }, (response, hasError) {
  1146. if (!hasError) {
  1147. SmartOrderBeanEntity entity = SmartOrderBeanEntity()
  1148. .fromJson(json.decode(response.data.toString()));
  1149. AnnualFeeOrderBeanEntity o = AnnualFeeOrderBeanEntity();
  1150. AnnualFeeOrderBeanData od = AnnualFeeOrderBeanData();
  1151. od.orderUid = entity.data.data[0].uid;
  1152. o.data = od;
  1153. showPayOrder(o);
  1154. }
  1155. }, (error) {});
  1156. }
  1157. Widget picItem(data) {
  1158. if (data is String) {
  1159. return Container(
  1160. width: 102,
  1161. child: Column(
  1162. children: [
  1163. ClipRRect(
  1164. child: MyViews().netImg(imgURL(data), 102, 102),
  1165. borderRadius: BorderRadius.circular(4),
  1166. ),
  1167. GestureDetector(
  1168. child: Container(
  1169. height: 30,
  1170. width: 30,
  1171. margin: EdgeInsets.only(top: 5),
  1172. child: Icon(
  1173. Icons.cancel,
  1174. color: MyColors.cFF4233,
  1175. ),
  1176. ),
  1177. onTap: () {
  1178. detailsPictures.remove(data);
  1179. if (detailsPictures.length == 5 &&
  1180. !detailsPictures.contains(null)) {
  1181. detailsPictures.add(null);
  1182. }
  1183. setState(() {});
  1184. })
  1185. ],
  1186. ),
  1187. );
  1188. } else if (data is File) {
  1189. return Container(
  1190. width: 102,
  1191. child: Column(
  1192. children: [
  1193. ClipRRect(
  1194. child: Image.file(
  1195. data,
  1196. height: 102,
  1197. width: 102,
  1198. fit: BoxFit.cover,
  1199. ),
  1200. borderRadius: BorderRadius.circular(4),
  1201. ),
  1202. GestureDetector(
  1203. child: Container(
  1204. height: 30,
  1205. width: 30,
  1206. margin: EdgeInsets.only(top: 5),
  1207. child: Icon(
  1208. Icons.cancel,
  1209. color: MyColors.cFF4233,
  1210. ),
  1211. ),
  1212. onTap: () {
  1213. detailsPictures.remove(data);
  1214. if (detailsPictures.length == 5 &&
  1215. !detailsPictures.contains(null)) {
  1216. detailsPictures.add(null);
  1217. }
  1218. setState(() {});
  1219. })
  1220. ],
  1221. ),
  1222. );
  1223. } else {
  1224. return Column(
  1225. children: [
  1226. Container(
  1227. height: 102,
  1228. width: 102,
  1229. decoration: BoxDecoration(
  1230. color: MyColors.cF0F0F0,
  1231. borderRadius: BorderRadius.all(Radius.circular(4))),
  1232. child: Icon(
  1233. Icons.add,
  1234. color: MyColors.cB6B6B6,
  1235. size: 44,
  1236. ),
  1237. ),
  1238. Container(
  1239. height: 35,
  1240. )
  1241. ],
  1242. );
  1243. }
  1244. }
  1245. Future<void> selectPic(data) async {
  1246. File f = await selectImage(isCover: false);
  1247. if (f == null) {
  1248. return;
  1249. }
  1250. if (data == null) {
  1251. if (detailsPictures.length == 6) {
  1252. detailsPictures[
  1253. detailsPictures.indexWhere((element) => element == data)] = f;
  1254. } else {
  1255. detailsPictures.insert(detailsPictures.length - 1, f);
  1256. }
  1257. } else {
  1258. detailsPictures[
  1259. detailsPictures.indexWhere((element) => element == data)] = f;
  1260. }
  1261. setState(() {});
  1262. }
  1263. //续费更新老广告
  1264. void updateOldAds() {
  1265. MyDio().update({
  1266. 'key': 'ad',
  1267. 'values': {"id": widget.data.id, "renewed": true}
  1268. }, (response, hasError) {
  1269. Navigator.pop(context, 1);
  1270. }, (error) {});
  1271. }
  1272. }