562 lines
24 KiB
Dart
562 lines
24 KiB
Dart
import 'package:circle_app/commons/Widgets/base_tip_widget.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:gradient_borders/box_borders/gradient_box_border.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../../../commons/colors/app_color.dart';
|
|
import '../../../net/api.dart';
|
|
import '../../../net/dio_manager.dart';
|
|
import '../../../utils/SharedPreferencesHelper.dart';
|
|
import '../../../utils/util.dart';
|
|
|
|
class WxEditDialog extends StatefulWidget {
|
|
String phone;
|
|
|
|
WxEditDialog(this.phone, {super.key});
|
|
@override
|
|
_WxEditDialogState createState() => _WxEditDialogState();
|
|
}
|
|
|
|
class _WxEditDialogState extends State<WxEditDialog> {
|
|
// TODO: add state variables and methods
|
|
TextEditingController wxEditingController = TextEditingController();
|
|
TextEditingController descEditingController = TextEditingController();
|
|
TextEditingController moneyEditingController = TextEditingController();
|
|
|
|
Map wxInfo = {};
|
|
|
|
int type = 2;
|
|
|
|
Map wxStatusInfo = {};
|
|
|
|
String content = '';
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
loadDescData();
|
|
loadMyWxInfoData();
|
|
loadWxStatus();
|
|
// updateWxText();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// TODO: add widget build method
|
|
return GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: () {
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
},
|
|
child: Scaffold(
|
|
backgroundColor: Colors.transparent,
|
|
body: Center(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
padding: EdgeInsets.only(left: 15.sp, right: 15.sp),
|
|
height: 520.sp,
|
|
margin: EdgeInsets.only(left: 15.sp, right: 15.sp),
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage(getBaseImage("newgui_bg")),
|
|
fit: BoxFit.fill,
|
|
)),
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
margin: EdgeInsets.only(top: 18.sp),
|
|
child: ShaderMask(
|
|
shaderCallback: (Rect bounds) {
|
|
return const LinearGradient(
|
|
begin: Alignment(0.0, -1.0),
|
|
end: Alignment.bottomCenter,
|
|
colors: [Color(0xFFCE51FF), Color(0xFFFF8450)],
|
|
).createShader(Offset.zero & bounds.size);
|
|
},
|
|
child: Text(
|
|
'联系方式设置',
|
|
style: TextStyle(
|
|
// color: AppColor.mainColor,
|
|
color: Colors.white,
|
|
fontSize: 18.sp,
|
|
shadows: const [
|
|
Shadow(
|
|
color: Color(0xffF657FF),
|
|
offset: Offset(0.0, -1))
|
|
]),
|
|
),
|
|
)),
|
|
Container(
|
|
margin: EdgeInsets.only(bottom: 10.sp, top: 15.sp),
|
|
// height: 30.sp,
|
|
child: Row(
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {
|
|
showTipPop();
|
|
},
|
|
child: Container(
|
|
child: Row(
|
|
children: [
|
|
Image.asset(
|
|
getMineImage(type == 1
|
|
? 'phone_icon'
|
|
: type == 3
|
|
? 'qq'
|
|
: 'wx'),
|
|
width: 40.sp,
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(
|
|
left: 4.sp, right: 4.sp),
|
|
child: Icon(
|
|
Icons.change_circle,
|
|
color: AppColor.mainColor,
|
|
size: 30.sp,
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Container(
|
|
margin: EdgeInsets.only(right: 15.sp),
|
|
decoration: BoxDecoration(
|
|
color: Color(0xFF260C3E),
|
|
borderRadius: BorderRadius.circular(10.sp),
|
|
border: GradientBoxBorder(
|
|
gradient: AppColor.mainVerLinearGradient,
|
|
width: 1.sp,
|
|
),
|
|
),
|
|
child: TextField(
|
|
controller: wxEditingController,
|
|
maxLength: 20,
|
|
style: TextStyle(
|
|
color: Colors.white, fontSize: 16.sp),
|
|
decoration: InputDecoration(
|
|
hintText: '请输入真实的联系方式',
|
|
hintStyle: TextStyle(
|
|
color: Colors.white70, fontSize: 14.sp),
|
|
border: InputBorder.none,
|
|
counterText: '',
|
|
contentPadding: EdgeInsets.only(left: 14.sp)),
|
|
),
|
|
)),
|
|
GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: () {
|
|
if (wxInfo.containsKey('hideContact')) {
|
|
wxInfo['hideContact'] =
|
|
wxInfo['hideContact'] == 0 ? 1 : 0;
|
|
} else {
|
|
wxInfo['hideContact'] = 0;
|
|
}
|
|
showOKToast(wxInfo['hideContact'] == 1
|
|
? '已对其他人隐藏联系方式'
|
|
: '已对其他人展示联系方式(需要解锁)');
|
|
setState(() {});
|
|
},
|
|
child: Column(
|
|
children: [
|
|
Image.asset(
|
|
getMineImage(
|
|
wxInfo.containsKey('hideContact')
|
|
? wxInfo['hideContact'] == 1
|
|
? 'no_show_icon'
|
|
: 'show_icon'
|
|
: 'show_icon'),
|
|
width: 30.sp,
|
|
),
|
|
//已隐藏 显示中
|
|
Text(
|
|
wxInfo.containsKey('hideContact')
|
|
? wxInfo['hideContact'] == 1
|
|
? '已隐藏'
|
|
: '显示中'
|
|
: '显示中',
|
|
style: TextStyle(
|
|
color:
|
|
Color(0xCCFFFFFF).withOpacity(0.5),
|
|
fontSize: 14.sp),
|
|
)
|
|
],
|
|
))
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(right: 0.sp),
|
|
decoration: BoxDecoration(
|
|
color: Color(0xFF260C3E),
|
|
borderRadius: BorderRadius.circular(10.sp),
|
|
border: GradientBoxBorder(
|
|
gradient: AppColor.mainVerLinearGradient,
|
|
width: 1.sp,
|
|
),
|
|
),
|
|
child: TextField(
|
|
controller: descEditingController,
|
|
maxLength: 30,
|
|
style: TextStyle(color: Colors.white, fontSize: 16.sp),
|
|
// keyboardType: TextInputType.phone,
|
|
decoration: InputDecoration(
|
|
hintText: '请输入解锁引导语',
|
|
hintStyle: TextStyle(
|
|
color: Colors.white70, fontSize: 14.sp),
|
|
border: InputBorder.none,
|
|
counterText: '',
|
|
contentPadding: EdgeInsets.only(left: 14.sp)),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.sp),
|
|
child: Row(
|
|
children: [
|
|
Image.asset(
|
|
getBaseImage('day3_icon'),
|
|
width: 18.sp,
|
|
height: 18.sp,
|
|
),
|
|
SizedBox(
|
|
width: 2.sp,
|
|
),
|
|
Text(
|
|
'设置解锁价格',
|
|
style: TextStyle(
|
|
color: Color(0xCCFFFFFF), fontSize: 14.sp),
|
|
),
|
|
SizedBox(
|
|
width: 60.sp,
|
|
height: 30.sp,
|
|
child: Container(
|
|
margin: EdgeInsets.only(left: 5.sp, right: 5.sp),
|
|
decoration: BoxDecoration(
|
|
color: Color(0xFF260C3E),
|
|
borderRadius: BorderRadius.circular(10.sp),
|
|
// border: GradientBoxBorder(
|
|
// gradient:
|
|
// AppColor.newMainVerLinearGradient,
|
|
// width: 1.sp,
|
|
// ),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: TextField(
|
|
controller: moneyEditingController,
|
|
maxLength: 4,
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
color: Colors.white, fontSize: 14.sp),
|
|
keyboardType: TextInputType.phone,
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.digitsOnly,
|
|
],
|
|
decoration: InputDecoration(
|
|
hintText: '',
|
|
isCollapsed: true,
|
|
hintStyle: TextStyle(
|
|
color: Colors.white70,
|
|
fontSize: 14.sp),
|
|
border: InputBorder.none,
|
|
counterText: '',
|
|
contentPadding: EdgeInsets.only(
|
|
left: 6.sp,
|
|
right: 6.sp,
|
|
bottom: 0,
|
|
top: 0)),
|
|
))
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Text(
|
|
'元',
|
|
style: TextStyle(
|
|
color: Color(0xCCFFFFFF), fontSize: 14.sp),
|
|
),
|
|
Text(
|
|
'(可填10-520)',
|
|
style: TextStyle(
|
|
color: Color(0xCCFFFFFF).withOpacity(0.5),
|
|
fontSize: 14.sp),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.sp),
|
|
child: Text(
|
|
'温馨提示:\n' + '${content}',
|
|
style: TextStyle(
|
|
height: 1.5,
|
|
color: Color(0xCCFFFFFF).withOpacity(0.5),
|
|
fontSize: 14.sp),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.sp),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () {
|
|
Get.back();
|
|
},
|
|
child: Container(
|
|
height: 30.sp,
|
|
width: 100.sp,
|
|
alignment: Alignment.center,
|
|
padding:
|
|
EdgeInsets.only(left: 10.sp, right: 10.sp),
|
|
margin: EdgeInsets.only(bottom: 10.sp),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey.withOpacity(0.7),
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Text(
|
|
'放弃赚钱',
|
|
style: TextStyle(
|
|
color: Colors.white.withOpacity(0.75),
|
|
fontSize: 14.sp,
|
|
fontWeight: FontWeight.w500),
|
|
)),
|
|
),
|
|
GestureDetector(
|
|
onTap: () async {
|
|
bool isPass = false;
|
|
if (type == 2) {
|
|
if (wxEditingController.text.length == 11) {
|
|
RegExp exp = RegExp(
|
|
r'^((13[0-9])|(14[0-9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\d{8}$');
|
|
isPass =
|
|
exp.hasMatch(wxEditingController.text);
|
|
}
|
|
|
|
if (wxEditingController.text.isNotEmpty &&
|
|
!isPass) {
|
|
RegExp wxReg = RegExp(
|
|
r'^[-_a-zA-Z][-_a-zA-Z0-9]{5,19}$');
|
|
if (!wxReg
|
|
.hasMatch(wxEditingController.text)) {
|
|
showOKToast('请输入正确的微信号');
|
|
return;
|
|
}
|
|
}
|
|
} else if (type == 3) {
|
|
isPass = isValidQQ(wxEditingController.text);
|
|
if (!isPass) {
|
|
showOKToast('请输入正确的QQ号');
|
|
return;
|
|
}
|
|
} else if (type == 1) {
|
|
if (wxEditingController.text.length == 11) {
|
|
RegExp exp = RegExp(
|
|
r'^((13[0-9])|(14[0-9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\d{8}$');
|
|
isPass =
|
|
exp.hasMatch(wxEditingController.text);
|
|
}
|
|
if (!isPass) {
|
|
showOKToast('请输入正确的手机号');
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (moneyEditingController.text.isNotEmpty) {
|
|
if (int.parse(moneyEditingController.text) <=
|
|
0) {
|
|
showOKToast('请设置联系方式解锁金额大于零');
|
|
return;
|
|
} else if (int.parse(
|
|
moneyEditingController.text) >
|
|
520 ||
|
|
int.parse(moneyEditingController.text) <
|
|
10) {
|
|
showOKToast('请填写解锁金额在10元-520元之间');
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (wxInfo.containsKey('10034')) {
|
|
showOKToast(wxInfo['10034']);
|
|
return;
|
|
} else if (wxInfo.containsKey('10595')) {
|
|
showOKToast(wxInfo['10595']);
|
|
}
|
|
Map<String, dynamic> params = {
|
|
"guideText": descEditingController.text,
|
|
"hideContact": wxInfo.containsKey('hideContact')
|
|
? wxInfo['hideContact']
|
|
: 0,
|
|
'contactType': type,
|
|
"contact": wxEditingController.text
|
|
};
|
|
|
|
if (moneyEditingController.text.isNotEmpty) {
|
|
params['price'] = moneyEditingController.text;
|
|
}
|
|
|
|
var result = await DioManager()
|
|
.postBody(url: Api.confset, params: params);
|
|
if (result['code'] == 200) {
|
|
showOKToast('已设置成功,快去邀请圈友解锁呗~');
|
|
Get.back();
|
|
} else if (result['code'] == 10081) {
|
|
showRechargeScreenDialog('set_contact');
|
|
}
|
|
},
|
|
child: Container(
|
|
height: 30.sp,
|
|
width: 100.sp,
|
|
alignment: Alignment.center,
|
|
padding:
|
|
EdgeInsets.only(left: 10.sp, right: 10.sp),
|
|
margin: EdgeInsets.only(bottom: 10.sp),
|
|
decoration: BoxDecoration(
|
|
// color: const Color(0xFFFF4D7C),
|
|
borderRadius: BorderRadius.circular(20),
|
|
gradient: AppColor.mainVerLinearGradient),
|
|
child: Text(
|
|
'确认',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 14.sp,
|
|
fontWeight: FontWeight.w500),
|
|
)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
Get.back();
|
|
},
|
|
child: Container(
|
|
margin: EdgeInsets.only(top: 10.sp),
|
|
alignment: Alignment.center,
|
|
child: Image.asset(
|
|
getBaseImage('close_icon'),
|
|
width: 24.sp,
|
|
))),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void updateWxText() async {
|
|
if (widget.phone.isNotEmpty) {
|
|
SharedPreferences sharedPreferences =
|
|
await SharedPreferences.getInstance();
|
|
String loginPhone = await sharedPreferences
|
|
.getString(SharedPreferencesHelper.LOGINPHONE) ??
|
|
"";
|
|
wxEditingController.text = loginPhone;
|
|
type = 1;
|
|
wxInfo['hideContact'] = 0;
|
|
setState(() {});
|
|
}
|
|
}
|
|
|
|
void loadMyWxInfoData() async {
|
|
var data =
|
|
await DioManager.instance.get(url: Api.mycontactConf, params: {});
|
|
if (data['code'] == 200) {
|
|
wxInfo = data['data'];
|
|
|
|
if (widget.phone.isNotEmpty) {
|
|
updateWxText();
|
|
} else {
|
|
wxEditingController.text = wxInfo['contact'] ?? '';
|
|
type = wxInfo['contactType'] ?? 2;
|
|
wxInfo['hideContact'] =
|
|
wxInfo['hideContact'] == null ? 0 : wxInfo['hideContact'];
|
|
descEditingController.text = wxInfo['guideText'] ?? '';
|
|
moneyEditingController.text =
|
|
wxInfo['price'] != null ? wxInfo['price'].toString() : '';
|
|
setState(() {});
|
|
}
|
|
}
|
|
}
|
|
|
|
void loadWxStatus() async {
|
|
var result = await DioManager.getInstance().get(
|
|
url: Api.updateWxNumState,
|
|
);
|
|
if (result['code'] == 10034) {
|
|
wxInfo['10034'] = result['msg'];
|
|
} else if (result['code'] == 10595) {
|
|
wxInfo['10595'] = result['msg'];
|
|
}
|
|
}
|
|
|
|
showTipPop() {
|
|
Get.bottomSheet(
|
|
CupertinoActionSheet(
|
|
title: Text(
|
|
'联系方式',
|
|
style: TextStyle(fontSize: 22),
|
|
), //标题
|
|
//提示内容
|
|
actions: <Widget>[
|
|
//操作按钮集合
|
|
CupertinoActionSheetAction(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
type = 1;
|
|
setState(() {});
|
|
},
|
|
child: Text('手机号'),
|
|
),
|
|
CupertinoActionSheetAction(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
type = 3;
|
|
setState(() {});
|
|
},
|
|
child: Text('QQ'),
|
|
),
|
|
CupertinoActionSheetAction(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
type = 2;
|
|
setState(() {});
|
|
},
|
|
child: Text('微信'),
|
|
),
|
|
],
|
|
cancelButton: CupertinoActionSheetAction(
|
|
//取消按钮
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
child: Text('取消'),
|
|
),
|
|
),
|
|
isScrollControlled: true);
|
|
}
|
|
|
|
void loadDescData() async {
|
|
var data = await DioManager.instance.get(url: Api.contactGuide,);
|
|
if (data['code'] == 10000) {
|
|
content = data['content'];
|
|
if (mounted) {
|
|
setState(() {});
|
|
}
|
|
}
|
|
}
|
|
}
|