|
...
|
...
|
@@ -2,9 +2,13 @@ import 'package:common_utils/common_utils.dart'; |
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_lunar_datetime_picker/date_init.dart';
|
|
|
|
import 'package:flutter_picker_plus/picker.dart';
|
|
|
|
import 'package:lunar/calendar/Lunar.dart';
|
|
|
|
import 'package:lunar/calendar/Solar.dart';
|
|
|
|
import 'package:one_key/provider/customer_provider.dart';
|
|
|
|
import 'package:one_key/res/colors.dart';
|
|
|
|
import 'package:one_key/utils/dialog_util.dart';
|
|
|
|
import 'package:one_key/utils/event_bus.dart';
|
|
|
|
import 'package:one_key/utils/pick_date_nonli_gongli/lunar_calendar_util.dart';
|
|
|
|
import 'package:one_key/utils/screen_util.dart';
|
|
|
|
import 'package:one_key/utils/utils.dart';
|
|
|
|
import 'package:one_key/widgets/MyDivider.dart';
|
|
...
|
...
|
@@ -22,7 +26,16 @@ import 'package:flutter_lunar_datetime_picker/datetime_picker_theme.dart' |
|
|
|
*/
|
|
|
|
class SetBirthdayPage extends StatefulWidget {
|
|
|
|
final String? gid;
|
|
|
|
const SetBirthdayPage({super.key, required this.gid});
|
|
|
|
final String from;
|
|
|
|
final String birthdayLunar;
|
|
|
|
final String birthdaySolar;
|
|
|
|
|
|
|
|
const SetBirthdayPage(
|
|
|
|
{super.key,
|
|
|
|
required this.gid,
|
|
|
|
this.from = 'store',
|
|
|
|
required this.birthdayLunar,
|
|
|
|
required this.birthdaySolar});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<SetBirthdayPage> createState() => _SetBirthdayPageState();
|
|
...
|
...
|
@@ -31,7 +44,42 @@ class SetBirthdayPage extends StatefulWidget { |
|
|
|
class _SetBirthdayPageState extends State<SetBirthdayPage> {
|
|
|
|
late CustomerProvider customerProvider;
|
|
|
|
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
String birthday = '';
|
|
|
|
String birthdayLunar = ''; //农历生日
|
|
|
|
String birthdaySolar = ''; //阳历生日
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
// TODO: implement initState
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
if (widget.birthdaySolar == 'null' || widget.birthdaySolar == '') {
|
|
|
|
birthdaySolar = '';
|
|
|
|
} else {
|
|
|
|
birthdaySolar = DateUtil.formatDate(
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(
|
|
|
|
int.parse(widget.birthdaySolar) * 1000),
|
|
|
|
format: DateFormats.zh_y_mo_d);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (widget.birthdayLunar == 'null' || widget.birthdayLunar == '') {
|
|
|
|
birthdayLunar = '';
|
|
|
|
} else {
|
|
|
|
DateTime time = DateTime.fromMillisecondsSinceEpoch(
|
|
|
|
int.parse(widget.birthdayLunar) * 1000);
|
|
|
|
|
|
|
|
// 获取当前阴历
|
|
|
|
Lunar currentLunarTime = Solar.fromDate(time).getLunar();
|
|
|
|
String yearStr = currentLunarTime.getYear().toString();
|
|
|
|
String monthStr = currentLunarTime.getMonth().abs().toString();
|
|
|
|
String dayStr = currentLunarTime.getDay().toString();
|
|
|
|
//转换成农历
|
|
|
|
|
|
|
|
birthdayLunar = (yearStr) +
|
|
|
|
'年' +
|
|
|
|
LunarCalendarUtil.formatLunarDate(
|
|
|
|
int.parse(monthStr), int.parse(dayStr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_item(
|
|
|
|
String title,
|
|
...
|
...
|
@@ -53,15 +101,16 @@ class _SetBirthdayPageState extends State<SetBirthdayPage> { |
|
|
|
fontSize: font(16), color: MyColours.color_438E93),
|
|
|
|
),
|
|
|
|
Spacer(),
|
|
|
|
InkWell(
|
|
|
|
onTap: onTapDel,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: w(10)),
|
|
|
|
child: Image.asset(
|
|
|
|
Utils.getImgPath('f_delete_red'),
|
|
|
|
width: w(20),
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
if (subTitle != '')
|
|
|
|
InkWell(
|
|
|
|
onTap: onTapDel,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: w(10)),
|
|
|
|
child: Image.asset(
|
|
|
|
Utils.getImgPath('f_delete_red'),
|
|
|
|
width: w(20),
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
InkWell(
|
|
|
|
onTap: onTapEdit,
|
|
|
|
child: Padding(
|
|
...
|
...
|
@@ -73,11 +122,13 @@ class _SetBirthdayPageState extends State<SetBirthdayPage> { |
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
VEmptyView(40),
|
|
|
|
Text(
|
|
|
|
'(${title})${subTitle}',
|
|
|
|
style: TextStyle(fontSize: font(16), color: MyColours.color_000000),
|
|
|
|
),
|
|
|
|
if (subTitle != '') VEmptyView(40),
|
|
|
|
if (subTitle != '')
|
|
|
|
Text(
|
|
|
|
'(${title})${subTitle}',
|
|
|
|
style:
|
|
|
|
TextStyle(fontSize: font(16), color: MyColours.color_000000),
|
|
|
|
),
|
|
|
|
VEmptyView(20),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: w(10)),
|
|
...
|
...
|
@@ -92,6 +143,35 @@ class _SetBirthdayPageState extends State<SetBirthdayPage> { |
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_del(String field) async {
|
|
|
|
Map<String, String?> params = {
|
|
|
|
'id': widget.gid,
|
|
|
|
'${field}': null,
|
|
|
|
};
|
|
|
|
bool sucess =
|
|
|
|
await customerProvider.setGuestInfo(context, params, showLoading: true);
|
|
|
|
|
|
|
|
if (sucess) {
|
|
|
|
Utils.showToast('删除成功');
|
|
|
|
|
|
|
|
if (field == 'n_day') {
|
|
|
|
//农历
|
|
|
|
birthdayLunar = '';
|
|
|
|
} else {
|
|
|
|
//阳历
|
|
|
|
birthdaySolar = '';
|
|
|
|
}
|
|
|
|
setState(() {});
|
|
|
|
if (widget.from == 'store') {
|
|
|
|
//刷新全店客情详情页
|
|
|
|
bus.emit('refresh_guest_info');
|
|
|
|
} else {
|
|
|
|
//刷新我的客情详情页
|
|
|
|
bus.emit('refresh_guest_info_my');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
customerProvider = Provider.of<CustomerProvider>(context, listen: true);
|
|
...
|
...
|
@@ -103,7 +183,26 @@ class _SetBirthdayPageState extends State<SetBirthdayPage> { |
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
VEmptyView(40),
|
|
|
|
_item('公历', '1993年1月3日', onTapDel: () {}, onTapEdit: () {
|
|
|
|
_item('公历', birthdaySolar, onTapDel: () {
|
|
|
|
//删除生日
|
|
|
|
//弹框确认是否删除
|
|
|
|
DialogUtil.cupertinoAlertDialog(context,
|
|
|
|
title: "",
|
|
|
|
content: "是否删除公历生日",
|
|
|
|
rTitle: "删除", rCallback: () {
|
|
|
|
// if (Navigator.canPop(context)) {
|
|
|
|
// Navigator.pop(context);
|
|
|
|
// }
|
|
|
|
_del('c_day');
|
|
|
|
});
|
|
|
|
}, onTapEdit: () {
|
|
|
|
DateTime now = DateTime.now();
|
|
|
|
if (widget.birthdaySolar != 'null' &&
|
|
|
|
widget.birthdaySolar != '') {
|
|
|
|
now = DateTime.fromMillisecondsSinceEpoch(
|
|
|
|
int.parse(widget.birthdaySolar) * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
DatePicker.showDatePicker(
|
|
|
|
context,
|
|
|
|
lunarPicker: false,
|
|
...
|
...
|
@@ -120,11 +219,37 @@ class _SetBirthdayPageState extends State<SetBirthdayPage> { |
|
|
|
doneStyle: TextStyle(
|
|
|
|
color: MyColours.color_438E93, fontSize: font(16))),
|
|
|
|
dateInitTime: DateInitTime(
|
|
|
|
currentTime: DateTime.now(),
|
|
|
|
currentTime: now,
|
|
|
|
maxTime: DateTime(2050, 12, 12),
|
|
|
|
minTime: DateTime(1900, 1, 1)),
|
|
|
|
onConfirm: (time, lunar) {
|
|
|
|
onConfirm: (time, lunar) async {
|
|
|
|
debugPrint(time.toString());
|
|
|
|
//保存
|
|
|
|
|
|
|
|
print(time.millisecondsSinceEpoch);
|
|
|
|
// 请求接口,设置生日
|
|
|
|
String from =
|
|
|
|
'${time.year}-${Utils.addZeroNumber(time.month)}-${Utils.addZeroNumber(time.day)}' +
|
|
|
|
' 00:00:00';
|
|
|
|
Map<String, String?> params = {
|
|
|
|
'id': widget.gid,
|
|
|
|
'c_day':
|
|
|
|
'${(DateUtil.getDateMsByTimeStr(from)! / 1000).floor()}',
|
|
|
|
};
|
|
|
|
bool sucess = await customerProvider
|
|
|
|
.setGuestInfo(context, params, showLoading: true);
|
|
|
|
if (sucess) {
|
|
|
|
Utils.showToast('保存成功');
|
|
|
|
birthdaySolar = '${time.year}年${time.month}月${time.day}日';
|
|
|
|
setState(() {});
|
|
|
|
if (widget.from == 'store') {
|
|
|
|
//刷新全店客情详情页
|
|
|
|
bus.emit('refresh_guest_info');
|
|
|
|
} else {
|
|
|
|
//刷新我的客情详情页
|
|
|
|
bus.emit('refresh_guest_info_my');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onChanged: (time, lunar) {
|
|
|
|
debugPrint("change:${time.toString()}");
|
|
...
|
...
|
@@ -168,7 +293,26 @@ class _SetBirthdayPageState extends State<SetBirthdayPage> { |
|
|
|
// });
|
|
|
|
}),
|
|
|
|
VEmptyView(40),
|
|
|
|
_item('农历', '1969年三月廿五', onTapDel: () {}, onTapEdit: () {
|
|
|
|
_item('农历', birthdayLunar, onTapDel: () {
|
|
|
|
//删除生日
|
|
|
|
|
|
|
|
//弹框确认是否删除
|
|
|
|
DialogUtil.cupertinoAlertDialog(context,
|
|
|
|
title: "",
|
|
|
|
content: "是否删除农历生日",
|
|
|
|
rTitle: "删除", rCallback: () {
|
|
|
|
// if (Navigator.canPop(context)) {
|
|
|
|
// Navigator.pop(context);
|
|
|
|
// }
|
|
|
|
_del('n_day');
|
|
|
|
});
|
|
|
|
}, onTapEdit: () {
|
|
|
|
DateTime now = DateTime.now();
|
|
|
|
if (widget.birthdayLunar != 'null' &&
|
|
|
|
widget.birthdayLunar != '') {
|
|
|
|
now = DateTime.fromMillisecondsSinceEpoch(
|
|
|
|
int.parse(widget.birthdayLunar) * 1000);
|
|
|
|
}
|
|
|
|
DatePicker.showDatePicker(
|
|
|
|
context,
|
|
|
|
lunarPicker: true,
|
|
...
|
...
|
@@ -185,11 +329,49 @@ class _SetBirthdayPageState extends State<SetBirthdayPage> { |
|
|
|
doneStyle: TextStyle(
|
|
|
|
color: MyColours.color_438E93, fontSize: font(16))),
|
|
|
|
dateInitTime: DateInitTime(
|
|
|
|
currentTime: DateTime.now(),
|
|
|
|
currentTime: now,
|
|
|
|
maxTime: DateTime(2050, 12, 12),
|
|
|
|
minTime: DateTime(1900, 1, 1)),
|
|
|
|
onConfirm: (time, lunar) {
|
|
|
|
onConfirm: (time, lunar) async {
|
|
|
|
debugPrint(time.toString());
|
|
|
|
|
|
|
|
print(time.millisecondsSinceEpoch);
|
|
|
|
// 请求接口,设置生日
|
|
|
|
String from =
|
|
|
|
'${time.year}-${Utils.addZeroNumber(time.month)}-${Utils.addZeroNumber(time.day)}' +
|
|
|
|
' 00:00:00';
|
|
|
|
Map<String, String?> params = {
|
|
|
|
'id': widget.gid,
|
|
|
|
'n_day':
|
|
|
|
'${(DateUtil.getDateMsByTimeStr(from)! / 1000).floor()}',
|
|
|
|
};
|
|
|
|
bool sucess = await customerProvider
|
|
|
|
.setGuestInfo(context, params, showLoading: true);
|
|
|
|
|
|
|
|
if (sucess) {
|
|
|
|
Utils.showToast('保存成功');
|
|
|
|
|
|
|
|
// 获取当前阴历
|
|
|
|
Lunar currentLunarTime = Solar.fromDate(time).getLunar();
|
|
|
|
String yearStr = currentLunarTime.getYear().toString();
|
|
|
|
String monthStr =
|
|
|
|
currentLunarTime.getMonth().abs().toString();
|
|
|
|
String dayStr = currentLunarTime.getDay().toString();
|
|
|
|
//转换成农历
|
|
|
|
|
|
|
|
birthdayLunar = (yearStr) +
|
|
|
|
'年' +
|
|
|
|
LunarCalendarUtil.formatLunarDate(
|
|
|
|
int.parse(monthStr), int.parse(dayStr));
|
|
|
|
setState(() {});
|
|
|
|
if (widget.from == 'store') {
|
|
|
|
//刷新全店客情详情页
|
|
|
|
bus.emit('refresh_guest_info');
|
|
|
|
} else {
|
|
|
|
//刷新我的客情详情页
|
|
|
|
bus.emit('refresh_guest_info_my');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onChanged: (time, lunar) {
|
|
|
|
debugPrint("change:${time.toString()}");
|
...
|
...
|
|