QinGang_interested/lib/pages/user/choose_userFirm_page.dart

195 lines
5.8 KiB
Dart
Raw Normal View History

2025-12-12 09:11:30 +08:00
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:qhd_prevention/customWidget/custom_button.dart';
import 'package:qhd_prevention/customWidget/toast_util.dart';
import 'package:qhd_prevention/pages/main_tab.dart';
import 'package:qhd_prevention/services/StorageService.dart';
import 'package:qhd_prevention/services/auth_service.dart';
import 'package:qhd_prevention/tools/tools.dart';
class ChooseUserfirmPage extends StatefulWidget {
const ChooseUserfirmPage({super.key, required this.firms, required this.userName, required this.password});
final List firms;
final String userName;
final String password;
@override
_ChooseUserfirmPageState createState() => _ChooseUserfirmPageState();
}
class _ChooseUserfirmPageState extends State<ChooseUserfirmPage> {
int _selectedIndex = -1;
String _displayLabel(Map m) {
final keys = ['corpName'];
for (final k in keys) {
if (m.containsKey(k) && m[k] != null) return m[k].toString();
}
// 如果都没有,则找到第一个 value 为字符串或数字的字段
for (final entry in m.entries) {
final v = entry.value;
if (v is String || v is num) return v.toString();
}
return '未命名企业';
}
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
Future<void> _login() async {
if (_selectedIndex < 0) {
ToastUtil.showNormal(context, '请选择已入职的相关方单位');
return;
}
final params = {
'corpId': widget.firms[_selectedIndex]['id'],
'corpName': widget.firms[_selectedIndex]['corpName'],
};
LoadingDialogHelper.show();
final result = await AuthService.gbsLogin(widget.userName, widget.password, params);
LoadingDialogHelper.hide();
if (result['success'] == true) {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => const MainPage(isChooseFirm: true,)),
);
}
// final result = AuthService.gbsLogin(username, password, params)
}
@override
Widget build(BuildContext context) {
final screenHeight = MediaQuery.of(context).size.height;
double height = 230.0;
return Scaffold(
backgroundColor: Colors.white,
resizeToAvoidBottomInset: true,
body: Stack(
children: [
// 背景图:铺满屏幕
Positioned(
left: 0,
top: 0,
right: 0,
child: Image.asset(
'assets/images/loginbg.png',
fit: BoxFit.fitWidth,
),
),
Positioned(
top: 0,
left: 20,
right: 0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 70), // 顶部间距
Image.asset(
"assets/images/logo.png",
width: 40,
height: 40,
),
const SizedBox(height: 10),
const Text(
"欢迎使用",
style: TextStyle(
color: Colors.white,
fontSize: 23,
fontWeight: FontWeight.w500,
),
),
const Text(
"秦港-相关方安全管理平台",
style: TextStyle(
color: Colors.white,
fontSize: 23,
fontWeight: FontWeight.w500,
),
),
const SizedBox(height: 20),
],
),
),
Positioned(
top: height,
left: 0,
right: 0,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 20),
child:Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// const SizedBox(width: 20,),
Text(
'请选择已入职的相关方单位',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
const SizedBox(width: 20,),
],
),
)
),
Positioned(
bottom: 0,
left: 0,
right: 0,
top: height + 50,
child:Container(
padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 0),
child: ListView.separated(
padding: const EdgeInsets.symmetric(vertical: 0),
itemCount: widget.firms.length + 1,
separatorBuilder: (_, __) => const SizedBox(height: 1,),
itemBuilder: (context, index) {
if (index == widget.firms.length) {
return CustomButton(text: '登录',
// padding: const EdgeInsets.symmetric(vertical: 0, horizontal: 100),
height: 40,
onPressed: () {
_login();
}
);
}
final firm = widget.firms[index];
return RadioListTile<int>(
value: index,
activeColor: Colors.blue,
groupValue: _selectedIndex,
onChanged: (v) {
setState(() {
_selectedIndex = v!;
});
},
title: Text(_displayLabel(firm)),
controlAffinity: ListTileControlAffinity.leading,
);
},
),
)
),
],
),
);
}
}