mobile_skt/lib/screens/hr_manage/components/edit_userinfo.dart

295 lines
10 KiB
Dart
Raw Normal View History

2024-04-09 08:31:17 +08:00
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sk_base_mobile/apis/api.dart';
2024-04-09 08:31:17 +08:00
import 'package:sk_base_mobile/app_theme.dart';
import 'package:sk_base_mobile/constants/bg_color.dart';
import 'package:sk_base_mobile/models/user_info.model.dart';
import 'package:sk_base_mobile/screens/hr_manage/components/dept_picker.dart';
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
import 'package:sk_base_mobile/util/snack_bar.util.dart';
import 'package:sk_base_mobile/widgets/core/sk_cascade_picker.dart';
import 'package:sk_base_mobile/widgets/core/sk_dialog_header.dart';
import 'package:sk_base_mobile/widgets/core/sk_text_input.dart';
import 'package:sk_base_mobile/widgets/gradient_button.dart';
/// 编辑用户信息
class EditUserInfo extends StatelessWidget {
final int userId;
final EditUserInfoController controller;
EditUserInfo({super.key, required this.userId})
: controller = Get.put(EditUserInfoController(userId));
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
},
child: buildBody(),
);
}
Widget buildBody() {
return Column(
children: [
const SkDialogHeader(title: '编辑员工信息'),
Expanded(
child: SingleChildScrollView(
child: Container(
padding: EdgeInsets.symmetric(
horizontal: ScreenAdaper.height(15),
vertical: ScreenAdaper.height(15)),
child: Column(children: [
buildAvatar(),
SizedBox(
height: ScreenAdaper.height(defaultPadding),
),
/// 姓名
2024-04-09 08:31:17 +08:00
SkTextInput(
isDense: true,
textController: controller.nameEditController,
labelText: '姓名',
),
SizedBox(
height: ScreenAdaper.height(defaultPadding),
),
/// 部门
2024-04-09 08:31:17 +08:00
SkTextInput(
isDense: true,
keyboardType: TextInputType.none,
textController: controller.deptEditController,
2024-04-09 08:31:17 +08:00
labelText: '所属部门',
onTap: (_) async {
Get.bottomSheet(DeptPicker(onSelected: (String label) {
controller.deptEditController.text = label;
}));
2024-04-09 08:31:17 +08:00
},
),
SizedBox(
height: ScreenAdaper.height(defaultPadding),
),
/// 角色
2024-04-09 08:31:17 +08:00
SkTextInput(
isDense: true,
keyboardType: TextInputType.none,
textController: TextEditingController(),
labelText: '角色',
onTap: (_) async {
Get.bottomSheet(Container(
height: ScreenAdaper.height(400),
decoration:
const BoxDecoration(color: AppTheme.nearlyWhite),
2024-04-09 08:31:17 +08:00
child: Column(children: [
Container(
padding: EdgeInsets.symmetric(
vertical: ScreenAdaper.height(20),
horizontal: ScreenAdaper.width(20)),
child: Row(
children: [
Text(
'取消',
style: TextStyle(
fontSize: ScreenAdaper.height(30)),
),
const Spacer(),
2024-04-09 08:31:17 +08:00
Text(
'确定',
style: TextStyle(
fontSize: ScreenAdaper.height(30),
color: AppTheme.primaryColor),
)
],
),
),
Expanded(
child: SingleChildScrollView(
child: ListBody(
children: <String>[
'角色1',
'角色2',
'角色3',
'角色4',
'角色5',
'角色6',
'角色7',
'角色8',
'角色9'
].map((String text) {
return Obx(
() => CheckboxListTile(
contentPadding: EdgeInsets.symmetric(
vertical: ScreenAdaper.height(0),
horizontal: ScreenAdaper.width(20)),
title: Text(text),
value:
controller.selectedDepts.contains(text),
onChanged: (bool? value) {
if (value == true) {
controller.selectedDepts.add(text);
} else {
controller.selectedDepts.remove(text);
}
},
),
);
}).toList(),
),
))
]),
));
}),
SizedBox(
height: ScreenAdaper.height(defaultPadding),
),
SkTextInput(
isDense: true,
textController: TextEditingController(),
labelText: '登录用户名',
),
SizedBox(
height: ScreenAdaper.height(defaultPadding),
),
SkTextInput(
isDense: true,
textController: TextEditingController(),
labelText: '手机号',
)
]),
),
)),
const GradientButton(
borderRadius: BorderRadius.zero,
buttonText: '提交',
)
// Container(
// decoration: BoxDecoration(color: AppTheme.primaryColor),
// height: 100,
// )
],
);
}
Widget buildAvatar() {
return Column(
children: [
SizedBox(
height: ScreenAdaper.height(10),
),
buildImageUploader(),
],
);
}
Widget builderImagePreview(String path, String type) {
return Stack(
children: [
Container(
margin: EdgeInsets.symmetric(horizontal: ScreenAdaper.width(5)),
width: ScreenAdaper.width(180),
height: ScreenAdaper.width(180),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(width: 1.0, color: AppTheme.dividerColor),
// color: AppTheme.primaryColor,
),
child: Center(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
fit: BoxFit.cover,
image: FileImage(File(path)),
),
),
),
),
),
Positioned(
top: ScreenAdaper.height(5),
right: ScreenAdaper.width(5),
child: GestureDetector(
onTap: () {
if (type == 'agent') {
// controller.uploadAgentImgFilesPath.remove(path);
} else {
// controller.uploadProductImgFilesPath.remove(path);
}
},
child: Icon(
Icons.close,
shadows: const [
Shadow(
color: Colors.black,
offset: Offset(1, 1),
blurRadius: 3,
),
Shadow(
color: Colors.black,
offset: Offset(-1, -1),
blurRadius: 3,
),
],
size: ScreenAdaper.height(40),
color: AppTheme.nearlyWhite,
),
))
],
);
}
// 上传照片控制器
Widget buildImageUploader() {
return GestureDetector(
onTap: () {
// controller.photoPicker(type);
},
child: Container(
margin: EdgeInsets.symmetric(horizontal: ScreenAdaper.width(5)),
width: ScreenAdaper.width(180),
height: ScreenAdaper.width(180),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
border: Border.all(width: 1.0, color: AppTheme.dividerColor),
// color: AppTheme.primaryColor,
),
child: Center(
child: Icon(
Icons.add_a_photo_rounded,
size: ScreenAdaper.height(60),
color: AppTheme.primaryColor,
))));
}
}
class EditUserInfoController extends GetxController {
int userId;
EditUserInfoController(this.userId);
final nameEditController = TextEditingController();
final deptEditController = TextEditingController();
2024-04-09 08:31:17 +08:00
final userInfo = Rxn<UserInfoModel>();
RxList selectedDepts = RxList([]);
@override
onReady() {
getUserInfo();
super.onReady();
}
Future<void> getUserInfo() async {
try {
final response = await Api.getUserInfo(userId);
if (response.data != null) {
userInfo.value = UserInfoModel.fromJson(response.data);
nameEditController.text = userInfo.value?.nickname ?? '';
}
} catch (e) {
SnackBarUtil().error('$e');
} finally {}
}
}