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.
 
 
 
 
 
 

481 lines
14 KiB

import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/user_info.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/flutter_utils.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:huixiang/view_widget/pay_selected_dialog.dart';
import 'package:pin_input_text_field/pin_input_text_field.dart';
import 'package:shared_preferences/shared_preferences.dart';
class PlatformCodePage extends StatefulWidget {
final Map<String, dynamic> arguments;
PlatformCodePage({this.arguments});
@override
State<StatefulWidget> createState() {
return _PlatformCodePage();
}
}
class _PlatformCodePage extends State<PlatformCodePage> {
ApiService apiService;
int codeType = 0;
UserInfo userInfo;
@override
void initState() {
super.initState();
}
///发送修改支付密码的短信验证
sendCode() async {
if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(Dio(),
context: context, token: value.getString("token"), showLoading: true);
}
BaseData baseData =
await apiService.sendVerifyByUpdatePayPwd().catchError((onError) {});
if (baseData != null && baseData.isSuccess) {
codeType = 1;
SmartDialog.showToast(baseData.data, alignment: Alignment.center);
} else {
SmartDialog.showToast(baseData.msg, alignment: Alignment.center);
}
}
///修改支付密码
modifyPayCode(String payCode,String code) async {
if (apiService == null) {
SharedPreferences value = await SharedPreferences.getInstance();
apiService = ApiService(Dio(),
context: context, token: value.getString("token"), showLoading: true);
}
BaseData baseData = await apiService.updatePayPwd({
"newPayPwd": payCode,
"smsCode": code,
}).catchError((error) {});
if (baseData != null && baseData.isSuccess) {
setState(() {
codeType=4;
});
SmartDialog.showToast(baseData.data, alignment: Alignment.center);
} else {
SmartDialog.showToast(baseData.msg, alignment: Alignment.center);
}
}
@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
},
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
leading: GestureDetector(
child: Icon(
Icons.arrow_back_ios,
color: Colors.black,
),
onTap: () {
Navigator.of(context).pop();
}),
title: Text(
S.of(context).pingtaizhifumima,
style: TextStyle(
fontWeight: MyFontWeight.regular,
fontSize: 17.sp,
color: Color(0xFF0D0D0D),
),
),
centerTitle: true,
elevation: 0.0,
),
body: Column(
children: [
if(codeType == 0)
verification(),
if(codeType ==1)
verificationIssued(),
if(codeType == 2 || codeType ==3)
settingCode(),
// if(codeType == 3)
// againSettingCode(),
if(codeType == 4)
codeSuccess(),
],
),
));
}
///设置密码
Widget settingCode() {
return Container(
alignment: Alignment.center,
margin: EdgeInsets.only(top: 28.h),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
codeType== 3?"请再次输入6位数字密码":"请输入6位数字密码",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 18.sp,
color: Color(0xFF353535),
),
),
SizedBox(
height: 12.h,
),
Text(
"将用于一心回乡APP下单时平台余额消费",
style: TextStyle(
fontWeight: MyFontWeight.medium,
fontSize: 14.sp,
color: Color(0xFFA29E9E),
),
),
Container(
margin: EdgeInsets.only(top: 24.h, bottom: 31.h),
padding: EdgeInsets.only(left: 48.w, right: 48.w),
height: 45.h,
child: PinInputTextField(
decoration: BoxLooseDecoration(
strokeColorBuilder: FixedColorBuilder(Color(0xFFEBEAEA)),
textStyle: TextStyle(
fontWeight: MyFontWeight.medium,
fontSize: 18.sp,
color: Color(0xFF353535),
),
radius: Radius.circular(4.r)),
),
),
GestureDetector(
onTap: (){
setState(() {
codeType = 3;
if(codeType == 3)
modifyPayCode("123656", "5394");
});
},
child: Container(
width: 163.w,
height: 46.h,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color(0xFFBBE7CC),
borderRadius: BorderRadius.circular(23.r),
),
child: Text(
codeType== 3?"确认":"下一步",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 18.sp,
color: Color(0xFFFFFFFF),
),
),
),
)
],
),
);
}
///再次输入密码
Widget againSettingCode() {
return Container(
alignment: Alignment.center,
margin: EdgeInsets.only(top: 28.h),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"请再次输入6位数字密码",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 18.sp,
color: Color(0xFF353535),
),
),
SizedBox(
height: 12.h,
),
Text(
"将用于一心回乡APP下单时平台余额消费",
style: TextStyle(
fontWeight: MyFontWeight.medium,
fontSize: 14.sp,
color: Color(0xFFA29E9E),
),
),
Container(
margin: EdgeInsets.only(top: 24.h, bottom: 31.h),
padding: EdgeInsets.only(left: 48.w, right: 48.w),
height: 45.h,
child: PinInputTextField(
decoration: BoxLooseDecoration(
strokeColorBuilder: FixedColorBuilder(Color(0xFFEBEAEA)),
textStyle: TextStyle(
fontWeight: MyFontWeight.medium,
fontSize: 18.sp,
color: Color(0xFF353535),
),
radius: Radius.circular(4.r)),
keyboardType: TextInputType.text,
),
),
GestureDetector(
onTap: (){
setState(() {
codeType = 4;
});
},
child: Container(
width: 163.w,
height: 46.h,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color(0xFFBBE7CC),
borderRadius: BorderRadius.circular(23.r),
),
child: Text(
"确认",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 18.sp,
color: Color(0xFFFFFFFF),
),
),
),
)
],
),
);
}
///忘记密码-验证
Widget verification() {
return Container(
alignment: Alignment.center,
margin: EdgeInsets.only(top: 28.h),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"为了确认身份,我们需要验证您的手机号",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 18.sp,
color: Color(0xFF353535),
),
),
SizedBox(
height: 14.h,
),
Text(
"点击发送短信,将会发送验证码至手机",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 14.sp,
color: Color(0xFFA29E9E),
),
),
SizedBox(
height: 14.h,
),
Text(
AppUtils.phoneEncode(widget.arguments["userInfo"]?.phone ?? ""),
style: TextStyle(
fontWeight: MyFontWeight.medium,
fontSize: 14.sp,
color: Color(0xFF353535),
),
),
GestureDetector(
onTap: () {
// sendCode();
setState(() {
codeType = 1;
});
},
child: Container(
width: 163.w,
height: 46.h,
alignment: Alignment.center,
margin: EdgeInsets.only(top: 34.h),
decoration: BoxDecoration(
color: Color(0xFF32A060),
borderRadius: BorderRadius.circular(23.r),
),
child: Text(
S.of(context).fasongduanxin,
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 18.sp,
color: Color(0xFFFFFFFF),
),
),
),
)
],
),
);
}
///验证码已发状态
Widget verificationIssued() {
return Container(
alignment: Alignment.center,
margin: EdgeInsets.only(top: 28.h),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"验证码已发至 176****998",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 18.sp,
color: Color(0xFF353535),
),
),
SizedBox(
height: 14.h,
),
Text(
"55S后可重发",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 14.sp,
color: Color(0xFFA29E9E),
),
),
SizedBox(
height: 14.h,
),
Container(
margin: EdgeInsets.only(top: 24.h, bottom: 31.h),
padding: EdgeInsets.only(left: 48.w, right: 48.w),
height: 55.h,
child: PinInputTextField(
pinLength: 4,
decoration: BoxLooseDecoration(
strokeColorBuilder: FixedColorBuilder(Color(0xFFEBEAEA)),
textStyle: TextStyle(
fontWeight: MyFontWeight.medium,
fontSize: 20.sp,
color: Color(0xFF353535),
),
radius: Radius.circular(4.r),
),
),
),
GestureDetector(
onTap: () {
setState(() {
codeType = 2;
});
},
child: Container(
width: 163.w,
height: 46.h,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color(0xFFBBE7CC),
borderRadius: BorderRadius.circular(23.r),
),
child: Text(
"下一步",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 18.sp,
color: Color(0xFFFFFFFF),
),
),
))
],
),
);
}
///设置密码成功状态
Widget codeSuccess() {
return Container(
alignment: Alignment.center,
margin: EdgeInsets.only(top: 31.h),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/image/icon_order_success.webp",
fit: BoxFit.cover,
width: 76,
height: 76,
),
SizedBox(
height: 16.h,
),
Text(
"设置密码成功",
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 21.sp,
color: Color(0xFF353535),
),
),
SizedBox(
height: 69.h,
),
GestureDetector(
onTap: () {
Navigator.of(context).pop();
},
child: Container(
width: double.infinity,
height: 46.h,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Color(0xFF32A060),
borderRadius: BorderRadius.circular(4.r),
),
margin: EdgeInsets.symmetric(horizontal: 16.w),
child: Text(
S.of(context).queren,
style: TextStyle(
fontWeight: MyFontWeight.semi_bold,
fontSize: 18.sp,
color: Color(0xFFFFFFFF),
),
),
),
)
],
),
);
}
///平台支付密码弹窗
assessShowBottomSheet() {
showModalBottomSheet(
context: context,
backgroundColor: Colors.transparent,
isScrollControlled: true,
builder: (context) {
return PaySelectedDialog();
},
);
}
}