release_goods_page.dart 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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. activeColor: MyColors.cFF4233,
  472. onChanged: (v) {
  473. setState(() {
  474. onSale = v;
  475. });
  476. },
  477. ),
  478. ),
  479. )
  480. ],
  481. ),
  482. ),
  483. ],
  484. ),
  485. margin: EdgeInsets.only(top: 10),
  486. ),
  487. Container(
  488. margin: EdgeInsets.only(top: 10),
  489. color: Colors.white,
  490. child: Column(
  491. children: [
  492. Container(
  493. width: double.infinity,
  494. margin: EdgeInsets.only(left: 16, top: 17),
  495. child: Text(
  496. '商品描述',
  497. style: TextStyle(
  498. color: MyColors.c333333, fontSize: 15),
  499. ),
  500. ),
  501. Container(
  502. margin:
  503. EdgeInsets.only(left: 15, right: 15, top: 17),
  504. constraints: BoxConstraints(minHeight: 86),
  505. decoration: BoxDecoration(
  506. border:
  507. Border.all(color: MyColors.cE7E7E7, width: 1),
  508. borderRadius: BorderRadius.all(
  509. Radius.circular(4),
  510. ),
  511. ),
  512. child: TextField(
  513. controller: _description,
  514. cursorColor: MyColors.cFF4233,
  515. maxLines: null,
  516. cursorWidth: 1.0,
  517. onTap: () {},
  518. decoration: InputDecoration(
  519. border: InputBorder.none,
  520. disabledBorder: InputBorder.none,
  521. enabledBorder: InputBorder.none,
  522. focusedBorder: InputBorder.none,
  523. isDense: true,
  524. hintText: '请输入',
  525. hintStyle: TextStyle(
  526. color: MyColors.c999999, fontSize: 14),
  527. contentPadding:
  528. const EdgeInsets.fromLTRB(14, 4.5, 8, 4.5),
  529. ),
  530. style: TextStyle(
  531. color: MyColors.c333333,
  532. fontSize: 14,
  533. height: 1.3,
  534. letterSpacing: 0.2),
  535. keyboardType: TextInputType.text,
  536. onChanged: (t) {},
  537. ),
  538. ),
  539. Container(
  540. width: double.infinity,
  541. margin: EdgeInsets.only(left: 16, top: 17),
  542. child: Text(
  543. '商品图片',
  544. style: TextStyle(
  545. color: MyColors.c333333, fontSize: 15),
  546. ),
  547. ),
  548. Container(
  549. margin: EdgeInsets.only(
  550. left: 15, right: 15, bottom: 17, top: 18),
  551. child: Row(
  552. children: [
  553. GestureDetector(
  554. onTap: () async {
  555. pictures[0] =
  556. await selectImage(isCover: false);
  557. setState(() {});
  558. },
  559. behavior: HitTestBehavior.translucent,
  560. child: pictures[0] == null
  561. ? p1 == ''
  562. ? Container(
  563. height: 102,
  564. width: 102,
  565. decoration: BoxDecoration(
  566. color: MyColors.cF0F0F0,
  567. borderRadius:
  568. BorderRadius.all(
  569. Radius.circular(4))),
  570. child: Icon(
  571. Icons.add,
  572. color: MyColors.cB6B6B6,
  573. size: 44,
  574. ),
  575. )
  576. : ClipRRect(
  577. child: MyViews()
  578. .netImg(imgURL(p1), 102, 102,placeholder: 'images/svg/goodsDefImg.svg'),
  579. borderRadius:
  580. BorderRadius.circular(4),
  581. )
  582. : ClipRRect(
  583. child: Image.file(
  584. pictures[0],
  585. height: 102,
  586. width: 102,
  587. fit: BoxFit.cover,
  588. ),
  589. borderRadius:
  590. BorderRadius.circular(4),
  591. ),
  592. ),
  593. GestureDetector(
  594. onTap: () async {
  595. pictures[1] =
  596. await selectImage(isCover: false);
  597. setState(() {});
  598. },
  599. behavior: HitTestBehavior.translucent,
  600. child: pictures[1] == null
  601. ? p2 == ''
  602. ? Container(
  603. height: 102,
  604. width: 102,
  605. decoration: BoxDecoration(
  606. color: MyColors.cF0F0F0,
  607. borderRadius:
  608. BorderRadius.all(
  609. Radius.circular(4))),
  610. child: Icon(
  611. Icons.add,
  612. color: MyColors.cB6B6B6,
  613. size: 44,
  614. ),
  615. )
  616. : ClipRRect(
  617. child: MyViews()
  618. .netImg(imgURL(p2), 102, 102,placeholder: 'images/svg/goodsDefImg.svg'),
  619. borderRadius:
  620. BorderRadius.circular(4),
  621. )
  622. : ClipRRect(
  623. child: Image.file(
  624. pictures[1],
  625. height: 102,
  626. width: 102,
  627. fit: BoxFit.cover,
  628. ),
  629. borderRadius:
  630. BorderRadius.circular(4),
  631. ),
  632. ),
  633. GestureDetector(
  634. onTap: () async {
  635. pictures[2] =
  636. await selectImage(isCover: false);
  637. setState(() {});
  638. },
  639. behavior: HitTestBehavior.translucent,
  640. child: pictures[2] == null
  641. ? p3 == ''
  642. ? Container(
  643. height: 102,
  644. width: 102,
  645. decoration: BoxDecoration(
  646. color: MyColors.cF0F0F0,
  647. borderRadius:
  648. BorderRadius.all(
  649. Radius.circular(4))),
  650. child: Icon(
  651. Icons.add,
  652. color: MyColors.cB6B6B6,
  653. size: 44,
  654. ),
  655. )
  656. : ClipRRect(
  657. child: MyViews()
  658. .netImg(imgURL(p3), 102, 102,placeholder: 'images/svg/goodsDefImg.svg'),
  659. borderRadius:
  660. BorderRadius.circular(4),
  661. )
  662. : ClipRRect(
  663. child: Image.file(
  664. pictures[2],
  665. height: 102,
  666. width: 102,
  667. fit: BoxFit.cover,
  668. ),
  669. borderRadius:
  670. BorderRadius.circular(4),
  671. ),
  672. ),
  673. ],
  674. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  675. ),
  676. ),
  677. ],
  678. ),
  679. ),
  680. GestureDetector(
  681. onTap: () {
  682. if(widget.data==null){
  683. checkData();
  684. }else{
  685. modifyCargo();
  686. }
  687. },
  688. behavior: HitTestBehavior.translucent,
  689. child: Container(
  690. width: double.infinity,
  691. height: 50,
  692. color: Colors.white,
  693. child: Text(
  694. widget.data==null?'发布':'保存',
  695. style:
  696. TextStyle(color: MyColors.cFF4233, fontSize: 16),
  697. ),
  698. alignment: Alignment.center,
  699. margin: EdgeInsets.only(top: 10, bottom: 20),
  700. ),
  701. )
  702. ],
  703. ),
  704. ),
  705. )
  706. ],
  707. ),
  708. backgroundColor: MyColors.cF7F7F7,
  709. ),
  710. );
  711. }
  712. queryGang() {
  713. MyDio().query({
  714. "key": "shop_user",
  715. "filters": {
  716. "or": true,
  717. "conditions": [
  718. "role!=$shopUserOwner",
  719. "user_uid==${MyCookie().getUID()}",
  720. "review_state==1"
  721. ],
  722. "filters": [
  723. {
  724. "conditions": ["role==$shopUserOwner", "user_uid==${MyCookie().getUID()}"]
  725. }
  726. ]
  727. },
  728. "dims": shopUserDims,
  729. "paging": [1, 2000]
  730. }, (response, hasError) {
  731. if (!hasError) {
  732. MyShopBeanEntity entity =
  733. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  734. shops = entity.data.data;
  735. shops.forEach((element) {
  736. //自己的公开店铺
  737. if(!element.privateShop&&element.ownerUid==MyCookie().getUID()&&element.shopState==shopStateNormal){
  738. element.canSend = true;
  739. }
  740. //自己在某个允许顾客间交易的私有店铺中
  741. if(element.innerTrade){
  742. element.canSend = true;
  743. }
  744. });
  745. shops.removeWhere((element) => !element.canSend);
  746. if(shops.length==0){
  747. showDialog(
  748. context: context,
  749. builder: (BuildContext context) {
  750. return Center(
  751. child: Container(
  752. decoration: BoxDecoration(
  753. color: Colors.white,
  754. borderRadius: BorderRadius.all(Radius.circular(8))),
  755. child: Column(
  756. children: [
  757. Expanded(
  758. child: Center(
  759. child: Padding(
  760. padding: const EdgeInsets.only(
  761. left: 15, right: 15),
  762. child: Text(
  763. '对不起你没有可以发布商品的店铺',
  764. style: TextStyle(
  765. color: MyColors.c333333,
  766. fontSize: 16,
  767. fontWeight: FontWeight.normal,
  768. decoration: TextDecoration.none),
  769. ),
  770. ),
  771. ),
  772. ),
  773. Container(
  774. height: 0.5,
  775. color: MyColors.cE7E7E7,
  776. ),
  777. Row(
  778. children: [
  779. Expanded(
  780. child: GestureDetector(
  781. onTap: () async {
  782. Navigator.pop(context);
  783. Navigator.pop(context);
  784. },
  785. behavior: HitTestBehavior.translucent,
  786. child: Container(
  787. alignment: Alignment.center,
  788. height: 55,
  789. child: Text(
  790. '确定',
  791. style: TextStyle(
  792. color: MyColors.cFF4233,
  793. fontSize: 16,
  794. fontWeight: FontWeight.normal,
  795. decoration: TextDecoration.none),
  796. ),
  797. ),
  798. )),
  799. ],
  800. )
  801. ],
  802. ),
  803. height: 126,
  804. margin: EdgeInsets.only(left: 48, right: 48),
  805. ),
  806. );
  807. },
  808. );
  809. }
  810. if (shops != null) {
  811. for (int i = 0; i < shops.length; i++) {
  812. if (i == 0) {
  813. typeValue1 = shops[i].shopName;
  814. }
  815. sortItems1.add(DropdownMenuItem(
  816. child: Text(
  817. '${shops[i].shopName}',
  818. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  819. ),
  820. value: '${shops[i].shopName}',
  821. ));
  822. }
  823. }
  824. setState(() {});
  825. }
  826. }, (error) {});
  827. }
  828. void checkData() {
  829. if (shops.isEmpty) {
  830. showToast('货帮获取失败,请稍后再试');
  831. return;
  832. }
  833. if (_title.text.isEmpty) {
  834. showToast('请填写商品名称');
  835. return;
  836. }
  837. if (_frontCover == null) {
  838. showToast('请选择商品封面');
  839. return;
  840. }
  841. bool hasP = false;
  842. pictures.forEach((element) {
  843. if (element != null) {
  844. hasP = true;
  845. }
  846. });
  847. if (!hasP) {
  848. showToast('请设置商品详情图片');
  849. return;
  850. }
  851. if (_costOfProduction.text.isEmpty) {
  852. showToast('请填写原价');
  853. return;
  854. }
  855. if (_markedPrice.text.isEmpty) {
  856. showToast('请填写标价');
  857. return;
  858. }
  859. if (_num.text.isEmpty) {
  860. showToast('请填写数量');
  861. return;
  862. }
  863. uploadCover();
  864. }
  865. void productsOnTheShelves() {
  866. if(widget.data!=null){
  867. MyDio().update({
  868. 'key': 'commodity',
  869. 'values': {
  870. 'id':widget.data.id,
  871. 'category': typeValue,
  872. 'title': _title.text.toString(),
  873. 'cover_path': coverPath,
  874. 'description': _description.text.toString(),
  875. 'original_price': double.parse(_costOfProduction.text.toString()),
  876. 'price': double.parse(_markedPrice.text.toString()),
  877. 'on_sale': onSale,
  878. 'stock': int.parse(_num.text.toString()),
  879. 'pictures': picturesPath,
  880. }
  881. }, (response, hasError) {
  882. if (!hasError) {
  883. showToast('保存成功');
  884. Navigator.pop(context);
  885. EventBus().emit('uploadGoods');
  886. }
  887. }, (error) {});
  888. }else{
  889. int sIndex = shops.indexWhere((element) => element.shopName == typeValue1);
  890. MyDio().save({
  891. 'key': 'commodity',
  892. 'object': {
  893. 'category': typeValue,
  894. 'shop_uid': shops[sIndex].shopUid,
  895. 'shop_name': shops[sIndex].shopName,
  896. 'shop_pic': shops[sIndex].shopPic,
  897. 'user_uid': MyCookie().getUID(),
  898. 'user_name': MyCookie().loginInformation.data.extra.name,
  899. 'user_pic': MyCookie().loginInformation.data.extra.picture,
  900. 'title': _title.text.toString(),
  901. 'cover_path': coverPath,
  902. 'description': _description.text.toString(),
  903. 'original_price': double.parse(_costOfProduction.text.toString()),
  904. 'price': double.parse(_markedPrice.text.toString()),
  905. 'on_sale': onSale,
  906. 'stock': int.parse(_num.text.toString()),
  907. 'pictures': picturesPath,
  908. }
  909. }, (response, hasError) {
  910. if (!hasError) {
  911. showToast('上传成功');
  912. Navigator.pop(context);
  913. EventBus().emit('uploadGoods');
  914. }
  915. }, (error) {});
  916. }
  917. }
  918. String coverPath = '';
  919. String picturesPath = '';
  920. void uploadCover() {
  921. if(_frontCover==null){
  922. if(widget.data!=null){
  923. coverPath = widget.data.coverPath;
  924. uploadPictureOne();
  925. }else{
  926. showToast('请选择商品封面');
  927. return;
  928. }
  929. }else{
  930. EasyLoading.instance
  931. ..contentPadding = EdgeInsets.symmetric(horizontal: 20, vertical: 12)
  932. ..alignment = Alignment.center
  933. ..loadingStyle = EasyLoadingStyle.light
  934. ..contentMargin = EdgeInsets.all(20);
  935. EasyLoading.show();
  936. print('uploadCover');
  937. upload(_frontCover, (r, hE) {
  938. if (!hE) {
  939. UploadImageBeanEntity data =
  940. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  941. coverPath = data.data[0].path;
  942. uploadPictureOne();
  943. } else {
  944. EasyLoading.dismiss();
  945. }
  946. }, (e) {
  947. EasyLoading.dismiss();
  948. });
  949. }
  950. }
  951. void uploadPictureOne() {
  952. print('uploadPictureOne');
  953. if (pictures[0] != null) {
  954. upload(pictures[0], (r, hE) {
  955. if (!hE) {
  956. UploadImageBeanEntity data =
  957. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  958. if (picturesPath == '') {
  959. picturesPath = data.data[0].path;
  960. } else {
  961. picturesPath = picturesPath + ',' + data.data[0].path;
  962. }
  963. uploadPictureTwo();
  964. } else {
  965. EasyLoading.dismiss();
  966. }
  967. }, (e) {
  968. EasyLoading.dismiss();
  969. });
  970. } else {
  971. if(widget.data!=null){
  972. if (picturesPath == '') {
  973. picturesPath = p1;
  974. } else {
  975. picturesPath = picturesPath + ',' + p1;
  976. }
  977. }
  978. uploadPictureTwo();
  979. }
  980. }
  981. void uploadPictureTwo() {
  982. print('uploadPictureTwo');
  983. if (pictures[1] != null) {
  984. upload(pictures[1], (r, hE) {
  985. if (!hE) {
  986. UploadImageBeanEntity data =
  987. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  988. if (picturesPath == '') {
  989. picturesPath = data.data[0].path;
  990. } else {
  991. picturesPath = picturesPath + ',' + data.data[0].path;
  992. }
  993. uploadPictureThree();
  994. } else {
  995. EasyLoading.dismiss();
  996. }
  997. }, (e) {
  998. EasyLoading.dismiss();
  999. });
  1000. } else {
  1001. if(widget.data!=null){
  1002. if (picturesPath == '') {
  1003. picturesPath = p2;
  1004. } else {
  1005. picturesPath = picturesPath + ',' + p2;
  1006. }
  1007. }
  1008. uploadPictureThree();
  1009. }
  1010. }
  1011. void uploadPictureThree() {
  1012. print('uploadPictureThree');
  1013. if (pictures[2] != null) {
  1014. upload(pictures[2], (r, hE) {
  1015. if (!hE) {
  1016. UploadImageBeanEntity data =
  1017. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  1018. if (picturesPath == '') {
  1019. picturesPath = data.data[0].path;
  1020. } else {
  1021. picturesPath = picturesPath + ',' + data.data[0].path;
  1022. }
  1023. productsOnTheShelves();
  1024. } else {
  1025. EasyLoading.dismiss();
  1026. }
  1027. }, (e) {
  1028. EasyLoading.dismiss();
  1029. });
  1030. } else {
  1031. if(widget.data!=null){
  1032. if (picturesPath == '') {
  1033. picturesPath = p3;
  1034. } else {
  1035. picturesPath = picturesPath + ',' + p3;
  1036. }
  1037. }
  1038. productsOnTheShelves();
  1039. }
  1040. }
  1041. Future<void> initCC() async {
  1042. commodityCategoryBeanData =
  1043. await MyData().getCommodityCategoryBeanData(context);
  1044. if (commodityCategoryBeanData.length > 0) {
  1045. typeValue = commodityCategoryBeanData[0].name;
  1046. }
  1047. commodityCategoryBeanData.forEach((element) {
  1048. sortItems.add(DropdownMenuItem(
  1049. child: Text(
  1050. '${element.name}',
  1051. style: TextStyle(color: MyColors.c666666, fontSize: 14),
  1052. ),
  1053. value: '${element.name}',
  1054. ));
  1055. });
  1056. setState(() {});
  1057. }
  1058. void modifyCargo() {
  1059. picturesPath = '';
  1060. uploadCover();
  1061. }
  1062. }