You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

208 lines
6.1 KiB

4 years ago
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/page.dart';
4 years ago
import 'package:huixiang/retrofit/data/user_bill.dart';
4 years ago
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
class VipBalancePage extends StatefulWidget {
4 years ago
final arguments;
VipBalancePage({this.arguments});
4 years ago
@override
State<StatefulWidget> createState() {
return _VipBalancePage();
}
}
class _VipBalancePage extends State<VipBalancePage> {
RefreshController _refreshController;
ApiService apiService;
@override
void initState() {
super.initState();
SharedPreferences.getInstance().then((value) => {
4 years ago
apiService = ApiService(Dio(),
context: context, token: value.getString('token')),
queryBillInfo(),
});
4 years ago
_refreshController = RefreshController(initialRefresh: false);
}
4 years ago
int current = 1;
List<UserBill> userBills = [];
4 years ago
4 years ago
queryBillInfo() async {
BaseData baseData = await apiService.queryBillInfo({
"current": current,
"model": {
"category": "",
"mid": widget.arguments["storeId"],
"title": "bill_tenant_balance",
"type": ""
},
"order": "descending",
"size": 10,
"sort": "id"
4 years ago
}).catchError((error) {
_refreshController.loadFailed();
_refreshController.refreshFailed();
});
if (baseData != null && baseData.isSuccess) {
4 years ago
PageInfo pageInfo = PageInfo.fromJson(baseData.data);
4 years ago
if (current == 1) {
userBills.clear();
4 years ago
}
4 years ago
userBills.addAll(pageInfo.records.map((e) => UserBill.fromJson(e)));
4 years ago
setState(() {
_refreshController.refreshCompleted();
_refreshController.loadComplete();
if (pageInfo.pageNum == pageInfo.pages) {
_refreshController.loadNoData();
} else {
4 years ago
current += 1;
4 years ago
}
});
} else {
_refreshController.loadFailed();
_refreshController.refreshFailed();
}
}
@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,
4 years ago
margin: EdgeInsets.only(left: 10.w),
4 years ago
padding: EdgeInsets.all(6),
child: Icon(
Icons.arrow_back_ios,
color: Colors.black,
size: 24,
),
),
),
titleSpacing: 2,
4 years ago
leadingWidth: 56.w,
4 years ago
),
body: Container(
child: ListView.builder(
itemBuilder: (context, position) {
4 years ago
return balanceItem(userBills[position]);
4 years ago
},
4 years ago
itemCount: userBills.length,
4 years ago
),
),
);
}
4 years ago
Widget balanceItem(UserBill userBill) {
4 years ago
return Container(
4 years ago
margin: EdgeInsets.only(left: 16.w, right: 16.w),
4 years ago
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
4 years ago
crossAxisAlignment: CrossAxisAlignment.center,
4 years ago
children: [
Container(
4 years ago
width: 19.w,
height: 19.h,
margin: EdgeInsets.only(left: 12.w, top: 12.h),
4 years ago
alignment: Alignment.center,
child: Image.asset(
4 years ago
userBill.pm == 0 ? "assets/image/icon_store_c.png" : "assets/image/icon_wallet_recharge.png",
),
4 years ago
),
Expanded(
child: Container(
width: double.infinity,
4 years ago
margin: EdgeInsets.only(left: 6.w, top: 12.h),
4 years ago
alignment: Alignment.centerLeft,
child: Text(
4 years ago
userBill.name,
4 years ago
style: TextStyle(
fontWeight: FontWeight.bold,
4 years ago
fontSize: 16.sp,
4 years ago
color: Color(0xFF353535),
),
),
),
flex: 1,
),
Padding(
4 years ago
padding: EdgeInsets.only(top: 12.h),
child: Text("${userBill.pm == 0 ? "-" : "+"}${userBill.number}",
style: TextStyle(fontSize: 16, color: Color(0xffF68034))),
4 years ago
),
],
),
4 years ago
SizedBox(
height: 8.h,
),
4 years ago
Container(
4 years ago
margin: EdgeInsets.only(left: 35.w),
child: Row(
4 years ago
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text.rich(
TextSpan(children: [
TextSpan(
4 years ago
text: userBill.createTime,
style: TextStyle(fontSize: 14.sp, color: Color(0xff727272),),
4 years ago
),
]),
),
Text.rich(
TextSpan(children: [
TextSpan(
4 years ago
text: S.of(context).yue_(userBill.balance),
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.bold,
color: Color(0xff727272),),
4 years ago
),
]),
),
],
4 years ago
),
),
4 years ago
Container(
4 years ago
margin: EdgeInsets.only(left: 35.w, top: 12.h, bottom: 12.h),
4 years ago
height: 1,
color: Color(0xFFF1F1F1),
),
],
),
);
}
}