store_house_page.dart 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import 'dart:convert';
  2. import 'package:dotted_border/dotted_border.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
  6. import 'package:lszlgl/base/base_lifecycle_state.dart';
  7. import 'package:lszlgl/base/base_vm.dart';
  8. import 'package:lszlgl/config/borders.dart';
  9. import 'package:lszlgl/main.dart';
  10. import 'package:lszlgl/model/api_rsp.dart';
  11. import 'package:lszlgl/model/rsp/storehouse_rsp.dart';
  12. import 'package:lszlgl/network/my_api.dart';
  13. import 'package:lszlgl/widget/page_widget.dart';
  14. import 'package:lszlgl/widget/storehouse_item.dart';
  15. class StoreHousePage extends StatefulWidget {
  16. final String houseNum;
  17. const StoreHousePage({super.key, required this.houseNum});
  18. @override
  19. State<StoreHousePage> createState() => _StoreHousePageState();
  20. }
  21. class _StoreHousePageState extends BaseLifecycleState<StoreHousePage> {
  22. final pageState = DataStatusModel<storehouseRsp?>().notifier<DataStatusModel<storehouseRsp?>>();
  23. storehouseRsp? data;
  24. final ValueNotifier<String> _title = ValueNotifier<String>('仓房信息');
  25. @override
  26. void onFirstShow(Duration timeStamp) {
  27. loadData();
  28. }
  29. @override
  30. void onDestroy() {
  31. pageState.dispose();
  32. }
  33. void loadData() async{
  34. pageState.update(pageState.value.loading());
  35. try{
  36. // String jsonStr = await Future.delayed(const Duration(seconds: 3),()async{
  37. // return rootBundle.loadString('assets/json/storehouse.json');
  38. // });
  39. // Map<String,dynamic> val = json.decode(jsonStr);
  40. // ApiRsp<List<storehouseRsp?>> res= ApiRsp<List<storehouseRsp>>.fromJson(
  41. // val,
  42. // (json) => json is List<dynamic>
  43. // ? json
  44. // .map<storehouseRsp>((i) => storehouseRsp.fromJson(i as Map<String, dynamic>))
  45. // .toList()
  46. // : List.empty(),
  47. // );
  48. var res = await MyApi.get(baseUrl: 'http://101.36.160.117:28088').getStoreMessage(widget.houseNum, 'zhijian');
  49. if(res.data == null ){
  50. pageState.update(pageState.value.empty());
  51. }else{
  52. data = res.data!.first;
  53. _title.value = data?.kqmc ?? '仓房信息' ;
  54. pageState.update(pageState.value.success(data: res.data!.first));
  55. }
  56. }catch(e){
  57. logger.e(e);
  58. pageState.update(pageState.value.error());
  59. }
  60. }
  61. @override
  62. Widget build(BuildContext context) {
  63. return myScaffold(
  64. child: KeyboardDismissOnTap(
  65. dismissOnCapturedTaps: true,
  66. child: Column(
  67. children: [
  68. ValueListenableBuilder(
  69. valueListenable: _title,
  70. builder: (_,String title,__){
  71. return myAppBar(title: title);
  72. },
  73. ),
  74. Expanded(
  75. child:Container(
  76. color: Colors.white,
  77. child: SingleChildScrollView(
  78. child: pageState.builder((v){
  79. if(v.status == DataStatus.error){
  80. return PageLoadingWidget.error(onTap: loadData);
  81. }
  82. if(v.status == DataStatus.empty){
  83. return const PageLoadingWidget.empty();
  84. }
  85. if(v.status == DataStatus.loading){
  86. return const PageLoadingWidget.loading();
  87. }
  88. return Column(
  89. //crossAxisAlignment: CrossAxisAlignment.stretch,
  90. children: [
  91. Padding(padding: const EdgeInsets.fromLTRB(22, 20, 22, 4),
  92. child: Column(
  93. crossAxisAlignment: CrossAxisAlignment.stretch,
  94. children: [
  95. Text(data?.cfmc ?? '',style: TextStyles.titA,),
  96. const SizedBox(height: 12),
  97. Text('仓房编号:${data?.tycfbm}',style: TextStyles.titA),
  98. const SizedBox(height: 12),
  99. const Divider(thickness: 0.6,),
  100. const SizedBox(height: 6),
  101. StorehouseItem(special: true,left: data?.cflx,right: data?.cfzt),
  102. StorehouseItem(left: '保管员',right: data?.bgr),
  103. StorehouseItem(left: '交付使用日期', right: data?.jfsyrq),
  104. const SizedBox(height: 10),
  105. const Divider(thickness: 0.6,),
  106. ],
  107. ),
  108. ),
  109. const StoreHouseTit(tit: '仓房信息'),
  110. Padding(padding: const EdgeInsets.fromLTRB(22, 8, 22, 4),
  111. child:Column(
  112. crossAxisAlignment: CrossAxisAlignment.stretch,
  113. children: [
  114. StorehouseItem(left: '设计仓容',right: '${data?.ajsjcr}吨',),
  115. StorehouseItem(left: '设计使用年限',right: '${data?.sjsynx}年',),
  116. StorehouseItem(left: '装粮线高',right: '${data?.cnzlxg}米',),
  117. StorehouseItem(left: '长*宽*高',right: data?.ckg,),
  118. const SizedBox(height: 10),
  119. const Divider(thickness: 0.6,),
  120. ],
  121. )
  122. ),
  123. const StoreHouseTit(tit: '粮食库存'),
  124. Container(
  125. padding: const EdgeInsets.symmetric(horizontal:22,vertical: 12),
  126. child: DottedBorder(
  127. strokeWidth: 0.8,
  128. color: Colors.grey,
  129. dashPattern:const[3,4],
  130. padding: const EdgeInsets.all(8),
  131. child: Column(
  132. crossAxisAlignment: CrossAxisAlignment.stretch,
  133. children: [
  134. StorehouseItem(left: '粮食品种',right: data?.itemList?.first?.lspzmc),
  135. StorehouseItem(left: '粮食等级',right: data?.itemList?.first?.lsdjmc),
  136. StorehouseItem(left: '库存',right: '${data?.itemList?.first?.jjsl}kg'),
  137. StorehouseItem(left: '储存性质',right: data?.itemList?.first?.lsxzmc),
  138. StorehouseItem(left: '粮权归属单位',right: data?.itemList?.first?.lqgsdw),
  139. StorehouseItem(left: '入仓时间',right: data?.itemList?.first?.timeStr()),
  140. StorehouseItem(left: '产地',right: data?.itemList?.first?.cd),
  141. StorehouseItem(left: '收货年度',right: '${data?.itemList?.first?.shnd}年'),
  142. ],
  143. ),
  144. ),
  145. )
  146. ],
  147. );
  148. }
  149. ),
  150. ),
  151. )
  152. ),
  153. ],
  154. )
  155. ),
  156. );
  157. }
  158. }