| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- import 'dart:convert';
- import 'package:bbyyy/beans/my_shop_bean_entity.dart';
- import 'package:bbyyy/beans/send_message_bean_entity.dart';
- import 'package:bbyyy/beans/user_balance_entity.dart';
- import 'package:bbyyy/beans/user_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/msgDB/my_msg_db.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_apis.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:flutter/material.dart';
- import 'package:flutter/services.dart';
- class RedPacketPage extends StatefulWidget {
- MyShopBeanDataData chatWith;
- RedPacketPage(this.chatWith);
- @override
- _RedPacketPageState createState() => _RedPacketPageState();
- }
- class _RedPacketPageState extends State<RedPacketPage> {
- TextEditingController _controller = TextEditingController();
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- Future.delayed(Duration.zero,(){
- queryPersonalInformation();
- });
- Future.delayed(Duration.zero,(){
- EasyLoading.show();
- getUserWalletBalance((re, hE) {
- if (!hE) {
- UserBalanceEntity balance =
- UserBalanceEntity.fromJson(json.decode(re.data.toString()));
- MyCookie().balance = balance.data;
- setState(() {
- EasyLoading.dismiss();
- });
- }
- }, (e) {
- EasyLoading.dismiss();
- }, context);
- });
- }
- void queryPersonalInformation() {
- MyDio().query({
- "key": "user",
- "filters": {
- "conditions": ["uid == ${MyCookie().getUID()}"]
- },
- "dims": userDims,
- "paging": [1, 20]
- }, (response, hasError) {
- if (!hasError) {
- UserBeanEntity entity =
- UserBeanEntity.fromJson(json.decode(response.data.toString()));
- MyCookie().userBean = entity.data.data[0];
- EventBus().emit('userChange');
- setState(() {});
- }
- }, (error) {});
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: Column(
- children: [
- MyViews().myAppBar('发送红包', context, []),
- Expanded(
- child: Column(
- children: [
- Container(
- margin: EdgeInsets.fromLTRB(17, 24, 17, 0),
- child: Row(
- children: [
- ClipRRect(
- child: MyViews()
- .netImg(imgURL(widget.chatWith.userPic), 24, 24),
- borderRadius: BorderRadius.circular(12),
- ),
- Container(
- child: MyViews().myText(
- widget.chatWith.userName, MyColors.c666666, 15),
- margin: EdgeInsets.only(left: 10),
- ),
- ],
- ),
- ),
- Container(
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.circular(4)),
- margin: EdgeInsets.symmetric(horizontal: 17, vertical: 14),
- padding: EdgeInsets.symmetric(horizontal: 20, vertical: 15),
- child: Column(
- children: [
- MyViews().myText('红包金额', MyColors.c333333, 16),
- Container(
- margin: EdgeInsets.only(top: 15),
- child: Row(
- children: [
- Text(
- '¥',
- style: TextStyle(
- color: MyColors.c333333, fontSize: 30),
- ),
- 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: 16),
- isDense: true,
- contentPadding: const EdgeInsets.fromLTRB(
- 14, 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.number,
- onChanged: (t) {
- setState(() {});
- },
- ),
- )
- ],
- ),
- ),
- ],
- crossAxisAlignment: CrossAxisAlignment.start,
- ),
- ),
- GestureDetector(
- onTap: () {
- sendRedEnvelope();
- },
- behavior: HitTestBehavior.translucent,
- child: Container(
- decoration: BoxDecoration(
- color: MyColors.cFF4233,
- borderRadius: BorderRadius.circular(20)),
- child: MyViews().myText('发送', Colors.white, 14),
- alignment: Alignment.center,
- height: 40,
- margin: EdgeInsets.only(
- top: 20, bottom: 15, left: 17, right: 17),
- ),
- ),
- ],
- ),
- ),
- ],
- ),
- );
- }
- double amount;
- void sendRedEnvelope() {
- try {
- amount = double.parse(_controller.text.toString());
- _controller.clear();
- if (amount > MyCookie().balance) {
- showToast('超过你拥有的积分');
- return;
- }
- if (amount <= 0) {
- showToast('请输入正确的金额');
- return;
- }
- MyDio().post(MyApis.getApi('redPacket'), {
- 'payer_uid': MyCookie().getUID(),
- 'payee_uid': widget.chatWith.userUid,
- 'amount': amount,
- }, (response, hasError) {
- if (!hasError) {
- showToast('发送成功');
- sendRedP();
- }
- }, (error) {});
- } catch (e) {
- showToast('请输入正确的金额');
- }
- }
- void sendRedP() {
- sendMsg(chatMsgTypeRedPackage, widget.chatWith.userUid, '$amount!@#${widget.chatWith.userName}',
- (re, hE) async {
- if (!hE) {
- SendMessageBeanEntity entity =
- SendMessageBeanEntity.fromJson(json.decode(re.data.toString()));
- MsgDB msgDB =
- MsgDB('table${MyCookie().getUID()}_${entity.data.receiverUid}');
- if (!msgDB.isTableExits) {
- await msgDB.open();
- }
- await msgDB.addTableData([entity.data]);
- EventBus().emit('hasNewMsg', entity.data);
- EventBus().emit('hasNewMsgInMsgPage', entity.data);
- Navigator.pop(context);
- }
- }, (e) {});
- }
- }
|