| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295 |
- 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) {});
- }
- }
|