release_goods_page.dart 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  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. ..contentMargin = EdgeInsets.all(20);
  933. EasyLoading.show();
  934. print('uploadCover');
  935. upload(_frontCover, (r, hE) {
  936. if (!hE) {
  937. UploadImageBeanEntity data =
  938. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  939. coverPath = data.data[0].path;
  940. uploadPictureOne();
  941. } else {
  942. EasyLoading.dismiss();
  943. }
  944. }, (e) {
  945. EasyLoading.dismiss();
  946. });
  947. }
  948. }
  949. void uploadPictureOne() {
  950. print('uploadPictureOne');
  951. if (pictures[0] != null) {
  952. upload(pictures[0], (r, hE) {
  953. if (!hE) {
  954. UploadImageBeanEntity data =
  955. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  956. if (picturesPath == '') {
  957. picturesPath = data.data[0].path;
  958. } else {
  959. picturesPath = picturesPath + ',' + data.data[0].path;
  960. }
  961. uploadPictureTwo();
  962. } else {
  963. EasyLoading.dismiss();
  964. }
  965. }, (e) {
  966. EasyLoading.dismiss();
  967. });
  968. } else {
  969. if(widget.data!=null){
  970. if (picturesPath == '') {
  971. picturesPath = p1;
  972. } else {
  973. picturesPath = picturesPath + ',' + p1;
  974. }
  975. }
  976. uploadPictureTwo();
  977. }
  978. }
  979. void uploadPictureTwo() {
  980. print('uploadPictureTwo');
  981. if (pictures[1] != null) {
  982. upload(pictures[1], (r, hE) {
  983. if (!hE) {
  984. UploadImageBeanEntity data =
  985. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  986. if (picturesPath == '') {
  987. picturesPath = data.data[0].path;
  988. } else {
  989. picturesPath = picturesPath + ',' + data.data[0].path;
  990. }
  991. uploadPictureThree();
  992. } else {
  993. EasyLoading.dismiss();
  994. }
  995. }, (e) {
  996. EasyLoading.dismiss();
  997. });
  998. } else {
  999. if(widget.data!=null){
  1000. if (picturesPath == '') {
  1001. picturesPath = p2;
  1002. } else {
  1003. picturesPath = picturesPath + ',' + p2;
  1004. }
  1005. }
  1006. uploadPictureThree();
  1007. }
  1008. }
  1009. void uploadPictureThree() {
  1010. print('uploadPictureThree');
  1011. if (pictures[2] != null) {
  1012. upload(pictures[2], (r, hE) {
  1013. if (!hE) {
  1014. UploadImageBeanEntity data =
  1015. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  1016. if (picturesPath == '') {
  1017. picturesPath = data.data[0].path;
  1018. } else {
  1019. picturesPath = picturesPath + ',' + data.data[0].path;
  1020. }
  1021. productsOnTheShelves();
  1022. } else {
  1023. EasyLoading.dismiss();
  1024. }
  1025. }, (e) {
  1026. EasyLoading.dismiss();
  1027. });
  1028. } else {
  1029. if(widget.data!=null){
  1030. if (picturesPath == '') {
  1031. picturesPath = p3;
  1032. } else {
  1033. picturesPath = picturesPath + ',' + p3;
  1034. }
  1035. }
  1036. productsOnTheShelves();
  1037. }
  1038. }
  1039. Future<void> initCC() async {
  1040. commodityCategoryBeanData =
  1041. await MyData().getCommodityCategoryBeanData(context);
  1042. if (commodityCategoryBeanData.length > 0) {
  1043. typeValue = commodityCategoryBeanData[0].name;
  1044. }
  1045. commodityCategoryBeanData.forEach((element) {
  1046. sortItems.add(DropdownMenuItem(
  1047. child: Text(
  1048. '${element.name}',
  1049. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  1050. ),
  1051. value: '${element.name}',
  1052. ));
  1053. });
  1054. setState(() {});
  1055. }
  1056. void modifyCargo() {
  1057. picturesPath = '';
  1058. uploadCover();
  1059. }
  1060. }