| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297 |
- 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/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/smart_order_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/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/paegs/pay_page/order_information_page.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 'associated_store_page.dart';
- import 'related_products_page.dart';
- class NewAdPage extends StatefulWidget {
- AdBeanDataData data;
- bool renew;
- NewAdPage(this.data, {this.renew = false});
- @override
- _NewAdPageState createState() => _NewAdPageState();
- }
- class _NewAdPageState extends State<NewAdPage> {
- TextEditingController _title = TextEditingController();
- TextEditingController _description = TextEditingController();
- TextEditingController _days = TextEditingController();
- TextEditingController _number = TextEditingController();
- List<DropdownMenuItem<String>> sortItems = [];
- List<AdPricingBeanData> pricing = [];
- String typeValue = '';
- int typeIndex = 0;
- File cover;
- String coverPath = '';
- String picturesPath = '';
- int associationType = -1;
- String startTime = '请选择时间';
- DateTime startDate;
- MyShopBeanDataData shop;
- GoodsBeanDataData product;
- int status;
- var detailsPictures = [];
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- detailsPictures.add(null);
- 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 ||
- widget.renew
- ? 4
- : 16),
- child: aboutRow([
- MyViews().myText('广告类型', MyColors.c333333, 15),
- widget.data == null ||
- !widget.data.paid ||
- widget.renew
- ? 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 ||
- widget.renew) {
- 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 ||
- widget.renew,
- 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),
- Expanded(
- child: Container(
- alignment: Alignment.centerRight,
- child: TextField(
- enabled: widget.data == null ||
- !widget.data.paid ||
- widget.renew,
- inputFormatters: [
- FilteringTextInputFormatter.allow(
- RegExp("[0-9]")),
- LengthLimitingTextInputFormatter(11)
- ],
- textAlign: TextAlign.end,
- controller: _number,
- 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(
- height: detailsPictures.length > 3 ? 279 : 137,
- margin: EdgeInsets.only(bottom: 15),
- child: GridView.builder(
- padding: EdgeInsets.symmetric(horizontal: 15),
- gridDelegate:
- SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: 3,
- childAspectRatio: 102 / 137,
- mainAxisSpacing: 5,
- crossAxisSpacing:
- (MediaQuery.of(context).size.width -
- 336) /
- 2),
- itemBuilder: (BuildContext context, int index) {
- return GestureDetector(
- child: picItem(detailsPictures[index]),
- onTap: () {
- selectPic(detailsPictures[index]);
- },
- behavior: HitTestBehavior.translucent,
- );
- },
- itemCount: detailsPictures.length,
- physics: NeverScrollableScrollPhysics(),
- ),
- ),
- 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<Widget> 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
- ..loadingStyle = EasyLoadingStyle.light
- ..contentMargin = EdgeInsets.all(20);
- EasyLoading.show();
- print('uploadCover');
- if (cover == null) {
- upPic();
- } else {
- upload(cover, (r, hE) {
- if (!hE) {
- UploadImageBeanEntity data =
- UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
- coverPath = data.data[0].path;
- upPic();
- } else {
- EasyLoading.dismiss();
- }
- }, (e) {
- EasyLoading.dismiss();
- });
- }
- }
- upPic() {
- List<File> fs = [];
- List<int> oP = [];
- for (int i = 0; i < detailsPictures.length; i++) {
- if (detailsPictures[i] is File) {
- fs.add(detailsPictures[i]);
- }
- if (detailsPictures[i] is String) {
- oP.add(i);
- }
- }
- if (fs.length == 0) {
- detailsPictures.forEach((element) {
- if (element is String) {
- if (picturesPath == '') {
- picturesPath = element;
- } else {
- picturesPath = picturesPath + ',' + element;
- }
- }
- });
- if (widget.data != null) {
- if (widget.renew) {
- saveAd();
- } else {
- updateAd();
- }
- } else {
- saveAd();
- }
- } else {
- uploadFiles(fs, (re, hE) {
- if (!hE) {
- UploadImageBeanEntity data =
- UploadImageBeanEntity().fromJson(json.decode(re.data.toString()));
- for (int i = 0; i < data.data.length; i++) {
- oP.forEach((element) {
- if (i == element) {
- if (picturesPath == '') {
- picturesPath = detailsPictures[i];
- } else {
- picturesPath = picturesPath + ',' + detailsPictures[i];
- }
- }
- });
- if (picturesPath == '') {
- picturesPath = data.data[i].path;
- } else {
- picturesPath = picturesPath + ',' + data.data[i].path;
- }
- }
- oP.forEach((element) {
- if (element >= picturesPath.split(',').length) {
- if (picturesPath == '') {
- picturesPath = detailsPictures[element];
- } else {
- picturesPath = picturesPath + ',' + detailsPictures[element];
- }
- }
- });
- if (widget.data != null) {
- if (widget.renew) {
- saveAd();
- } else {
- updateAd();
- }
- } else {
- saveAd();
- }
- } else {
- EasyLoading.dismiss();
- }
- }, (e) {
- EasyLoading.dismiss();
- });
- }
- }
- void showPayOrder(AnnualFeeOrderBeanEntity order) {
- EasyLoading.instance
- ..contentPadding = EdgeInsets.symmetric(horizontal: 0, vertical: 12)
- ..alignment = Alignment.bottomCenter
- ..loadingStyle = EasyLoadingStyle.light
- ..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: () {
- MyTools().toPage(
- context,
- OrderInformationPage(
- false,
- orderType: orderTypeAdvertise,
- amount: price,
- uid: order.data.orderUid,
- buyerUid: MyCookie().getUID(),
- buyerName: MyCookie().getName(),
- buyerPic: MyCookie().getPic(),
- commodityCount: 1,
- commodityTitle: '广告费用',
- commodityCover: '',
- sellName: '平台',
- sellPic: '',
- sellUid: 0,
- ), (then) {
- if (then is int && then == 1) {
- if(widget.data!=null&&widget.data.paid){
- updateOldAds();
- }else{
- Navigator.pop(context,then);
- }
- }
- });
- EasyLoading.dismiss();
- },
- 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),
- ),
- )
- ],
- ),
- )
- ],
- ),
- ),
- );
- }
- void initAd() {
- _title.text = widget.data.title;
- coverPath = widget.data.coverPath;
- _number.text = widget.data.mobile;
- typeIndex = widget.data.type;
- typeValue = typeIndex == 0 ? '货帮/商品部分广告' : '首页banner';
- if (widget.renew) {
- } else {
- startTime = widget.data.startDate;
- _days.text = widget.data.days.toString();
- }
- _description.text = widget.data.description;
- widget.data.pictures.split(',').forEach((element) {
- if (detailsPictures.length < 6) {
- detailsPictures.insert(detailsPictures.length - 1, element);
- } else if (detailsPictures.length == 6) {
- detailsPictures[5] = 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),
- );
- }
- }
- void updateAd() {
- var values = {
- "id": widget.data.id,
- "title": _title.text.toString(),
- "description": _description.text.toString(),
- "cover_path": coverPath,
- "pictures": picturesPath,
- "mobile": _number.text.toString()
- };
- 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) {
- payForInsertionOrder();
- } 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,
- "renewed": false,
- "mobile": _number.text.toString()
- };
- 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) {
- if(!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) {});
- }
- void payForInsertionOrder() {
- MyDio().query({
- 'key': 'order',
- "filters": {
- "conditions": [
- "commodity_id == ${widget.data.id}",
- "type == $orderTypeAdvertise"
- ]
- },
- "dims": orderDims,
- "paging": [1, 1]
- }, (response, hasError) {
- if (!hasError) {
- SmartOrderBeanEntity entity = SmartOrderBeanEntity()
- .fromJson(json.decode(response.data.toString()));
- AnnualFeeOrderBeanEntity o = AnnualFeeOrderBeanEntity();
- AnnualFeeOrderBeanData od = AnnualFeeOrderBeanData();
- od.orderUid = entity.data.data[0].uid;
- o.data = od;
- showPayOrder(o);
- }
- }, (error) {});
- }
- Widget picItem(data) {
- if (data is String) {
- return Container(
- width: 102,
- child: Column(
- children: [
- ClipRRect(
- child: MyViews().netImg(imgURL(data), 102, 102),
- borderRadius: BorderRadius.circular(4),
- ),
- GestureDetector(
- child: Container(
- height: 30,
- width: 30,
- margin: EdgeInsets.only(top: 5),
- child: Icon(
- Icons.cancel,
- color: MyColors.cFF4233,
- ),
- ),
- onTap: () {
- detailsPictures.remove(data);
- if (detailsPictures.length == 5 &&
- !detailsPictures.contains(null)) {
- detailsPictures.add(null);
- }
- setState(() {});
- })
- ],
- ),
- );
- } else if (data is File) {
- return Container(
- width: 102,
- child: Column(
- children: [
- ClipRRect(
- child: Image.file(
- data,
- height: 102,
- width: 102,
- fit: BoxFit.cover,
- ),
- borderRadius: BorderRadius.circular(4),
- ),
- GestureDetector(
- child: Container(
- height: 30,
- width: 30,
- margin: EdgeInsets.only(top: 5),
- child: Icon(
- Icons.cancel,
- color: MyColors.cFF4233,
- ),
- ),
- onTap: () {
- detailsPictures.remove(data);
- if (detailsPictures.length == 5 &&
- !detailsPictures.contains(null)) {
- detailsPictures.add(null);
- }
- setState(() {});
- })
- ],
- ),
- );
- } else {
- return Column(
- children: [
- 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,
- ),
- ),
- Container(
- height: 35,
- )
- ],
- );
- }
- }
- Future<void> selectPic(data) async {
- File f = await selectImage(isCover: false);
- if (f == null) {
- return;
- }
- if (data == null) {
- if (detailsPictures.length == 6) {
- detailsPictures[
- detailsPictures.indexWhere((element) => element == data)] = f;
- } else {
- detailsPictures.insert(detailsPictures.length - 1, f);
- }
- } else {
- detailsPictures[
- detailsPictures.indexWhere((element) => element == data)] = f;
- }
- setState(() {});
- }
- //续费更新老广告
- void updateOldAds() {
- MyDio().update({'key': 'ad', 'values': {
- "id": widget.data.id,
- "renewed":true
- }}, (response, hasError) {
- Navigator.pop(context,1);
- }, (error) { });
- }
- }
|