release_goods_page.dart 41 KB

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