import 'dart:convert'; import 'package:bbyyy/beans/my_coupon_bean_entity.dart'; import 'package:bbyyy/beans/user_balance_entity.dart'; import 'package:bbyyy/https/MyDio.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/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/paegs/mine_page/coupon_page/coupon_view.dart'; import 'package:bbyyy/paegs/pay_page/pay_page.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_svg/svg.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; class OrderInformationPage extends StatefulWidget { int orderType; double amount; int uid; String sellName; int sellUid; String sellPic; String buyerName; int buyerUid; String buyerPic; int commodityCount; String commodityCover; String commodityTitle; bool cancelOrder; OrderInformationPage(this.cancelOrder, {this.orderType, this.sellName, this.sellPic, this.sellUid, this.amount, this.buyerName, this.uid, this.buyerUid, this.buyerPic, this.commodityCover, this.commodityTitle, this.commodityCount}); @override _OrderInformationPageState createState() => _OrderInformationPageState(); } class _OrderInformationPageState extends State { bool payWay = false; //true - 支付宝 false - 微信 String coupon = '未选择优惠券'; MyCouponBeanDataData couponData; @override void initState() { // TODO: implement initState super.initState(); Future.delayed(Duration.zero,(){ getUserWalletBalance((re,hE){ if (!hE) { UserBalanceEntity balance = UserBalanceEntity().fromJson(json.decode(re.data.toString())); payWay = widget.amount>balance.data; setState(() {}); } },(e){ },context); }); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: MyColors.cEFEFEF, body: Column( children: [ MyViews().myAppBar('订单信息', context, []), Container( height: 10, color: MyColors.cEFEFEF, ), Expanded( child: SingleChildScrollView( child: Column( children: [ Container( child: orderInformation(), color: Colors.white, padding: EdgeInsets.symmetric(vertical: 10), ), Container( height: 10, color: MyColors.cEFEFEF, ), Container( color: Colors.white, child: Row( children: [ MyViews().myText('支付方式', MyColors.c333333, 14), GestureDetector( onTap: () { showCupertinoModalPopup( context: context, builder: (BuildContext context) { return CupertinoActionSheet( title: MyViews() .myText('选择支付方式', MyColors.c333333, 20), actions: [ CupertinoActionSheetAction( child: Row( children: [ SvgPicture.asset( 'images/svg/支付宝.svg', width: 24, height: 24, ), Container( child: MyViews().myText('支付宝支付', MyColors.c333333, 16), margin: EdgeInsets.only( left: 6, right: 6), ), ], mainAxisAlignment: MainAxisAlignment.center, ), onPressed: (() { payWay = true; setState(() {}); Navigator.pop(context, 'Edit'); }), ), CupertinoActionSheetAction( child: Row( children: [ SvgPicture.asset( 'images/svg/积分支付.svg', width: 24, height: 24, ), Container( child: MyViews().myText( '积分支付', MyColors.c333333, 16), margin: EdgeInsets.only( left: 6, right: 6), ), ], mainAxisAlignment: MainAxisAlignment.center, ), onPressed: (() { payWay = false; setState(() {}); Navigator.pop(context, 'Edit'); }), ), ], cancelButton: CupertinoActionSheetAction( child: Text("取消"), isDefaultAction: true, onPressed: (() { Navigator.pop(context, 'Cancel'); }), ), ); }); }, behavior: HitTestBehavior.translucent, child: Row( children: [ SvgPicture.asset( 'images/svg/${payWay ? '支付宝' : '积分支付'}.svg', width: 20, height: 20, ), Container( child: MyViews().myText( '${payWay ? '支付宝' : '积分'}支付', MyColors.c333333, 13), margin: EdgeInsets.only(left: 6, right: 6), ), SvgPicture.asset( 'images/svg/箭头.svg', color: MyColors.c999999, width: 6, height: 11, ), ], ), ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), alignment: Alignment.centerLeft, padding: EdgeInsets.all(10), ), Container( height: 10, color: MyColors.cEFEFEF, ), Container( color: Colors.white, child: Row( children: [ MyViews().myText('优惠券', MyColors.c333333, 16), GestureDetector( onTap: () { MyTools().toPage(context, ChooseACoupon(), (then) { if (then is MyCouponBeanDataData) { couponData = then; coupon = couponType(couponData.type) + ': ${couponData.amount}元'; setState(() {}); } }); }, behavior: HitTestBehavior.translucent, child: Row( children: [ Container( child: MyViews() .myText(coupon, MyColors.c333333, 13), margin: EdgeInsets.only(left: 6, right: 6), ), SvgPicture.asset( 'images/svg/箭头.svg', color: MyColors.c999999, width: 6, height: 11, ), ], ), ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ), alignment: Alignment.centerLeft, padding: EdgeInsets.all(10), ), ], ), ), ), Container( color: Colors.white, child: SafeArea( top: false, child: Container( color: Colors.white, padding: EdgeInsets.only(right: 10, left: 10), height: 60, child: Row( children: [ Row( children: [ MyViews().myText('合计:', MyColors.c333333, 16), MyViews().myText( '¥${couponData == null ? widget.amount.toStringAsFixed(2) : NumUtil.subtract(widget.amount, couponData.amount) < 0 ? 0.0.toStringAsFixed(2) : NumUtil.subtract(widget.amount, couponData.amount).toStringAsFixed(2)}', MyColors.cFF4233, 18), ], ), Expanded( child: Row( children: [ GestureDetector( onTap: () { toPayPage(); }, behavior: HitTestBehavior.translucent, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(20), color: MyColors.cFF4233), height: 40, width: 160, child: MyViews().myText('确 认', Colors.white, 14), alignment: Alignment.center), ) ], mainAxisAlignment: MainAxisAlignment.end, ), ) ], ), ), ), ) ], ), ); } Widget orderInformation() { if (widget.orderType == orderTypeThirdPlatform) { //第三方平台订单 return Container( margin: EdgeInsets.symmetric(horizontal: 12), child: Row( children: [ Container( child: SvgPicture.asset( 'images/svg/第三方.svg', height: 45, width: 45, ), margin: EdgeInsets.only(right: 8), height: 60, width: 60, decoration: BoxDecoration( border: Border.all(color: MyColors.cEBEBEB, width: 1)), alignment: Alignment.center, ), Expanded( child: Container( height: 60, child: Column( children: [ MyViews() .myText('第三方订单(${widget.uid})', MyColors.c333333, 13), Row( children: [ MyViews() .myText('¥${widget.amount}', MyColors.cFF4233, 12), MyViews().myText( 'x${widget.commodityCount}', MyColors.c999999, 12), ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, ), ), ), ], ), ); } else if (widget.orderType == orderTypeAnnualFee) { //平台年费 return Container( margin: EdgeInsets.symmetric(horizontal: 12), child: Row( children: [ Container( child: Image.asset( 'images/app_logo.png', height: 45, width: 45, ), margin: EdgeInsets.only(right: 8), height: 60, width: 60, decoration: BoxDecoration( border: Border.all(color: MyColors.cEBEBEB, width: 1)), alignment: Alignment.center, ), Expanded( child: Container( height: 60, child: Column( children: [ MyViews().myText('平台年费', MyColors.c333333, 13), Row( children: [ MyViews() .myText('¥${widget.amount}', MyColors.cFF4233, 12), MyViews().myText( 'x${widget.commodityCount}', MyColors.c999999, 12), ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, ), ), ), ], ), ); } else if (widget.orderType == orderTypeAdvertise) { //平台广告订单 return Container( margin: EdgeInsets.symmetric(horizontal: 12), child: Row( children: [ Container( child: SvgPicture.asset( 'images/svg/平台广告.svg', height: 45, width: 45, ), margin: EdgeInsets.only(right: 8), height: 60, width: 60, decoration: BoxDecoration( border: Border.all(color: MyColors.cEBEBEB, width: 1)), alignment: Alignment.center, ), Expanded( child: Container( height: 60, child: Column( children: [ MyViews().myText('广告费', MyColors.c333333, 13), Row( children: [ MyViews() .myText('¥${widget.amount}', MyColors.cFF4233, 12), MyViews().myText( 'x${widget.commodityCount}', MyColors.c999999, 12), ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, ), ), ), ], ), ); } else if (widget.orderType == orderTypeCommodity) { //商品订单 return Container( margin: EdgeInsets.only(left: 10, right: 10), child: Row( children: [ MyViews().netImg(imgURL(widget.commodityCover), 60, 60, placeholder: 'images/svg/goodsDefImg.svg'), Expanded( child: Container( padding: EdgeInsets.only(left: 8), height: 60, child: Column( children: [ Text( '${widget.commodityTitle}', style: TextStyle(color: MyColors.c333333, fontSize: 13), maxLines: 2, overflow: TextOverflow.ellipsis, softWrap: true, ), Row( children: [ Text( '¥${double.parse('${widget.amount}').toStringAsFixed(2)}', style: TextStyle(color: MyColors.cFF4233, fontSize: 12), ), Text( 'x${widget.commodityCount}', style: TextStyle(color: MyColors.c999999, fontSize: 12), ), ], mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, ), ], crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), ) ], ), ); } else if (widget.orderType == orderTypeVirtualProduct) { //虚拟物品 return Container( margin: EdgeInsets.only(left: 10, right: 10), child: Row( children: [ Container( child: SvgPicture.asset( 'images/svg/虚拟物品.svg', height: 45, width: 45, ), margin: EdgeInsets.only(right: 8), height: 60, width: 60, decoration: BoxDecoration( border: Border.all(color: MyColors.cEBEBEB, width: 1)), alignment: Alignment.center, ), Expanded( child: Container( padding: EdgeInsets.only(left: 8), height: 60, child: Column( children: [ Text( '虚拟道具', style: TextStyle(color: MyColors.c333333, fontSize: 13), maxLines: 2, overflow: TextOverflow.ellipsis, softWrap: true, ), Row( children: [ Text( '¥${double.parse('${widget.amount}').toStringAsFixed(2)}', style: TextStyle(color: MyColors.cFF4233, fontSize: 12), ), Text( 'x${widget.commodityCount}', style: TextStyle(color: MyColors.c999999, fontSize: 12), ), ], mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, ), ], crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), ) ], ), ); } else if (widget.orderType == orderTypeOfflineTransfer) { //线下付款 return Container( margin: EdgeInsets.only(left: 10, right: 10), child: Row( children: [ Container( child: SvgPicture.asset( 'images/svg/线下付款.svg', height: 45, width: 45, ), margin: EdgeInsets.only(right: 8), height: 60, width: 60, decoration: BoxDecoration( border: Border.all(color: MyColors.cEBEBEB, width: 1)), alignment: Alignment.center, ), Expanded( child: Container( padding: EdgeInsets.only(left: 8), height: 60, child: Column( children: [ Text( '到店付款', style: TextStyle(color: MyColors.c333333, fontSize: 13), maxLines: 2, overflow: TextOverflow.ellipsis, softWrap: true, ), Row( children: [ Text( '¥${double.parse('${widget.amount}').toStringAsFixed(2)}', style: TextStyle(color: MyColors.cFF4233, fontSize: 12), ), Text( 'x${widget.commodityCount}', style: TextStyle(color: MyColors.c999999, fontSize: 12), ), ], mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, ), ], crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), ) ], ), ); } else { return Container( margin: EdgeInsets.only(left: 10, right: 10), child: Row( children: [ MyViews().netImg(imgURL(widget.commodityCover), 82, 84, placeholder: 'images/svg/goodsDefImg.svg'), Expanded( child: Container( padding: EdgeInsets.only(left: 8), height: 82, child: Column( children: [ Text( '${widget.commodityTitle}', style: TextStyle(color: MyColors.c333333, fontSize: 13), maxLines: 2, overflow: TextOverflow.ellipsis, softWrap: true, ), Row( children: [ Text( '¥${double.parse('${widget.amount}').toStringAsFixed(2)}', style: TextStyle(color: MyColors.cFF4233, fontSize: 12), ), Text( 'x${widget.commodityCount}', style: TextStyle(color: MyColors.c999999, fontSize: 12), ), ], mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start, ), ], crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, ), ), ) ], ), ); } } void toPayPage() { MyTools().toPage( context, PayPage(widget.uid, widget.cancelOrder, widget.amount, payWay ? payWayAliPay : payWayWallet, couponData), (then) { if (then is int) { if (then == 1) { Navigator.pop(context,then); } } }); } } class ChooseACoupon extends StatefulWidget { @override _ChooseACouponState createState() => _ChooseACouponState(); } class _ChooseACouponState extends State { int page = 1; RefreshController controller = RefreshController(initialRefresh: true); List coupons = []; @override void initState() { // TODO: implement initState super.initState(); EventBus().on('showCouponIndex', (arg) { setState(() {}); }); } @override void dispose() { // TODO: implement dispose super.dispose(); EventBus().off('showCouponIndex'); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: MyColors.cF7F7F7, body: Column( children: [ MyViews().myAppBar('优惠券', context, []), Expanded( child: SmartRefresher( controller: controller, onRefresh: onRefresh, onLoading: onLoading, enablePullUp: true, enablePullDown: true, child: coupons.length == 0 ? SingleChildScrollView(child: noData()) : ListView.builder( itemBuilder: (c, index) { return GestureDetector( onTap: () { Navigator.pop(context, coupons[index]); }, behavior: HitTestBehavior.translucent, child: CouponView().ticketItem(coupons[index]), ); }, itemCount: coupons.length, padding: EdgeInsets.only( top: 5, left: 24, right: 24, bottom: 20), ), ), ), ], ), ); } void onRefresh() { page = 1; checkCoupons(); } void onLoading() { page++; checkCoupons(); } checkCoupons() { MyDio().query({ "key": "coupon", "filters": { "conditions": ["user_uid==${MyCookie().getUID()}", "used == false"] }, "dims": couponDims, "paging": [page, 20] }, (response, hasError) { if (!hasError) { MyCouponBeanEntity entity = MyCouponBeanEntity() .fromJson(json.decode(response.data.toString())); if (page == 1) { coupons.clear(); } coupons.addAll(entity.data.data); setState(() {}); } endRe(controller); }, (error) { endRe(controller); }); } }