YSHomeListDetailEmail.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_tzh/home/view/YSInputView.dart';
  4. import 'package:flutter_tzh/tool/YSChooseView.dart';
  5. import 'package:flutter_tzh/tool/YSNetWork.dart';
  6. import '../base/YSBase.dart';
  7. import '../tool/YSTools.dart';
  8. class YSHomeListDetailEmail extends StatefulWidget {
  9. final String planNum;
  10. const YSHomeListDetailEmail({Key? key, required this.planNum}) : super(key: key);
  11. @override
  12. YSHomeListDetailEmailState createState() => YSHomeListDetailEmailState();
  13. }
  14. class YSHomeListDetailEmailState extends State<YSHomeListDetailEmail> {
  15. final List _dataArray = [
  16. {'title':'收件地址','array':[
  17. {'title':'收件人','key':'name'},
  18. {'title':'电 话','key':'phone'},
  19. {'title':'地 址','key':'address'}
  20. ]},
  21. {'title':'快递单号','array':[
  22. {'title':'快递公司','type':3,'key':'express'},
  23. {'title':'快递单号','type':1,'key':'expressCode'}
  24. ]},
  25. {'title':'备注信息','array':[
  26. {'title':'备注信息','type':2,'key':'remark'},
  27. ]},
  28. ];
  29. final List _expressList = [];
  30. @override
  31. void initState() {
  32. networkDelay((){
  33. _getDeliveryIndex();
  34. });
  35. super.initState();
  36. }
  37. _getDeliveryIndex() async{
  38. YSNetWork.ysRequestHttp(context, type: RequestType.get, api: '/delivery/index', parameter: {}, successSetter: (dict){
  39. Map data = dict['data']??{};
  40. Map item0 = _dataArray.firstWhere((element) => element['title']=='收件地址');
  41. List array0 = item0['array']??[];
  42. for (var element in array0) {
  43. element['value'] = data['delivery'][element['key']];
  44. }
  45. List expressList = data['expressList']??[];
  46. _expressList.clear();
  47. for (var element in expressList) {
  48. _expressList.add({'label':element});
  49. }
  50. setState(() {});
  51. });
  52. }
  53. @override
  54. Widget build(BuildContext context) {
  55. return YSBase(
  56. ysTitle: '邮寄',
  57. ysChild: SingleChildScrollView(
  58. child: Column(
  59. children: [
  60. SizedBox(
  61. height: ysHeight(context)-ysTOP(context)-44-hsp(72),
  62. child: SingleChildScrollView(
  63. padding: EdgeInsets.only(left: hsp(20),right: hsp(20),top: hsp(20)),
  64. child: Column(
  65. children: [
  66. ListView.separated(
  67. itemBuilder: (context, index) {
  68. Map item = _dataArray[index];
  69. List array = item['array']??[];
  70. return Container(
  71. padding: EdgeInsets.all(hsp(15)),
  72. decoration: BoxDecoration(
  73. color: const Color(0xFF2E3138),
  74. borderRadius: const BorderRadius.all(Radius.circular(24)),
  75. border: Border.all(color: const Color(0xFF3E434E),width: hsp(1))
  76. ),
  77. child: Column(
  78. children: [
  79. if('${item['title']}'.isNotEmpty)Container(
  80. height: hsp(30),
  81. alignment: Alignment.centerLeft,
  82. child: Text('${item['title']}',style: TextStyle(fontSize: zsp(14),color: const Color(0xFFDBE1EA)),),
  83. ),
  84. ListView.builder(
  85. itemBuilder: (context, indexSub) {
  86. Map itemSub = array[indexSub];
  87. int type = itemSub['type']??0;
  88. return Container(
  89. padding: EdgeInsets.only(top: hsp(10)),
  90. child: LayoutBuilder(builder: (context,conSize){
  91. return type==2?YSInputView(
  92. item: itemSub
  93. ):Row(
  94. children: [
  95. SizedBox(
  96. width: conSize.maxWidth*0.3,
  97. child: Text('${itemSub['title']}:',style: TextStyle(fontSize: zsp(14),color: ysTitleColor),),
  98. ),
  99. Container(
  100. width: conSize.maxWidth*0.7,
  101. alignment: Alignment.centerRight,
  102. child: type==1?CupertinoTextField(
  103. placeholderStyle: TextStyle(fontSize: zsp(14),color: ysValueColor),
  104. style: TextStyle(fontSize: zsp(14),color: ysValueColor),
  105. padding: const EdgeInsets.all(0),
  106. placeholder: '请输入${item['title']}',
  107. decoration: const BoxDecoration(color: Colors.transparent),
  108. textAlign: TextAlign.right,
  109. onChanged: (value){
  110. if(value.isNotEmpty){
  111. itemSub['value'] = value;
  112. }else{
  113. itemSub.remove('value');
  114. }
  115. },
  116. ):type==3?GestureDetector(
  117. onTap: (){
  118. ysShowBottomAlertView(context, YSPicker(dataArray: _expressList, choose: (value){
  119. itemSub['value'] = value['label'];
  120. setState(() {});
  121. }),isBarr: true);
  122. },
  123. behavior: HitTestBehavior.opaque,
  124. child: Row(
  125. children: [
  126. Container(
  127. width: conSize.maxWidth*0.7-hsp(20),
  128. alignment: Alignment.centerRight,
  129. child: Text(itemSub['value']??'请选择${item['title']}',style: TextStyle(fontSize: zsp(14),color: ysValueColor),),
  130. ),
  131. Icon(Icons.chevron_right,size: hsp(20),color: Colors.white,)
  132. ],
  133. ),
  134. ):Text(itemSub['value']??'',style: TextStyle(fontSize: zsp(14),color: ysValueColor),),
  135. )
  136. ],
  137. );
  138. }),
  139. );
  140. },
  141. itemCount: array.length,
  142. padding: const EdgeInsets.all(0),
  143. physics: const NeverScrollableScrollPhysics(),
  144. shrinkWrap: true,
  145. )
  146. ],
  147. ),
  148. );
  149. },
  150. separatorBuilder: (context,index){
  151. return Container(height: hsp(12),);
  152. },
  153. itemCount: _dataArray.length,
  154. shrinkWrap: true,
  155. padding: EdgeInsets.only(bottom: hsp(12)),
  156. physics: const NeverScrollableScrollPhysics(),
  157. ),
  158. ],
  159. ),
  160. ),
  161. ),
  162. GestureDetector(
  163. behavior: HitTestBehavior.opaque,
  164. onTap: () async{
  165. //{'title':'快递单号','array':[
  166. // {'title':'快递公司','value':'顺丰快递','type':3},
  167. // {'title':'快递单号','value':'请输入快递单号','type':1}
  168. // ]},
  169. // {'title':'快递信息','array':[
  170. // {'title':'快递信息','type':2},
  171. // ]},
  172. Map item1 = _dataArray.firstWhere((element) => element['title']=='快递单号');
  173. List array1 = item1['array']??[];
  174. Map item2 = _dataArray.firstWhere((element) => element['title']=='快递信息');
  175. List array2 = item2['array']??[];
  176. Map request = {'planNum':widget.planNum};
  177. for (var element in array1) {
  178. if(element['value']==null){
  179. ysFlutterToast('请完善${element['title']}');
  180. return;
  181. }else{
  182. request[element['key']] = element['value'];
  183. }
  184. }
  185. for (var element in array2) {
  186. if(element['value']==null){
  187. ysFlutterToast('请完善${element['title']}');
  188. return;
  189. }else{
  190. request[element['key']] = element['value'];
  191. }
  192. }
  193. LogUtil.d(request);
  194. YSNetWork.ysRequestHttp(context, type: RequestType.post, api: '/samp/express', parameter: request, successSetter: (dict){
  195. ysFlutterToast('样本已邮寄');
  196. Navigator.of(context).pop('');
  197. },isLoading: true);
  198. },
  199. child: Image.asset('images/tzh_submit.png',height: hsp(72),),
  200. )
  201. ],
  202. ),
  203. ),
  204. );
  205. }
  206. }