123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- import 'package:easy_refresh/easy_refresh.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
- import 'package:lszlgl/base/base_lifecycle_state.dart';
- import 'package:lszlgl/base/base_vm.dart';
- import 'package:lszlgl/config/colors.dart';
- import 'package:lszlgl/model/rsp/sample_task_rsp.dart';
- import 'package:lszlgl/network/my_api.dart';
- import 'package:lszlgl/page/sample_task/sample_list_vm.dart';
- import 'package:lszlgl/page/sample_task/sample_task_list_tab_page.dart';
- import 'package:lszlgl/service/dict_service.dart';
- import 'package:lszlgl/utils/date_time_utils.dart';
- import 'package:lszlgl/utils/inject.dart';
- import 'package:lszlgl/widget/button.dart';
- import 'package:lszlgl/widget/page_widget.dart';
- import '../../main.dart';
- import 'reap_sample_detail/reap_sample_task_page.dart';
- import 'stock_sample_detail/stock_sample_task_page.dart';
- /// 扦样环节列表
- class SampleTaskListPage extends StatefulWidget {
- final StepType type;
- final int tabIndex;
- const SampleTaskListPage({
- super.key,
- required this.type,
- required this.tabIndex,
- });
- @override
- State<SampleTaskListPage> createState() => _SampleTaskListPageState();
- }
- class _SampleTaskListPageState extends BaseLifecycleState<SampleTaskListPage> with AutomaticKeepAliveClientMixin {
- late SampleListVM vm;
- /// 详情
- void startTaskDetail(bool detail, SampleTaskItem data) async {
- bool? success;
- switch (widget.type) {
- case StepType.reap:
- success = await MyRouter.startReapSampleTask(args: ReapSampleTaskPageArgs(detail: detail, id: data.id));
- break;
- case StepType.stock:
- success = await MyRouter.startStockSampleTask(args: StockSampleTaskPageArgs(detail: detail, id: data.id));
- break;
- }
- if (success ?? false) {
- vm.refreshAll();
- }
- }
- /// 领取扦样任务
- void receiveTask(SampleTaskItem data) async {
- var delete = await MyNavigator.showDialog(
- builder: (_) => AlertDialog(
- title: const Text('系统提示'),
- content: const Text('任务认领后不可撤销,请确认是否认领任务!'),
- actions: [
- MyButton(
- '领取',
- alignment: null,
- backgroundColor: const Color(0xFFCE615A),
- onTap: () => MyNavigator.dismiss(status: SmartStatus.dialog, result: true),
- ),
- MyButton('取消', alignment: null, onTap: () => MyNavigator.dismiss()),
- ],
- ),
- );
- if (!(delete ?? false)) return;
- MyNavigator.showLoading();
- try {
- var rsp = await MyApi.get().receiveSampleTaskSgjc(data.id ?? 0);
- MyNavigator.dismissLoading();
- if (rsp.data == 1) {
- MyNavigator.showToast('领取成功');
- vm.refreshAll();
- }
- } catch (e) {
- logger.e(e);
- MyNavigator.dismissLoading();
- }
- }
- @override
- void onInit() {
- vm = Inject.get<SampleListVM>()!;
- }
- @override
- void onFirstShow(Duration timeStamp) {
- vm.refresh(widget.tabIndex);
- }
- @override
- Widget build(BuildContext context) {
- super.build(context);
- return Container(
- clipBehavior: Clip.hardEdge,
- decoration: const BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
- ),
- alignment: Alignment.center,
- child: buildBody(),
- );
- }
- Widget buildBody() {
- return EasyRefresh.builder(
- controller: vm.ctrlList[widget.tabIndex],
- onRefresh: () => vm.getData(widget.tabIndex, refresh: true),
- onLoad: () => vm.getData(widget.tabIndex, refresh: false),
- childBuilder: (_, physics) => buildList(physics),
- );
- }
- Widget buildList(ScrollPhysics physics) {
- var sliver = vm.pageStateList[widget.tabIndex].builder((v) {
- var list = v.data;
- if (v.status == DataStatus.error) {
- // 加载失败
- return SliverToBoxAdapter(child: PageLoadingWidget.error(onTap: () => vm.refresh(widget.tabIndex)));
- } else if (list == null || list.isEmpty) {
- // 无数据
- return const SliverToBoxAdapter(child: PageLoadingWidget.empty());
- } else {
- return SliverList.builder(
- itemCount: list.length,
- itemBuilder: (_, index) => buildItem(index, list[index]),
- );
- }
- });
- return CustomScrollView(
- physics: physics,
- slivers: [sliver],
- );
- }
- Widget buildItem(int index, SampleTaskItem item) {
- return GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- if (item.deliveryStatus != 2) return;
- startTaskDetail(true, item);
- },
- child: Container(
- margin: const EdgeInsets.only(left: 12, right: 12, top: 12),
- decoration: const BoxDecoration(
- color: Color(0xFFF5FFFD),
- borderRadius: BorderRadius.all(Radius.circular(8)),
- ),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const SizedBox(height: 15),
- buildTop(item.getDeliveryStatusText()),
- buildNumber(item.qyrwdh ?? ''),
- buildGrid(item),
- buildBottom(item),
- const SizedBox(height: 15),
- ],
- ),
- ),
- );
- }
- Widget buildTop(String state) {
- return Row(
- children: [
- buildVLine(),
- const Expanded(
- child: Text(
- '样品单号',
- style: TextStyle(color: MyColor.c_333333, fontSize: 14, fontWeight: FontWeight.w500),
- ),
- ),
- buildState(state),
- ],
- );
- }
- Widget buildVLine() {
- return Container(
- width: 4,
- height: 18,
- margin: const EdgeInsets.only(right: 8),
- decoration: const BoxDecoration(
- color: MyColor.c_25A6EE,
- borderRadius: BorderRadius.all(Radius.circular(2)),
- ),
- );
- }
- Widget buildState(String state) {
- return Container(
- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
- decoration: BoxDecoration(
- color: MyColor.c_25A6EE.withOpacity(0.1),
- borderRadius: const BorderRadius.horizontal(left: Radius.circular(100)),
- ),
- child: Text(
- '状态:$state',
- style: const TextStyle(color: MyColor.c_1383C2, fontSize: 13),
- ),
- );
- }
- Widget buildNumber(String number) {
- return Padding(
- padding: const EdgeInsets.only(left: 8, top: 4, bottom: 8),
- child: Text(
- number,
- style: const TextStyle(color: MyColor.c_333333, fontSize: 14, fontWeight: FontWeight.w500),
- ),
- );
- }
- Widget buildGrid(SampleTaskItem item) {
- List<Map<String, String?>> infoList = [];
- if (item.deliveryStatus != 2) {
- // 未扦样
- infoList.add({'采样品种': item.cypzName});
- if (item.jyzb != null) {
- infoList.add({'检验指标': item.jyzb});
- }
- infoList.add({'扦样地区': item.qydq});
- if (item.ypdj != null) {
- infoList.add({'样品层级': DictService.getDict(DictType.ypdj, value: item.ypdj)?.label});
- }
- } else {
- // 已扦样
- infoList.addAll([
- {'采样品种': item.cypzName},
- {'扦样地区': item.qydq},
- ]);
- if (item.ypdj != null) {
- infoList.add({'样品层级': DictService.getDict(DictType.ypdj, value: item.ypdj)?.label});
- }
- if (item.jyzb != null) {
- infoList.add({'检验指标': item.jyzb});
- }
- infoList.addAll([
- {'扦样人员': item.dgryName},
- {'扦样时间': item.qysj},
- ]);
- }
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 8),
- child: LayoutBuilder(builder: (context, constraints) {
- return Wrap(
- spacing: 4,
- runSpacing: 4,
- children: infoList.map((item) {
- return SizedBox(
- width: constraints.maxWidth / 2 - 2,
- child: Text(
- '${item.keys.first}:${item.values.first ?? ''}',
- style: const TextStyle(fontSize: 13, color: MyColor.c_666666),
- ),
- );
- }).toList(),
- );
- }),
- );
- }
- Widget buildBottom(SampleTaskItem item) {
- if (item.deliveryStatus == 2) return const SizedBox.shrink();
- Widget button = const SizedBox.shrink();
- if (widget.type == StepType.reap && item.deliveryStatus == 0) {
- button = MyButton(
- '任务领取',
- onTap: () => receiveTask(item),
- fountSize: 13,
- alignment: null,
- padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
- );
- } else {
- button = MyButton(
- '开始扦样',
- onTap: () => startTaskDetail(false, item),
- fountSize: 13,
- alignment: null,
- padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
- );
- }
- return Column(
- children: [
- buildDivider(),
- Row(
- children: [
- const SizedBox(width: 8),
- Expanded(
- child: Text(
- '扦样单据创建于${DateTimeUtils.yyyymmdd(timestamp: item.createTime) ?? ''}',
- style: const TextStyle(fontSize: 13, color: MyColor.c_666666),
- ),
- ),
- const SizedBox(width: 4),
- button,
- const SizedBox(width: 12),
- ],
- ),
- ],
- );
- }
- Widget buildDivider() {
- return Container(
- width: double.infinity,
- height: 1,
- color: MyColor.c_3BD2E5.withOpacity(0.15),
- margin: const EdgeInsets.symmetric(vertical: 10),
- );
- }
- @override
- bool get wantKeepAlive => true;
- }
|