|
|
@@ -0,0 +1,371 @@
|
|
|
+import 'dart:convert';
|
|
|
+import 'dart:math';
|
|
|
+
|
|
|
+import 'package:bbyyy/beans/offline_payment_bean_entity.dart';
|
|
|
+import 'package:bbyyy/beans/store_bean_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/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:flutter/material.dart';
|
|
|
+import 'package:flutter/services.dart';
|
|
|
+import 'package:flutter_svg/svg.dart';
|
|
|
+import 'package:number_precision/number_precision.dart';
|
|
|
+
|
|
|
+class NewPayToTheGangPage extends StatefulWidget {
|
|
|
+ int shopUid;
|
|
|
+ int type;
|
|
|
+
|
|
|
+ NewPayToTheGangPage(this.shopUid, this.type);
|
|
|
+
|
|
|
+ @override
|
|
|
+ _NewPayToTheGangPageState createState() => _NewPayToTheGangPageState();
|
|
|
+}
|
|
|
+
|
|
|
+class _NewPayToTheGangPageState extends State<NewPayToTheGangPage> {
|
|
|
+ TextEditingController _controller = TextEditingController();
|
|
|
+
|
|
|
+ @override
|
|
|
+ void initState() {
|
|
|
+ // TODO: implement initState
|
|
|
+ super.initState();
|
|
|
+ Future.delayed(Duration.zero, () {
|
|
|
+ queryStoreInformation();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ Widget build(BuildContext context) {
|
|
|
+ return GestureDetector(
|
|
|
+ onTap: () {
|
|
|
+ MyTools().hideKeyboard(context);
|
|
|
+ },
|
|
|
+ child: Scaffold(
|
|
|
+ body: Container(
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ gradient: LinearGradient(
|
|
|
+ colors: MyColors.lg2,
|
|
|
+ begin: Alignment.topCenter,
|
|
|
+ end: Alignment.bottomCenter),
|
|
|
+ ),
|
|
|
+ child: Column(
|
|
|
+ children: [
|
|
|
+ SafeArea(
|
|
|
+ bottom: false,
|
|
|
+ child: Container(
|
|
|
+ height: 45,
|
|
|
+ width: double.infinity,
|
|
|
+ child: Stack(
|
|
|
+ children: [
|
|
|
+ Text(
|
|
|
+ '支付',
|
|
|
+ style: TextStyle(color: Colors.white, fontSize: 16),
|
|
|
+ ),
|
|
|
+ Positioned(
|
|
|
+ left: 0,
|
|
|
+ child: GestureDetector(
|
|
|
+ onTap: () {
|
|
|
+ Navigator.pop(context);
|
|
|
+ },
|
|
|
+ behavior: HitTestBehavior.translucent,
|
|
|
+ child: Transform.rotate(
|
|
|
+ angle: pi,
|
|
|
+ child: Padding(
|
|
|
+ padding: EdgeInsets.only(
|
|
|
+ left: 16, right: 16, top: 8, bottom: 8),
|
|
|
+ child: SvgPicture.asset(
|
|
|
+ 'images/svg/箭头.svg',
|
|
|
+ color: Colors.white,
|
|
|
+ height: 14,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ alignment: Alignment.center,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Expanded(
|
|
|
+ child: SingleChildScrollView(
|
|
|
+ child: Container(
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: Colors.white,
|
|
|
+ borderRadius: BorderRadius.circular(15)),
|
|
|
+ margin: EdgeInsets.symmetric(horizontal: 15, vertical: 30),
|
|
|
+ child: Column(
|
|
|
+ children: [
|
|
|
+ Container(
|
|
|
+ margin: EdgeInsets.only(top: 40),
|
|
|
+ child: ClipRRect(
|
|
|
+ child: MyViews().netImg(
|
|
|
+ imgURL(store == null ? '' : store.picture),
|
|
|
+ 65,
|
|
|
+ 65),
|
|
|
+ borderRadius: BorderRadius.circular(32.5),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ margin: EdgeInsets.only(top: 20, bottom: 30),
|
|
|
+ child: RichText(
|
|
|
+ textAlign: TextAlign.center,
|
|
|
+ text: TextSpan(
|
|
|
+ text: '您正在向 ',
|
|
|
+ children: [
|
|
|
+ TextSpan(
|
|
|
+ text: '${store == null ? '' : store.name}',
|
|
|
+ style: TextStyle(
|
|
|
+ color: MyColors.c333333,
|
|
|
+ fontSize: 20,
|
|
|
+ fontWeight: FontWeight.bold)),
|
|
|
+ TextSpan(
|
|
|
+ text: ' 付款',
|
|
|
+ ),
|
|
|
+ if (store != null && store.payDiscount != 0)
|
|
|
+ TextSpan(
|
|
|
+ text: '\n实付金额为',
|
|
|
+ ),
|
|
|
+ if (store != null && store.payDiscount != 0)
|
|
|
+ TextSpan(
|
|
|
+ text:
|
|
|
+ '${NP.minus(amount, balanceDisplay(amount * (1 - store.payDiscount)))}',
|
|
|
+ style: TextStyle(
|
|
|
+ color: MyColors.cE2A62D,
|
|
|
+ fontSize: 20,
|
|
|
+ fontWeight: FontWeight.bold)),
|
|
|
+ if (store != null && store.payDiscount != 0)
|
|
|
+ TextSpan(
|
|
|
+ text: '元',
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ style: TextStyle(
|
|
|
+ color: MyColors.c333333, fontSize: 15),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ margin: EdgeInsets.symmetric(horizontal: 22),
|
|
|
+ child: Column(
|
|
|
+ children: [
|
|
|
+ Row(
|
|
|
+ children: [
|
|
|
+ Container(
|
|
|
+ margin: EdgeInsets.only(bottom: 9),
|
|
|
+ child: Text(
|
|
|
+ '付款金额:',
|
|
|
+ style: TextStyle(
|
|
|
+ color: MyColors.c999999,
|
|
|
+ fontSize: 15),
|
|
|
+ )),
|
|
|
+ Expanded(
|
|
|
+ child: TextField(
|
|
|
+ inputFormatters: [
|
|
|
+ FilteringTextInputFormatter.allow(
|
|
|
+ RegExp("[0-9.]")),
|
|
|
+ ],
|
|
|
+ controller: _controller,
|
|
|
+ cursorColor: MyColors.cFF4233,
|
|
|
+ cursorWidth: 1.0,
|
|
|
+ decoration: InputDecoration(
|
|
|
+ border: InputBorder.none,
|
|
|
+ disabledBorder: InputBorder.none,
|
|
|
+ enabledBorder: InputBorder.none,
|
|
|
+ focusedBorder: InputBorder.none,
|
|
|
+ hintText: '请输入…',
|
|
|
+ hintStyle: TextStyle(
|
|
|
+ color: MyColors.c999999,
|
|
|
+ fontSize: 15),
|
|
|
+ isDense: true,
|
|
|
+ contentPadding:
|
|
|
+ const EdgeInsets.fromLTRB(
|
|
|
+ 5, 4.5, 8, 4.5)),
|
|
|
+ maxLines: 1,
|
|
|
+ style: TextStyle(
|
|
|
+ color: MyColors.c333333,
|
|
|
+ fontSize: 32,
|
|
|
+ fontWeight: FontWeight.bold,
|
|
|
+ height: 1.3,
|
|
|
+ letterSpacing: 0.2),
|
|
|
+ keyboardType:
|
|
|
+ TextInputType.numberWithOptions(
|
|
|
+ decimal: true),
|
|
|
+ onChanged: (t) {
|
|
|
+ try {
|
|
|
+ amount = double.parse(
|
|
|
+ _controller.text.toString());
|
|
|
+ } catch (e) {
|
|
|
+ amount = 0;
|
|
|
+ }
|
|
|
+ setState(() {});
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ height: 0.5,
|
|
|
+ color: MyColors.cE7E7E7,
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ if (store != null && store.payDiscount != 0)
|
|
|
+ Row(
|
|
|
+ children: [
|
|
|
+ Container(
|
|
|
+ margin: EdgeInsets.only(top: 9, left: 22),
|
|
|
+ child: RichText(
|
|
|
+ text: TextSpan(
|
|
|
+ text: '店铺折扣金额:',
|
|
|
+ children: [
|
|
|
+ TextSpan(
|
|
|
+ text:
|
|
|
+ '${balanceDisplay(amount * (1 - store.payDiscount))}',
|
|
|
+ style: TextStyle(
|
|
|
+ color: MyColors.cE2A62D,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ TextSpan(
|
|
|
+ text: '元',
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ style: TextStyle(
|
|
|
+ color: MyColors.c999999, fontSize: 14),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ GestureDetector(
|
|
|
+ onTap: () {
|
|
|
+ generateOrders();
|
|
|
+ },
|
|
|
+ behavior: HitTestBehavior.translucent,
|
|
|
+ child: Container(
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: MyColors.cFF4233,
|
|
|
+ borderRadius: BorderRadius.circular(20),
|
|
|
+ ),
|
|
|
+ height: 40,
|
|
|
+ child: Text(
|
|
|
+ '确认支付',
|
|
|
+ style:
|
|
|
+ TextStyle(color: Colors.white, fontSize: 14),
|
|
|
+ ),
|
|
|
+ alignment: Alignment.center,
|
|
|
+ margin: EdgeInsets.symmetric(
|
|
|
+ horizontal: 22, vertical: 40),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ StoreBeanDataData store;
|
|
|
+ double amount = 0.0;
|
|
|
+
|
|
|
+ void queryStoreInformation() {
|
|
|
+ EasyLoading.show();
|
|
|
+ MyDio().query({
|
|
|
+ "key": "shop",
|
|
|
+ "filters": {
|
|
|
+ "conditions": ["uid == ${widget.shopUid}"]
|
|
|
+ },
|
|
|
+ "dims": shopDims,
|
|
|
+ "paging": [1, 5]
|
|
|
+ }, (response, hasError) {
|
|
|
+ if (!hasError) {
|
|
|
+ StoreBeanEntity entity =
|
|
|
+ StoreBeanEntity().fromJson(json.decode(response.data.toString()));
|
|
|
+ store = entity.data.data[0];
|
|
|
+ setState(() {
|
|
|
+ EasyLoading.dismiss();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, (error) {});
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成订单
|
|
|
+ generateOrders() {
|
|
|
+ EasyLoading.show();
|
|
|
+ try {
|
|
|
+ amount = double.parse(_controller.text.toString());
|
|
|
+ MyDio().save({
|
|
|
+ 'key': 'order',
|
|
|
+ 'object': {
|
|
|
+ 'uuid': widget.type == orderTypeOfflineTransfer
|
|
|
+ ? generateMd5(reOS('付款给店主${DateTime.now()}'))
|
|
|
+ : generateMd5(reOS('扫码付款${DateTime.now()}')),
|
|
|
+ 'shop_uid': store.uid,
|
|
|
+ 'shop_pic': store.picture,
|
|
|
+ 'shop_name': store.name,
|
|
|
+ 'seller_pic': store.ownerPic,
|
|
|
+ 'seller_uid': store.ownerUid,
|
|
|
+ 'seller_name': store.ownerName,
|
|
|
+ 'buyer_name': MyCookie().getName(),
|
|
|
+ 'buyer_uid': MyCookie().getUID(),
|
|
|
+ 'buyer_pic': MyCookie().userBean.picture,
|
|
|
+ 'type': widget.type,
|
|
|
+ 'amount': amount
|
|
|
+ }
|
|
|
+ }, (response, hasError) {
|
|
|
+ if (!hasError) {
|
|
|
+ OfflinePaymentBeanEntity entity = OfflinePaymentBeanEntity()
|
|
|
+ .fromJson(json.decode(response.data.toString()));
|
|
|
+ payTheOrder(entity.data);
|
|
|
+ }
|
|
|
+ }, (error) {});
|
|
|
+ } catch (e) {
|
|
|
+ showToast('请输入正确的金额');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void payTheOrder(int orderUID) {
|
|
|
+ _controller.clear();
|
|
|
+ MyTools().toPage(
|
|
|
+ context,
|
|
|
+ OrderInformationPage(
|
|
|
+ false,
|
|
|
+ orderType: widget.type,
|
|
|
+ amount: amount,
|
|
|
+ uid: orderUID,
|
|
|
+ buyerUid: MyCookie().getUID(),
|
|
|
+ buyerName: MyCookie().getName(),
|
|
|
+ buyerPic: MyCookie().getPic(),
|
|
|
+ commodityCount: 1,
|
|
|
+ commodityTitle: '到店支付',
|
|
|
+ commodityCover: '',
|
|
|
+ sellName: store.ownerName,
|
|
|
+ sellPic: store.ownerPic,
|
|
|
+ sellUid: store.ownerUid,
|
|
|
+ discountAmount: store.payDiscount==0?0:balanceDisplay(amount * (1 - store.payDiscount)),
|
|
|
+ ), (then) {
|
|
|
+ if (then is int && then == 1) {
|
|
|
+ Navigator.pop(context);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // MyTools().toPage(context, PayPage(orderUID, true, amount), (then) {
|
|
|
+ // if (then is String) {
|
|
|
+ // if (then == '支付成功') {
|
|
|
+ // Navigator.pop(context);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ }
|
|
|
+}
|