x1ongzhu 6 лет назад
Родитель
Сommit
7f951b4cbe

BIN
images/2x/icon_baodi_03.png


BIN
images/3x/icon_baodi_03.png


BIN
images/icon_baodi_03.png


+ 23 - 0
lib/model/CheckinConfig.dart

@@ -0,0 +1,23 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'CheckinConfig.g.dart';
+
+@JsonSerializable()
+class CheckinConfig {
+  CheckinConfig.empty();
+  CheckinConfig(this.weekDay, this.moneyCoin, this.pointsRatio, this.minPoints, this.probability, this.checked);
+  String weekDay;
+  double moneyCoin;
+  double pointsRatio;
+  double minPoints;
+  double probability;
+  int checked;
+
+  factory CheckinConfig.fromJson(Map<String, dynamic> json) => _$CheckinConfigFromJson(json);
+
+  Map<String, dynamic> toJson() => _$CheckinConfigToJson(this);
+  @override
+  String toString() {
+    return _$CheckinConfigToJson(this).toString();
+  }
+}

+ 27 - 0
lib/model/CheckinConfig.g.dart

@@ -0,0 +1,27 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'CheckinConfig.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+CheckinConfig _$CheckinConfigFromJson(Map<String, dynamic> json) {
+  return CheckinConfig(
+      json['weekDay'] as String,
+      (json['moneyCoin'] as num)?.toDouble(),
+      (json['pointsRatio'] as num)?.toDouble(),
+      (json['minPoints'] as num)?.toDouble(),
+      (json['probability'] as num)?.toDouble(),
+      json['checked'] as int);
+}
+
+Map<String, dynamic> _$CheckinConfigToJson(CheckinConfig instance) =>
+    <String, dynamic>{
+      'weekDay': instance.weekDay,
+      'moneyCoin': instance.moneyCoin,
+      'pointsRatio': instance.pointsRatio,
+      'minPoints': instance.minPoints,
+      'probability': instance.probability,
+      'checked': instance.checked
+    };

+ 17 - 2
lib/pages/CompetitionRooms.dart

@@ -1,7 +1,9 @@
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
+import 'package:flutter_redux/flutter_redux.dart';
 import 'package:wanna_battle/model/UserPlayTimes.dart';
+import 'package:wanna_battle/styles/totast.dart';
 import '../model/CompetitionInfo.dart';
 import '../styles/colors.dart';
 import 'package:gradient_text/gradient_text.dart';
@@ -9,6 +11,7 @@ import '../model/HouseInfo.dart';
 import '../net/HttpManager.dart';
 import '../net/Result.dart';
 import './RoomInfo.dart';
+import '../redux/AppState.dart';
 
 class CompetitionRooms extends StatefulWidget {
   CompetitionRooms(this.competitionInfo);
@@ -188,7 +191,7 @@ class _Room extends StatelessWidget {
     }
     return GestureDetector(
       onTap: () {
-        Navigator.push(context, CupertinoPageRoute(builder: (context) => RoomInfo(houseInfo)));
+        joinRoom(context, houseInfo.id);
       },
       child: Container(
         height: 43,
@@ -215,7 +218,7 @@ class _Room extends StatelessWidget {
                   style: TextStyle(color: Colors.white, fontSize: 11),
                   children: <TextSpan>[
                     TextSpan(text: '参赛人数:'),
-                    TextSpan(text: houseInfo.playerNumber.toString(), style: TextStyle(color: Color(0xFF38A968))),
+                    TextSpan(text: (houseInfo.playerNumber ?? 0).toString(), style: TextStyle(color: Color(0xFF38A968))),
                     TextSpan(text: '/${houseInfo.maxNumber}'),
                   ],
                 ),
@@ -245,4 +248,16 @@ class _Room extends StatelessWidget {
       ),
     );
   }
+
+  Future<void> joinRoom(context, houseId) async {
+    Toast.show(context, '加载中', -1, 'loading');
+    Result res = await HttpManager.post('houseInfo/join', data: {'houseId': houseId, 'userId': StoreProvider.of<AppState>(context).state.userInfo.id});
+    Toast.hide();
+    if (res.success) {
+      Toast.show(context, '加入成功', 1500, 'success');
+      Navigator.push(context, CupertinoPageRoute(builder: (context) => RoomInfo(houseInfo)));
+    } else {
+      Toast.show(context, res.error, 1500, 'info');
+    }
+  }
 }

+ 167 - 85
lib/widget/CheckinDialog.dart

