123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- import 'package:fis_common/index.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/architecture/utils/prompt_box.dart';
- import 'package:vitalapp/components/appbar.dart';
- import 'package:vitalapp/components/search_input.dart';
- import 'package:vitalapp/components/table/table.dart';
- import 'package:vitalapp/components/table/table_column.dart';
- import 'package:vitalapp/managers/interfaces/excelData.dart';
- import 'package:vitalapp/managers/interfaces/models/excel_data.dart';
- import 'package:vitalapp/pages/widgets/overflow_tooltip_wrapper.dart';
- import 'package:vitalapp/pages/widgets/text_tooltip.dart';
- class ExcelDatasView extends StatefulWidget {
- final List<ExcelDataRecord> records;
- final String templateKey;
- ExcelDatasView(this.records, this.templateKey);
- @override
- State<StatefulWidget> createState() {
- return ExcelDatasViewState();
- }
- }
- class ExcelDatasViewState extends State<ExcelDatasView> {
- final _searchController = TextEditingController();
- List<ExcelDataRecord> _pendingUploadDatas = [];
- List<ExcelDataRecord> _errorDatas = [];
- List<int> _selecteds = [];
- bool _isShowErrorData = false;
- bool _isSelectedAll = true;
- @override
- void initState() {
- //sampleBarcode对应的就是体检系统的条码
- _pendingUploadDatas = widget.records
- .where((element) =>
- element.excelDatas
- .firstWhereOrNull((element) => element.key == "sampleBarcode")
- ?.value
- .isNotNullOrEmpty ??
- false)
- .toList();
- _errorDatas = widget.records
- .where((element) =>
- element.excelDatas
- .firstWhereOrNull((element) => element.key == "sampleBarcode")
- ?.value
- .isNullOrEmpty ??
- false)
- .toList();
- _selectedAll();
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- backgroundColor: Colors.white,
- appBar: VAppBar(
- titleWidget: Text(
- "数据上传",
- style: const TextStyle(fontSize: 24, color: Colors.white),
- ),
- actions: [
- if (!_isShowErrorData)
- TextButton.icon(
- onPressed: () async {
- List<ExcelDataRecord> pendingUploadDatas = [];
- for(int i in _selecteds){
- pendingUploadDatas.add(_pendingUploadDatas[i]);
- }
- var result = await Get.find<IExcelDataManager>()
- .uploadDatas(pendingUploadDatas, widget.templateKey);
- if (result) {
- PromptBox.toast('上传成功');
- Get.back();
- } else {
- PromptBox.toast('上传失败');
- }
- },
- label: Text(
- '提交',
- style: TextStyle(fontSize: 20, color: Colors.white),
- ),
- icon: Icon(Icons.save, size: 32, color: Colors.white),
- ),
- ],
- ),
- body: _buildBody(),
- );
- }
- Widget _buildBody() {
- return Column(
- children: [
- Container(
- height: 40,
- child: _buildHead(),
- margin: EdgeInsets.symmetric(vertical: 10),
- ),
- Expanded(
- child: VitalTable<ExcelDataRecord>(
- source: _isShowErrorData ? _errorDatas : _pendingUploadDatas,
- columns: _buildColumns(),
- headerTextStyle: const TextStyle(
- fontSize: 12,
- ),
- autoHeight: false,
- showSelect: !_isShowErrorData,
- onRowSelected: (value, index, selectedIndexs) {
- _selecteds.add(index);
- },
- selecteds: _selecteds,
- checkCellWidth: 40,
- cellPadding: EdgeInsets.symmetric(vertical: 2, horizontal: 1),
- ),
- ),
- ],
- );
- }
- Widget _buildHead() {
- return Row(
- children: [
- SizedBox(width: 10),
- _buildSearchInput(),
- SizedBox(width: 20),
- _buildTips(),
- SizedBox(width: 10),
- if (_errorDatas.isNotEmpty) _buildSwichButton(),
- if (_isShowErrorData) ...[
- SizedBox(width: 10),
- Icon(
- Icons.warning,
- color: Colors.orange,
- ),
- Text(
- "请检查样本号是否正确!",
- style: TextStyle(color: Colors.orange),
- ),
- ],
- ],
- );
- }
- void _selectedAll() {
- int index = 0;
- for (var data in _pendingUploadDatas) {
- _selecteds.add(index);
- index++;
- }
- }
- Widget _buildSearchInput() {
- return Container(
- width: 400,
- margin: EdgeInsets.only(left: 20),
- child: VSearchInput(
- textEditingController: _searchController,
- placeholder: "请输入姓名",
- onSearch: (v) {
- if (_isShowErrorData) {
- var errorDatas = widget.records
- .where((element) =>
- element.excelDatas
- .firstWhereOrNull(
- (element) => element.key == "sampleBarcode")
- ?.value
- .isNullOrEmpty ??
- false)
- .toList();
- _errorDatas = errorDatas
- .where((element) =>
- element.excelDatas
- .firstWhereOrNull(
- (element) => element.key == "patientName")
- ?.value
- .contains(v) ??
- false)
- .toList();
- } else {
- var pendingUploadDatas = widget.records
- .where((element) =>
- element.excelDatas
- .firstWhereOrNull(
- (element) => element.key == "sampleBarcode")
- ?.value
- .isNotNullOrEmpty ??
- false)
- .toList();
- _pendingUploadDatas = pendingUploadDatas
- .where((element) =>
- element.excelDatas
- .firstWhereOrNull(
- (element) => element.key == "patientName")
- ?.value
- .contains(v) ??
- false)
- .toList();
- if (_isSelectedAll) {
- _selecteds.clear();
- int index = 0;
- for (var data in _pendingUploadDatas) {
- _selecteds.add(index);
- index++;
- }
- }
- }
- setState(() {});
- },
- ),
- );
- }
- Widget _buildTips() {
- var tips =
- "共计 ${widget.records.length} 条数据,其中校验通过 ${_pendingUploadDatas.length} 条数据";
- if (_errorDatas.length > 0) {
- tips += ",校验不通过${_errorDatas.length}条数据";
- }
- return Text(tips);
- }
- Widget _buildSwichButton() {
- return OutlinedButton(
- onPressed: () {
- setState(() {
- _isShowErrorData = !_isShowErrorData;
- });
- },
- child: Text(
- _isShowErrorData ? "查看校验通过数据" : "查看校验不通过数据",
- ),
- );
- }
- List<TableColumn<ExcelDataRecord>> _buildColumns() {
- if (widget.records.isEmpty) {
- return [];
- }
- ExcelDataRecord firstRecord = widget.records.first;
- var items = firstRecord.excelDatas;
- var textStyle = TextStyle(
- fontSize: 12,
- overflow: TextOverflow.ellipsis,
- fontFamily: "NotoSansSC",
- );
- return [
- ...items.map(
- (e) => TableColumn<ExcelDataRecord>(
- headerText: e.des,
- flex: (e.key == "sampleBarcode" || e.key == "samplingTime") ? 6 : 5,
- render: (rowData, index) => Center(
- child: Text(
- rowData.excelDatas
- .firstWhere((element) => element.key == e.key)
- .value,
- style: textStyle,
- ),
- ),
- ),
- )
- ];
- }
- }
|