| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077 |
- 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,
- 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
- ..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();
- }
- }
|