@@ -3,101 +3,182 @@ import 'package:flutter/cupertino.dart';
 import 'package:wanna_battle/styles/colors.dart';
 import 'package:wanna_battle/styles/totast.dart';
 import '../styles/colors.dart';
-import '../widget/Dialog.dart';
+import '../model/CheckinConfig.dart';
+import '../net/HttpManager.dart';
 
 void showCheckinDialog(BuildContext context) {
-  Navigator.of(context).push(
-    PageRouteBuilder(
-      opaque: false,
-      transitionDuration: Duration(milliseconds: 300),
-      transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
-        return FadeTransition(
-          opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
+  showGeneralDialog(
+    context: context,
+    pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) {
+      return Center(
+        child: Material(
+          color: Colors.transparent,
+          child: _CheckinDialog(),
+        ),
+      );
+    },
+    barrierDismissible: true,
+    barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel,
+    barrierColor: Colors.black26,
+    transitionBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
+      final curvedValue = Curves.easeInOutBack.transform(animation.value) - 1.0;
+      return Transform(
+        transform: Matrix4.translationValues(0.0, curvedValue * 200, 0.0),
+        child: Opacity(
+          opacity: animation.value,
           child: child,
-        );
-      },
-      pageBuilder: (BuildContext context, _, __) {
-        return _CheckinDialog1();
-      },
-    ),
+        ),
+      );
+    },
+    transitionDuration: const Duration(milliseconds: 300),
   );
 }
 
