admin
2022-05-07 4c7cde7ae5ed57335405459e47de4bbd2726c4ba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
import 'dart:ui';
 
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:makemoney/api/gold_corn_api.dart';
import 'package:makemoney/model/gold_core_model.dart';
import 'package:makemoney/model/user/extract_money_model.dart';
import 'package:makemoney/ui/widget/button.dart';
import 'package:makemoney/ui/widget/common_ui.dart';
import 'package:makemoney/ui/widget/dialog.dart';
import 'package:makemoney/ui/widget/refresh_listview.dart';
import 'package:makemoney/utils/ui_constant.dart';
import 'package:makemoney/utils/ui_utils.dart';
 
import '../../ui/widget/nav.dart';
 
class GoldCornPage extends StatefulWidget {
  GoldCornPage({Key? key, required this.title}) : super(key: key);
 
  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.
 
  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".
 
  final String title;
 
  @override
  _GoldCornPageState createState() => _GoldCornPageState();
}
 
class _GoldCornPageState extends State<GoldCornPage>
    with SingleTickerProviderStateMixin {
  TabController? _tabController;
 
  int _balance = 0;
  int _exchanging = 0;
 
  int selectedIndex = 0;
 
  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 2, vsync: this);
    _tabController!.index = 0;
    _getGoldCornInfo();
  }
 
  void _getGoldCornInfo() async {
    Map<String, dynamic>? result =
        await GoldCornApiUtil.getGoldCornInfo(context);
    if (result == null) {
      return;
    }
    if (result["code"] != 0) {
      ToastUtil.toast(result["msg"], context);
      return;
    }
    setState(() {
      _balance = result["data"]["balance"];
      _exchanging = result["data"]["exchanging"];
    });
  }
 
  BoxDecoration getItemDecoration(Color bgColor, Color shadowColor) {
    return BoxDecoration(
        borderRadius: const BorderRadius.all(Radius.elliptical(10, 10)),
        color: bgColor,
        boxShadow: [
          BoxShadow(
              color: shadowColor,
              blurRadius: 2.0,
              offset: const Offset(0.0, 5.0), //阴影y轴偏移量
              spreadRadius: 1 //阴影扩散程度
              )
        ]);
  }
 
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: const Color(0xFFF0F0F0),
        body: Column(
          children: [
            TopNavBar(title: "金币"),
            Expanded(
                child: Container(
                    padding: const EdgeInsets.only(left: 10, right: 10),
                    child: Column(children: [
                      const SizedBox(
                        height: 10,
                      ),
                      //余额视图
                      AspectRatio(
                          aspectRatio: 3.3875,
                          child: Stack(
                              alignment: Alignment.bottomCenter,
                              children: [
                                Image.asset(
                                    "assets/imgs/mine/ic_gold_corn_bg.png"),
                                Container(
                                    margin: EdgeInsets.only(
                                        left: 20, top: 14, bottom: 10),
                                    child: Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      mainAxisSize: MainAxisSize.min,
                                      children: [
                                        const Text(
                                          "金币",
                                          style: TextStyle(
                                              color: Colors.white,
                                              fontSize: 12),
                                        ),
                                        const SizedBox(
                                          height: 5,
                                        ),
                                        Text.rich(TextSpan(
                                            text: "$_balance",
                                            style: const TextStyle(
                                                color: Colors.white,
                                                fontSize: 30),
                                            children: const [
                                              TextSpan(
                                                  text: "个",
                                                  style: TextStyle(
                                                      color: Colors.white,
                                                      fontSize: 15))
                                            ])),
                                        Expanded(child: Container()),
                                        _exchanging > 0
                                            ? Row(
                                                crossAxisAlignment:
                                                    CrossAxisAlignment.center,
                                                children: [
                                                    Text(
                                                      "折算中:$_exchanging个",
                                                      style: const TextStyle(
                                                          color: Colors.white,
                                                          fontSize: 12),
                                                    ),
                                                    const SizedBox(
                                                      width: 5,
                                                    ),
                                                    InkWell(
                                                        onTap: () {
                                                          DialogUtil.showDialog(
                                                              context,
                                                              MyAlertDialog(
                                                                "温馨提示",
                                                                "每日00:00后系统自动将所有金币按照\"一定的\"比例折算为现金。",
                                                                () {
                                                                  popPage(
                                                                      context);
                                                                },
                                                                sureName: "好的",
                                                              ));
                                                        },
                                                        child: Image.asset(
                                                          "assets/imgs/mine/icon_balance_question.png",
                                                          height: 12,
                                                        )),
                                                  ])
                                            : Container(),
                                      ],
                                    )),
                              ])),
 
                      //绑定微信
 
                      const SizedBox(
                        height: 12,
                      ),
                      Stack(alignment: Alignment.bottomCenter, children: [
                        Container(
                            height: 47,
                            decoration: const BoxDecoration(
                              color: Color(0xFFE6E6E6),
                              borderRadius: BorderRadius.only(
                                  topLeft: Radius.circular(13),
                                  topRight: Radius.circular(13)),
                            )),
                        Padding(padding:const EdgeInsets.only(bottom:0), child:
                        Row(
                          children: [
                            Expanded(flex: 1, child: getNavItem("金币记录", 0)),
                            Expanded(flex: 1, child: getNavItem("折算记录", 1)),
                          ],
                        ))
                      ]),
                      Expanded(
                          child: Container(
                        color: Colors.white,
                        child: TabBarView(
                          controller: _tabController,
                          physics: const NeverScrollableScrollPhysics(),
                          children: [
                            KeepAliveWrapper(
                                child: GoldCornRecord(
                              exchange: false,
                            )),
                            KeepAliveWrapper(
                                child: GoldCornRecord(
                              exchange: true,
                            )),
                          ],
                        ),
                      ))
                    ])))
          ],
        ));
  }
 
  Widget getNavItem(title, index) {
    return InkWell(
        onTap: () {
          setState(() {
            selectedIndex = index;
          });
          _tabController!.index = index;
        },
        child: Container(
          height: 50,
          alignment: Alignment.center,
          decoration: selectedIndex == index
              ? BoxDecoration(
                  color: Colors.white,
                  borderRadius: const BorderRadius.only(
                      topLeft: Radius.circular(13),
                      topRight: Radius.circular(13)),
                  boxShadow: [
                      BoxShadow(
                          color: const Color(0x80989898),
                          offset: Offset((index == 0 ? 2 : -2), 0))
                    ])
              : null,
          child: Text(
            title,
            style: TextStyle(
                color: selectedIndex == index
                    ? ColorConstant.theme
                    : const Color(0xFF666666),
                fontSize: 15),
          ),
        ));
  }
}
 
