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.
576 lines
20 KiB
576 lines
20 KiB
import 'package:dio/dio.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter/services.dart'; |
|
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
|
import 'package:pull_to_refresh/pull_to_refresh.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
import 'package:shimmer/shimmer.dart'; |
|
|
|
import '../../generated/l10n.dart'; |
|
import '../../retrofit/data/base_data.dart'; |
|
import '../../retrofit/data/title_info_list.dart'; |
|
import '../../retrofit/retrofit_api.dart'; |
|
import '../../utils/flutter_utils.dart'; |
|
import '../../utils/font_weight.dart'; |
|
import '../../view_widget/border_text.dart'; |
|
import '../../view_widget/classic_header.dart'; |
|
import '../../view_widget/my_appbar.dart'; |
|
import '../../view_widget/my_footer.dart'; |
|
import '../../view_widget/no_data_view.dart'; |
|
import '../../view_widget/round_button.dart'; |
|
|
|
class InvoicesTitleInfo extends StatefulWidget { |
|
final Map<String, dynamic> arguments; |
|
|
|
InvoicesTitleInfo({this.arguments}); |
|
|
|
@override |
|
State<StatefulWidget> createState() { |
|
return _InvoicesTitleInfo(); |
|
} |
|
} |
|
|
|
class _InvoicesTitleInfo extends State<InvoicesTitleInfo> { |
|
final RefreshController refreshController = RefreshController(); |
|
String networkError = ""; |
|
int networkStatus = 0; |
|
ApiService apiService; |
|
List<Records> records = []; |
|
int _current = 1; |
|
|
|
|
|
@override |
|
void initState() { |
|
super.initState(); |
|
_onRefresh(); |
|
} |
|
|
|
///离开页面记着销毁和清除 |
|
@override |
|
void dispose() { |
|
super.dispose(); |
|
refreshController.dispose(); |
|
} |
|
|
|
_onRefresh({bool isShowLoad = true}) async { |
|
if (isShowLoad) |
|
EasyLoading.show( |
|
status: S.current.zhengzaijiazai, |
|
maskType: EasyLoadingMaskType.black); |
|
await queryInvoiceHeadersList(); |
|
EasyLoading.dismiss(); |
|
if (!mounted) return; |
|
if (refreshController.isRefresh) refreshController.refreshCompleted(); |
|
setState(() {}); |
|
} |
|
|
|
///查询抬头信心列表 |
|
queryInvoiceHeadersList() async { |
|
if (apiService == null) { |
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
apiService = ApiService( |
|
Dio(), |
|
context: context, |
|
token: value.getString("token"), |
|
); |
|
} |
|
BaseData<TitleInfoList> baseData = await apiService.invoiceHeaderList({ |
|
"current": _current, |
|
"map": {}, |
|
"model": {}, |
|
"order": "descending", |
|
"size": 50, |
|
"sort": "id" |
|
}).catchError((error) { |
|
networkError = AppUtils.dioErrorTypeToString(error.type); |
|
networkStatus = -1; |
|
setState(() {}); |
|
refreshController.refreshFailed(); |
|
refreshController.loadFailed(); |
|
}); |
|
if (!mounted) return; |
|
if (baseData != null && baseData.isSuccess) { |
|
records.addAll(baseData?.data?.records ?? []); |
|
if ((baseData?.data?.records ?? []).isEmpty || |
|
records.length.toString() == baseData.data.total) |
|
refreshController.loadNoData(); |
|
else |
|
refreshController.loadComplete(); |
|
networkStatus = 1; |
|
} else { |
|
SmartDialog.showToast(baseData.msg, alignment: Alignment.center); |
|
} |
|
} |
|
|
|
///删除抬头信息 |
|
delTitleInfo(ids) async { |
|
try { |
|
EasyLoading.show( |
|
status: S.current.zhengzaijiazai, |
|
maskType: EasyLoadingMaskType.black); |
|
if (apiService == null) { |
|
SharedPreferences value = await SharedPreferences.getInstance(); |
|
apiService = ApiService( |
|
Dio(), |
|
context: context, |
|
token: value.getString("token"), |
|
); |
|
} |
|
BaseData baseData = await apiService.delInvoiceHeader(ids).catchError((error) { |
|
networkError = AppUtils.dioErrorTypeToString(error.type); |
|
networkStatus = -1; |
|
setState(() {}); |
|
refreshController.refreshFailed(); |
|
refreshController.loadFailed(); |
|
}); |
|
if (baseData != null && baseData.isSuccess) { |
|
await editOnRefresh(); |
|
Future.delayed(Duration(milliseconds: 500), () { |
|
SmartDialog.showToast("删除信息成功", alignment: Alignment.center); |
|
}); |
|
} else { |
|
SmartDialog.showToast(baseData.msg, alignment: Alignment.center); |
|
} |
|
} finally { |
|
EasyLoading.dismiss(); |
|
} |
|
} |
|
|
|
editOnRefresh() { |
|
_current = 1; |
|
records.clear(); |
|
_onRefresh(isShowLoad: false); |
|
} |
|
|
|
@override |
|
Widget build(BuildContext context) { |
|
return Scaffold( |
|
resizeToAvoidBottomInset: false, |
|
appBar: MyAppBar( |
|
title: "抬头管理", |
|
titleColor: Colors.black, |
|
background: Colors.white, |
|
leadingColor: Colors.black, |
|
), |
|
body: networkStatus == -1 |
|
? noNetwork() |
|
: Column( |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Expanded( |
|
child: Container( |
|
child: SmartRefresher( |
|
controller: refreshController, |
|
enablePullDown: true, |
|
// enablePullUp: records.length == 0 ? false : true, |
|
header: MyHeader(), |
|
footer: CustomFooter( |
|
builder: (context, mode) { |
|
return MyFooter(mode); |
|
}, |
|
), |
|
onRefresh: () { |
|
_current = 1; |
|
records.clear(); |
|
_onRefresh(isShowLoad: false); |
|
}, |
|
onLoading: () { |
|
_current++; |
|
_onRefresh(isShowLoad: false); |
|
}, |
|
physics: BouncingScrollPhysics(), |
|
scrollController: ScrollController(), |
|
child: Container( |
|
margin: EdgeInsets.only(bottom: 20.h), |
|
child: networkStatus == 0 |
|
? ListView.builder( |
|
itemCount: 10, |
|
physics: BouncingScrollPhysics(), |
|
shrinkWrap: true, |
|
itemBuilder: (context, position) { |
|
return GestureDetector( |
|
behavior: HitTestBehavior.opaque, |
|
onTap: () {}, |
|
child: titleInfoListSm(), |
|
); |
|
}, |
|
) |
|
: ((records == null || records.length == 0) |
|
? NoDataView( |
|
src: "assets/image/guan_zhu.webp", |
|
isShowBtn: false, |
|
text: "暂无抬头信息", |
|
fontSize: 16, |
|
margin: EdgeInsets.only(top:120), |
|
) |
|
: ListView.builder( |
|
itemCount: records?.length ?? 0, |
|
physics: BouncingScrollPhysics(), |
|
shrinkWrap: true, |
|
itemBuilder: (context, position) { |
|
return GestureDetector( |
|
behavior: HitTestBehavior.opaque, |
|
onTap: () { |
|
if(widget.arguments["enterType"] == 0){ |
|
Navigator.of(context).pop({ |
|
"id":records[position]?.id ?? "", |
|
"phone":records[position]?.companyPhone ?? "", |
|
"name":records[position]?.name ?? "" |
|
}); |
|
}}, |
|
child: titleInfoList(records[position]), |
|
); |
|
}, |
|
))), |
|
), |
|
)), |
|
if (networkStatus == 1) |
|
GestureDetector( |
|
onTap: () { |
|
Navigator.of(context) |
|
.pushNamed('/router/add_invoices_title',arguments:{ |
|
"titleName":"添加抬头", |
|
}).then((value) { |
|
_current = 1; |
|
records.clear(); |
|
_onRefresh(isShowLoad: false); |
|
}); |
|
}, |
|
child: Container( |
|
padding: EdgeInsets.symmetric(vertical:16.h), |
|
margin: EdgeInsets.only(bottom:25.h,left:20.w,right: 20.w), |
|
decoration: BoxDecoration( |
|
color: Color(0xff32A060), |
|
borderRadius: BorderRadius.circular( |
|
45 |
|
), |
|
), |
|
width: double.infinity, |
|
alignment: Alignment.center, |
|
child: Text( |
|
"添加抬头", |
|
style: TextStyle( |
|
color: Colors.white, |
|
fontSize: 16.sp, |
|
fontWeight: MyFontWeight.medium, |
|
), |
|
), |
|
), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget titleInfoList(Records records) { |
|
return Container( |
|
padding: EdgeInsets.only( |
|
top: ((records?.type ?? "") == "PERSONAL") ? 30.h : 14.h, |
|
bottom: ((records?.type ?? "") == "PERSONAL") ? 30.h : 14.h, |
|
left: 12.w), |
|
margin: EdgeInsets.only(top: 12.h, bottom: 4.h, right: 14.w, left: 14.w), |
|
decoration: BoxDecoration( |
|
color: Colors.white, |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Color(0x0F06152E), |
|
offset: Offset(0, 2), |
|
blurRadius: 4, |
|
spreadRadius: 0, |
|
) |
|
], |
|
borderRadius: BorderRadius.circular(8), |
|
), |
|
child: Row( |
|
children: [ |
|
Expanded( |
|
child: Column( |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
children: [ |
|
Text( |
|
records?.name ?? "", |
|
maxLines: 1, |
|
overflow: TextOverflow.ellipsis, |
|
style: TextStyle( |
|
color: Colors.black, |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.bold, |
|
), |
|
), |
|
if ((records?.type ?? "") == "COMPANY") |
|
Padding( |
|
padding: EdgeInsets.only(top: 20.h), |
|
child: Text( |
|
"税号:${records?.taxId ?? ""}", |
|
style: TextStyle( |
|
color: Color(0xff353535), |
|
fontSize: 14.sp, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
)), |
|
], |
|
)), |
|
GestureDetector( |
|
behavior: HitTestBehavior.opaque, |
|
onTap: () { |
|
Navigator.of(context).pushNamed('/router/add_invoices_title',arguments: { |
|
"titleName":"编辑抬头", |
|
"titleType":records.type == "COMPANY" ? 1:0, |
|
"records":records, |
|
}).then((value){ |
|
if(value == 1) |
|
editOnRefresh(); |
|
}); |
|
}, |
|
child: Padding( |
|
padding: EdgeInsets.only(left:30.w,right: 12.w), |
|
child: Image.asset( |
|
"assets/image/title_info_edit.webp", |
|
width: 16.h, |
|
height: 16.h, |
|
fit: BoxFit.fitWidth, |
|
))), |
|
GestureDetector( |
|
behavior: HitTestBehavior.opaque, |
|
onTap: () { |
|
showTitleInfoDialog(records?.id ?? ""); |
|
}, |
|
child: Padding( |
|
padding: EdgeInsets.only(left: 12.w, right: 31.w), |
|
child: Image.asset( |
|
"assets/image/title_del.webp", |
|
width: 15.h, |
|
height: 16.h, |
|
fit: BoxFit.fitWidth, |
|
)), |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget titleInfoListSm() { |
|
return Container( |
|
padding: EdgeInsets.only(top: 12, bottom: 12, left: 16), |
|
margin: EdgeInsets.symmetric(horizontal: 14, vertical: 6), |
|
decoration: BoxDecoration( |
|
color: Colors.white, |
|
boxShadow: [ |
|
BoxShadow( |
|
color: Color(0x0F06152E), |
|
offset: Offset(0, 2), |
|
blurRadius: 4, |
|
spreadRadius: 0, |
|
) |
|
], |
|
borderRadius: BorderRadius.circular(8), |
|
), |
|
child: Row( |
|
children: [ |
|
Expanded( |
|
child: Column( |
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
children: [ |
|
Shimmer.fromColors( |
|
baseColor: Color(0XFFD8D8D8), |
|
highlightColor: Color(0XFFD8D8D8), |
|
child: Container( |
|
margin: EdgeInsets.only(bottom: 16), |
|
decoration: BoxDecoration( |
|
color: Color(0XFFD8D8D8), |
|
borderRadius: BorderRadius.circular(2), |
|
), |
|
width: 180.w, |
|
height: 20.h, |
|
), |
|
), |
|
Row( |
|
children: [ |
|
Shimmer.fromColors( |
|
baseColor: Color(0XFFD8D8D8), |
|
highlightColor: Color(0XFFD8D8D8), |
|
child: Container( |
|
margin: EdgeInsets.only(right: 10), |
|
decoration: BoxDecoration( |
|
color: Color(0XFFD8D8D8), |
|
borderRadius: BorderRadius.circular(2), |
|
), |
|
width: 40.w, |
|
height: 20.h, |
|
), |
|
), |
|
Shimmer.fromColors( |
|
baseColor: Color(0XFFD8D8D8), |
|
highlightColor: Color(0XFFD8D8D8), |
|
child: Container( |
|
decoration: BoxDecoration( |
|
color: Color(0XFFD8D8D8), |
|
borderRadius: BorderRadius.circular(2), |
|
), |
|
width: 120, |
|
height: 20, |
|
), |
|
), |
|
], |
|
), |
|
], |
|
)), |
|
Row( |
|
children: [ |
|
Shimmer.fromColors( |
|
baseColor: Color(0XFFD8D8D8), |
|
highlightColor: Color(0XFFD8D8D8), |
|
child: Container( |
|
margin: EdgeInsets.only(right: 24), |
|
decoration: BoxDecoration( |
|
color: Color(0XFFD8D8D8), |
|
borderRadius: BorderRadius.circular(2), |
|
), |
|
width: 16.w, |
|
height: 16.h, |
|
), |
|
), |
|
Shimmer.fromColors( |
|
baseColor: Color(0XFFD8D8D8), |
|
highlightColor: Color(0XFFD8D8D8), |
|
child: Container( |
|
margin: EdgeInsets.only(right: 25), |
|
decoration: BoxDecoration( |
|
color: Color(0XFFD8D8D8), |
|
borderRadius: BorderRadius.circular(2), |
|
), |
|
width: 16, |
|
height: 16, |
|
), |
|
), |
|
], |
|
), |
|
], |
|
), |
|
); |
|
} |
|
|
|
Widget noNetwork() { |
|
return Container( |
|
width: double.infinity, |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
children: [ |
|
Text( |
|
// "无法连接到网络", |
|
networkError.substring(0, networkError.indexOf(",")), |
|
style: TextStyle( |
|
fontSize: 14.sp, |
|
color: Color(0xFF0D0D0D), |
|
fontWeight: MyFontWeight.bold), |
|
), |
|
Padding( |
|
padding: EdgeInsets.symmetric(vertical: 10.h), |
|
child: Text( |
|
"请检查网络设置或稍后重试", |
|
style: TextStyle( |
|
fontSize: 12.sp, |
|
color: Color(0xFF7A797F), |
|
fontWeight: MyFontWeight.regular), |
|
), |
|
), |
|
GestureDetector( |
|
behavior: HitTestBehavior.opaque, |
|
onTap: () { |
|
_onRefresh(); |
|
}, |
|
child: Container( |
|
decoration: BoxDecoration( |
|
color: Color(0xff32A060), |
|
borderRadius: BorderRadius.circular(15), |
|
), |
|
padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 3.h), |
|
child: Text( |
|
"重试", |
|
style: TextStyle( |
|
fontSize: 14.sp, |
|
color: Colors.white, |
|
fontWeight: MyFontWeight.regular), |
|
)), |
|
) |
|
], |
|
), |
|
); |
|
} |
|
|
|
//抬头信心删除提示弹窗 |
|
showTitleInfoDialog(id) { |
|
showDialog( |
|
context: context, |
|
builder: (context) { |
|
return AlertDialog( |
|
content: Container( |
|
width: MediaQuery.of(context).size.width - 84, |
|
height: 139, |
|
child: Column( |
|
mainAxisAlignment: MainAxisAlignment.center, |
|
crossAxisAlignment: CrossAxisAlignment.center, |
|
children: [ |
|
Text( |
|
"确认要删除这条数据吗?", |
|
style: TextStyle( |
|
color: Colors.black, |
|
fontSize: 16, |
|
fontWeight: MyFontWeight.regular, |
|
), |
|
), |
|
SizedBox(height: 35), |
|
Row( |
|
children: [ |
|
Expanded( |
|
child: InkWell( |
|
child: BorderText( |
|
text: S.of(context).quxiao, |
|
textColor: Color(0xff32A060), |
|
fontSize: 16.sp, |
|
fontWeight: FontWeight.bold, |
|
borderColor: Color(0xff32A060), |
|
radius: 4, |
|
padding: EdgeInsets.all(12), |
|
borderWidth: 1, |
|
), |
|
onTap: () { |
|
Navigator.of(context).pop(); |
|
}, |
|
), |
|
flex: 1, |
|
), |
|
SizedBox( |
|
width: 16.w, |
|
), |
|
Expanded( |
|
child: InkWell( |
|
child: RoundButton( |
|
text: S.of(context).shanchu, |
|
textColor: Colors.white, |
|
radius: 4, |
|
padding: EdgeInsets.all(12), |
|
backgroup: Color(0xff32A060), |
|
fontSize: 16.sp, |
|
fontWeight: FontWeight.bold, |
|
), |
|
onTap: () { |
|
delTitleInfo(id); |
|
Navigator.of(context).pop(); |
|
}, |
|
), |
|
flex: 1, |
|
), |
|
], |
|
) |
|
], |
|
), |
|
), |
|
); |
|
}, |
|
); |
|
} |
|
}
|
|
|