|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
import 'package:huixiang/generated/l10n.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/base_data.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/coupon.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/page.dart';
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
class VipBalancePage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _VipBalancePage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _VipBalancePage extends State<VipBalancePage> {
|
|
|
|
RefreshController _refreshController;
|
|
|
|
|
|
|
|
ApiService apiService;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
SharedPreferences.getInstance().then((value) => {
|
|
|
|
apiService = ApiService(Dio(), context: context, token: value.getString('token')),
|
|
|
|
queryCard(),
|
|
|
|
});
|
|
|
|
|
|
|
|
_refreshController = RefreshController(initialRefresh: false);
|
|
|
|
}
|
|
|
|
|
|
|
|
int pageNum = 1;
|
|
|
|
List<Coupon> coupons = [];
|
|
|
|
|
|
|
|
// void _onRefresh() async {
|
|
|
|
// pageNum = 1;
|
|
|
|
// queryCard();
|
|
|
|
// }
|
|
|
|
|
|
|
|
queryCard() async {
|
|
|
|
BaseData baseData = await apiService.queryCard({
|
|
|
|
"centre": true,
|
|
|
|
"pageNum": pageNum,
|
|
|
|
"pageSize": 10,
|
|
|
|
"searchKey": "",
|
|
|
|
"state": 3
|
|
|
|
}).catchError((error) {
|
|
|
|
_refreshController.loadFailed();
|
|
|
|
_refreshController.refreshFailed();
|
|
|
|
});
|
|
|
|
if (baseData.isSuccess) {
|
|
|
|
PageInfo pageInfo = PageInfo.fromJson(baseData.data);
|
|
|
|
if (pageNum == 1) {
|
|
|
|
coupons.clear();
|
|
|
|
}
|
|
|
|
coupons.addAll(pageInfo.list.map((e) => Coupon.fromJson(e)));
|
|
|
|
setState(() {
|
|
|
|
_refreshController.refreshCompleted();
|
|
|
|
_refreshController.loadComplete();
|
|
|
|
if (pageInfo.pageNum == pageInfo.pages) {
|
|
|
|
_refreshController.loadNoData();
|
|
|
|
} else {
|
|
|
|
pageNum += 1;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
_refreshController.loadFailed();
|
|
|
|
_refreshController.refreshFailed();
|
|
|
|
Fluttertoast.showToast(msg: baseData.msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(
|
|
|
|
S.of(context).yuemingxi,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
centerTitle: false,
|
|
|
|
backgroundColor: Color(0xFFF7F7F7),
|
|
|
|
elevation: 0,
|
|
|
|
leading: GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
margin: EdgeInsets.only(left: 10),
|
|
|
|
padding: EdgeInsets.all(6),
|
|
|
|
child: Icon(
|
|
|
|
Icons.arrow_back_ios,
|
|
|
|
color: Colors.black,
|
|
|
|
size: 24,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
titleSpacing: 2,
|
|
|
|
leadingWidth: 56,
|
|
|
|
),
|
|
|
|
body: Container(
|
|
|
|
child: ListView.builder(
|
|
|
|
itemBuilder: (context, position) {
|
|
|
|
return balanceItem();
|
|
|
|
},
|
|
|
|
itemCount: coupons.length,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
Widget balanceItem(){
|
|
|
|
return Container(
|
|
|
|
margin: EdgeInsets.only(left: 16,right: 16),
|
|
|
|
child: Column(
|
|
|
|
// mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
|
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 19,
|
|
|
|
height: 19,
|
|
|
|
margin: EdgeInsets.only(left: 12, top: 12),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Image.asset(
|
|
|
|
"assets/image/icon_store_c.png",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
width: double.infinity,
|
|
|
|
margin: EdgeInsets.only(left: 6, top: 12),
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: Text(
|
|
|
|
"门店消费",
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 16,
|
|
|
|
color: Color(0xFF353535),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
flex: 1,
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 12),
|
|
|
|
child: Text("-200",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
color: Color(0xffF68034))),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(height: 8,),
|
|
|
|
Container(
|
|
|
|
margin: EdgeInsets.only(left: 35),
|
|
|
|
child:Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text.rich(
|
|
|
|
TextSpan(children: [
|
|
|
|
TextSpan(
|
|
|
|
text: "2021-06-19 13:03",
|
|
|
|
style: TextStyle(fontSize: 14, color: Color(0xff727272)),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
Text.rich(
|
|
|
|
TextSpan(children: [
|
|
|
|
TextSpan(
|
|
|
|
text: "余额:200.00",
|
|
|
|
style: TextStyle(fontSize: 14,fontWeight: FontWeight.bold, color: Color(0xff727272)),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),),
|
|
|
|
Container(
|
|
|
|
margin: EdgeInsets.only(left: 35,top: 12,bottom: 12),
|
|
|
|
height: 1,
|
|
|
|
color: Color(0xFFF1F1F1),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|