270 lines
8.9 KiB
Dart
270 lines
8.9 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:sk_base_mobile/apis/api.dart';
|
|
import 'package:sk_base_mobile/app_theme.dart';
|
|
import 'package:sk_base_mobile/constants/bg_color.dart';
|
|
import 'package:sk_base_mobile/models/role.model.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/logger_util.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_multi_picker.dart';
|
|
import 'package:sk_base_mobile/widgets/core/sk_multi_picker_dialog.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),
|
|
),
|
|
|
|
/// 姓名
|
|
SkTextInput(
|
|
isDense: true,
|
|
textController: controller.nameEditController,
|
|
customLabel: true,
|
|
labelText: '姓名',
|
|
),
|
|
SizedBox(
|
|
height: ScreenAdaper.height(defaultPadding),
|
|
),
|
|
|
|
/// 部门
|
|
SkTextInput(
|
|
isDense: true,
|
|
customLabel: true,
|
|
keyboardType: TextInputType.none,
|
|
textController: controller.deptEditController,
|
|
labelText: '所属部门',
|
|
onTap: (_) async {
|
|
Get.bottomSheet(DeptPicker(onSelected: (String label) {
|
|
controller.deptEditController.text = label;
|
|
}));
|
|
},
|
|
),
|
|
SizedBox(
|
|
height: ScreenAdaper.height(defaultPadding),
|
|
),
|
|
|
|
/// 角色
|
|
SkMultiPickerDropdown(
|
|
isDense: true,
|
|
customLabel: true,
|
|
keyboardType: TextInputType.none,
|
|
textController: controller.roleEditController,
|
|
labelText: '角色',
|
|
hint: '选择角色',
|
|
onTap: (_) async {
|
|
Get.bottomSheet(SkMutiPickerDialog(
|
|
onSelected: (List<PickerItem> selectedData) {
|
|
controller.roleEditController.text;
|
|
}, getData: () async {
|
|
try {
|
|
final res =
|
|
await Api.getRoles({'page': 1, 'pageSize': 30});
|
|
if (res.data != null) {
|
|
List<PickerItem<int>> result =
|
|
res.data!.items.map<PickerItem<int>>((e) {
|
|
RoleModel data = RoleModel.fromJson(e);
|
|
return PickerItem(
|
|
label: data.name,
|
|
value: data.id!,
|
|
subLabel: data.remark,
|
|
checked: false);
|
|
}).toList();
|
|
return result;
|
|
}
|
|
return [];
|
|
} catch (e) {
|
|
LoggerUtil().error(e);
|
|
return [];
|
|
}
|
|
})).then(
|
|
(value) => Get.delete<SkMutiPickerDialogController>());
|
|
}),
|
|
SizedBox(
|
|
height: ScreenAdaper.height(defaultPadding),
|
|
),
|
|
SkTextInput(
|
|
isDense: true,
|
|
textController: controller.nickNameEditController,
|
|
customLabel: true,
|
|
labelText: '登录用户名',
|
|
),
|
|
SizedBox(
|
|
height: ScreenAdaper.height(defaultPadding),
|
|
),
|
|
SkTextInput(
|
|
isDense: true,
|
|
customLabel: 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();
|
|
final roleEditController = TextEditingController();
|
|
final nickNameEditController = TextEditingController();
|
|
final userInfo = Rxn<UserInfoModel>();
|
|
|
|
@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 {}
|
|
}
|
|
}
|