YSChooseView.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'YSNetWork.dart';
  4. import 'YSTools.dart';
  5. class YSPicker extends StatefulWidget {
  6. final List dataArray;
  7. final String title;
  8. final ValueSetter choose;
  9. const YSPicker({Key? key, this.title = 'label',required this.dataArray, required this.choose,}) : super(key: key);
  10. @override
  11. YSPickerState createState() => YSPickerState();
  12. }
  13. class YSPickerState extends State<YSPicker> {
  14. Map _value = {};
  15. @override
  16. void initState() {
  17. if(widget.dataArray.isNotEmpty){
  18. _value = widget.dataArray[0];
  19. }
  20. super.initState();
  21. }
  22. @override
  23. Widget build(BuildContext context) {
  24. return Container(
  25. color: Colors.transparent,
  26. height: hsp(300),
  27. child: Column(
  28. crossAxisAlignment: CrossAxisAlignment.end,
  29. children: [
  30. Container(
  31. height: hsp(50),
  32. padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  33. decoration: BoxDecoration(
  34. color: ysBgColor,
  35. border: const Border(bottom: BorderSide(width: 0.5,color: Colors.white24))
  36. ),
  37. child: Row(
  38. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  39. children: [
  40. GestureDetector(
  41. child: Text('取消',style: TextStyle(fontSize: zsp(15),color: Colors.white60),),
  42. onTap: (){
  43. Navigator.pop(context);
  44. },
  45. ),
  46. GestureDetector(
  47. child: Text('确定',style: TextStyle(fontSize: zsp(15),color: Colors.white),),
  48. onTap: (){
  49. if(_value.isNotEmpty){
  50. widget.choose(_value);
  51. }
  52. Navigator.pop(context);
  53. },
  54. )
  55. ],
  56. ),
  57. ),
  58. Container(
  59. height: hsp(250),
  60. padding: const EdgeInsets.all(10),
  61. color: ysBgColor,
  62. child: CupertinoPicker(
  63. itemExtent: hsp(50),
  64. onSelectedItemChanged: (value){
  65. _value = widget.dataArray[value];
  66. },
  67. children: [
  68. for(int i=0;i<widget.dataArray.length;i++)Container(
  69. alignment: Alignment.center,
  70. child: Text('${widget.dataArray[i][widget.title]}',style: const TextStyle(color: Colors.white),),
  71. )
  72. ],
  73. ),
  74. ),
  75. ],
  76. ),
  77. );
  78. }
  79. }
  80. class YSMultipleChoose extends StatefulWidget {
  81. final String projectId;
  82. final ValueSetter<List> choose;
  83. const YSMultipleChoose({Key? key, required this.projectId, required this.choose}) : super(key: key);
  84. @override
  85. YSMultipleChooseState createState() => YSMultipleChooseState();
  86. }
  87. class YSMultipleChooseState extends State<YSMultipleChoose> {
  88. List _dataArray = [];
  89. List _chooseArray = [];
  90. @override
  91. void initState() {
  92. Future.delayed(const Duration(seconds: 0)).then((value) {
  93. _getData();
  94. });
  95. super.initState();
  96. }
  97. @override
  98. Widget build(BuildContext context) {
  99. return Container(
  100. color: Colors.transparent,
  101. height: hsp(300),
  102. child: Column(
  103. crossAxisAlignment: CrossAxisAlignment.end,
  104. children: [
  105. Container(
  106. height: hsp(50),
  107. padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  108. decoration: const BoxDecoration(
  109. color: Colors.white,
  110. border: Border(bottom: BorderSide(width: 0.5,color: Color(0xFFEEEEEE)))
  111. ),
  112. child: Row(
  113. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  114. children: [
  115. GestureDetector(
  116. child: Text('取消',style: TextStyle(fontSize: zsp(15),color: const Color(0xFF999999)),),
  117. onTap: (){
  118. Navigator.pop(context);
  119. },
  120. ),
  121. GestureDetector(
  122. child: Text('确定',style: TextStyle(fontSize: zsp(15),color: const Color(0xFF108DE9)),),
  123. onTap: (){
  124. if(_chooseArray.isNotEmpty){
  125. widget.choose(_chooseArray);
  126. }
  127. Navigator.pop(context);
  128. },
  129. )
  130. ],
  131. ),
  132. ),
  133. Container(
  134. height: hsp(250),
  135. color: ysBgColor,
  136. child: ListView.separated(
  137. itemBuilder: (context,index){
  138. Map item = _dataArray[index];
  139. bool isChoose = _chooseArray.contains(item);
  140. return GestureDetector(
  141. onTap: (){
  142. if(isChoose){
  143. _chooseArray.remove(item);
  144. }else{
  145. _chooseArray.add(item);
  146. }
  147. setState(() {});
  148. },
  149. child: Container(
  150. color: Colors.white,
  151. padding: EdgeInsets.all(hsp(16)),
  152. child: LayoutBuilder(
  153. builder: (context,conSize){
  154. return Row(
  155. children: [
  156. Icon(
  157. isChoose?Icons.check_circle:Icons.radio_button_unchecked,
  158. size: hsp(15),
  159. color: Color(isChoose?0xFF377DFE:0xFF4A4A4A),
  160. ),
  161. Container(
  162. width: conSize.maxWidth-hsp(15),
  163. padding: EdgeInsets.only(left: hsp(5)),
  164. child: Text(item['partsName']??'',style: TextStyle(fontSize: zsp(14),color: const Color(0xFF4A4A4A)),),
  165. )
  166. ],
  167. );
  168. },
  169. ),
  170. ),
  171. );
  172. },
  173. separatorBuilder: (context,index){
  174. return Divider(height: hsp(1),thickness: hsp(1),color: ysBgColor,);
  175. },
  176. itemCount: _dataArray.length,
  177. padding: const EdgeInsets.all(0),
  178. ),
  179. ),
  180. ],
  181. ),
  182. );
  183. }
  184. _getData() async{
  185. YSNetWork.ysRequestHttp(context, type: RequestType.post, api: 'maintain/parts/appDetailByProjectId',
  186. parameter: {'projectId':widget.projectId,'codeStr':'app','recordId':YSData().detailsId}, successSetter: (dict){
  187. _dataArray = dict['data']??[];
  188. setState(() {});
  189. });
  190. }
  191. }
  192. class YSPickerWithSearchView extends StatefulWidget {
  193. final List dataArray;
  194. final ValueSetter choose;
  195. const YSPickerWithSearchView({Key? key, required this.dataArray, required this.choose}) : super(key: key);
  196. @override
  197. YSPickerWithSearchViewState createState() => YSPickerWithSearchViewState();
  198. }
  199. class YSPickerWithSearchViewState extends State<YSPickerWithSearchView> {
  200. String _searchStr = '';
  201. List _searchArray = [];
  202. @override
  203. void initState() {
  204. _searchArray.addAll(widget.dataArray);
  205. super.initState();
  206. }
  207. @override
  208. Widget build(BuildContext context) {
  209. return Container(
  210. decoration: const BoxDecoration(
  211. color: Colors.white,
  212. borderRadius: BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10))
  213. ),
  214. height: hsp(600),
  215. child: Column(
  216. crossAxisAlignment: CrossAxisAlignment.end,
  217. children: [
  218. Container(
  219. height: hsp(50),
  220. padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  221. child: Row(
  222. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  223. children: [
  224. Container(),
  225. Text('选择车辆',style: TextStyle(fontSize: zsp(16),color: Colors.black),),
  226. Container(
  227. height: hsp(15),
  228. width: hsp(15),
  229. decoration: BoxDecoration(
  230. color: Colors.white,
  231. border: Border.all(color: Colors.black,width: 1),
  232. borderRadius: const BorderRadius.all( Radius.circular(50))
  233. ),
  234. alignment: Alignment.center,
  235. child: Icon(Icons.close,size: hsp(10),color: Colors.black,),
  236. )
  237. ],
  238. ),
  239. ),
  240. Container(
  241. height: hsp(50),
  242. alignment: Alignment.center,
  243. padding: EdgeInsets.only(top: hsp(5),bottom: hsp(5),left: hsp(30),right: hsp(30)),
  244. child: CupertinoTextField(
  245. decoration: BoxDecoration(
  246. borderRadius: const BorderRadius.all(Radius.circular(50)),
  247. border: Border.all(color: Colors.grey.withOpacity(0.6),width: 1)
  248. ),
  249. padding: EdgeInsets.only(left: hsp(10),right: hsp(10),top: hsp(10),bottom: hsp(10)),
  250. prefix: Row(
  251. children: [
  252. Padding(
  253. padding: EdgeInsets.only(left: hsp(15)),
  254. child: Icon(Icons.search,size: hsp(20),color: Colors.grey,),
  255. )
  256. ],
  257. ),
  258. onChanged: (value){
  259. _searchStr = value;
  260. _searchArray = widget.dataArray.where((element) => '${element['LicensePlate']}'.contains(_searchStr)).toList();
  261. setState(() {});
  262. },
  263. ),
  264. ),
  265. Container(
  266. height: hsp(500),
  267. alignment: Alignment.center,
  268. child: ListView.separated(
  269. padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
  270. itemBuilder: (context,index){
  271. Map item = _searchArray[index];
  272. String licensePlate = item['LicensePlate']??'';
  273. String fStr = licensePlate.substring(0,1);
  274. List licensePlateArray = licensePlate.split(_searchStr);
  275. if(licensePlateArray.length>1){
  276. licensePlateArray.insert(1,_searchStr);
  277. }
  278. return GestureDetector(
  279. onTap: (){
  280. FocusScope.of(context).unfocus();
  281. widget.choose(item);
  282. Navigator.pop(context);
  283. },
  284. behavior: HitTestBehavior.opaque,
  285. child: Container(
  286. height: hsp(50),
  287. alignment: Alignment.centerLeft,
  288. child: LayoutBuilder(
  289. builder: (context,conSize){
  290. return Row(
  291. children: [
  292. Container(
  293. height: hsp(30),
  294. width: hsp(30),
  295. decoration: const BoxDecoration(
  296. color: Colors.blue,
  297. borderRadius: BorderRadius.all(Radius.circular(50))
  298. ),
  299. alignment: Alignment.center,
  300. child: Text(fStr,style: TextStyle(fontSize: zsp(13),color: Colors.white),),
  301. ),
  302. SizedBox(
  303. width: conSize.maxWidth-hsp(30),
  304. child: RichText(text: TextSpan(
  305. style: TextStyle(fontSize: zsp(15),color: Colors.black),
  306. text: ' ',
  307. children: <TextSpan>[
  308. for (int i = 0;i<licensePlateArray.length;i++)TextSpan(
  309. text: licensePlateArray[i],
  310. style: TextStyle(fontSize: zsp(15),color: licensePlateArray[i]==_searchStr?Colors.red:Colors.black)
  311. )
  312. ]
  313. ),),
  314. )
  315. ],
  316. );
  317. },
  318. ),
  319. ),
  320. );
  321. },
  322. separatorBuilder: (context,index){
  323. return Divider(height: 0.5,thickness: 0.5,color: Colors.grey.withOpacity(0.3),);
  324. },
  325. itemCount: _searchArray.length
  326. ),
  327. )
  328. ],
  329. ),
  330. );
  331. }
  332. }