release_goods_page.dart 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:bbyyy/beans/commodity_category_bean_entity.dart';
  4. import 'package:bbyyy/beans/goods_bean_entity.dart';
  5. import 'package:bbyyy/beans/my_shop_bean_entity.dart';
  6. import 'package:bbyyy/beans/upload_image_bean_entity.dart';
  7. import 'package:bbyyy/https/MyDio.dart';
  8. import 'package:bbyyy/https/my_request.dart';
  9. import 'package:bbyyy/https/url.dart';
  10. import 'package:bbyyy/my_tools/const.dart';
  11. import 'package:bbyyy/my_tools/dims.dart';
  12. import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
  13. import 'package:bbyyy/my_tools/event_bus.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_datas.dart';
  17. import 'package:bbyyy/my_tools/my_tools.dart';
  18. import 'package:bbyyy/my_tools/my_views.dart';
  19. import 'package:flutter/cupertino.dart';
  20. import 'package:flutter/material.dart';
  21. import 'package:flutter/services.dart';
  22. import 'package:flutter_svg/flutter_svg.dart';
  23. class ReleaseGoodsPage extends StatefulWidget {
  24. GoodsBeanDataData data;
  25. ReleaseGoodsPage(this.data);
  26. @override
  27. _ReleaseGoodsPageState createState() => _ReleaseGoodsPageState();
  28. }
  29. class _ReleaseGoodsPageState extends State<ReleaseGoodsPage> {
  30. List<DropdownMenuItem<String>> sortItems = [];
  31. List<DropdownMenuItem<String>> sortItems1 = [];
  32. String typeValue = '';
  33. String typeValue1 = '';
  34. File _frontCover;
  35. TextEditingController _title = TextEditingController();
  36. TextEditingController _costOfProduction = TextEditingController();
  37. TextEditingController _markedPrice = TextEditingController();
  38. TextEditingController _num = TextEditingController();
  39. TextEditingController _description = TextEditingController();
  40. List<MyShopBeanDataData> shops = [];
  41. bool onSale = true;
  42. List<File> pictures = [null, null, null];
  43. List<CommodityCategoryBeanData> commodityCategoryBeanData = [];
  44. String p1 = '';
  45. String p2 = '';
  46. String p3 = '';
  47. @override
  48. initState() {
  49. // TODO: implement initState
  50. super.initState();
  51. queryGang();
  52. initCC();
  53. if (widget.data != null) {
  54. _title.text = widget.data.title;
  55. _costOfProduction.text = widget.data.originalPrice.toString();
  56. onSale = widget.data.onSale;
  57. _markedPrice.text = widget.data.price.toString();
  58. _num.text = widget.data.stock.toString();
  59. _description.text = widget.data.description;
  60. picturesPath = widget.data.pictures;
  61. picturesPath.split(',').forEach((element) {
  62. if (p1 == '') {
  63. p1 = element;
  64. } else if (p2 == '') {
  65. p2 = element;
  66. } else if (p3 == '') {
  67. p3 = element;
  68. }
  69. });
  70. }
  71. }
  72. @override
  73. Widget build(BuildContext context) {
  74. return GestureDetector(
  75. onTap: () {
  76. MyTools().hideKeyboard(context);
  77. },
  78. child: Scaffold(
  79. body: Column(
  80. children: [
  81. MyViews()
  82. .myAppBar(widget.data == null ? '发布商品' : '修改商品', context, []),
  83. Expanded(
  84. child: SingleChildScrollView(
  85. child: Column(
  86. children: [
  87. Container(
  88. color: Colors.white,
  89. child: Column(
  90. children: [
  91. // Padding(
  92. // padding: EdgeInsets.only(
  93. // left: 16, right: 13, top: 4, bottom: 4),
  94. // child: Row(
  95. // children: [
  96. // Text(
  97. // '发布类型',
  98. // style: TextStyle(
  99. // color: MyColors.c333333, fontSize: 15),
  100. // ),
  101. // Expanded(
  102. // child: Container(
  103. // alignment: Alignment.centerRight,
  104. // child: DropdownButtonHideUnderline(
  105. // child: DropdownButton(
  106. // items: sortItems,
  107. // onChanged: (value) {
  108. // setState(() {
  109. // typeValue = value;
  110. // });
  111. // },
  112. // value: typeValue,
  113. // ),
  114. // ),
  115. // ),
  116. // )
  117. // ],
  118. // ),
  119. // ),
  120. // Container(
  121. // height: 0.5,
  122. // color: MyColors.cE7E7E7,
  123. // margin: EdgeInsets.only(left: 16, right: 14),
  124. // ),
  125. Padding(
  126. padding: EdgeInsets.only(
  127. left: 16, right: 13, top: 15, bottom: 15),
  128. child: Row(
  129. children: [
  130. Text(
  131. '商品名称',
  132. style: TextStyle(
  133. color: MyColors.c333333, fontSize: 15),
  134. ),
  135. Expanded(
  136. child: Container(
  137. alignment: Alignment.centerRight,
  138. child: TextField(
  139. textAlign: TextAlign.end,
  140. controller: _title,
  141. cursorColor: MyColors.cFF4233,
  142. cursorWidth: 1.0,
  143. onTap: () {},
  144. decoration: InputDecoration(
  145. border: InputBorder.none,
  146. disabledBorder: InputBorder.none,
  147. enabledBorder: InputBorder.none,
  148. focusedBorder: InputBorder.none,
  149. isDense: true,
  150. hintText: '请输入',
  151. hintStyle: TextStyle(
  152. color: MyColors.c999999,
  153. fontSize: 14),
  154. contentPadding:
  155. const EdgeInsets.fromLTRB(
  156. 14, 4.5, 8, 4.5),
  157. ),
  158. maxLines: 1,
  159. style: TextStyle(
  160. color: MyColors.c333333,
  161. fontSize: 14,
  162. height: 1.3,
  163. letterSpacing: 0.2),
  164. keyboardType: TextInputType.text,
  165. onChanged: (t) {},
  166. ),
  167. ),
  168. )
  169. ],
  170. ),
  171. ),
  172. Container(
  173. height: 0.5,
  174. color: MyColors.cE7E7E7,
  175. margin: EdgeInsets.only(left: 16, right: 14),
  176. ),
  177. Padding(
  178. padding: EdgeInsets.only(
  179. left: 16, right: 13, top: 15, bottom: 15),
  180. child: Row(
  181. children: [
  182. Text(
  183. '封面图片',
  184. style: TextStyle(
  185. color: MyColors.c333333, fontSize: 15),
  186. ),
  187. Expanded(
  188. child: GestureDetector(
  189. onTap: () async {
  190. _frontCover = await selectImage();
  191. setState(() {});
  192. },
  193. behavior: HitTestBehavior.translucent,
  194. child: Container(
  195. alignment: Alignment.centerRight,
  196. child: _frontCover == null
  197. ? (widget.data == null
  198. ? SvgPicture.asset(
  199. 'images/svg/更换头像.svg',
  200. height: 40,
  201. width: 40,
  202. )
  203. : MyViews().netImg(
  204. imgURL(widget.data.coverPath),
  205. 40,
  206. 40))
  207. : ClipRRect(
  208. child: Image.file(
  209. _frontCover,
  210. height: 40,
  211. width: 40,
  212. ),
  213. borderRadius:
  214. BorderRadius.circular(4),
  215. ),
  216. ),
  217. ),
  218. )
  219. ],
  220. ),
  221. ),
  222. Container(
  223. height: 0.5,
  224. color: MyColors.cE7E7E7,
  225. margin: EdgeInsets.only(left: 16, right: 14),
  226. ),
  227. Padding(
  228. padding: EdgeInsets.only(
  229. left: 16, right: 13, top: 4, bottom: 4),
  230. child: Row(
  231. children: [
  232. Text(
  233. '商品类型',
  234. style: TextStyle(
  235. color: MyColors.c333333, fontSize: 15),
  236. ),
  237. Expanded(
  238. child: Container(
  239. alignment: Alignment.centerRight,
  240. child: DropdownButtonHideUnderline(
  241. child: DropdownButton(
  242. items: sortItems,
  243. onChanged: (value) {
  244. setState(() {
  245. typeValue = value;
  246. });
  247. },
  248. value: typeValue,
  249. ),
  250. ),
  251. ),
  252. )
  253. ],
  254. ),
  255. ),
  256. Visibility(
  257. visible: widget.data==null,
  258. child: Column(children: [
  259. Container(
  260. height: 0.5,
  261. color: MyColors.cE7E7E7,
  262. margin: EdgeInsets.only(left: 16, right: 14),
  263. ),
  264. Padding(
  265. padding: EdgeInsets.only(
  266. left: 16, right: 13, top: 4, bottom: 4),
  267. child: Row(
  268. children: [
  269. Text(
  270. '所属货帮',
  271. style: TextStyle(
  272. color: MyColors.c333333, fontSize: 15),
  273. ),
  274. Expanded(
  275. child: Container(
  276. alignment: Alignment.centerRight,
  277. child: DropdownButtonHideUnderline(
  278. child: DropdownButton(
  279. items: sortItems1,
  280. onChanged: (value) {
  281. setState(() {
  282. typeValue1 = value;
  283. });
  284. },
  285. value: typeValue1,
  286. ),
  287. ),
  288. ),
  289. )
  290. ],
  291. ),
  292. ),
  293. ],),
  294. ),
  295. Container(
  296. height: 0.5,
  297. color: MyColors.cE7E7E7,
  298. margin: EdgeInsets.only(left: 16, right: 14),
  299. ),
  300. Padding(
  301. padding: EdgeInsets.only(
  302. left: 16, right: 13, top: 15, bottom: 15),
  303. child: Row(
  304. children: [
  305. Text(
  306. '原价',
  307. style: TextStyle(
  308. color: MyColors.c333333, fontSize: 15),
  309. ),
  310. Expanded(
  311. child: Container(
  312. alignment: Alignment.centerRight,
  313. child: TextField(
  314. textAlign: TextAlign.end,
  315. controller: _costOfProduction,
  316. cursorColor: MyColors.cFF4233,
  317. cursorWidth: 1.0,
  318. onTap: () {},
  319. decoration: InputDecoration(
  320. border: InputBorder.none,
  321. disabledBorder: InputBorder.none,
  322. enabledBorder: InputBorder.none,
  323. focusedBorder: InputBorder.none,
  324. isDense: true,
  325. hintText: '请输入',
  326. hintStyle: TextStyle(
  327. color: MyColors.c999999,
  328. fontSize: 14),
  329. contentPadding:
  330. const EdgeInsets.fromLTRB(
  331. 14, 4.5, 8, 4.5),
  332. ),
  333. maxLines: 1,
  334. style: TextStyle(
  335. color: MyColors.c333333,
  336. fontSize: 14,
  337. height: 1.3,
  338. letterSpacing: 0.2),
  339. keyboardType: TextInputType.number,
  340. onChanged: (t) {},
  341. ),
  342. ),
  343. )
  344. ],
  345. ),
  346. ),
  347. Container(
  348. height: 0.5,
  349. color: MyColors.cE7E7E7,
  350. margin: EdgeInsets.only(left: 16, right: 14),
  351. ),
  352. Padding(
  353. padding: EdgeInsets.only(
  354. left: 16, right: 13, top: 15, bottom: 15),
  355. child: Row(
  356. children: [
  357. Text(
  358. '标价',
  359. style: TextStyle(
  360. color: MyColors.c333333, fontSize: 15),
  361. ),
  362. Expanded(
  363. child: Container(
  364. alignment: Alignment.centerRight,
  365. child: TextField(
  366. textAlign: TextAlign.end,
  367. controller: _markedPrice,
  368. cursorColor: MyColors.cFF4233,
  369. cursorWidth: 1.0,
  370. onTap: () {},
  371. decoration: InputDecoration(
  372. border: InputBorder.none,
  373. disabledBorder: InputBorder.none,
  374. enabledBorder: InputBorder.none,
  375. focusedBorder: InputBorder.none,
  376. isDense: true,
  377. hintText: '请输入',
  378. hintStyle: TextStyle(
  379. color: MyColors.c999999,
  380. fontSize: 14),
  381. contentPadding:
  382. const EdgeInsets.fromLTRB(
  383. 14, 4.5, 8, 4.5),
  384. ),
  385. maxLines: 1,
  386. style: TextStyle(
  387. color: MyColors.c333333,
  388. fontSize: 14,
  389. height: 1.3,
  390. letterSpacing: 0.2),
  391. keyboardType: TextInputType.number,
  392. onChanged: (t) {},
  393. ),
  394. ),
  395. )
  396. ],
  397. ),
  398. ),
  399. Container(
  400. height: 0.5,
  401. color: MyColors.cE7E7E7,
  402. margin: EdgeInsets.only(left: 16, right: 14),
  403. ),
  404. Padding(
  405. padding: EdgeInsets.only(
  406. left: 16, right: 13, top: 15, bottom: 15),
  407. child: Row(
  408. children: [
  409. Text(
  410. '数量',
  411. style: TextStyle(
  412. color: MyColors.c333333, fontSize: 15),
  413. ),
  414. Expanded(
  415. child: Container(
  416. alignment: Alignment.centerRight,
  417. child: TextField(
  418. textAlign: TextAlign.end,
  419. controller: _num,
  420. cursorColor: MyColors.cFF4233,
  421. cursorWidth: 1.0,
  422. onTap: () {},
  423. decoration: InputDecoration(
  424. border: InputBorder.none,
  425. disabledBorder: InputBorder.none,
  426. enabledBorder: InputBorder.none,
  427. focusedBorder: InputBorder.none,
  428. isDense: true,
  429. hintText: '请输入',
  430. hintStyle: TextStyle(
  431. color: MyColors.c999999,
  432. fontSize: 14),
  433. contentPadding:
  434. const EdgeInsets.fromLTRB(
  435. 14, 4.5, 8, 4.5),
  436. ),
  437. maxLines: 1,
  438. style: TextStyle(
  439. color: MyColors.c333333,
  440. fontSize: 14,
  441. height: 1.3,
  442. letterSpacing: 0.2),
  443. keyboardType: TextInputType.number,
  444. onChanged: (t) {},
  445. ),
  446. ),
  447. )
  448. ],
  449. ),
  450. ),
  451. Container(
  452. height: 0.5,
  453. color: MyColors.cE7E7E7,
  454. margin: EdgeInsets.only(left: 16, right: 14),
  455. ),
  456. Padding(
  457. padding: EdgeInsets.only(
  458. left: 16, right: 13, top: 15, bottom: 15),
  459. child: Row(
  460. children: [
  461. Text(
  462. '是否上架',
  463. style: TextStyle(
  464. color: MyColors.c333333, fontSize: 15),
  465. ),
  466. Expanded(
  467. child: Container(
  468. alignment: Alignment.centerRight,
  469. child: CupertinoSwitch(
  470. value: onSale,
  471. onChanged: (v) {
  472. setState(() {
  473. onSale = v;
  474. });
  475. },
  476. ),
  477. ),
  478. )
  479. ],
  480. ),
  481. ),
  482. ],
  483. ),
  484. margin: EdgeInsets.only(top: 10),
  485. ),
  486. Container(
  487. margin: EdgeInsets.only(top: 10),
  488. color: Colors.white,
  489. child: Column(
  490. children: [
  491. Container(
  492. width: double.infinity,
  493. margin: EdgeInsets.only(left: 16, top: 17),
  494. child: Text(
  495. '商品描述',
  496. style: TextStyle(
  497. color: MyColors.c333333, fontSize: 15),
  498. ),
  499. ),
  500. Container(
  501. margin:
  502. EdgeInsets.only(left: 15, right: 15, top: 17),
  503. constraints: BoxConstraints(minHeight: 86),
  504. decoration: BoxDecoration(
  505. border:
  506. Border.all(color: MyColors.cE7E7E7, width: 1),
  507. borderRadius: BorderRadius.all(
  508. Radius.circular(4),
  509. ),
  510. ),
  511. child: TextField(
  512. controller: _description,
  513. cursorColor: MyColors.cFF4233,
  514. maxLines: null,
  515. cursorWidth: 1.0,
  516. onTap: () {},
  517. decoration: InputDecoration(
  518. border: InputBorder.none,
  519. disabledBorder: InputBorder.none,
  520. enabledBorder: InputBorder.none,
  521. focusedBorder: InputBorder.none,
  522. isDense: true,
  523. hintText: '请输入',
  524. hintStyle: TextStyle(
  525. color: MyColors.c999999, fontSize: 14),
  526. contentPadding:
  527. const EdgeInsets.fromLTRB(14, 4.5, 8, 4.5),
  528. ),
  529. style: TextStyle(
  530. color: MyColors.c333333,
  531. fontSize: 14,
  532. height: 1.3,
  533. letterSpacing: 0.2),
  534. keyboardType: TextInputType.text,
  535. onChanged: (t) {},
  536. ),
  537. ),
  538. Container(
  539. width: double.infinity,
  540. margin: EdgeInsets.only(left: 16, top: 17),
  541. child: Text(
  542. '商品图片',
  543. style: TextStyle(
  544. color: MyColors.c333333, fontSize: 15),
  545. ),
  546. ),
  547. Container(
  548. margin: EdgeInsets.only(
  549. left: 15, right: 15, bottom: 17, top: 18),
  550. child: Row(
  551. children: [
  552. GestureDetector(
  553. onTap: () async {
  554. pictures[0] =
  555. await selectImage(isCover: false);
  556. setState(() {});
  557. },
  558. behavior: HitTestBehavior.translucent,
  559. child: pictures[0] == null
  560. ? p1 == ''
  561. ? Container(
  562. height: 102,
  563. width: 102,
  564. decoration: BoxDecoration(
  565. color: MyColors.cF0F0F0,
  566. borderRadius:
  567. BorderRadius.all(
  568. Radius.circular(4))),
  569. child: Icon(
  570. Icons.add,
  571. color: MyColors.cB6B6B6,
  572. size: 44,
  573. ),
  574. )
  575. : ClipRRect(
  576. child: MyViews()
  577. .netImg(imgURL(p1), 102, 102,placeholder: 'images/svg/goodsDefImg.svg'),
  578. borderRadius:
  579. BorderRadius.circular(4),
  580. )
  581. : ClipRRect(
  582. child: Image.file(
  583. pictures[0],
  584. height: 102,
  585. width: 102,
  586. fit: BoxFit.cover,
  587. ),
  588. borderRadius:
  589. BorderRadius.circular(4),
  590. ),
  591. ),
  592. GestureDetector(
  593. onTap: () async {
  594. pictures[1] =
  595. await selectImage(isCover: false);
  596. setState(() {});
  597. },
  598. behavior: HitTestBehavior.translucent,
  599. child: pictures[1] == null
  600. ? p2 == ''
  601. ? Container(
  602. height: 102,
  603. width: 102,
  604. decoration: BoxDecoration(
  605. color: MyColors.cF0F0F0,
  606. borderRadius:
  607. BorderRadius.all(
  608. Radius.circular(4))),
  609. child: Icon(
  610. Icons.add,
  611. color: MyColors.cB6B6B6,
  612. size: 44,
  613. ),
  614. )
  615. : ClipRRect(
  616. child: MyViews()
  617. .netImg(imgURL(p2), 102, 102,placeholder: 'images/svg/goodsDefImg.svg'),
  618. borderRadius:
  619. BorderRadius.circular(4),
  620. )
  621. : ClipRRect(
  622. child: Image.file(
  623. pictures[1],
  624. height: 102,
  625. width: 102,
  626. fit: BoxFit.cover,
  627. ),
  628. borderRadius:
  629. BorderRadius.circular(4),
  630. ),
  631. ),
  632. GestureDetector(
  633. onTap: () async {
  634. pictures[2] =
  635. await selectImage(isCover: false);
  636. setState(() {});
  637. },
  638. behavior: HitTestBehavior.translucent,
  639. child: pictures[2] == null
  640. ? p3 == ''
  641. ? Container(
  642. height: 102,
  643. width: 102,
  644. decoration: BoxDecoration(
  645. color: MyColors.cF0F0F0,
  646. borderRadius:
  647. BorderRadius.all(
  648. Radius.circular(4))),
  649. child: Icon(
  650. Icons.add,
  651. color: MyColors.cB6B6B6,
  652. size: 44,
  653. ),
  654. )
  655. : ClipRRect(
  656. child: MyViews()
  657. .netImg(imgURL(p3), 102, 102,placeholder: 'images/svg/goodsDefImg.svg'),
  658. borderRadius:
  659. BorderRadius.circular(4),
  660. )
  661. : ClipRRect(
  662. child: Image.file(
  663. pictures[2],
  664. height: 102,
  665. width: 102,
  666. fit: BoxFit.cover,
  667. ),
  668. borderRadius:
  669. BorderRadius.circular(4),
  670. ),
  671. ),
  672. ],
  673. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  674. ),
  675. ),
  676. ],
  677. ),
  678. ),
  679. GestureDetector(
  680. onTap: () {
  681. if(widget.data==null){
  682. checkData();
  683. }else{
  684. modifyCargo();
  685. }
  686. },
  687. behavior: HitTestBehavior.translucent,
  688. child: Container(
  689. width: double.infinity,
  690. height: 50,
  691. color: Colors.white,
  692. child: Text(
  693. widget.data==null?'发布':'保存',
  694. style:
  695. TextStyle(color: MyColors.cFF4233, fontSize: 16),
  696. ),
  697. alignment: Alignment.center,
  698. margin: EdgeInsets.only(top: 10, bottom: 20),
  699. ),
  700. )
  701. ],
  702. ),
  703. ),
  704. )
  705. ],
  706. ),
  707. backgroundColor: MyColors.cF7F7F7,
  708. ),
  709. );
  710. }
  711. queryGang() {
  712. MyDio().query({
  713. "key": "shop_user",
  714. "filters": {
  715. "or": true,
  716. "conditions": [
  717. "role!=$shopUserOwner",
  718. "user_uid==${MyCookie().getUID()}",
  719. "review_state==1"
  720. ],
  721. "filters": [
  722. {
  723. "conditions": ["role==$shopUserOwner", "user_uid==${MyCookie().getUID()}"]
  724. }
  725. ]
  726. },
  727. "dims": shopUserDims,
  728. "paging": [1, 2000]
  729. }, (response, hasError) {
  730. if (!hasError) {
  731. MyShopBeanEntity entity =
  732. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  733. shops = entity.data.data;
  734. shops.forEach((element) {
  735. //自己的公开店铺
  736. if(!element.privateShop&&element.ownerUid==MyCookie().getUID()&&element.shopState==shopStateNormal){
  737. element.canSend = true;
  738. }
  739. //自己在某个允许顾客间交易的私有店铺中
  740. if(element.innerTrade){
  741. element.canSend = true;
  742. }
  743. });
  744. shops.removeWhere((element) => !element.canSend);
  745. if(shops.length==0){
  746. showDialog(
  747. context: context,
  748. builder: (BuildContext context) {
  749. return Center(
  750. child: Container(
  751. decoration: BoxDecoration(
  752. color: Colors.white,
  753. borderRadius: BorderRadius.all(Radius.circular(8))),
  754. child: Column(
  755. children: [
  756. Expanded(
  757. child: Center(
  758. child: Padding(
  759. padding: const EdgeInsets.only(
  760. left: 15, right: 15),
  761. child: Text(
  762. '对不起你没有可以发布商品的店铺',
  763. style: TextStyle(
  764. color: MyColors.c333333,
  765. fontSize: 16,
  766. fontWeight: FontWeight.normal,
  767. decoration: TextDecoration.none),
  768. ),
  769. ),
  770. ),
  771. ),
  772. Container(
  773. height: 0.5,
  774. color: MyColors.cE7E7E7,
  775. ),
  776. Row(
  777. children: [
  778. Expanded(
  779. child: GestureDetector(
  780. onTap: () async {
  781. Navigator.pop(context);
  782. Navigator.pop(context);
  783. },
  784. behavior: HitTestBehavior.translucent,
  785. child: Container(
  786. alignment: Alignment.center,
  787. height: 55,
  788. child: Text(
  789. '确定',
  790. style: TextStyle(
  791. color: MyColors.cFF4233,
  792. fontSize: 16,
  793. fontWeight: FontWeight.normal,
  794. decoration: TextDecoration.none),
  795. ),
  796. ),
  797. )),
  798. ],
  799. )
  800. ],
  801. ),
  802. height: 126,
  803. margin: EdgeInsets.only(left: 48, right: 48),
  804. ),
  805. );
  806. },
  807. );
  808. }
  809. if (shops != null) {
  810. for (int i = 0; i < shops.length; i++) {
  811. if (i == 0) {
  812. typeValue1 = shops[i].shopName;
  813. }
  814. sortItems1.add(DropdownMenuItem(
  815. child: Text(
  816. '${shops[i].shopName}',
  817. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  818. ),
  819. value: '${shops[i].shopName}',
  820. ));
  821. }
  822. }
  823. setState(() {});
  824. }
  825. }, (error) {});
  826. }
  827. void checkData() {
  828. if (shops.isEmpty) {
  829. showToast('货帮获取失败,请稍后再试');
  830. return;
  831. }
  832. if (_title.text.isEmpty) {
  833. showToast('请填写商品名称');
  834. return;
  835. }
  836. if (_frontCover == null) {
  837. showToast('请选择商品封面');
  838. return;
  839. }
  840. bool hasP = false;
  841. pictures.forEach((element) {
  842. if (element != null) {
  843. hasP = true;
  844. }
  845. });
  846. if (!hasP) {
  847. showToast('请设置商品详情图片');
  848. return;
  849. }
  850. if (_costOfProduction.text.isEmpty) {
  851. showToast('请填写原价');
  852. return;
  853. }
  854. if (_markedPrice.text.isEmpty) {
  855. showToast('请填写标价');
  856. return;
  857. }
  858. if (_num.text.isEmpty) {
  859. showToast('请填写数量');
  860. return;
  861. }
  862. uploadCover();
  863. }
  864. void productsOnTheShelves() {
  865. if(widget.data!=null){
  866. MyDio().update({
  867. 'key': 'commodity',
  868. 'values': {
  869. 'id':widget.data.id,
  870. 'category': typeValue,
  871. 'title': _title.text.toString(),
  872. 'cover_path': coverPath,
  873. 'description': _description.text.toString(),
  874. 'original_price': double.parse(_costOfProduction.text.toString()),
  875. 'price': double.parse(_markedPrice.text.toString()),
  876. 'on_sale': onSale,
  877. 'stock': int.parse(_num.text.toString()),
  878. 'pictures': picturesPath,
  879. }
  880. }, (response, hasError) {
  881. if (!hasError) {
  882. showToast('保存成功');
  883. Navigator.pop(context);
  884. EventBus().emit('uploadGoods');
  885. }
  886. }, (error) {});
  887. }else{
  888. int sIndex = shops.indexWhere((element) => element.shopName == typeValue1);
  889. MyDio().save({
  890. 'key': 'commodity',
  891. 'object': {
  892. 'category': typeValue,
  893. 'shop_uid': shops[sIndex].shopUid,
  894. 'shop_name': shops[sIndex].shopName,
  895. 'shop_pic': shops[sIndex].shopPic,
  896. 'user_uid': MyCookie().getUID(),
  897. 'user_name': MyCookie().loginInformation.data.extra.name,
  898. 'user_pic': MyCookie().loginInformation.data.extra.picture,
  899. 'title': _title.text.toString(),
  900. 'cover_path': coverPath,
  901. 'description': _description.text.toString(),
  902. 'original_price': double.parse(_costOfProduction.text.toString()),
  903. 'price': double.parse(_markedPrice.text.toString()),
  904. 'on_sale': onSale,
  905. 'stock': int.parse(_num.text.toString()),
  906. 'pictures': picturesPath,
  907. }
  908. }, (response, hasError) {
  909. if (!hasError) {
  910. showToast('上传成功');
  911. Navigator.pop(context);
  912. EventBus().emit('uploadGoods');
  913. }
  914. }, (error) {});
  915. }
  916. }
  917. String coverPath = '';
  918. String picturesPath = '';
  919. void uploadCover() {
  920. if(_frontCover==null){
  921. if(widget.data!=null){
  922. coverPath = widget.data.coverPath;
  923. uploadPictureOne();
  924. }else{
  925. showToast('请选择商品封面');
  926. return;
  927. }
  928. }else{
  929. EasyLoading.instance
  930. ..contentPadding = EdgeInsets.symmetric(horizontal: 20, vertical: 12)
  931. ..alignment = Alignment.center
  932. ..loadingStyle = EasyLoadingStyle.light
  933. ..contentMargin = EdgeInsets.all(20);
  934. EasyLoading.show();
  935. print('uploadCover');
  936. upload(_frontCover, (r, hE) {
  937. if (!hE) {
  938. UploadImageBeanEntity data =
  939. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  940. coverPath = data.data[0].path;
  941. uploadPictureOne();
  942. } else {
  943. EasyLoading.dismiss();
  944. }
  945. }, (e) {
  946. EasyLoading.dismiss();
  947. });
  948. }
  949. }
  950. void uploadPictureOne() {
  951. print('uploadPictureOne');
  952. if (pictures[0] != null) {
  953. upload(pictures[0], (r, hE) {
  954. if (!hE) {
  955. UploadImageBeanEntity data =
  956. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  957. if (picturesPath == '') {
  958. picturesPath = data.data[0].path;
  959. } else {
  960. picturesPath = picturesPath + ',' + data.data[0].path;
  961. }
  962. uploadPictureTwo();
  963. } else {
  964. EasyLoading.dismiss();
  965. }
  966. }, (e) {
  967. EasyLoading.dismiss();
  968. });
  969. } else {
  970. if(widget.data!=null){
  971. if (picturesPath == '') {
  972. picturesPath = p1;
  973. } else {
  974. picturesPath = picturesPath + ',' + p1;
  975. }
  976. }
  977. uploadPictureTwo();
  978. }
  979. }
  980. void uploadPictureTwo() {
  981. print('uploadPictureTwo');
  982. if (pictures[1] != null) {
  983. upload(pictures[1], (r, hE) {
  984. if (!hE) {
  985. UploadImageBeanEntity data =
  986. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  987. if (picturesPath == '') {
  988. picturesPath = data.data[0].path;
  989. } else {
  990. picturesPath = picturesPath + ',' + data.data[0].path;
  991. }
  992. uploadPictureThree();
  993. } else {
  994. EasyLoading.dismiss();
  995. }
  996. }, (e) {
  997. EasyLoading.dismiss();
  998. });
  999. } else {
  1000. if(widget.data!=null){
  1001. if (picturesPath == '') {
  1002. picturesPath = p2;
  1003. } else {
  1004. picturesPath = picturesPath + ',' + p2;
  1005. }
  1006. }
  1007. uploadPictureThree();
  1008. }
  1009. }
  1010. void uploadPictureThree() {
  1011. print('uploadPictureThree');
  1012. if (pictures[2] != null) {
  1013. upload(pictures[2], (r, hE) {
  1014. if (!hE) {
  1015. UploadImageBeanEntity data =
  1016. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  1017. if (picturesPath == '') {
  1018. picturesPath = data.data[0].path;
  1019. } else {
  1020. picturesPath = picturesPath + ',' + data.data[0].path;
  1021. }
  1022. productsOnTheShelves();
  1023. } else {
  1024. EasyLoading.dismiss();
  1025. }
  1026. }, (e) {
  1027. EasyLoading.dismiss();
  1028. });
  1029. } else {
  1030. if(widget.data!=null){
  1031. if (picturesPath == '') {
  1032. picturesPath = p3;
  1033. } else {
  1034. picturesPath = picturesPath + ',' + p3;
  1035. }
  1036. }
  1037. productsOnTheShelves();
  1038. }
  1039. }
  1040. Future<void> initCC() async {
  1041. commodityCategoryBeanData =
  1042. await MyData().getCommodityCategoryBeanData(context);
  1043. if (commodityCategoryBeanData.length > 0) {
  1044. typeValue = commodityCategoryBeanData[0].name;
  1045. }
  1046. commodityCategoryBeanData.forEach((element) {
  1047. sortItems.add(DropdownMenuItem(
  1048. child: Text(
  1049. '${element.name}',
  1050. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  1051. ),
  1052. value: '${element.name}',
  1053. ));
  1054. });
  1055. setState(() {});
  1056. }
  1057. void modifyCargo() {
  1058. picturesPath = '';
  1059. uploadCover();
  1060. }
  1061. }