162 lines
5.9 KiB
Dart
162 lines
5.9 KiB
Dart
|
|
import 'dart:io';
|
||
|
|
import 'dart:convert';
|
||
|
|
import 'package:qhd_prevention/services/StorageService.dart';
|
||
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:qhd_prevention/customWidget/custom_alert_dialog.dart';
|
||
|
|
import 'package:qhd_prevention/customWidget/toast_util.dart';
|
||
|
|
import 'package:qhd_prevention/http/ApiService.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 MineChangeFirmPage extends StatefulWidget {
|
||
|
|
const MineChangeFirmPage({super.key});
|
||
|
|
|
||
|
|
@override
|
||
|
|
State<MineChangeFirmPage> createState() => _MineChangeFirmPageState();
|
||
|
|
}
|
||
|
|
|
||
|
|
class _MineChangeFirmPageState extends State<MineChangeFirmPage> {
|
||
|
|
// 入职企业列表
|
||
|
|
List<dynamic> list = [];
|
||
|
|
String joinedUnitId = '';
|
||
|
|
|
||
|
|
@override
|
||
|
|
void initState() {
|
||
|
|
super.initState();
|
||
|
|
Map jsonData = json.decode(
|
||
|
|
StorageService.instance.getString('key.saveJoinFirmInfo') ?? '{}',
|
||
|
|
);
|
||
|
|
joinedUnitId = jsonData['unitId'] ?? '';
|
||
|
|
_getList();
|
||
|
|
}
|
||
|
|
|
||
|
|
void _getList() async {
|
||
|
|
LoadingDialogHelper.show();
|
||
|
|
var res = await BasicInfoApi.getJoinFirmList();
|
||
|
|
LoadingDialogHelper.dismiss();
|
||
|
|
if (res['success'] == true) {
|
||
|
|
setState(() {
|
||
|
|
list = res['data'];
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 切换账号
|
||
|
|
Future<void> _changeAccount(dynamic data) async {
|
||
|
|
await CustomAlertDialog.showConfirm(
|
||
|
|
context,
|
||
|
|
title: '温馨提示',
|
||
|
|
content: '确认切换到企业"${data['corpName']}"?',
|
||
|
|
onConfirm: () async {
|
||
|
|
LoadingDialogHelper.show();
|
||
|
|
final prefs = await SharedPreferences.getInstance();
|
||
|
|
final phone = prefs.getString('savePhone') ?? '';
|
||
|
|
final pwd = prefs.getString('savePass') ?? '';
|
||
|
|
var params = {'unitId': data['id']};
|
||
|
|
try {
|
||
|
|
var res = await AuthService.gbsLogin(phone, pwd, params);
|
||
|
|
LoadingDialogHelper.dismiss();
|
||
|
|
if (res['success'] == true) {
|
||
|
|
Navigator.pushReplacement(
|
||
|
|
context,
|
||
|
|
MaterialPageRoute(
|
||
|
|
builder: (_) => const MainPage(isChooseFirm: true),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
} else {
|
||
|
|
ToastUtil.showNormal(context, res['errMessage'] ?? '切换账户失败,请重试');
|
||
|
|
}
|
||
|
|
} catch (e) {
|
||
|
|
LoadingDialogHelper.dismiss();
|
||
|
|
ToastUtil.showNormal(context, '切换账户失败,请重试');
|
||
|
|
}
|
||
|
|
},
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return Scaffold(
|
||
|
|
// backgroundColor: Colors.white,
|
||
|
|
appBar: MyAppbar(title: '切换账号'),
|
||
|
|
body: Column(
|
||
|
|
children: [
|
||
|
|
Container(
|
||
|
|
width: MediaQuery.of(context).size.width,
|
||
|
|
color: Colors.blue.shade50,
|
||
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
||
|
|
// height: 40,
|
||
|
|
child: Center(child: Text('点击企业名称以切换账号')),
|
||
|
|
),
|
||
|
|
const SizedBox(height: 10),
|
||
|
|
Container(
|
||
|
|
height: 40.0 * list.length,
|
||
|
|
width: MediaQuery.of(context).size.width - 24,
|
||
|
|
decoration: BoxDecoration(
|
||
|
|
color: Colors.white,
|
||
|
|
border: Border.all(color: Colors.grey.shade300),
|
||
|
|
),
|
||
|
|
child:
|
||
|
|
list.isEmpty
|
||
|
|
? NoDataWidget.show()
|
||
|
|
: ListView.builder(
|
||
|
|
padding: EdgeInsets.zero,
|
||
|
|
itemCount: list.length,
|
||
|
|
itemBuilder: (context, index) {
|
||
|
|
if (index >= list.length) {
|
||
|
|
// 加载更多时在列表底部显示加载指示器
|
||
|
|
return Padding(
|
||
|
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||
|
|
child: Center(child: CircularProgressIndicator()),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
var data = list[index];
|
||
|
|
return SizedBox(
|
||
|
|
height: 40.0,
|
||
|
|
child: Column(
|
||
|
|
children: [
|
||
|
|
GestureDetector(
|
||
|
|
onTap: () async {
|
||
|
|
_changeAccount(data);
|
||
|
|
},
|
||
|
|
child: SizedBox(
|
||
|
|
height: 39.0,
|
||
|
|
child: Center(
|
||
|
|
child: Row(
|
||
|
|
mainAxisAlignment:
|
||
|
|
MainAxisAlignment.center,
|
||
|
|
children: [
|
||
|
|
Text('${data['corpName'] ?? 'aaaa'}'),
|
||
|
|
if (joinedUnitId ==
|
||
|
|
data['id']) ...[
|
||
|
|
const Icon(
|
||
|
|
Icons.check,
|
||
|
|
size: 20,
|
||
|
|
color: Colors.green,
|
||
|
|
),
|
||
|
|
] else ...[
|
||
|
|
const SizedBox(width: 20),
|
||
|
|
],
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
if (index < list.length - 1)
|
||
|
|
const Divider(height: 1),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
);
|
||
|
|
},
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|