123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- import 'dart:math';
- import 'package:flutter/material.dart';
- import 'package:flutter_alipay/flutter_alipay.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:flutter_spinkit/flutter_spinkit.dart';
- import 'package:fluwx/fluwx.dart' as fluwx;
- import 'package:liftmanager/common/user_db.dart';
- import 'package:liftmanager/internal/wode/model/vipfee_model.dart';
- import 'package:liftmanager/net/api_service.dart';
- import 'package:liftmanager/res/colors.dart';
- import 'package:liftmanager/utils/fast_notification.dart';
- import 'package:liftmanager/utils/theme_utils.dart';
- import 'package:liftmanager/utils/toast.dart';
- import 'package:liftmanager/widgets/app_bar.dart';
- import 'package:liftmanager/widgets/load_image.dart';
- class VipService extends StatefulWidget {
- VipService(this.id, this.selectId);
- final String id;
- ///月卡季卡id
- final String selectId;
- @override
- State<StatefulWidget> createState() {
- return VipServiceState();
- }
- }
- class VipServiceState extends State<VipService> {
- static const payType = [
- {
- "icon": "tab_first/pay_yue",
- "title": "账户余额",
- },
- {
- "icon": "tab_first/pay_zhifubao",
- "title": "支付宝",
- },
- {
- "icon": "tab_first/pay_winxin",
- "title": "微信",
- },
- ];
- int indexNow = -1;
- String checkFalse = "tab_first/check_false";
- String checkTrue = "tab_first/check_true";
- List<Records> moneyList;
- String moneyKey;
- String isRed = "";
- String title = "";
- int rewardType;
- @override
- void initState() {
- super.initState();
- moneyKey = widget.selectId;
- getVipFeeList();
- setSchema();
- _initFluwx();
- }
- _initFluwx() async {
- await fluwx.registerWxApi(
- appId: "wx0f10e6386fb9969e",
- doOnAndroid: true,
- doOnIOS: true,
- universalLink: "https://www.edtyun.com/");
- var result = await fluwx.isWeChatInstalled();
- setState(() {});
- }
- void setSchema() async {
- // await FlutterAlipay.setIosUrlSchema("tytylift");
- await FlutterAlipay.setIosUrlSchema("com.tyty.lift.managers");
- }
- Future getVipFeeList() async {
- await NewApiService().getVipFeeList(widget.id, onSuccess: (res) {
- moneyList = res.records;
- setState(() {});
- }, onError: (code, msg) {
- toasts(msg);
- });
- }
- randomInt(int min, int max) {
- return new Random().nextInt(max) % (max - min + 1) + min;
- }
- // 确认充值
- void confirmReward() async {
- if (moneyKey == null) {
- toasts("请选择一项");
- return;
- }
- if (indexNow == -1) {
- toasts("请选择支付方式");
- return;
- }
- String payway;
- if (indexNow == 1) {
- payway = 'alipay';
- await NewApiService().getRechargeVIP(
- payway: payway,
- orders: moneyKey,
- onSuccess: (res) {
- callAlipay(res);
- },
- onError: (code, msg) {
- toasts(msg);
- },
- );
- } else if (indexNow == 2) {
- payway = 'wx';
- await NewApiService().getRechargeVIPwx(
- payway: payway,
- orders: moneyKey,
- onSuccess: (res) {
- wxMethod(res);
- },
- onError: (code, msg) {
- toasts(msg);
- },
- );
- } else {
- toasts("暂不支持该支付方式");
- return;
- }
- }
- dynamic _wxPay;
- wxMethod(_payInfo) {
- print(_payInfo["appid"]);
- fluwx
- .payWithWeChat(
- appId: _payInfo["appid"],
- partnerId: _payInfo["partnerid"],
- prepayId: _payInfo["prepayid"],
- packageValue: _payInfo["package"],
- nonceStr: _payInfo["noncestr"],
- timeStamp: int.parse(_payInfo["timestamp"]),
- sign: _payInfo["sign"])
- .then((data) {
- print(data);
- });
- _wxPay?.cancel();
- _wxPay = fluwx.responseFromPayment
- .listen((fluwx.WeChatPaymentResponse response) async {
- print("WeChatPaymentResponse" + response.errCode.toString());
- if (response.errCode == -2) {
- //支付取消
- toasts("支付取消");
- } else if (response.errCode == -1) {
- //支付失败
- toasts("支付失败");
- } else if (response.errCode == 0) {
- //支付成功
- toasts("支付成功");
- upDataUserLogin();
- String initThisUserMoney = randomInt(1111, 9999).toString() +
- DateTime.now().millisecondsSinceEpoch.toString();
- FastNotification.push("initUserMoney", initThisUserMoney);
- Navigator.pop(context);
- }
- });
- }
- //更新用户信息
- Future upDataUserLogin() async {
- await NewApiService().upDataUserLogin(onSuccess: (res) {
- User().setCurrentUser(res, type: "upDataAppMenus");
- String initThisUserMoney = randomInt(1111, 9999).toString() +
- DateTime.now().millisecondsSinceEpoch.toString();
- FastNotification.push("initUserMoney", initThisUserMoney);
- String initThisUserInfomation = randomInt(1111, 9999).toString() +
- DateTime.now().millisecondsSinceEpoch.toString();
- FastNotification.push("initUserInfomation", initThisUserInfomation);
- }, onError: (code, msg) {
- toasts(msg);
- });
- }
- // 调用支付宝
- void callAlipay(String _payInfo) async {
- AlipayResult payResult;
- try {
- print("The pay info is : " + _payInfo);
- payResult = await FlutterAlipay.pay(_payInfo);
- } on Exception catch (e) {
- payResult = null;
- }
- print(payResult);
- if (payResult != null) {
- if (payResult.resultStatus == "9000") {
- toasts("支付成功");
- upDataUserLogin();
- String initThisUserMoney = randomInt(1111, 9999).toString() +
- DateTime.now().millisecondsSinceEpoch.toString();
- FastNotification.push("initUserMoney", initThisUserMoney);
- Navigator.pop(context);
- } else {
- toasts(payResult.memo);
- }
- } else {
- toasts("支付异常");
- }
- }
- @override
- Widget build(BuildContext context) {
- double width = MediaQuery.of(context).size.width;
- double height = MediaQuery.of(context).size.height;
- return Container(
- child: Scaffold(
- appBar: MyAppBar(
- centerTitle: "开通会员",
- ),
- body: Container(
- child: Stack(
- children: <Widget>[
- Container(
- // padding: EdgeInsets.only(top:70),
- child: ListView(
- children: <Widget>[
- // Container(
- // padding: EdgeInsets.only(
- // left: ScreenUtil().setWidth(20),
- // right: ScreenUtil().setWidth(15),
- // top: ScreenUtil().setWidth(15),
- // bottom: ScreenUtil().setWidth(15)),
- // decoration: BoxDecoration(
- // // border: Border(
- // // bottom:
- // // BorderSide(width: 5, color: Color(0xfff5f5f5)),
- // // ),
- // ),
- // child: Row(
- // mainAxisAlignment: MainAxisAlignment.spaceBetween,
- // children: <Widget>[
- // Text(
- // "请选择一项",
- // style:
- // TextStyle(fontSize: ScreenUtil().setSp(16)),
- // textAlign: TextAlign.start,
- // ),
- // ]),
- // ),
- // moneyList != null && moneyList != []
- // ? Container(
- // padding: EdgeInsets.only(
- // left: ScreenUtil().setWidth(10)),
- // child: Wrap(
- // alignment: WrapAlignment.start,
- // crossAxisAlignment: WrapCrossAlignment.center,
- // children: moneyList.asMap().keys.map((index) {
- // return InkWell(
- // onTap: () {
- // setState(() {
- // moneyKey = moneyList[index].id.toString();
- // isRed = moneyList[index].id.toString();
- // });
- // },
- // child: Container(
- // width: width / 4 - 15,
- // padding: EdgeInsets.only(
- // bottom: ScreenUtil().setWidth(16),
- // top: ScreenUtil().setWidth(16)),
- // margin: EdgeInsets.only(
- // left: 5, right: 5, bottom: 5, top: 5),
- // decoration: BoxDecoration(
- // color: ThemeUtils.getTabsBg(context),
- // borderRadius: BorderRadius.circular(5),
- // boxShadow: [
- // BoxShadow(
- // offset: Offset(0, 0), //x,y轴
- // color: Colors.grey[300], //投影颜色
- // blurRadius: 5, //投影距离
- // )
- // ],
- // ),
- // child: Column(
- // children: <Widget>[
- // Text(
- // moneyList[index].name ?? "",
- // style: TextStyle(
- // color: isRed ==
- // moneyList[index]
- // .id
- // .toString()
- // ? Color(0xffff0000)
- // : Color(0xff666666),
- // fontSize: ScreenUtil().setSp(15)),
- // textAlign: TextAlign.center,
- // ),
- // Text(
- // (moneyList[index].price != null
- // ? moneyList[index]
- // .price
- // .toString()
- // : "0.0") +
- // "元",
- // style: TextStyle(
- // color: isRed ==
- // moneyList[index]
- // .id
- // .toString()
- // ? Color(0xffff0000)
- // : Color(0xff666666),
- // fontSize: ScreenUtil().setSp(15)),
- // textAlign: TextAlign.center,
- // )
- // ],
- // ),
- // ),
- // );
- // }).toList(),
- // ))
- // : loadCircle(),
- Container(
- padding: EdgeInsets.only(
- left: ScreenUtil().setWidth(20),
- right: ScreenUtil().setWidth(15),
- // top: ScreenUtil().setWidth(50),
- bottom: ScreenUtil().setWidth(10)),
- decoration: BoxDecoration(
- border: Border(
- bottom:
- BorderSide(width: 0.5, color: Color(0xfff5f5f5)),
- ),
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(
- "选择支付方式",
- style:
- TextStyle(fontSize: ScreenUtil().setSp(16)),
- textAlign: TextAlign.start,
- ),
- ]),
- ),
- Container(
- padding: EdgeInsets.only(
- left: ScreenUtil().setWidth(15),
- bottom: ScreenUtil().setWidth(80),
- right: ScreenUtil().setWidth(15)),
- child: Column(
- children: payType.asMap().keys.map((i) {
- return i != 0
- ? Container(
- decoration: BoxDecoration(
- border: Border(
- bottom: BorderSide(
- width: 0.5, color: Color(0xfff5f5f5)),
- ),
- ),
- height: ScreenUtil().setWidth(60),
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Row(
- children: <Widget>[
- LoadAssetImage(
- // image: AssetImage(i['img']),
- payType[i]["icon"],
- width: ScreenUtil().setWidth(26),
- height: ScreenUtil().setWidth(26),
- // alignment: Alignment.centerLeft,
- ),
- Container(width: 5, child: null),
- Text(
- payType[i]["title"],
- style: TextStyle(
- fontSize:
- ScreenUtil().setSp(16)),
- textAlign: TextAlign.start,
- ),
- ],
- ),
- InkWell(
- child: Container(
- // padding: EdgeInsets.only(top:10,left:5,right:5,bottom:10),
- child: LoadAssetImage(
- // image: AssetImage(i['img']),
- indexNow == i
- ? checkTrue
- : checkFalse,
- width: ScreenUtil().setWidth(20),
- height: ScreenUtil().setWidth(20),
- // alignment: Alignment.centerLeft,
- ),
- ),
- onTap: () {
- setState(() {
- indexNow = i;
- });
- },
- ),
- ],
- ),
- )
- : Container(child: null);
- }).toList(),
- ),
- )
- ],
- ),
- ),
- Positioned(
- bottom: 0,
- left: 0,
- child: Container(
- width: width,
- padding: EdgeInsets.only(
- top: ScreenUtil().setWidth(15),
- bottom: ScreenUtil().setWidth(15),
- left: ScreenUtil().setWidth(25),
- right: ScreenUtil().setWidth(25),
- ),
- color: ThemeUtils.getTabsBg(context),
- child: Container(
- height: ScreenUtil().setWidth(44),
- decoration: BoxDecoration(
- color: Colours.blue_app_main,
- borderRadius: BorderRadius.circular(22.0),
- // gradient: const LinearGradient(
- // colors: [Color(0xFF00D9FF), Color(0xFF0287FF)],
- // ),
- ),
- child: FlatButton(
- // padding: EdgeInsets.all(15.0),
- child: Text("立即支付"),
- textColor: Colors.white,
- onPressed: () {
- // upDataUserLogin();
- confirmReward();
- },
- ),
- ),
- ),
- )
- ],
- ),
- ),
- ),
- );
- }
- Widget loadCircle() {
- return Container(
- padding: EdgeInsets.only(top: 10, bottom: 10),
- color: ThemeUtils.getTabsBg(context),
- child: Center(
- child: SpinKitFadingCircle(
- color: Colors.blueAccent,
- size: 30.0,
- ),
- ),
- );
- }
- }
|