YSGather.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_tzh/base/YSBase.dart';
  4. import 'package:flutter_tzh/home/view/YSInputView.dart';
  5. import 'package:flutter_tzh/tool/YSDatePicker.dart';
  6. import 'package:flutter_tzh/tool/YSNetWork.dart';
  7. import 'package:flutter_tzh/tool/YSTools.dart';
  8. import '../base/YSTabBar.dart';
  9. class YSGather extends StatefulWidget {
  10. const YSGather({Key? key}) : super(key: key);
  11. @override
  12. YSGatherState createState() => YSGatherState();
  13. }
  14. class YSGatherState extends State<YSGather> {
  15. final List _dataArray = [
  16. {'title':'地块','type':1,'key':'landId'},
  17. {'title':'采样计划名称','type':2,'controller':TextEditingController(),'key':'name'},
  18. {'title':'收件人','type':2,'controller':TextEditingController(),'key':'email'},
  19. {'title':'主题','type':2,'controller':TextEditingController(),'key':'subject'},
  20. {'title':'取样时间范围','type':1,'key':'time'},
  21. {'title':'采样内容','type':2,'key':'content'},
  22. {'title':'邮件内容','type':3,'key':'text'}
  23. ];
  24. bool _isAlert = false;
  25. List _info = [];
  26. String _dk = '[地块]';
  27. String _sj = '[采样时间]';
  28. String _text = '';
  29. _getContent() {
  30. Map nr = _dataArray.firstWhere((element) => element['title']=='邮件内容');
  31. String content = nr['value']??'';
  32. Map dk = _dataArray.firstWhere((element) => element['title']=='地块');
  33. if(dk['valueLabel']!=null){
  34. _dk = '[${dk['valueLabel']}]';
  35. }
  36. Map fw = _dataArray.firstWhere((element) => element['title']=='取样时间范围');
  37. if(fw['valueLabel']!=null){
  38. _sj = '[${fw['valueLabel']}]';
  39. }
  40. content = '$_text 我们计划在$_sj对$_dk进行采样工作,以收集必要的数据和样本。这次采样旨在了解地块的土壤、水质或其他相关特征\n'
  41. '您的参与对于确保采样的准确性和可靠性非常重要。我们邀请您到场并全程参与采样工作。您的专业知识和经验将为我们的研究提供宝贵的支持。\n'
  42. '请您在$_sj准时到达采样地点。如有需要,请提前做好一切准备工作,确保您能够充分发挥自己的专业能力。如果您需要携带任何特定的工具或个人保护装备,请务必提前告知我们。\n'
  43. '谢谢!';
  44. nr['value'] = content;
  45. LogUtil.d(nr);
  46. setState(() {});
  47. }
  48. _getUserTemplate() async{
  49. YSNetWork.ysRequestHttp(context, type: RequestType.get, api: '/user/template', parameter: {}, successSetter: (dict){
  50. Map data = dict['data'];
  51. _info = data['info']??[];
  52. if(_info.isNotEmpty){
  53. Map zt = _dataArray.firstWhere((element) => element['title']=='主题');
  54. TextEditingController ztController = zt['controller'];
  55. zt['value'] = data['subject'];
  56. ztController.text = data['subject']??'';
  57. _text = data['text'];
  58. }
  59. });
  60. }
  61. @override
  62. void initState() {
  63. networkDelay((){
  64. _getUserTemplate();
  65. });
  66. super.initState();
  67. }
  68. @override
  69. void dispose() {
  70. for (var element in _dataArray) {
  71. TextEditingController controller = element['controller']??TextEditingController();
  72. controller.dispose();
  73. }
  74. super.dispose();
  75. }
  76. @override
  77. Widget build(BuildContext context) {
  78. return GestureDetector(
  79. child: YSBase(
  80. ysTitle: '新建土地',
  81. ysChild: GestureDetector(
  82. onTap: (){
  83. _isAlert = false;
  84. setState(() {});
  85. },
  86. child: SingleChildScrollView(
  87. child: Stack(
  88. children: [
  89. Column(
  90. children: [
  91. SizedBox(
  92. height: ysHeight(context)-ysTOP(context)-44-hsp(72),
  93. child: ListView.separated(
  94. itemBuilder: (context, index) {
  95. Map item = _dataArray[index];
  96. return LayoutBuilder(builder: (context, constraints) {
  97. return Container(
  98. padding: EdgeInsets.only(left: hsp(12),right: hsp(12),top: hsp(5),bottom: hsp(5)),
  99. decoration: BoxDecoration(
  100. color: const Color(0xFF1A1C1F),
  101. borderRadius: const BorderRadius.all(Radius.circular(3)),
  102. border: Border.all(color: const Color(0xFF3E434E),width: hsp(1))
  103. ),
  104. child: item['type']==1?GestureDetector(
  105. onTap: () {
  106. FocusScope.of(context).unfocus();
  107. if(item['title']=='取样时间范围'){
  108. showDateRangePicker(
  109. context: context,
  110. firstDate: DateTime.now(),
  111. lastDate: DateTime.now().add(const Duration(days: 10000)),
  112. builder: (context,child){
  113. return Theme(data: Theme.of(context).copyWith(
  114. appBarTheme: Theme.of(context).appBarTheme.copyWith(backgroundColor: const Color(0xFF23262B)),
  115. scaffoldBackgroundColor: const Color(0xFF23262B),
  116. textTheme: Theme.of(context).textTheme.copyWith(
  117. bodyText2: TextStyle(fontSize: zsp(14),color: Colors.white),
  118. ),
  119. colorScheme: Theme.of(context).colorScheme.copyWith(primary: const Color(0xFF31D19E),onSurface: Colors.grey)
  120. ), child: child!);
  121. // return Theme(
  122. // data: ThemeData.dark(),
  123. // child: child!,
  124. // );
  125. },
  126. initialEntryMode: DatePickerEntryMode.calendarOnly,
  127. ).then((value) {
  128. if(value!=null){
  129. String start = timeFormat(value.start.millisecondsSinceEpoch,format: 'yyyy-MM-dd');
  130. String end = timeFormat(value.end.millisecondsSinceEpoch,format: 'yyyy-MM-dd');
  131. item['valueLabel'] = '$start - $end';
  132. item['value'] = start;
  133. item['value2'] = end;
  134. _getContent();
  135. }
  136. });
  137. }else if(item['title']=='地块'){
  138. FocusScope.of(context).unfocus();
  139. _isAlert = !_isAlert;
  140. setState(() {});
  141. // ysShowCenterAlertView(context, Container(
  142. // height: hsp(200),
  143. // color: Colors.white,
  144. // margin: EdgeInsets.only(top: ysTOP(context)+44+hsp(76),left: hsp(20),right: hsp(20),bottom: (ysHeight(context)-ysTOP(context)-44-hsp(76))*0.5),
  145. // ),isTrans: true,isBarr: true);
  146. }
  147. },
  148. behavior: HitTestBehavior.opaque,
  149. child: Row(
  150. children: [
  151. SizedBox(
  152. width: constraints.maxWidth-hsp(39),
  153. child: Column(
  154. mainAxisSize: MainAxisSize.min,
  155. crossAxisAlignment: CrossAxisAlignment.start,
  156. children: [
  157. Text(item['title'],style: TextStyle(fontSize: zsp(11),color: const Color(0xFFACB5C5)),),
  158. SizedBox(
  159. height: hsp(20),
  160. child: Text(item['valueLabel']??item['value']??'请选择${item['title']}',style: TextStyle(fontSize: zsp(16),color: Colors.white),),
  161. )
  162. ],
  163. ),
  164. ),
  165. Image.asset('images/tzh_down.png',height: hsp(10),width: hsp(10),)
  166. ],
  167. ),
  168. ):Column(
  169. mainAxisSize: MainAxisSize.min,
  170. crossAxisAlignment: CrossAxisAlignment.start,
  171. children: [
  172. Text(item['title'],style: TextStyle(fontSize: zsp(11),color: const Color(0xFFACB5C5)),),
  173. item['type']==3?YSInputView2(
  174. key: Key('${item['value']}'),
  175. item: item,
  176. length: 300,
  177. height: 200,
  178. ):SizedBox(
  179. height: hsp(20),
  180. child: item['type']==4?Text(
  181. item['value']??'',style: TextStyle(fontSize: zsp(16),color: Colors.white),
  182. ):CupertinoTextField(
  183. placeholder: '请输入${item['title']}',
  184. style: TextStyle(fontSize: zsp(16),color: Colors.white),
  185. padding: const EdgeInsets.all(0),
  186. placeholderStyle: TextStyle(fontSize: zsp(16),color: Colors.white),
  187. decoration: const BoxDecoration(
  188. color: Colors.transparent
  189. ),
  190. maxLines: 100,
  191. onChanged: (value){
  192. if(value.isNotEmpty){
  193. item['value'] = value;
  194. }else{
  195. item.remove('value');
  196. }
  197. },
  198. controller: item['controller'],
  199. )
  200. )
  201. ],
  202. ),
  203. );
  204. });
  205. },
  206. separatorBuilder: (context,index){
  207. return Container(height: hsp(12),);
  208. },
  209. itemCount: _dataArray.length,
  210. padding: EdgeInsets.only(left: hsp(20),right: hsp(20),top: hsp(30)),
  211. ),
  212. ),
  213. GestureDetector(
  214. onTap: (){
  215. LogUtil.d(_dataArray);
  216. Map request = {};
  217. for (var element in _dataArray) {
  218. if(element['value']==null){
  219. ysFlutterToast('请完善${element['title']}');
  220. return;
  221. }else{
  222. if(element['key']=='time'){
  223. request['startTime'] = element['value'];
  224. request['endTime'] = element['value2'];
  225. }else{
  226. request[element['key']] = element['value'];
  227. }
  228. }
  229. }
  230. LogUtil.d(request);
  231. YSNetWork.ysRequestHttp(context, type: RequestType.post, api: '/samp/add', parameter: request, successSetter: (dict){
  232. ysFlutterToast('新增采样成功');
  233. Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context){
  234. return const YSTabBar();
  235. }), (route) => false);
  236. },isLoading: true);
  237. },
  238. behavior: HitTestBehavior.opaque,
  239. child: SizedBox(
  240. height: hsp(72),
  241. child: Image.asset('images/continue.png'),
  242. ),
  243. )
  244. ],
  245. ),
  246. if(_isAlert)Container(
  247. width: ysWidth(context)-hsp(40),
  248. color: const Color(0xFF1A1C1F),
  249. margin: EdgeInsets.only(top: hsp(76),left: hsp(20)),
  250. child: ListView.builder(
  251. itemBuilder: (context, index) {
  252. Map item = _info[index];
  253. return GestureDetector(
  254. onTap: (){
  255. _isAlert = false;
  256. Map dk = _dataArray.firstWhere((element) => element['title']=='地块');
  257. Map sjr = _dataArray.firstWhere((element) => element['title']=='收件人');
  258. dk['value'] = '${item['landId']}';
  259. dk['valueLabel'] = '${item['name']}';
  260. sjr['value'] = item['email'];
  261. TextEditingController controller = sjr['controller'];
  262. controller.text = sjr['value'];
  263. _getContent();
  264. },
  265. behavior: HitTestBehavior.opaque,
  266. child: Container(
  267. alignment: Alignment.centerLeft,
  268. padding: EdgeInsets.only(left: hsp(12),right: hsp(12)),
  269. height: hsp(46),
  270. decoration: BoxDecoration(
  271. border: Border.all(color: const Color(0xFF3E434E),width: hsp(1))
  272. ),
  273. child: Text(item['name']??'',style: TextStyle(fontSize: zsp(16),color: Colors.white),),
  274. ),
  275. );
  276. },
  277. itemCount: _info.length,
  278. padding: const EdgeInsets.all(0),
  279. shrinkWrap: true,
  280. physics: const NeverScrollableScrollPhysics(),
  281. ),
  282. )
  283. ],
  284. ),
  285. ),
  286. ),
  287. ),
  288. );
  289. }
  290. }