import 'dart:convert'; import 'dart:io'; import 'package:bbyyy/beans/ad_bean_entity.dart'; import 'package:bbyyy/beans/ad_pricing_bean_entity.dart'; import 'package:bbyyy/beans/alipay_result_bean_entity.dart'; import 'package:bbyyy/beans/annual_fee_order_bean_entity.dart'; import 'package:bbyyy/beans/goods_bean_entity.dart'; import 'package:bbyyy/beans/my_shop_bean_entity.dart'; import 'package:bbyyy/beans/pay_by_alipay_bean_entity.dart'; import 'package:bbyyy/beans/upload_image_bean_entity.dart'; import 'package:bbyyy/beans/user_balance_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_tools.dart'; import 'package:bbyyy/my_tools/my_views.dart'; import 'package:bbyyy/pay/pay_tools.dart'; import 'package:flustars/flustars.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_svg/svg.dart'; import 'package:tobias/tobias.dart'; import 'associated_store_page.dart'; import 'related_products_page.dart'; class NewAdPage extends StatefulWidget { AdBeanDataData data; NewAdPage(this.data); @override _NewAdPageState createState() => _NewAdPageState(); } class _NewAdPageState extends State { TextEditingController _title = TextEditingController(); TextEditingController _description = TextEditingController(); TextEditingController _days = TextEditingController(); List> sortItems = []; List pricing = []; String typeValue = ''; int typeIndex = 0; File cover; String coverPath = ''; String picturesPath = ''; List pictures = [null, null, null]; int associationType = -1; String startTime = '请选择时间'; DateTime startDate; MyShopBeanDataData shop; GoodsBeanDataData product; int status; @override void initState() { // TODO: implement initState super.initState(); if(widget.data!=null){ if (widget.data.paid == false) { status = 1; } else { var sT = DateTime.parse(widget.data.startDate); var eT = sT.add(Duration(days: widget.data.days)); if (sT.isBefore(DateTime.now()) && eT.isAfter(DateTime.now())) { status = 0; } else if (sT.isAfter(DateTime.now())) { status = 3; } else if (eT.isBefore(DateTime.now())) { status = 2; } } } Future.delayed(Duration.zero, () { advertisingPricing((re, hE) { if (!hE) { AdPricingBeanEntity entity = AdPricingBeanEntity().fromJson(json.decode(re.data.toString())); if (entity.data.isEmpty) { return; } pricing = entity.data; typeValue = entity.data[0].type == 0 ? '店铺/商品部分广告' : '首页banner'; typeIndex = entity.data[0].type; entity.data.forEach((element) { sortItems.add(DropdownMenuItem( child: Container( child: Text( element.type == 0 ? '店铺/商品部分广告' : '首页banner', style: TextStyle(color: MyColors.c333333, fontSize: 15), textAlign: TextAlign.end, ), alignment: Alignment.centerRight, width: 150, ), value: element.type == 0 ? '店铺/商品部分广告' : '首页banner', )); }); if (widget.data != null) { initAd(); } setState(() {}); } }); }); } @override Widget build(BuildContext context) { return GestureDetector( onTap: () { MyTools().hideKeyboard(context); }, behavior: HitTestBehavior.translucent, child: Scaffold( backgroundColor: MyColors.cF7F7F7, body: Column( children: [ MyViews().myAppBar('发布广告', context, []), Container( height: 10, color: MyColors.cF7F7F7, ), Expanded( child: SingleChildScrollView( child: Column( children: [ Container( color: Colors.white, child: Column( children: [ //广告标题 Container( padding: EdgeInsets.all(16), child: aboutRow([ MyViews().myText('广告标题', MyColors.c333333, 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: 15), contentPadding: const EdgeInsets.fromLTRB( 14, 4.5, 8, 4.5), ), maxLines: 1, style: TextStyle( color: MyColors.c333333, fontSize: 15, height: 1.3, letterSpacing: 0.2), keyboardType: TextInputType.text, onChanged: (t) {}, ), ), ), ]), ), Container( height: 0.5, color: MyColors.cE7E7E7, margin: EdgeInsets.symmetric(horizontal: 16), ), //首页图片 Container( padding: EdgeInsets.all(16), child: aboutRow([ MyViews().myText('首页图片', MyColors.c333333, 15), GestureDetector( onTap: () async { cover = await selectImage(); setState(() {}); }, behavior: HitTestBehavior.translucent, child: getCover(), ) ]), ), Container( height: 0.5, color: MyColors.cE7E7E7, margin: EdgeInsets.symmetric(horizontal: 16), ), //广告类型 Container( padding: EdgeInsets.symmetric( horizontal: 16, vertical: widget.data == null || !widget.data.paid ? 4 : 16), child: aboutRow([ MyViews().myText('广告类型', MyColors.c333333, 15), widget.data == null || !widget.data.paid ? DropdownButtonHideUnderline( child: DropdownButton( items: sortItems, onChanged: (value) { setState(() { typeValue = value; }); }, value: typeValue, ), ) : MyViews() .myText(typeValue, MyColors.c333333, 15), ]), ), Container( height: 0.5, color: MyColors.cE7E7E7, margin: EdgeInsets.symmetric(horizontal: 16), ), //开始投放时间 Container( padding: EdgeInsets.all(16), child: aboutRow([ MyViews().myText('开始投放时间', MyColors.c333333, 15), GestureDetector( onTap: () async { if (widget.data == null || !widget.data.paid) { var result = await showDatePicker( context: context, initialDate: DateTime.now(), firstDate: DateTime.now(), lastDate: DateTime.now() .add(Duration(days: 500)), ); setState(() { startTime = result.toString().substring(0, 10); startDate = result; }); } }, behavior: HitTestBehavior.translucent, child: MyViews() .myText(startTime, MyColors.c333333, 15), ), ]), ), Container( height: 0.5, color: MyColors.cE7E7E7, margin: EdgeInsets.symmetric(horizontal: 16), ), //停止投放时间 Container( padding: EdgeInsets.all(16), child: aboutRow([ MyViews().myText('投放天数', MyColors.c333333, 15), Expanded( child: Container( alignment: Alignment.centerRight, child: TextField( enabled: widget.data == null || !widget.data.paid, inputFormatters: [ FilteringTextInputFormatter.allow( RegExp("[0-9]")), ], textAlign: TextAlign.end, controller: _days, 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: 15), contentPadding: const EdgeInsets.fromLTRB( 14, 4.5, 8, 4.5), ), maxLines: 1, style: TextStyle( color: MyColors.c333333, fontSize: 15, height: 1.3, letterSpacing: 0.2), keyboardType: TextInputType.number, onChanged: (t) {}, ), ), ), ]), ), Container( height: 10, color: MyColors.cF7F7F7, ), //详情描述 Container( padding: EdgeInsets.all(16), child: aboutRow([ MyViews().myText('详情描述', MyColors.c333333, 15), ]), ), Container( margin: EdgeInsets.only( left: 15, right: 15, bottom: 15), 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( height: 0.5, color: MyColors.cE7E7E7, margin: EdgeInsets.symmetric(horizontal: 16), ), //详情图片 Container( padding: EdgeInsets.all(16), child: aboutRow([ MyViews().myText('详情图片', MyColors.c333333, 15), ]), ), Container( margin: EdgeInsets.only( left: 15, right: 15, bottom: 17), child: Row( children: [ GestureDetector( onTap: () async { pictures[0] = await selectImage(isCover: false); setState(() {}); }, behavior: HitTestBehavior.translucent, child: getP1(), ), GestureDetector( onTap: () async { pictures[1] = await selectImage(isCover: false); setState(() {}); }, behavior: HitTestBehavior.translucent, child: getP2(), ), GestureDetector( onTap: () async { pictures[2] = await selectImage(isCover: false); setState(() {}); }, behavior: HitTestBehavior.translucent, child: getP3(), ), ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), Container( height: 10, color: MyColors.cF7F7F7, ), //广告关联类型 Container( padding: EdgeInsets.symmetric( horizontal: 16, vertical: 4), child: aboutRow([ MyViews().myText('广告关联类型', MyColors.c333333, 15), Row( children: [ Checkbox( activeColor: MyColors.cFF4233, value: associationType == 0, onChanged: (v) { shop = null; product = null; setState(() { if (v) { associationType = 0; } else { associationType = -1; } }); }), MyViews().myText('店铺', MyColors.c333333, 15), Checkbox( activeColor: MyColors.cFF4233, value: associationType == 1, onChanged: (v) { setState(() { if (v) { associationType = 1; } else { associationType = -1; } }); }), MyViews().myText('商品', MyColors.c333333, 15), ], ), ]), ), //关联 Visibility( visible: associationType != -1, child: Column( children: [ Container( height: 0.5, color: MyColors.cE7E7E7, margin: EdgeInsets.symmetric(horizontal: 16), ), Container( padding: EdgeInsets.all(16), child: aboutRow([ MyViews().myText( associationType == 0 ? '关联店铺' : '关联商品', MyColors.c333333, 15), GestureDetector( onTap: () { MyTools().hideKeyboard(context); MyTools().toPage( context, associationType == 0 ? AssociatedStorePage() : RelatedProductsPage(), (then) { if (then is MyShopBeanDataData) { shop = then; setState(() {}); } if (then is GoodsBeanDataData) { product = then; setState(() {}); } }); }, behavior: HitTestBehavior.translucent, child: associatedView()), ]), ), ], ), ), Container( height: 10, color: MyColors.cF7F7F7, ), GestureDetector( onTap: () { uploadCover(); }, behavior: HitTestBehavior.translucent, child: Container( height: 50, child: MyViews().myText( widget.data == null ? '发 布' : '保 存', MyColors.cFF4233, 16), alignment: Alignment.center, ), ), Container( height: 10, color: MyColors.cF7F7F7, ), Visibility( visible: status==1||status==2, child: GestureDetector( onTap: () { showSimpleDialog('确认删除此广告?',context,(){ Navigator.pop(context); deleteAD(widget.data); }); }, behavior: HitTestBehavior.translucent, child: Container( height: 50, child: MyViews().myText( '删 除', MyColors.cFF4233, 16), alignment: Alignment.center, ), ), ), Container( height: 50, color: MyColors.cF7F7F7, ), ], ), ) ], ), ), ), ], ), ), ); } Widget aboutRow(List ws) { return Row( children: ws, mainAxisAlignment: MainAxisAlignment.spaceBetween, ); } associatedView() { if (associationType == 0) { if (shop == null) { return MyViews().myText('选择关联店铺', MyColors.c333333, 15); } else { return Row( children: [ ClipRRect( child: MyViews().netImg(imgURL(shop.shopPic), 24, 24), borderRadius: BorderRadius.circular(12), ), Container( child: MyViews().myText(shop.shopName, MyColors.c333333, 15), margin: EdgeInsets.only(left: 8), ) ], ); } } else { if (product == null) { return MyViews().myText('选择关联商品', MyColors.c333333, 15); } else { return Row( children: [ ClipRRect( child: MyViews().netImg(imgURL(product.coverPath), 24, 24), borderRadius: BorderRadius.circular(12), ), Container( child: MyViews().myText(product.title, MyColors.c333333, 15), margin: EdgeInsets.only(left: 8), ) ], ); } } } void uploadCover() { if (_title.text.isEmpty) { showToast('请填写标题'); return; } if (cover == null && coverPath == '') { showToast('请选择首页图片'); return; } if (startTime == '请选择时间') { showToast('请选择时间'); return; } if (_days.text.isEmpty) { showToast('请填写投放天数'); return; } if (_description.text.isEmpty) { showToast('请填写描述'); return; } EasyLoading.instance ..contentPadding = EdgeInsets.symmetric(horizontal: 20, vertical: 12) ..alignment = Alignment.center ..contentMargin = EdgeInsets.all(20); EasyLoading.show(); print('uploadCover'); if (cover == null) { uploadPictureOne(); } else { upload(cover, (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() { 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 (p1 != '') { 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 (p2 != '') { 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; } if (widget.data != null) { updateAd(); } else { saveAd(); } } else { EasyLoading.dismiss(); } }, (e) { EasyLoading.dismiss(); }); } else { if (p3 != '') { if (picturesPath == '') { picturesPath = p3; } else { picturesPath = picturesPath + ',' + p3; } } if (widget.data != null) { updateAd(); } else { saveAd(); } } } void showPayOrder(AnnualFeeOrderBeanEntity order) { EasyLoading.instance ..contentPadding = EdgeInsets.symmetric(horizontal: 0, vertical: 12) ..alignment = Alignment.bottomCenter ..contentMargin = EdgeInsets.fromLTRB(20, 20, 20, 65); double price = NumUtil.multiply( int.parse(_days.text.toString()), pricing[pricing.indexWhere((element) => element.type == typeIndex)] .pricing); EasyLoading.show( indicator: Material( color: Colors.white, child: Column( children: [ Container( margin: EdgeInsets.symmetric(horizontal: 12), child: Row( children: [ Container( child: Image.asset( 'images/app_logo.png', height: 27, width: 27, ), margin: EdgeInsets.only(right: 8), height: 45, width: 45, decoration: BoxDecoration( border: Border.all(color: MyColors.cEBEBEB, width: 1)), alignment: Alignment.center, ), Expanded( child: Container( height: 45, child: Column( children: [ MyViews().myText('广告费', MyColors.c333333, 13), Row( children: [ MyViews().myText('¥${price.toStringAsFixed(2)}', MyColors.cFF4233, 12), ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, ), ), ), ], ), ), Container( height: 0.5, color: MyColors.cE7E7E7, margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11), ), Container( margin: EdgeInsets.symmetric(horizontal: 12), child: Row( children: [ MyViews().myText('卖家信息:', MyColors.c333333, 13), Row( children: [ Container( margin: EdgeInsets.only(right: 5), child: ClipRRect( child: Image.asset( 'images/app_logo.png', height: 23, width: 23, ), borderRadius: BorderRadius.circular(11.5), ), ), MyViews().myText('$appName', MyColors.c333333, 13), ], ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), Container( height: 0.5, color: MyColors.cE7E7E7, margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11), ), Container( margin: EdgeInsets.symmetric(horizontal: 12), child: Row( children: [ MyViews().myText('买家信息:', MyColors.c333333, 13), Row( children: [ Container( margin: EdgeInsets.only(right: 5), child: ClipRRect( child: MyViews().netImg( imgURL(MyCookie().userBean.picture), 23, 23), borderRadius: BorderRadius.circular(11.5), ), ), MyViews().myText( '${MyCookie().userBean.name}(${MyCookie().userBean.uid})', MyColors.c333333, 13), ], ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), Container( height: 0.5, color: MyColors.cE7E7E7, margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11), ), Container( margin: EdgeInsets.symmetric(horizontal: 12), child: Row( children: [ MyViews().myText('下单时间:', MyColors.c333333, 13), MyViews().myText( '${DateTime.now().toString().substring(0, 19)}', MyColors.c333333, 13) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), Container( height: 0.5, color: MyColors.cE7E7E7, margin: EdgeInsets.symmetric(horizontal: 12, vertical: 11), ), Container( margin: EdgeInsets.symmetric(horizontal: 20), child: Row( children: [ Expanded( child: GestureDetector( onTap: () { EasyLoading.dismiss(); Navigator.pop(context, widget.data == null); }, behavior: HitTestBehavior.translucent, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.only( topLeft: Radius.circular(20), bottomLeft: Radius.circular(20), ), border: Border.all( color: MyColors.cFF4233, width: 1)), height: 40, child: MyViews().myText('稍后支付', MyColors.cFF4233, 14), alignment: Alignment.center), ), ), Expanded( child: GestureDetector( onTap: () { getUserWalletBalance((re, hE) { if (!hE) { UserBalanceEntity balance = UserBalanceEntity() .fromJson(json.decode(re.data.toString())); if (balance.data >= price) { payOrder(payWayWallet, order.data.orderUid, (re, hE) { if (!hE) { showToast('支付成功'); EventBus().emit('payAnOrder'); Navigator.pop(context, widget.data == null); } }, (e) {}, context); } else { payOrder(payWayAliPay, order.data.orderUid, (re, hE) { if (!hE) { PayByAlipayBeanEntity entity = PayByAlipayBeanEntity().fromJson( json.decode(re.data.toString())); EventBus().on('alipayPaymentCallback', (arg) { EventBus().off('alipayPaymentCallback'); EasyLoading.dismiss(); showToast('支付成功'); EventBus().emit('reNoPayOrder'); Navigator.pop(context, widget.data == null); }); print(entity.data); EasyLoading.instance ..contentPadding = EdgeInsets.symmetric( horizontal: 20, vertical: 12) ..alignment = Alignment.center ..contentMargin = EdgeInsets.all(20); EasyLoading.show(); aliPay(entity.data).then((value) { print(json.encode(value)); AlipayResultBeanEntity e = AlipayResultBeanEntity().fromJson( json.decode(json.encode(value))); try { int r = int.parse(e.resultStatus); if (r == 9000) { showToast('支付成功'); Navigator.pop( context, widget.data == null); } else { showToast(aliPayResultStatus(r)); resetOrder(order.data.orderUid); } } catch (e) { EasyLoading.dismiss(); } }); // EventBus().emit('payAnOrder'); } }, (e) {}, context); // showToast('积分余额不足'); } } }, (e) {}, context); }, behavior: HitTestBehavior.translucent, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.only( topRight: Radius.circular(20), bottomRight: Radius.circular(20), ), color: MyColors.cFF4233), height: 40, child: MyViews().myText('立即支付', Colors.white, 14), alignment: Alignment.center), ), ) ], ), ) ], ), ), ); } String p1 = ''; String p2 = ''; String p3 = ''; void initAd() { _title.text = widget.data.title; coverPath = widget.data.coverPath; typeIndex = widget.data.type; typeValue = typeIndex == 0 ? '店铺/商品部分广告' : '首页banner'; startTime = widget.data.startDate; _days.text = widget.data.days.toString(); _description.text = widget.data.description; widget.data.pictures.split(',').forEach((element) { if (p1 == '') { p1 = element; } else if (p2 == '') { p2 = element; } else if (p3 == '') { p3 = element; } }); if (widget.data.linkId == 0) { associationType = -1; } else { associationType = widget.data.linkType; } setState(() {}); if (associationType != -1) { if (associationType == 0) { MyDio().query({ "key": "shop_user", "filters": { "conditions": ["id==${widget.data.linkId}"], }, "dims": shopUserDims, "paging": [1, 1], "order_by": ["shop_name,DESC"] }, (response, hasError) { if (!hasError) { MyShopBeanEntity entity = MyShopBeanEntity() .fromJson(json.decode(response.data.toString())); if (entity.data.data.length != 0) { shop = entity.data.data[0]; setState(() {}); } } }, (error) {}); } else if (associationType == 1) { MyDio().query({ "key": "commodity", "filters": { "conditions": ["id == ${widget.data.linkId}"] }, "dims": commodityDims, "paging": [1, 1] }, (response, hasError) { if (!hasError) { GoodsBeanEntity entity = GoodsBeanEntity() .fromJson(json.decode(response.data.toString())); if (entity.data.data.length != 0) { product = entity.data.data[0]; setState(() {}); } } }, (error) {}); } } } getCover() { if (cover == null && coverPath == '') { return SvgPicture.asset( 'images/svg/更换头像.svg', height: 40, width: 40, ); } else if (cover != null) { return ClipRRect( child: Image.file( cover, height: 40, width: 40, ), borderRadius: BorderRadius.circular(4), ); } else if (coverPath != '') { return ClipRRect( child: MyViews().netImg(imgURL(coverPath), 40, 40), borderRadius: BorderRadius.circular(4), ); } } getP1() { if (pictures[0] == null && p1 == '') { return 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, ), ); } else if (pictures[0] != null) { return ClipRRect( child: Image.file( pictures[0], height: 102, width: 102, fit: BoxFit.cover, ), borderRadius: BorderRadius.circular(4), ); } else if (p1 != '') { return ClipRRect( child: MyViews().netImg(imgURL(p1), 102, 102), borderRadius: BorderRadius.circular(4), ); } } getP2() { if (pictures[1] == null && p2 == '') { return 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, ), ); } else if (pictures[1] != null) { return ClipRRect( child: Image.file( pictures[1], height: 102, width: 102, fit: BoxFit.cover, ), borderRadius: BorderRadius.circular(4), ); } else if (p2 != '') { return ClipRRect( child: MyViews().netImg(imgURL(p2), 102, 102), borderRadius: BorderRadius.circular(4), ); } } getP3() { if (pictures[2] == null && p3 == '') { return 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, ), ); } else if (pictures[2] != null) { return ClipRRect( child: Image.file( pictures[2], height: 102, width: 102, fit: BoxFit.cover, ), borderRadius: BorderRadius.circular(4), ); } else if (p3 != '') { return ClipRRect( child: MyViews().netImg(imgURL(p3), 102, 102), borderRadius: BorderRadius.circular(4), ); } } void updateAd() { var values = { "id": widget.data.id, "title": _title.text.toString(), "description": _description.text.toString(), "cover_path": coverPath, "pictures": picturesPath }; if (associationType == 0 && shop != null) { values['link_type'] = associationType; values['link_id'] = shop.id; } if (associationType == 1 && product != null) { values['link_type'] = associationType; values['link_id'] = product.id; } MyDio().update({'key': 'ad', 'values': values}, (response, hasError) { if (!hasError) { widget.data.title = _title.text.toString(); widget.data.description = _description.text.toString(); widget.data.coverPath = coverPath; widget.data.pictures = picturesPath; AnnualFeeOrderBeanEntity entity = AnnualFeeOrderBeanEntity() .fromJson(json.decode(response.data.toString())); if (!widget.data.paid) { showPayOrder(entity); }else{ EasyLoading.dismiss(); Navigator.pop(context, widget.data == null); } } }, (error) {}); } void saveAd() { var object = { "type": typeValue == '店铺/商品部分广告' ? 0 : 1, "start_date": startTime, "days": int.parse(_days.text.toString()), "user_uid": MyCookie().getUID(), "user_name": MyCookie().getName(), "user_pic": MyCookie().userBean.picture, "title": _title.text.toString(), "description": _description.text.toString(), "cover_path": coverPath, "pictures": picturesPath }; if (associationType == 0 && shop != null) { object['link_type'] = associationType; object['link_id'] = shop.id; } if (associationType == 1 && product != null) { object['link_type'] = associationType; object['link_id'] = product.id; } MyDio().save({'key': 'ad', 'object': object}, (response, hasError) { AnnualFeeOrderBeanEntity entity = AnnualFeeOrderBeanEntity() .fromJson(json.decode(response.data.toString())); showPayOrder(entity); }, (error) {}); } void deleteAD(AdBeanDataData ad) { MyDio().del({ 'key': 'ad', 'ids': [ad.id] }, (response, hasError) { Navigator.pop(context,widget.data==null); }, (error) {}); } }