class GoldCornRecord extends StatefulWidget {
  GoldCornRecord({Key? key, required this.exchange}) : super(key: key);
 
  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.
 
  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".
 
  final bool exchange;
 
  @override
  _GoldCornRecordState createState() => _GoldCornRecordState();
}
 
class _GoldCornRecordState extends State<GoldCornRecord> {
  final MyRefreshController _refreshController =
      MyRefreshController(initialRefresh: false);
 
  int _page = 1;
 
  List<GoldCoreRecordModel> _recordList = [];
 
  @override
  void initState() {
    super.initState();
    _refresh();
  }
 
  //下拉刷新
  void _refresh() {
    if (_refreshController.dataNormal != null) {
      _refreshController.dataNormal!();
    }
    _refreshController.loadComplete();
    _getRecordList(1);
  }
 
  //上拉加载
  void _loadMore() {
    _getRecordList(_page + 1);
  }
 
  //获取队员列表
  void _getRecordList(int page) async {
    setState(() {
      _page = page;
    });
 
    Map<String, dynamic>? result = await (widget.exchange
        ? GoldCornApiUtil.listExchangeRecord(context, _page)
        : GoldCornApiUtil.listGetRecord(context, _page));
 
    _refreshController.refreshCompleted();
    _refreshController.loadComplete();
 
    if (result == null && _page == 1&&_recordList.isEmpty) {
      _refreshController.apiError!();
    }
 
    if (result == null || result["code"] != 0) {
      //页码回滚
      if (_page > 1) {
        setState(() {
          _page = _page - 1;
        });
      }
      return;
    }
    //解析数据
    int count = result["data"]["count"];
    List<dynamic> list = result["data"]["list"];
    List<GoldCoreRecordModel> tempList = [];
    list.forEach((element) {
      if (widget.exchange) {
        tempList.add(GoldCoreRecordModel(
            title: "+¥${element["money"]}元",
            dateTime: element["dateTime"],
            num: element["num"]));
      } else {
        tempList.add(GoldCoreRecordModel.fromJson(element));
      }
    });
 
    if (_page == 1) {
      setState(() {
        _recordList = tempList;
      });
    } else {
      setState(() {
        _recordList.addAll(tempList);
      });
    }
 
    //判断数据
 
    if (_recordList.isEmpty) {
      //空数据
      _refreshController.dataEmpty!();
    } else {
      _refreshController.dataNormal!();
      if (count <= _recordList.length) {
        //没有数据了
        _refreshController.loadNoData();
      }
    }
  }
 
  @override
  Widget build(BuildContext context) {
    return RefreshListView(
      refreshController: _refreshController,
      refresh: () {
        _refresh();
      },
      loadMore: () {
        _loadMore();
      },
      loadTextColor: const Color(0xFFFF8316),
      content: ListView.builder(
        itemCount: _recordList.length,
        itemBuilder: (BuildContext context, int index) {
          return _getItemView(index, () {});
        },
      ),
    );
  }
 
  Widget _getItemView(int index, GestureTapCallback onTap) {
    return InkWell(
        onTap: () {
          onTap();
        },
        child: Padding(
            padding:
                const EdgeInsets.only(top: 20, left: 16, right: 16, bottom: 5),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      _recordList[index].title!,
                      style: const TextStyle(color: Colors.black, fontSize: 14),
                    ),
                    Text(
                      _recordList[index].dateTime!,
                      style: const TextStyle(
                          color: Color(0xFF999999), fontSize: 12, height: 1.5),
                    )
                  ],
                ),
                Column(children: [
                  Row(
                    children: [
                      Image.asset(
                        "assets/imgs/icon_goldcorn.png",
                        height: 22,
                      ),
                      Text(
                        widget.exchange
                            ? " -${_recordList[index].num}"
                            : " +${_recordList[index].num}",
                        style: const TextStyle(
                            color: Color(0xFFFF8316), fontSize: 15),
                      )
                    ],
                  ),
                ])
              ],
            )));
  }
}