-class _CheckinDialog1 extends Dialog {
+class _CheckinDialog extends StatefulWidget {
+  @override
+  State<StatefulWidget> createState() {
+    return _CheckinDialogState();
+  }
+}
+
+class _CheckinDialogState extends State<_CheckinDialog> {
+  Map<int, CheckinConfig> record;
+  bool todayChecked = false;
+
+  Future<void> getRecords() async {
+    final res = await HttpManager.get('checkinRecord/weekRecord');
+    if (res.success) {
+      Map<int, CheckinConfig> map = {};
+      res.data.forEach((k, v) {
+        map[int.parse(k)] = CheckinConfig.fromJson(v);
+      });
+      bool todayChecked = false;
+      if (map[DateTime.now().weekday] != null && map[DateTime.now().weekday].checked == 1) {
+        todayChecked = true;
+      }
+      setState(() {
+        record = map;
+        this.todayChecked = todayChecked;
+      });
+    }
+  }
+
+  Future<void> checkin() async {
+    Toast.show(context, '加载中', -1, 'loading');
+    final res = await HttpManager.get('checkinRecord/checkin');
+    print(res.data.toString());
+    Toast.hide();
+    if (res.success) {
+      Toast.show(context, '签到成功', 1500, 'info');
+    } else {
+      Toast.show(context, res.error, 1500, 'info');
+    }
+    Navigator.of(context).pop();
+  }
+
+  @override
+  void initState() {
+    super.initState();
+
+    Future.delayed(Duration.zero, () async {
+      getRecords();
+    });
+  }
+
   @override
   Widget build(BuildContext context) {
-    return WillPopScope(
-      child: Scaffold(
-        backgroundColor: Color(0xb3000000),
-        body: Container(
-          child: SizedBox.expand(
-            child: UnconstrainedBox(
-              child: Container(
-                width: 330,
-                height: 390,
-                decoration: BoxDecoration(color: Color(0xE6293559), border: Border.all(width: 1, color: Color(0xFF1990F8))),
-                child: Column(
-                  crossAxisAlignment: CrossAxisAlignment.center,
-                  mainAxisAlignment: MainAxisAlignment.center,
-                  children: <Widget>[
-                    Text(
-                      '每日签到',
-                      style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
-                    ),
-                    Container(
-                      margin: EdgeInsets.only(top: 30),
-                      child: Row(
-                        mainAxisAlignment: MainAxisAlignment.center,
-                        children: <Widget>[
-                          item('星期一', 1, '50金币', 1),
-                          item('星期二', 1, '50金币', 2),
-                          item('星期三', 1, '50金币', 3),
-                          item('星期四', 1, '50金币', 1),
-                        ],
-                      ),
-                    ),
-                    Container(
-                      margin: EdgeInsets.only(top: 25),
-                      child: Row(
-                        mainAxisAlignment: MainAxisAlignment.center,
-                        children: <Widget>[
-                          item('星期五', 1, '50金币', 2),
-                          item('星期六', 1, '50金币', 3),
-                          item('星期日', 1, '50金币', 1),
-                        ],
-                      ),
-                    ),
-                    Container(
-                      margin: EdgeInsets.only(top: 40),
-                      child: MaterialButton(
-                        minWidth: 220,
-                        elevation: 0,
-                        highlightElevation: 0,
-                        color: PRIMARY_COLOR,
-                        child: Text(
-                          '立即签到',
-                          style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.bold),
-                        ),
-                        onPressed: () {
-                          Toast.show(context, '签到成功', 2000, 'info');
-                          Navigator.of(context).pop();
-                        },
-                      ),
-                    )
-                  ],
+    return Container(
+      width: 330,
+      height: 390,
+      decoration: BoxDecoration(color: Color(0xE6293559), border: Border.all(width: 1, color: Color(0xFF1990F8))),
+      child: record == null
+          ? null
+          : Column(
+              crossAxisAlignment: CrossAxisAlignment.center,
+              mainAxisAlignment: MainAxisAlignment.center,
+              children: <Widget>[
+                Text(
+                  '每日签到',
+                  style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
                 ),
-              ),
+                Container(
+                  margin: EdgeInsets.only(top: 30),
+                  child: Row(
+                    mainAxisAlignment: MainAxisAlignment.center,
+                    children: <Widget>[
+                      item(record[1]),
+                      item(record[2]),
+                      item(record[3]),
+                      item(record[4]),
+                    ],
+                  ),
+                ),
+                Container(
+                  margin: EdgeInsets.only(top: 25),
+                  child: Row(
+                    mainAxisAlignment: MainAxisAlignment.center,
+                    children: <Widget>[
+                      item(record[5]),
+                      item(record[6]),
+                    ],
+                  ),
+                ),
+                todayChecked
+                    ? Container(
+                        margin: EdgeInsets.only(top: 40),
+                        child: MaterialButton(
+                          minWidth: 220,
+                          elevation: 0,
+                          highlightElevation: 0,
+                          color: Color(0xFF4F5C87),
+                          child: Text(
+                            '今日已签到',
+                            style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.bold),
+                          ),
+                          onPressed: () {
+                            Navigator.of(context).pop();
+                          },
+                        ),
+                      )
+                    : Container(
+                        margin: EdgeInsets.only(top: 40),
+                        child: MaterialButton(
+                          minWidth: 220,
+                          elevation: 0,
+                          highlightElevation: 0,
+                          color: PRIMARY_COLOR,
+                          child: Text(
+                            '立即签到',
+                            style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.bold),
+                          ),
+                          onPressed: () {
+                            checkin();
+                          },
+                        ),
+                      )
+              ],
             ),
-          ),
-        ),
-      ),
-      onWillPop: () {
-        return Future.value(true);
-      },
     );
   }
 
-  Widget item(String weekDay, int type, String name, int checked) {
+  Widget item(CheckinConfig config) {
+    String weekDay = config.weekDay;
+    String icon;
+    String name;
+    if (config.moneyCoin != null) {
+      icon = 'images/icon_jinbi_qiandao.png';
+      name = config.moneyCoin.toString() + '金币';
+    } else if (config.pointsRatio != null) {
+      icon = 'images/qiandao_icon_jiacheng.png';
+      name = '加成卡';
+    } else if (config.minPoints != null) {
+      icon = 'images/icon_baodi_03.png';
+      name = '保底卡';
+    } else if (config.probability != null) {
+      icon = 'images/qiandao_icon_gailv.png';
+      name = '概率卡';
+    }
+    int checked = config.checked;
     List<Widget> list = [
       Container(
         decoration: BoxDecoration(
@@ -108,7 +189,8 @@ class _CheckinDialog1 extends Dialog {
       ),
       Center(
         child: Image.asset(
-          'images/icon_jinbi_qiandao.png',
+          icon,
+          width: 33,
         ),
       ),
     ];
@@ -128,7 +210,7 @@ class _CheckinDialog1 extends Dialog {
           ),
           child: Center(
             child: Text(
-              '签到',
+              '��签到',
               style: TextStyle(color: Colors.white, fontSize: 10),
             ),
           ),
@@ -156,7 +238,7 @@ class _CheckinDialog1 extends Dialog {
           Container(
             margin: EdgeInsets.only(top: 2),
             child: Text(
-              '50金币',
+              name,
               style: TextStyle(
                 color: PRIMARY_COLOR,
                 fontSize: 12,