starwork_flutter/lib/views/team/addPerson/add_person_view.dart

614 lines
30 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:starwork_flutter/api/model/team/response/depart_list_reponse.dart';
import 'package:starwork_flutter/api/model/team/response/role_list_response.dart';
import 'package:starwork_flutter/base/app_logger.dart';
import 'package:starwork_flutter/common/constant/app_colors.dart';
import 'package:starwork_flutter/common/constant/app_view_parameter_keys.dart';
import 'package:starwork_flutter/common/widgets/custom_cell_list_widget.dart';
import 'package:starwork_flutter/common/widgets/custom_cell_widget.dart';
import 'package:starwork_flutter/common/widgets/custome_app_bar_wdiget.dart';
import 'package:starwork_flutter/extension/function_extension.dart';
import 'package:starwork_flutter/routes/app_routes.dart';
import 'add_person_controller.dart';
class AddPersonView extends GetView<AddPersonController> {
@override
Widget build(BuildContext context) {
// 即使不使用,只是引用一下 controller 就能触发初始化
final _ = controller; // 添加这一行
return GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
},
child: Scaffold(
backgroundColor: AppColors.scaffoldBackgroundColor,
appBar: CustomAppBarWidget(
title: '添加人员'.tr,
backgroundColor: AppColors.scaffoldBackgroundColor,
),
body: SafeArea(
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(
left: 10.w,
right: 10.w,
bottom: 10.h,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'基本信息'.tr,
style: TextStyle(
fontSize: 12.sp,
color: Colors.black54,
fontWeight: FontWeight.w400,
),
),
SizedBox(
height: 6.h,
),
Obx(
() => CustomCellListWidget(
children: [
CustomCellWidget(
onTap: () async {
final result = await Get.toNamed(AppRoutes.teamSelectOrganization);
if (result != null && result is DepartItem) {
controller.selectedDepartItem.value = result;
}
},
leftText: '组织'.tr,
leftIcon: Icon(
Icons.circle,
size: 4.w,
color: Colors.red,
),
rightWidget: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Obx(
() => Text(
controller.selectedDepartItem.value.departName ?? '请选择',
style: TextStyle(
fontSize: 14.sp,
color: Colors.black54,
fontWeight: FontWeight.w400,
),
),
),
SizedBox(
width: 4.w,
),
Icon(
Icons.arrow_forward_ios_rounded,
size: 16.sp,
color: Colors.grey[300],
)
],
),
),
CustomCellWidget(
onTap: () {},
leftText: '姓名'.tr,
leftIcon: Icon(
Icons.circle,
size: 4.w,
color: Colors.red,
),
rightWidget: Expanded(
flex: 3,
child: TextField(
controller: controller.nameInputController,
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 14.sp,
),
decoration: InputDecoration(
isCollapsed: true,
hintText: '请输入姓名'.tr,
hintStyle: TextStyle(
fontSize: 14.sp,
color: Colors.black54,
fontWeight: FontWeight.w400,
),
// 设置无边框
border: InputBorder.none,
contentPadding: EdgeInsets.zero,
// 获取焦点时的边框
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
),
),
),
),
CustomCellWidget(
onTap: () {},
leftText: '手机号'.tr,
leftIcon: controller.isOpeningAccount.value
? Icon(
Icons.circle,
size: 4.w,
color: Colors.red,
)
: null,
rightWidget: Expanded(
flex: 3,
child: TextField(
controller: controller.phoneInputController,
keyboardType: TextInputType.number,
textInputAction: TextInputAction.next,
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 14.sp,
),
decoration: InputDecoration(
isCollapsed: true,
hintText: controller.isOpeningAccount.value ? '若开通账号则必填'.tr : '请输入手机号'.tr,
hintStyle: TextStyle(
fontSize: 14.sp,
color: Colors.black54,
fontWeight: FontWeight.w400,
),
// 设置无边框
border: InputBorder.none,
contentPadding: EdgeInsets.zero,
// 获取焦点时的边框
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
),
),
),
),
CustomCellWidget(
onTap: () {},
leftText: '开通账号'.tr,
leftSubText: '可登录并使用应用或管理功能',
leftIcon: Icon(
Icons.circle,
size: 4.w,
color: Colors.red,
),
rightWidget: Obx(
() => CupertinoSwitch(
value: controller.isOpeningAccount.value,
onChanged: (bool value) {
controller.isOpeningAccount.value = value;
},
activeColor: Colors.blue, // 可选打开时的颜色iOS 默认为系统蓝色,可自定义)
trackColor: Colors.grey, // 可选:关闭时的背景轨道颜色
),
),
),
CustomCellWidget(
onTap: () async {
var result =
await Get.toNamed(AppRoutes.teamSelectRole, arguments: controller.selectedRoles);
if (result != null) {
// 处理返回的角色数据
if (result is List<RoleListResponse>) {
controller.selectedRoles.value = result;
controller.selectedRoles.refresh();
// 收起键盘
FocusScope.of(Get.context!).unfocus();
}
}
},
leftText: '分配权限'.tr,
leftIcon: Icon(
Icons.circle,
size: 4.w,
color: Colors.red,
),
rightWidget: Container(
alignment: Alignment.centerRight,
constraints: BoxConstraints(
maxWidth: 200.w,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Obx(
() => Expanded(
child: Text(
textAlign: TextAlign.end,
controller.getSelectedRoleDisplayText(),
style: TextStyle(
fontSize: 14.sp,
color: Colors.black54,
fontWeight: FontWeight.w400,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
),
SizedBox(
width: 4.w,
),
Icon(
Icons.arrow_forward_ios_rounded,
size: 16.sp,
color: Colors.grey[300],
)
],
),
),
)
],
),
),
SizedBox(
height: 10.h,
),
Text(
'扩展信息'.tr,
style: TextStyle(
fontSize: 12.sp,
color: Colors.black54,
fontWeight: FontWeight.w400,
),
),
SizedBox(
height: 10.h,
),
CustomCellListWidget(
children: [
CustomCellWidget(
onTap: () {},
leftText: '工号'.tr,
rightWidget: Expanded(
flex: 3,
child: TextField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 14.sp,
),
decoration: InputDecoration(
isCollapsed: true,
hintText: '选填'.tr,
hintStyle: TextStyle(
fontSize: 14.sp,
color: Colors.black54,
fontWeight: FontWeight.w400,
),
// 设置无边框
border: InputBorder.none,
contentPadding: EdgeInsets.zero,
// 获取焦点时的边框
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
),
),
),
),
CustomCellWidget(
onTap: () {},
leftText: '性别'.tr,
rightWidget: Obx(
() => Row(
children: [
Radio<String>(
value: 'male',
activeColor: Colors.blue,
groupValue: controller.selectedGender.value,
visualDensity: VisualDensity.compact,
onChanged: (value) {
controller.selectedGender.value = value!;
},
),
Text(''),
Radio<String>(
value: 'female',
activeColor: Colors.blue,
groupValue: controller.selectedGender.value,
visualDensity: VisualDensity.compact,
onChanged: (value) {
controller.selectedGender.value = value!;
},
),
Text(''),
],
),
),
),
CustomCellWidget(
onTap: () async {
var result = await Get.toNamed(AppRoutes.teamAddPersonEditValidity, arguments: {
AppViewParameterKeys.isLongTerm: controller.isLongTerm.value,
AppViewParameterKeys.startDate: controller.startDate.value,
AppViewParameterKeys.endDate: controller.endDate.value,
});
if (result != null) {
controller.isLongTerm.value = result[AppViewParameterKeys.isLongTerm];
if (controller.isLongTerm.isFalse) {
controller.startDate.value = result[AppViewParameterKeys.startDate];
controller.endDate.value = result[AppViewParameterKeys.endDate];
}
}
},
leftText: '有效期'.tr,
rightWidget: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Obx(
() => Text(
controller.isLongTerm.value
? '长期'.tr
: '${controller.formatTimestamp(controller.startDate.value)} - '
'${controller.formatTimestamp(controller.endDate.value)}',
style: TextStyle(
fontSize: 14.sp,
color: Colors.black54,
fontWeight: FontWeight.w400,
),
),
),
SizedBox(
width: 4.w,
),
Icon(
Icons.arrow_forward_ios_rounded,
size: 16.sp,
color: Colors.grey[300],
)
],
),
),
CustomCellWidget(
onTap: () {},
leftText: '职务'.tr,
rightWidget: Expanded(
flex: 3,
child: TextField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 14.sp,
),
decoration: InputDecoration(
isCollapsed: true,
hintText: '选填'.tr,
hintStyle: TextStyle(
fontSize: 14.sp,
color: Colors.black54,
fontWeight: FontWeight.w400,
),
// 设置无边框
border: InputBorder.none,
contentPadding: EdgeInsets.zero,
// 获取焦点时的边框
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
),
),
),
),
CustomCellWidget(
onTap: () {},
leftText: '备注'.tr,
rightWidget: Expanded(
flex: 3,
child: TextField(
controller: controller.remarkInputController,
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 14.sp,
),
decoration: InputDecoration(
isCollapsed: true,
hintText: '选填'.tr,
hintStyle: TextStyle(
fontSize: 14.sp,
color: Colors.black54,
fontWeight: FontWeight.w400,
),
// 设置无边框
border: InputBorder.none,
contentPadding: EdgeInsets.zero,
// 获取焦点时的边框
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
),
),
),
),
CustomCellWidget(
onTap: () {},
leftText: '身份证号码'.tr,
rightWidget: Expanded(
flex: 3,
child: TextField(
controller: controller.idCardInputController,
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 14.sp,
),
decoration: InputDecoration(
isCollapsed: true,
hintText: '选填'.tr,
hintStyle: TextStyle(
fontSize: 14.sp,
color: Colors.black54,
fontWeight: FontWeight.w400,
),
// 设置无边框
border: InputBorder.none,
contentPadding: EdgeInsets.zero,
// 获取焦点时的边框
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
),
),
),
),
],
),
SizedBox(
height: 10.h,
),
SizedBox(
width: double.infinity,
child: Text(
textAlign: TextAlign.center,
'温馨提示:人脸/指纹/卡片信息需先保存后录入',
style: TextStyle(
fontSize: 12.sp,
color: Colors.grey,
fontWeight: FontWeight.w400,
),
),
),
SizedBox(
height: 10.h,
),
CustomCellListWidget(
children: [
CustomCellWidget(
onTap: () {
controller.showFunctionNotOpen();
},
leftText: '其他添加方式'.tr,
rightWidget: Icon(
Icons.arrow_forward_ios_rounded,
size: 16.sp,
color: Colors.grey,
),
),
],
),
],
),
Column(
children: [
Row(
children: [
Checkbox(
value: true,
// 转换为 bool
onChanged: (bool? value) {},
),
Text(
'向用户发送短信邀请通知',
style: TextStyle(
fontSize: 12.sp,
color: Colors.grey,
fontWeight: FontWeight.w400,
),
)
],
),
SizedBox(
width: double.infinity,
child: Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () {
if (controller.selectedDepartItem.value.departNo == null) {
controller.showToast('请先选择组织'.tr);
return;
}
if (controller.nameInputController.text.isEmpty) {
controller.showToast('请输入姓名'.tr);
return;
}
if (controller.phoneInputController.text.isEmpty &&
controller.isOpeningAccount.isTrue) {
controller.showToast('请输入手机号'.tr);
return;
}
if (controller.selectedRoles.isEmpty) {
controller.showToast('请先选择角色'.tr);
return;
}
controller.savePerson();
}.debounce(),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.grey[100],
padding: EdgeInsets.symmetric(vertical: 12.h),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.r),
),
),
child: Text(
'保存'.tr,
style: TextStyle(
fontSize: 16.sp,
color: Colors.blue,
fontWeight: FontWeight.w500,
),
),
),
),
SizedBox(
width: 10.w,
),
Expanded(
child: ElevatedButton(
onPressed: () {
if (controller.selectedDepartItem.value.departNo == null) {
controller.showToast('请先选择组织'.tr);
return;
}
if (controller.nameInputController.text.isEmpty) {
controller.showToast('请输入姓名'.tr);
return;
}
if (controller.phoneInputController.text.isEmpty &&
controller.isOpeningAccount.isTrue) {
controller.showToast('请输入手机号'.tr);
return;
}
if (controller.selectedRoles.isEmpty) {
controller.showToast('请先选择角色'.tr);
return;
}
controller.savePerson(isSustain: true);
}.debounce(),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
padding: EdgeInsets.symmetric(vertical: 12.h),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.r)),
),
child: Text(
'保存并继续添加'.tr,
style: TextStyle(
fontSize: 16.sp,
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
),
),
],
),
),
],
)
],
),
),
),
),
),
);
}
}