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.
 
 
 
 
 
 

325 lines
11 KiB

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../../generated/l10n.dart';
import '../../../retrofit/business_api.dart';
import '../../../retrofit/data/add_vip_info.dart';
import '../../../retrofit/data/base_data.dart';
import '../../../utils/business_instance.dart';
import '../../../utils/flutter_utils.dart';
import '../../../view_widget/settlement_tips_dialog.dart';
class AddVip extends StatefulWidget {
final Map<String, dynamic> arguments;
AddVip({this.arguments});
@override
State<StatefulWidget> createState() {
return _AddVip();
}
}
class _AddVip extends State<AddVip> {
final TextEditingController vipPhoneController = TextEditingController();
final TextEditingController vipNameController = TextEditingController();
bool isKeyBoardShow = false;
FocusNode _focusNode = FocusNode();
BusinessApiService businessService;
AddVipInfo addVipInfo;
String networkError = "";
int networkStatus = 0;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
print("object: ${MediaQuery.of(context).viewInsets.bottom}");
if (MediaQuery.of(context).viewInsets.bottom == 0) {
if (isKeyBoardShow) {
isKeyBoardShow = false;
//关闭键盘 软键盘关闭了, 清除输入控件的焦点, 否则重新进入页面会导致软键盘再弹出问题
FocusScope.of(context).requestFocus(FocusNode());
}
} else {
isKeyBoardShow = true;
}
});
});
}
///离开页面记着销毁和清除
@override
void dispose() {
_focusNode.unfocus();
super.dispose();
}
///新增会员接口
addMember(String mobile,String nickName) async {
try {
EasyLoading.show(
status: S.current.zhengzaijiazai,
maskType: EasyLoadingMaskType.black);
if (businessService == null) {
businessService = BusinessApiService(Dio(),
context: context,
token: BusinessInstance.instance.businessToken,
tenant: BusinessInstance.instance.businessTenant,
storeId: widget.arguments["storeId"]);
}
BaseData<AddVipInfo> baseData = await businessService.createMemberSourceByMobile(mobile,nickName).catchError((error) {
networkError = AppUtils.dioErrorTypeToString(error.type);
networkStatus = -1;
setState(() {});});
if (baseData != null && baseData.isSuccess) {
addVipInfo = baseData.data;
Navigator.of(context).pop();
SmartDialog.show(
widget: SettlementTips(
() {},
text: "会员新增成功,请前往会员管理查询会员新增情况",
color: Color(0xFF30415B),
));
networkStatus = 1;
}else{
SmartDialog.show(
widget: SettlementTips(
() {},
text: baseData.msg,
color: Color(0xFF30415B),
));
networkStatus = 1;
}
} finally {
EasyLoading.dismiss();
setState(() {});
}
}
@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
FocusScope.of(context).unfocus();
},
child: Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
appBar: MyAppBar(
title: "新增会员",
titleColor: Colors.black,
background: Colors.white,
leadingColor: Colors.black,
brightness: Brightness.dark,
),
body:networkStatus == -1?noNetwork():Container(
margin: EdgeInsets.only(top: 24.h, left: 16.w, right: 16.w),
child: Column(
children: [
Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Color(0x0F06152E),
offset: Offset(0, 2),
blurRadius: 4,
spreadRadius: 0,
)
],
borderRadius: BorderRadius.circular(8),
),
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: Row(
children: [
Expanded(
child: Text.rich(
TextSpan(
children: [
TextSpan(
text: "会员手机号",
style: TextStyle(
color: Color(0xFF1A1A1A),
fontSize: 14.sp,
fontWeight: FontWeight.w500,
),
),
TextSpan(
text: "*",
style: TextStyle(
color: Color(0xFFFA5151),
fontSize: 14.sp,
fontWeight: FontWeight.w500,
),
),
],
),
),
),
Expanded(
child: TextField(
controller: vipPhoneController,
decoration: InputDecoration(
hintText: "请输入会员手机号",
hintTextDirection: TextDirection.rtl,
hintStyle: TextStyle(
color: Color(0xFF1A1A1A),
fontSize: 14.sp,
fontWeight: MyFontWeight.regular,
),
border: InputBorder.none,
contentPadding: EdgeInsets.only(left: 16.w),
),
textAlign: TextAlign.right,
style: TextStyle(
color: Color(0xFF1A1A1A),
fontSize: 14.sp,
fontWeight: MyFontWeight.regular),
),
),
],
),
),
Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Color(0x0F06152E),
offset: Offset(0, 2),
blurRadius: 4,
spreadRadius: 0,
)
],
borderRadius: BorderRadius.circular(8),
),
padding: EdgeInsets.symmetric(horizontal: 16.w),
margin: EdgeInsets.only(top: 16.h),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Text(
"会员姓名",
style: TextStyle(
color: Color(0xFF1A1A1A),
fontSize: 14.sp,
fontWeight: FontWeight.w500,
),
),
),
Expanded(
child: TextField(
controller: vipNameController,
decoration: InputDecoration(
hintText: "请输入会员姓名",
hintTextDirection: TextDirection.rtl,
hintStyle: TextStyle(
color: Color(0xFF1A1A1A),
fontSize: 14.sp,
fontWeight: MyFontWeight.regular),
border: InputBorder.none,
contentPadding: EdgeInsets.only(left: 16.w),
),
textAlign: TextAlign.right,
style: TextStyle(
color: Color(0xFF1A1A1A),
fontSize: 14.sp,
fontWeight: MyFontWeight.regular),
),
),
],
)),
Spacer(),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
if (vipPhoneController.text == "") {
SmartDialog.showToast("请输入会员手机号",
alignment: Alignment.center);
return;
} else {
addMember(vipPhoneController?.text ?? "",vipNameController?.text ?? "");
}
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(27),
color: Color(0xFF30415B),
),
width: double.infinity,
alignment: Alignment.center,
padding: EdgeInsets.symmetric(vertical: 16.h),
margin: EdgeInsets.only(bottom: 34.h),
child: Text(
"确认新增",
style: TextStyle(
color: Colors.white,
fontSize: 16.sp,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
),
),
);
}
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: () {
addMember(vipPhoneController?.text ?? "",vipNameController?.text ?? "");
},
child: Container(
decoration: BoxDecoration(
color: Color(0xFF30415B),
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),
)),
)
],
),
);
}
}