160 lines
5.0 KiB
Dart
160 lines
5.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:qhd_prevention/customWidget/bottom_picker.dart';
|
|
import 'package:qhd_prevention/customWidget/custom_button.dart';
|
|
import 'package:qhd_prevention/customWidget/item_list_widget.dart';
|
|
import 'package:qhd_prevention/customWidget/toast_util.dart';
|
|
import 'package:qhd_prevention/http/modules/basic_info_api.dart';
|
|
import 'package:qhd_prevention/pages/main_tab.dart';
|
|
import 'package:qhd_prevention/pages/my_appbar.dart';
|
|
import 'package:qhd_prevention/services/SessionService.dart';
|
|
import 'package:qhd_prevention/services/auth_service.dart';
|
|
import 'package:qhd_prevention/tools/tools.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class OnboardingFullPage extends StatefulWidget {
|
|
const OnboardingFullPage({super.key, required this.scanData});
|
|
final Map scanData;
|
|
@override
|
|
State<OnboardingFullPage> createState() => _OnboardingFullPageState();
|
|
}
|
|
|
|
class _OnboardingFullPageState extends State<OnboardingFullPage> {
|
|
Map<String, dynamic> pd = {};
|
|
// 部门列表
|
|
List<dynamic> _deptList = [];
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_getDept();
|
|
}
|
|
// 获取部门
|
|
Future<void> _getDept() async {
|
|
try {
|
|
final data = {
|
|
'eqCorpinfoId': widget.scanData['id'],
|
|
// 'eqParentId': widget.scanData['corpinfoId'],
|
|
};
|
|
final result = await BasicInfoApi.getDeptTree(data);
|
|
if (result['success'] == true) {
|
|
_deptList = result['data'];
|
|
}
|
|
} catch (e) {
|
|
}
|
|
}
|
|
// 提交
|
|
Future<void> _saveSuccess() async {
|
|
if (!FormUtils.hasValue(pd, 'corpinfoId')) {
|
|
ToastUtil.showNormal(context, '请选择部门');
|
|
return;
|
|
}
|
|
if (!FormUtils.hasValue(pd, 'postName')) {
|
|
ToastUtil.showNormal(context, '请输入岗位');
|
|
return;
|
|
}
|
|
LoadingDialogHelper.show();
|
|
pd['id'] = widget.scanData['id'];
|
|
try {
|
|
final result = await BasicInfoApi.userFirmEntry(pd);
|
|
LoadingDialogHelper.hide();
|
|
if (result['success'] == true) {
|
|
ToastUtil.showNormal(context, '操作成功');
|
|
_relogin();
|
|
}
|
|
} catch (e) {
|
|
LoadingDialogHelper.hide();
|
|
ToastUtil.showNormal(context, '操作成功');
|
|
}
|
|
}
|
|
/// 重新登录
|
|
Future<void> _relogin() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final username = prefs.getString('savePhone') ?? '';
|
|
final password = prefs.getString('savePass') ?? '';
|
|
|
|
try {
|
|
Map data = {
|
|
'id': widget.scanData['id'] ?? '',
|
|
'corpinfoId':widget.scanData['corpinfoId'] ?? '',
|
|
};
|
|
final result = await AuthService.gbsLogin(username, password, data);
|
|
if (result['success'] == true) {
|
|
Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => const MainPage(isChooseFirm: true,)),
|
|
);
|
|
}
|
|
} catch (e) {
|
|
ToastUtil.showNormal(context, '重新登录失败');
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: MyAppbar(title: '信息补充'),
|
|
body: SafeArea(
|
|
child: ItemListWidget.itemContainer(
|
|
horizontal: 5,
|
|
ListView(
|
|
children: [
|
|
ItemListWidget.selectableLineTitleTextRightButton(
|
|
verticalInset: 15,
|
|
label: '选择入职部门:',
|
|
isEditable: true,
|
|
text: pd['departmentName'] ?? '请选择',
|
|
isRequired: true,
|
|
onTap: () async {
|
|
if (_deptList.isEmpty) {
|
|
ToastUtil.showNormal(context, '暂无部门信息');
|
|
return;
|
|
}
|
|
final found = await BottomPicker.show(
|
|
context,
|
|
items: _deptList,
|
|
itemBuilder:
|
|
(i) =>
|
|
Text(i['name']!, textAlign: TextAlign.center),
|
|
initialIndex: 0,
|
|
);
|
|
//FocusHelper.clearFocus(context);
|
|
|
|
if (found != null) {
|
|
setState(() {
|
|
pd['departmentId'] = found['id'];
|
|
pd['departmentName'] = found['name'];
|
|
pd['corpinfoId'] = found['corpinfoId'];
|
|
pd['corpinfoName'] = found['corpinfoName'];
|
|
|
|
});
|
|
}
|
|
},
|
|
),
|
|
const Divider(),
|
|
ItemListWidget.singleLineTitleText(
|
|
label: '岗位(工种):',
|
|
isRequired: true,
|
|
hintText: '请输入姓名',
|
|
text: "",
|
|
isEditable: true,
|
|
onChanged: (value) {
|
|
pd['postName'] = value;
|
|
},
|
|
),
|
|
const Divider(),
|
|
const SizedBox(height: 20),
|
|
CustomButton(
|
|
text: '保存',
|
|
backgroundColor: Colors.blue,
|
|
onPressed: () {
|
|
_saveSuccess();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|