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