| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079 |
- import 'dart:convert';
- import 'dart:io';
- import 'package:bbyyy/beans/commodity_category_bean_entity.dart';
- import 'package:bbyyy/beans/goods_bean_entity.dart';
- import 'package:bbyyy/beans/my_shop_bean_entity.dart';
- import 'package:bbyyy/beans/upload_image_bean_entity.dart';
- import 'package:bbyyy/https/MyDio.dart';
- import 'package:bbyyy/https/my_request.dart';
- import 'package:bbyyy/https/url.dart';
- import 'package:bbyyy/my_tools/const.dart';
- import 'package:bbyyy/my_tools/dims.dart';
- import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
- import 'package:bbyyy/my_tools/event_bus.dart';
- import 'package:bbyyy/my_tools/my_colors.dart';
- import 'package:bbyyy/my_tools/my_cookie.dart';
- import 'package:bbyyy/my_tools/my_datas.dart';
- import 'package:bbyyy/my_tools/my_tools.dart';
- import 'package:bbyyy/my_tools/my_views.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_svg/flutter_svg.dart';
- class ReleaseGoodsPage extends StatefulWidget {
- GoodsBeanDataData data;
- ReleaseGoodsPage(this.data);
- @override
- _ReleaseGoodsPageState createState() => _ReleaseGoodsPageState();
- }
- class _ReleaseGoodsPageState extends State<ReleaseGoodsPage> {
- List<DropdownMenuItem<String>> sortItems = [];
- List<DropdownMenuItem<String>> sortItems1 = [];
- String typeValue = '';
- String typeValue1 = '';
- File _frontCover;
- TextEditingController _title = TextEditingController();
- TextEditingController _costOfProduction = TextEditingController();
- TextEditingController _markedPrice = TextEditingController();
- TextEditingController _num = TextEditingController();
- TextEditingController _description = TextEditingController();
- List<MyShopBeanDataData> shops = [];
- bool onSale = true;
- List<File> pictures = [null, null, null];
- List<CommodityCategoryBeanData> commodityCategoryBeanData = [];
- String p1 = '';
- String p2 = '';
- String p3 = '';
- @override
- initState() {
- // TODO: implement initState
- super.initState();
- queryGang();
- initCC();
- if (widget.data != null) {
- _title.text = widget.data.title;
- _costOfProduction.text = widget.data.originalPrice.toString();
- onSale = widget.data.onSale;
- _markedPrice.text = widget.data.price.toString();
- _num.text = widget.data.stock.toString();
- _description.text = widget.data.description;
- picturesPath = widget.data.pictures;
- picturesPath.split(',').forEach((element) {
- if (p1 == '') {
- p1 = element;
- } else if (p2 == '') {
- p2 = element;
- } else if (p3 == '') {
- p3 = element;
- }
- });
- }
- }
- @override
- Widget build(BuildContext context) {
- return GestureDetector(
- onTap: () {
- MyTools().hideKeyboard(context);
- },
- child: Scaffold(
- body: Column(
- children: [
- MyViews()
- .myAppBar(widget.data == null ? '发布商品' : '修改商品', context, []),
- Expanded(
- child: SingleChildScrollView(
- child: Column(
- children: [
- Container(
- color: Colors.white,
- child: Column(
- children: [
- // Padding(
- // padding: EdgeInsets.only(
- // left: 16, right: 13, top: 4, bottom: 4),
- // child: Row(
- // children: [
- // Text(
- // '发布类型',
- // style: TextStyle(
- // color: MyColors.c333333, fontSize: 15),
- // ),
- // Expanded(
- // child: Container(
- // alignment: Alignment.centerRight,
- // child: DropdownButtonHideUnderline(
- // child: DropdownButton(
- // items: sortItems,
- // onChanged: (value) {
- // setState(() {
- // typeValue = value;
- // });
- // },
- // value: typeValue,
- // ),
- // ),
- // ),
- // )
- // ],
- // ),
- // ),
- // Container(
- // height: 0.5,
- // color: MyColors.cE7E7E7,
- // margin: EdgeInsets.only(left: 16, right: 14),
- // ),
- Padding(
- padding: EdgeInsets.only(
- left: 16, right: 13, top: 15, bottom: 15),
- child: Row(
- children: [
- Text(
- '商品名称',
- style: TextStyle(
- color: MyColors.c333333, fontSize: 15),
- ),
- Expanded(
- child: Container(
- alignment: Alignment.centerRight,
- child: TextField(
- textAlign: TextAlign.end,
- controller: _title,
- cursorColor: MyColors.cFF4233,
- cursorWidth: 1.0,
- onTap: () {},
- decoration: InputDecoration(
- border: InputBorder.none,
- disabledBorder: InputBorder.none,
- enabledBorder: InputBorder.none,
- focusedBorder: InputBorder.none,
- isDense: true,
- hintText: '请输入',
- hintStyle: TextStyle(
- color: MyColors.c999999,
- fontSize: 14),
- contentPadding:
- const EdgeInsets.fromLTRB(
- 14, 4.5, 8, 4.5),
- ),
- maxLines: 1,
- style: TextStyle(
- color: MyColors.c333333,
- fontSize: 14,
- height: 1.3,
- letterSpacing: 0.2),
- keyboardType: TextInputType.text,
- onChanged: (t) {},
- ),
- ),
- )
- ],
- ),
- ),
- Container(
- height: 0.5,
- color: MyColors.cE7E7E7,
- margin: EdgeInsets.only(left: 16, right: 14),
- ),
- Padding(
- padding: EdgeInsets.only(
- left: 16, right: 13, top: 15, bottom: 15),
- child: Row(
- children: [
- Text(
- '封面图片',
- style: TextStyle(
- color: MyColors.c333333, fontSize: 15),
- ),
- Expanded(
- child: GestureDetector(
- onTap: () async {
- _frontCover = await selectImage();
- setState(() {});
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- alignment: Alignment.centerRight,
- child: _frontCover == null
- ? (widget.data == null
- ? SvgPicture.asset(
- 'images/svg/更换头像.svg',
- height: 40,
- width: 40,
- )
- : MyViews().netImg(
- imgURL(widget.data.coverPath),
- 40,
- 40))
- : ClipRRect(
- child: Image.file(
- _frontCover,
- height: 40,
- width: 40,
- ),
- borderRadius:
- BorderRadius.circular(4),
- ),
- ),
- ),
- )
- ],
- ),
- ),
- Container(
- height: 0.5,
- color: MyColors.cE7E7E7,
- margin: EdgeInsets.only(left: 16, right: 14),
- ),
- Padding(
- padding: EdgeInsets.only(
- left: 16, right: 13, top: 4, bottom: 4),
- child: Row(
- children: [
- Text(
- '商品类型',
- style: TextStyle(
- color: MyColors.c333333, fontSize: 15),
- ),
- Expanded(
- child: Container(
- alignment: Alignment.centerRight,
- child: DropdownButtonHideUnderline(
- child: DropdownButton(
- items: sortItems,
- onChanged: (value) {
- setState(() {
- typeValue = value;
- });
- },
- value: typeValue,
- ),
- ),
- ),
- )
- ],
- ),
- ),
- Visibility(
- visible: widget.data==null,
- child: Column(children: [
- Container(
- height: 0.5,
- color: MyColors.cE7E7E7,
- margin: EdgeInsets.only(left: 16, right: 14),
- ),
- Padding(
- padding: EdgeInsets.only(
- left: 16, right: 13, top: 4, bottom: 4),
- child: Row(
- children: [
- Text(
- '所属货帮',
- style: TextStyle(
- color: MyColors.c333333, fontSize: 15),
- ),
- Expanded(
- child: Container(
- alignment: Alignment.centerRight,
- child: DropdownButtonHideUnderline(
- child: DropdownButton(
- items: sortItems1,
- onChanged: (value) {
- setState(() {
- typeValue1 = value;
- });
- },
- value: typeValue1,
- ),
- ),
- ),
- )
- ],
- ),
- ),
- ],),
- ),
- Container(
- height: 0.5,
- color: MyColors.cE7E7E7,
- margin: EdgeInsets.only(left: 16, right: 14),
- ),
- Padding(
- padding: EdgeInsets.only(
- left: 16, right: 13, top: 15, bottom: 15),
- child: Row(
- children: [
- Text(
- '原价',
- style: TextStyle(
- color: MyColors.c333333, fontSize: 15),
- ),
- Expanded(
- child: Container(
- alignment: Alignment.centerRight,
- child: TextField(
- textAlign: TextAlign.end,
- controller: _costOfProduction,
- cursorColor: MyColors.cFF4233,
- cursorWidth: 1.0,
- onTap: () {},
- decoration: InputDecoration(
- border: InputBorder.none,
- disabledBorder: InputBorder.none,
- enabledBorder: InputBorder.none,
- focusedBorder: InputBorder.none,
- isDense: true,
- hintText: '请输入',
- hintStyle: TextStyle(
- color: MyColors.c999999,
- fontSize: 14),
- contentPadding:
- const EdgeInsets.fromLTRB(
- 14, 4.5, 8, 4.5),
- ),
- maxLines: 1,
- style: TextStyle(
- color: MyColors.c333333,
- fontSize: 14,
- height: 1.3,
- letterSpacing: 0.2),
- keyboardType: TextInputType.number,
- onChanged: (t) {},
- ),
- ),
- )
- ],
- ),
- ),
- Container(
- height: 0.5,
- color: MyColors.cE7E7E7,
- margin: EdgeInsets.only(left: 16, right: 14),
- ),
- Padding(
- padding: EdgeInsets.only(
- left: 16, right: 13, top: 15, bottom: 15),
- child: Row(
- children: [
- Text(
- '标价',
- style: TextStyle(
- color: MyColors.c333333, fontSize: 15),
- ),
- Expanded(
- child: Container(
- alignment: Alignment.centerRight,
- child: TextField(
- textAlign: TextAlign.end,
- controller: _markedPrice,
- cursorColor: MyColors.cFF4233,
- cursorWidth: 1.0,
- onTap: () {},
- decoration: InputDecoration(
- border: InputBorder.none,
- disabledBorder: InputBorder.none,
- enabledBorder: InputBorder.none,
- focusedBorder: InputBorder.none,
- isDense: true,
- hintText: '请输入',
- hintStyle: TextStyle(
- color: MyColors.c999999,
- fontSize: 14),
- contentPadding:
- const EdgeInsets.fromLTRB(
- 14, 4.5, 8, 4.5),
- ),
- maxLines: 1,
- style: TextStyle(
- color: MyColors.c333333,
- fontSize: 14,
- height: 1.3,
- letterSpacing: 0.2),
- keyboardType: TextInputType.number,
- onChanged: (t) {},
- ),
- ),
- )
- ],
- ),
- ),
- Container(
- height: 0.5,
- color: MyColors.cE7E7E7,
- margin: EdgeInsets.only(left: 16, right: 14),
- ),
- Padding(
- padding: EdgeInsets.only(
- left: 16, right: 13, top: 15, bottom: 15),
- child: Row(
- children: [
- Text(
- '数量',
- style: TextStyle(
- color: MyColors.c333333, fontSize: 15),
- ),
- Expanded(
- child: Container(
- alignment: Alignment.centerRight,
- child: TextField(
- textAlign: TextAlign.end,
- controller: _num,
- cursorColor: MyColors.cFF4233,
- cursorWidth: 1.0,
- onTap: () {},
- decoration: InputDecoration(
- border: InputBorder.none,
- disabledBorder: InputBorder.none,
- enabledBorder: InputBorder.none,
- focusedBorder: InputBorder.none,
- isDense: true,
- hintText: '请输入',
- hintStyle: TextStyle(
- color: MyColors.c999999,
- fontSize: 14),
- contentPadding:
- const EdgeInsets.fromLTRB(
- 14, 4.5, 8, 4.5),
- ),
- maxLines: 1,
- style: TextStyle(
- color: MyColors.c333333,
- fontSize: 14,
- height: 1.3,
- letterSpacing: 0.2),
- keyboardType: TextInputType.number,
- onChanged: (t) {},
- ),
- ),
- )
- ],
- ),
- ),
- Container(
- height: 0.5,
- color: MyColors.cE7E7E7,
- margin: EdgeInsets.only(left: 16, right: 14),
- ),
- Padding(
- padding: EdgeInsets.only(
- left: 16, right: 13, top: 15, bottom: 15),
- child: Row(
- children: [
- Text(
- '是否上架',
- style: TextStyle(
- color: MyColors.c333333, fontSize: 15),
- ),
- Expanded(
- child: Container(
- alignment: Alignment.centerRight,
- child: CupertinoSwitch(
- value: onSale,
- activeColor: MyColors.cFF4233,
- onChanged: (v) {
- setState(() {
- onSale = v;
- });
- },
- ),
- ),
- )
- ],
- ),
- ),
- ],
- ),
- margin: EdgeInsets.only(top: 10),
- ),
- Container(
- margin: EdgeInsets.only(top: 10),
- color: Colors.white,
- child: Column(
- children: [
- Container(
- width: double.infinity,
- margin: EdgeInsets.only(left: 16, top: 17),
- child: Text(
- '商品描述',
- style: TextStyle(
- color: MyColors.c333333, fontSize: 15),
- ),
- ),
- Container(
- margin:
- EdgeInsets.only(left: 15, right: 15, top: 17),
- constraints: BoxConstraints(minHeight: 86),
- decoration: BoxDecoration(
- border:
- Border.all(color: MyColors.cE7E7E7, width: 1),
- borderRadius: BorderRadius.all(
- Radius.circular(4),
- ),
- ),
- child: TextField(
- controller: _description,
- cursorColor: MyColors.cFF4233,
- maxLines: null,
- cursorWidth: 1.0,
- onTap: () {},
- decoration: InputDecoration(
- border: InputBorder.none,
- disabledBorder: InputBorder.none,
- enabledBorder: InputBorder.none,
- focusedBorder: InputBorder.none,
- isDense: true,
- hintText: '请输入',
- hintStyle: TextStyle(
- color: MyColors.c999999, fontSize: 14),
- contentPadding:
- const EdgeInsets.fromLTRB(14, 4.5, 8, 4.5),
- ),
- style: TextStyle(
- color: MyColors.c333333,
- fontSize: 14,
- height: 1.3,
- letterSpacing: 0.2),
- keyboardType: TextInputType.text,
- onChanged: (t) {},
- ),
- ),
- Container(
- width: double.infinity,
- margin: EdgeInsets.only(left: 16, top: 17),
- child: Text(
- '商品图片',
- style: TextStyle(
- color: MyColors.c333333, fontSize: 15),
- ),
- ),
- Container(
- margin: EdgeInsets.only(
- left: 15, right: 15, bottom: 17, top: 18),
- child: Row(
- children: [
- GestureDetector(
- onTap: () async {
- pictures[0] =
- await selectImage(isCover: false);
- setState(() {});
- },
- behavior: HitTestBehavior.translucent,
- child: pictures[0] == null
- ? p1 == ''
- ? Container(
- height: 102,
- width: 102,
- decoration: BoxDecoration(
- color: MyColors.cF0F0F0,
- borderRadius:
- BorderRadius.all(
- Radius.circular(4))),
- child: Icon(
- Icons.add,
- color: MyColors.cB6B6B6,
- size: 44,
- ),
- )
- : ClipRRect(
- child: MyViews()
- .netImg(imgURL(p1), 102, 102,placeholder: 'images/svg/goodsDefImg.svg'),
- borderRadius:
- BorderRadius.circular(4),
- )
- : ClipRRect(
- child: Image.file(
- pictures[0],
- height: 102,
- width: 102,
- fit: BoxFit.cover,
- ),
- borderRadius:
- BorderRadius.circular(4),
- ),
- ),
- GestureDetector(
- onTap: () async {
- pictures[1] =
- await selectImage(isCover: false);
- setState(() {});
- },
- behavior: HitTestBehavior.translucent,
- child: pictures[1] == null
- ? p2 == ''
- ? Container(
- height: 102,
- width: 102,
- decoration: BoxDecoration(
- color: MyColors.cF0F0F0,
- borderRadius:
- BorderRadius.all(
- Radius.circular(4))),
- child: Icon(
- Icons.add,
- color: MyColors.cB6B6B6,
- size: 44,
- ),
- )
- : ClipRRect(
- child: MyViews()
- .netImg(imgURL(p2), 102, 102,placeholder: 'images/svg/goodsDefImg.svg'),
- borderRadius:
- BorderRadius.circular(4),
- )
- : ClipRRect(
- child: Image.file(
- pictures[1],
- height: 102,
- width: 102,
- fit: BoxFit.cover,
- ),
- borderRadius:
- BorderRadius.circular(4),
- ),
- ),
- GestureDetector(
- onTap: () async {
- pictures[2] =
- await selectImage(isCover: false);
- setState(() {});
- },
- behavior: HitTestBehavior.translucent,
- child: pictures[2] == null
- ? p3 == ''
- ? Container(
- height: 102,
- width: 102,
- decoration: BoxDecoration(
- color: MyColors.cF0F0F0,
- borderRadius:
- BorderRadius.all(
- Radius.circular(4))),
- child: Icon(
- Icons.add,
- color: MyColors.cB6B6B6,
- size: 44,
- ),
- )
- : ClipRRect(
- child: MyViews()
- .netImg(imgURL(p3), 102, 102,placeholder: 'images/svg/goodsDefImg.svg'),
- borderRadius:
- BorderRadius.circular(4),
- )
- : ClipRRect(
- child: Image.file(
- pictures[2],
- height: 102,
- width: 102,
- fit: BoxFit.cover,
- ),
- borderRadius:
- BorderRadius.circular(4),
- ),
- ),
- ],
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- ),
- ),
- ],
- ),
- ),
- GestureDetector(
- onTap: () {
- if(widget.data==null){
- checkData();
- }else{
- modifyCargo();
- }
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- width: double.infinity,
- height: 50,
- color: Colors.white,
- child: Text(
- widget.data==null?'发布':'保存',
- style:
- TextStyle(color: MyColors.cFF4233, fontSize: 16),
- ),
- alignment: Alignment.center,
- margin: EdgeInsets.only(top: 10, bottom: 20),
- ),
- )
- ],
- ),
- ),
- )
- ],
- ),
- backgroundColor: MyColors.cF7F7F7,
- ),
- );
- }
- queryGang() {
- MyDio().query({
- "key": "shop_user",
- "filters": {
- "or": true,
- "conditions": [
- "role!=$shopUserOwner",
- "user_uid==${MyCookie().getUID()}",
- "review_state==1"
- ],
- "filters": [
- {
- "conditions": ["role==$shopUserOwner", "user_uid==${MyCookie().getUID()}"]
- }
- ]
- },
- "dims": shopUserDims,
- "paging": [1, 2000]
- }, (response, hasError) {
- if (!hasError) {
- MyShopBeanEntity entity =
- MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
- shops = entity.data.data;
- shops.forEach((element) {
- //自己的公开店铺
- if(!element.privateShop&&element.ownerUid==MyCookie().getUID()&&element.shopState==shopStateNormal){
- element.canSend = true;
- }
- //自己在某个允许顾客间交易的私有店铺中
- if(element.innerTrade){
- element.canSend = true;
- }
- });
- shops.removeWhere((element) => !element.canSend);
- if(shops.length==0){
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return Center(
- child: Container(
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.all(Radius.circular(8))),
- child: Column(
- children: [
- Expanded(
- child: Center(
- child: Padding(
- padding: const EdgeInsets.only(
- left: 15, right: 15),
- child: Text(
- '对不起你没有可以发布商品的货帮',
- style: TextStyle(
- color: MyColors.c333333,
- fontSize: 16,
- fontWeight: FontWeight.normal,
- decoration: TextDecoration.none),
- ),
- ),
- ),
- ),
- Container(
- height: 0.5,
- color: MyColors.cE7E7E7,
- ),
- Row(
- children: [
- Expanded(
- child: GestureDetector(
- onTap: () async {
- Navigator.pop(context);
- Navigator.pop(context);
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- alignment: Alignment.center,
- height: 55,
- child: Text(
- '确定',
- style: TextStyle(
- color: MyColors.cFF4233,
- fontSize: 16,
- fontWeight: FontWeight.normal,
- decoration: TextDecoration.none),
- ),
- ),
- )),
- ],
- )
- ],
- ),
- height: 126,
- margin: EdgeInsets.only(left: 48, right: 48),
- ),
- );
- },
- );
- }
- if (shops != null) {
- for (int i = 0; i < shops.length; i++) {
- if (i == 0) {
- typeValue1 = shops[i].shopName;
- }
- sortItems1.add(DropdownMenuItem(
- child: Text(
- '${shops[i].shopName}',
- style: TextStyle(color: MyColors.c666666, fontSize: 14),
- ),
- value: '${shops[i].shopName}',
- ));
- }
- }
- setState(() {});
- }
- }, (error) {});
- }
- void checkData() {
- if (shops.isEmpty) {
- showToast('货帮获取失败,请稍后再试');
- return;
- }
- if (_title.text.isEmpty) {
- showToast('请填写商品名称');
- return;
- }
- if (_frontCover == null) {
- showToast('请选择商品封面');
- return;
- }
- bool hasP = false;
- pictures.forEach((element) {
- if (element != null) {
- hasP = true;
- }
- });
- if (!hasP) {
- showToast('请设置商品详情图片');
- return;
- }
- if (_costOfProduction.text.isEmpty) {
- showToast('请填写原价');
- return;
- }
- if (_markedPrice.text.isEmpty) {
- showToast('请填写标价');
- return;
- }
- if (_num.text.isEmpty) {
- showToast('请填写数量');
- return;
- }
- uploadCover();
- }
- void productsOnTheShelves() {
- if(widget.data!=null){
- MyDio().update({
- 'key': 'commodity',
- 'values': {
- 'id':widget.data.id,
- 'category': typeValue,
- 'title': _title.text.toString(),
- 'cover_path': coverPath,
- 'description': _description.text.toString(),
- 'original_price': double.parse(_costOfProduction.text.toString()),
- 'price': double.parse(_markedPrice.text.toString()),
- 'on_sale': onSale,
- 'stock': int.parse(_num.text.toString()),
- 'pictures': picturesPath,
- }
- }, (response, hasError) {
- if (!hasError) {
- showToast('保存成功');
- Navigator.pop(context);
- EventBus().emit('uploadGoods');
- }
- }, (error) {});
- }else{
- int sIndex = shops.indexWhere((element) => element.shopName == typeValue1);
- MyDio().save({
- 'key': 'commodity',
- 'object': {
- 'category': typeValue,
- 'shop_uid': shops[sIndex].shopUid,
- 'shop_name': shops[sIndex].shopName,
- 'shop_pic': shops[sIndex].shopPic,
- 'user_uid': MyCookie().getUID(),
- 'user_name': MyCookie().loginInformation.data.extra.name,
- 'user_pic': MyCookie().loginInformation.data.extra.picture,
- 'title': _title.text.toString(),
- 'cover_path': coverPath,
- 'description': _description.text.toString(),
- 'original_price': double.parse(_costOfProduction.text.toString()),
- 'price': double.parse(_markedPrice.text.toString()),
- 'on_sale': onSale,
- 'stock': int.parse(_num.text.toString()),
- 'pictures': picturesPath,
- }
- }, (response, hasError) {
- if (!hasError) {
- showToast('上传成功');
- Navigator.pop(context);
- EventBus().emit('uploadGoods');
- }
- }, (error) {});
- }
- }
- String coverPath = '';
- String picturesPath = '';
- void uploadCover() {
- if(_frontCover==null){
- if(widget.data!=null){
- coverPath = widget.data.coverPath;
- uploadPictureOne();
- }else{
- showToast('请选择商品封面');
- return;
- }
- }else{
- EasyLoading.instance
- ..contentPadding = EdgeInsets.symmetric(horizontal: 20, vertical: 12)
- ..alignment = Alignment.center
- ..loadingStyle = EasyLoadingStyle.light
- ..contentMargin = EdgeInsets.all(20);
- EasyLoading.show();
- print('uploadCover');
- upload(_frontCover, (r, hE) {
- if (!hE) {
- UploadImageBeanEntity data =
- UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
- coverPath = data.data[0].path;
- uploadPictureOne();
- } else {
- EasyLoading.dismiss();
- }
- }, (e) {
- EasyLoading.dismiss();
- });
- }
- }
- void uploadPictureOne() {
- print('uploadPictureOne');
- if (pictures[0] != null) {
- upload(pictures[0], (r, hE) {
- if (!hE) {
- UploadImageBeanEntity data =
- UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
- if (picturesPath == '') {
- picturesPath = data.data[0].path;
- } else {
- picturesPath = picturesPath + ',' + data.data[0].path;
- }
- uploadPictureTwo();
- } else {
- EasyLoading.dismiss();
- }
- }, (e) {
- EasyLoading.dismiss();
- });
- } else {
- if(widget.data!=null){
- if (picturesPath == '') {
- picturesPath = p1;
- } else {
- picturesPath = picturesPath + ',' + p1;
- }
- }
- uploadPictureTwo();
- }
- }
- void uploadPictureTwo() {
- print('uploadPictureTwo');
- if (pictures[1] != null) {
- upload(pictures[1], (r, hE) {
- if (!hE) {
- UploadImageBeanEntity data =
- UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
- if (picturesPath == '') {
- picturesPath = data.data[0].path;
- } else {
- picturesPath = picturesPath + ',' + data.data[0].path;
- }
- uploadPictureThree();
- } else {
- EasyLoading.dismiss();
- }
- }, (e) {
- EasyLoading.dismiss();
- });
- } else {
- if(widget.data!=null){
- if (picturesPath == '') {
- picturesPath = p2;
- } else {
- picturesPath = picturesPath + ',' + p2;
- }
- }
- uploadPictureThree();
- }
- }
- void uploadPictureThree() {
- print('uploadPictureThree');
- if (pictures[2] != null) {
- upload(pictures[2], (r, hE) {
- if (!hE) {
- UploadImageBeanEntity data =
- UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
- if (picturesPath == '') {
- picturesPath = data.data[0].path;
- } else {
- picturesPath = picturesPath + ',' + data.data[0].path;
- }
- productsOnTheShelves();
- } else {
- EasyLoading.dismiss();
- }
- }, (e) {
- EasyLoading.dismiss();
- });
- } else {
- if(widget.data!=null){
- if (picturesPath == '') {
- picturesPath = p3;
- } else {
- picturesPath = picturesPath + ',' + p3;
- }
- }
- productsOnTheShelves();
- }
- }
- Future<void> initCC() async {
- commodityCategoryBeanData =
- await MyData().getCommodityCategoryBeanData(context);
- if (commodityCategoryBeanData.length > 0) {
- typeValue = commodityCategoryBeanData[0].name;
- }
- commodityCategoryBeanData.forEach((element) {
- sortItems.add(DropdownMenuItem(
- child: Text(
- '${element.name}',
- style: TextStyle(color: MyColors.c666666, fontSize: 14),
- ),
- value: '${element.name}',
- ));
- });
- setState(() {});
- }
- void modifyCargo() {
- picturesPath = '';
- uploadCover();
- }
- }
|