import 'package:flutter/material.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/main.dart'; import 'package:lszlgl/model/rsp/storehouse_rsp.dart'; import 'package:lszlgl/network/my_api.dart'; import 'package:lszlgl/widget/page_widget.dart'; import 'package:lszlgl/widget/storehouse_item.dart'; class StoreHousePage extends StatefulWidget { final String houseNum; const StoreHousePage({super.key, required this.houseNum}); @override State createState() => _StoreHousePageState(); } class _StoreHousePageState extends BaseLifecycleState { final pageState = DataStatusModel().notifier>(); storehouseRsp? data; List cflist=[]; @override void onFirstShow(Duration timeStamp) { loadData(); } @override void onDestroy() { pageState.dispose(); } void loadData() async { pageState.update(pageState.value.loading()); try { // String jsonStr = await Future.delayed(const Duration(seconds: 3),()async{ // return rootBundle.loadString('assets/json/storehouse.json'); // }); // Map val = json.decode(jsonStr); // ApiRsp> res= ApiRsp>.fromJson( // val, // (json) => json is List // ? json // .map((i) => storehouseRsp.fromJson(i as Map)) // .toList() // : List.empty(), // ); var res = await MyApi.get(baseUrl: 'http://121.36.17.6:28088') .getStoreMessage(widget.houseNum, 'zhijian'); if (res.data?.first.tycfbm == null) { pageState.update(pageState.value.empty()); } else { data = res.data!.first; // cflist = (data?.cflx ?? '').split(RegExp(r'[()()]')); cflist.removeWhere((val) => val == ''); pageState.update(pageState.value.success(data: res.data!.first)); } } catch (e) { logger.e(e); pageState.update(pageState.value.error()); } } @override Widget build(BuildContext context) { return myScaffold( child: Column( children: [ AppBar( title: Row( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset(sh_titicon, width: 20, height: 20), const SizedBox(width: 6), const Text('电子货位卡') ], ), ), Expanded( child: Container( clipBehavior: Clip.hardEdge, decoration: const BoxDecoration( color: MyColor.c_background, borderRadius: BorderRadius.all(Radius.circular(10))), margin: const EdgeInsets.symmetric(horizontal: 10), child: SingleChildScrollView( child: pageState.builder((v) { if (v.status == DataStatus.error) { return PageLoadingWidget.error(onTap: loadData); } if (v.status == DataStatus.empty) { return const PageLoadingWidget.empty(); } if (v.status == DataStatus.loading) { return const PageLoadingWidget.loading(); } return Column( children: [ Padding( padding: const EdgeInsets.fromLTRB(0, 0, 0, 12), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Container( padding: const EdgeInsets.all(12), decoration: const BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(12)), image: DecorationImage( image: AssetImage(sh_TitBgIm), fit: BoxFit.fill), ), child: Text( data?.kqmc ?? '仓房', textAlign: TextAlign.center, style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold), )), const SizedBox(height: 12), Container( decoration: const BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(12))), child: Stack( children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const StoreHouseTit(tit: '基本信息'), const SizedBox(height: 12), Padding( padding: const EdgeInsets.only(left: 12.0), child: Row( children: [ const Text( '仓房编号', style: TextStyle( fontSize: 15, fontWeight: FontWeight.w600), ), const SizedBox( width: 6, ), Container( alignment: Alignment.center, padding: const EdgeInsets.symmetric( horizontal: 4), decoration: const BoxDecoration( color: MyColor.c_28A3ED, borderRadius: BorderRadius.all(Radius.circular(2))), child: Center( child: Text( data?.cfmc ?? '', style: const TextStyle( fontSize: 14, color: Colors.white, fontWeight: FontWeight.bold, fontFeatures: [FontFeature.caseSensitiveForms()] ), ), ), ) ], ), ), Padding( padding: const EdgeInsets.only(left: 12.0), child: Text(data?.tycfbm ?? '', style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 15)), ), const SizedBox( height: 8, ), const Divider( thickness: 0.6, color: Color(0xFFEEEEEE), indent: 12, ), if(cflist.first.isNotEmpty) Padding( padding: const EdgeInsets.fromLTRB(12,12,12,8), child: Text(cflist.first ?? '', style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 15)), ), if(cflist.length>=2) Padding( padding: const EdgeInsets.fromLTRB(12,0,12,12), child: Text(cflist[1] ?? '', style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 15,color: Colors.grey)), ), const Divider( thickness: 0.6, color: Color(0xFFEEEEEE), indent: 12, ), SHImageAndNameWidget( image: sh_bgyim, title: '保管员', content: data?.bgr, fontSize: 13, imageR: sh_jgtimeim, titleR: '交付使用日期', contentR: data?.jfsyrq, ), const SizedBox( height: 6, ), ], ), Positioned( top: 12, right: 12, child: Container( decoration: BoxDecoration( borderRadius: const BorderRadius.all(Radius.circular(40)), border: Border.all( color: const Color(0xFFFF0000), width: 4.0), ), width: 80, height: 80, child: Center( child: Transform.rotate( angle: 0.5, child: Text( data?.cfzt ?? '', textScaler: TextScaler.noScaling, style: const TextStyle( color: Color(0xFFFF0000), fontSize: 28, fontWeight: FontWeight.w800,), ), ), ), ), ), ], ), ), const SizedBox(height: 12), Container( decoration: const BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(12))), child: Column( children: [ const StoreHouseTit(tit: '仓房信息'), SHImageAndNameWidget( image: sh_cang, title: '设计仓容', content: '${data?.ajsjcr}吨', fontSize: 15, imageR: sh_nian, titleR: '设计使用年限', contentR: '${data?.sjsynx}年', ), const Divider( thickness: 0.6, color: Color(0xFFEEEEEE), indent: 12, ), SHImageAndNameWidget( image: sh_chang, title: '长*宽*高(米)', content: data?.ckg, fontSize: 15, imageR: sh_xiangao, titleR: '装粮线高(米)', contentR: data?.cnzlxg), const SizedBox( height: 6, ), ], ), ), const SizedBox(height: 12), Container( decoration: const BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(12))), child: Stack( children: [ Column( children: [ const StoreHouseTit(tit: '粮食库存'), Padding( padding: const EdgeInsets.symmetric(horizontal: 12), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( padding: const EdgeInsets.symmetric(horizontal: 6), alignment: Alignment.center, decoration: BoxDecoration( color: const Color(0xFFEBF8FE), border: Border.all( color: const Color(0xFF60B5F4), width: 1.0), borderRadius: BorderRadius.circular(4) // 设置边框样式 ), child: Text( '产地:${data?.itemList?.first?.cd}', style: const TextStyle( fontSize: 14, color: Color(0xFF60B5F4)), ), ), Container( padding: const EdgeInsets.symmetric(horizontal: 6), alignment: Alignment.center, decoration: BoxDecoration( color: const Color(0xFFFAFAEE), border: Border.all( color: const Color(0xFFE6B32A), width: 1.0), borderRadius: BorderRadius.circular(4) // 设置边框样式 ), child: Text( '粮食等级:${data?.itemList?.first?.lsdjmc}', style: const TextStyle( fontSize: 14, color: Color(0xFFE6B32A)), ), ), ], ), ), SHImageAndNameWidget( image: sh_xingzhi, title: '储存性质', content: data?.itemList?.first?.lsxzmc, fontSize: 15, imageR: sh_niandu, titleR: '收获年度', contentR: '${data?.itemList?.first?.shnd}年'), const Divider( thickness: 0.6, color: Color(0xFFEEEEEE), indent: 12, ), SHImageAndNameWidget( image: sh_kucun, title: '库存', content: '${data?.itemList?.first?.jjsl}吨', fontSize: 15, imageR: sh_rucang, titleR: '入仓时间', contentR: data?.itemList?.first?.timeStr()), const Divider( thickness: 0.6, color: Color(0xFFEEEEEE), indent: 12, ), Padding( padding: const EdgeInsets.all(12), child: Row( children: [ Image.asset( sh_danwei, width: 32, height: 32, ), const SizedBox( width: 6, ), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text( '粮权归属单位', style: TextStyle( fontWeight: FontWeight.bold, fontSize: 15, color: Colors.grey), ), Text( data?.itemList?.first?.lqgsdw ?? '', style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 15), ) ], ), ) ], ), ), const SizedBox(height: 6), ], ), Positioned( top: 12, right: 0, child: Container( padding: const EdgeInsets.symmetric( horizontal: 18, vertical: 2), decoration: const BoxDecoration( color: Color(0xFF60B5F4), borderRadius: BorderRadius.only( topLeft: Radius.circular(10), bottomLeft: Radius.circular(10)), ), child: Text( '品种:${data?.itemList?.first?.lspzmc}', style: const TextStyle(color: Colors.white), ), ), ), ], ), ) ], ), ), ], ); }), ), )), ], ) ); } }