position_list.dart 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. import 'dart:async';
  2. import 'package:amap_location_flutter_plugin/amap_location_flutter_plugin.dart';
  3. import 'package:amap_location_flutter_plugin/amap_location_option.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:liftmanager/widgets/app_search_bar.dart';
  6. import 'package:liftmanager/res/resources.dart';
  7. import 'package:liftmanager/routers/fluro_navigator.dart';
  8. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  9. import 'package:flutter_screenutil/flutter_screenutil.dart';
  10. import 'package:liftmanager/mvp/base_page_state.dart';
  11. import 'package:liftmanager/internal/bbs/presenter/position_list_presenter.dart';
  12. import 'package:liftmanager/internal/search/presenter/base_list_provider.dart';
  13. import 'package:liftmanager/internal/bbs/model/mix_model.dart';
  14. import 'package:liftmanager/widgets/state_layout.dart';
  15. import 'package:liftmanager/widgets/my_refresh_list.dart';
  16. import 'package:liftmanager/utils/time_format.dart';
  17. import 'package:city_pickers/city_pickers.dart';
  18. import 'package:provider/provider.dart';
  19. import 'package:liftmanager/internal/search/search_router.dart';
  20. import 'package:liftmanager/net/api_service.dart';
  21. import 'package:liftmanager/utils/toast.dart';
  22. import 'package:flutter_picker/flutter_picker.dart';
  23. import 'package:liftmanager/internal/wode/model/table_dicts_model.dart';
  24. import 'package:permission_handler/permission_handler.dart';
  25. class PositionList extends StatefulWidget {
  26. @override
  27. PositionListState createState() => PositionListState();
  28. }
  29. class PositionListState
  30. extends BasePageState<PositionList, PositionListPresenterSeconds> {
  31. Map<String, Object> _locationResult;
  32. StreamSubscription<Map<String, Object>> _locationListener;
  33. AmapLocationFlutterPlugin _locationPlugin = new AmapLocationFlutterPlugin();
  34. BaseListProvider<Records> provider = BaseListProvider<Records>();
  35. int _page = 1;
  36. List<dynamic> categoryList = [
  37. {"title": "地址", "label": "请选择地址"},
  38. {"title": "所属职位", "label": "所属职位"},
  39. {"title": "薪资范围", "label": "薪资范围"}
  40. ];
  41. ScrollController _scrollController = new ScrollController();
  42. @override
  43. void initState() {
  44. provider.setStateTypeNotNotify(StateType.loading);
  45. super.initState();
  46. ///移除定位监听
  47. if (null != _locationListener) {
  48. _locationListener.cancel();
  49. }
  50. ///销毁定位
  51. if (null != _locationPlugin) {
  52. _locationPlugin.destroy();
  53. }
  54. getInitLocation();
  55. _locationListener = _locationPlugin
  56. .onLocationChanged()
  57. .listen((Map<String, Object> result) {
  58. setState(() {
  59. _locationPlugin.stopLocation();
  60. _locationResult = result;
  61. print(_locationResult["city"]);
  62. print(_locationResult["province"]);
  63. // address latitude longitude
  64. provinceName = _locationResult["province"];
  65. categoryList[0]['label'] = _locationResult["city"];
  66. _onRefresh();
  67. setState(() {});
  68. _locationResult.forEach((key, value) {
  69. print(111);
  70. print('key:$key :');
  71. print('value:$value :');
  72. });
  73. });
  74. });
  75. getJobClass();
  76. }
  77. // 获取定位权限
  78. Future<bool> requestPermission() async {
  79. final permissions = await PermissionHandler()
  80. .requestPermissions([PermissionGroup.location]);
  81. if (permissions[PermissionGroup.location] == PermissionStatus.granted) {
  82. return true;
  83. } else {
  84. toasts('需要定位权限!');
  85. return false;
  86. }
  87. }
  88. getInitLocation() async {
  89. // if (await requestPermission()) {
  90. // final location = await AmapLocation.fetchLocation();
  91. // provinceName = location.province;
  92. // cityName = location.city;
  93. // categoryList[0]['label'] = location.city;
  94. // _onRefresh();
  95. // setState(() {});
  96. // }else {
  97. // _onRefresh();
  98. // }
  99. if (await requestPermission()) {
  100. if (null != _locationPlugin) {
  101. ///开始定位之前设置定位参数
  102. _setLocationOption();
  103. _locationPlugin.startLocation();
  104. }
  105. }
  106. }
  107. void _setLocationOption() {
  108. if (null != _locationPlugin) {
  109. AMapLocationOption locationOption = new AMapLocationOption();
  110. ///是否单次定位
  111. locationOption.onceLocation = true;
  112. ///是否需要返回逆地理信息
  113. locationOption.needAddress = true;
  114. ///逆地理信息的语言类型
  115. locationOption.geoLanguage = GeoLanguage.DEFAULT;
  116. ///设置Android端连续定位的定位间隔
  117. locationOption.locationInterval = 20000;
  118. ///设置Android端的定位模式<br>
  119. ///可选值:<br>
  120. ///<li>[AMapLocationMode.Battery_Saving]</li>
  121. ///<li>[AMapLocationMode.Device_Sensors]</li>
  122. ///<li>[AMapLocationMode.Hight_Accuracy]</li>
  123. locationOption.locationMode = AMapLocationMode.Hight_Accuracy;
  124. ///设置iOS端的定位最小更新距离<br>
  125. locationOption.distanceFilter = -1;
  126. ///设置iOS端期望的定位精度
  127. /// 可选值:<br>
  128. /// <li>[DesiredAccuracy.Best] 最高精度</li>
  129. /// <li>[DesiredAccuracy.BestForNavigation] 适用于导航场景的高精度 </li>
  130. /// <li>[DesiredAccuracy.NearestTenMeters] 10米 </li>
  131. /// <li>[DesiredAccuracy.Kilometer] 1000米</li>
  132. /// <li>[DesiredAccuracy.ThreeKilometers] 3000米</li>
  133. locationOption.desiredAccuracy = DesiredAccuracy.NearestTenMeters;
  134. ///设置iOS端是否允许系统暂停定位
  135. locationOption.pausesLocationUpdatesAutomatically = false;
  136. ///将定位参数设置给定位插件
  137. _locationPlugin.setLocationOption(locationOption);
  138. }
  139. }
  140. @override
  141. void dispose() {
  142. _scrollController.dispose();
  143. ///移除定位监听
  144. if (null != _locationListener) {
  145. _locationListener.cancel();
  146. }
  147. ///销毁定位
  148. if (null != _locationPlugin) {
  149. _locationPlugin.destroy();
  150. }
  151. super.dispose();
  152. }
  153. List<TableDictsModel> jobClass = [];
  154. // 获取招聘职位分类
  155. Future getJobClass() async {
  156. NewApiService().queryConstant('recruitment_info', 'job', onSuccess: (res) {
  157. jobClass = res;
  158. setState(() {});
  159. }, onError: (code, msg) {
  160. toasts(msg);
  161. });
  162. }
  163. Result addressResult = new Result();
  164. String provinceName;
  165. String cityName;
  166. // 选择地址
  167. void _clickEventFunc() async {
  168. Result tempResult = await CityPickers.showCityPicker(
  169. theme:ThemeData.light(),
  170. context: context,
  171. showType:ShowType.pc,
  172. locationCode: addressResult != null
  173. ?
  174. addressResult.areaId ??
  175. addressResult.cityId
  176. ??addressResult.provinceId
  177. : null, // 初始化地址信息
  178. );
  179. if (tempResult != null) {
  180. print(tempResult);
  181. addressResult = tempResult;
  182. provinceName = tempResult.provinceName;
  183. cityName = tempResult.cityName;
  184. categoryList[0]['label'] = addressResult.cityName;
  185. _onRefresh();
  186. setState(() {});
  187. }
  188. }
  189. changTypeClass(item, index) {
  190. if (index == 0) {
  191. // 选择地址
  192. _clickEventFunc();
  193. } else if (index == 1) {
  194. // 所属职位
  195. showPositionModal(context);
  196. } else if (index == 2) {
  197. // 薪资范围
  198. showSalaryModal(context);
  199. }
  200. setState(() {});
  201. }
  202. // 所属职位
  203. List jobClassData = [];
  204. String jobSelected;
  205. showPositionModal(BuildContext context) {
  206. jobClassData.clear();
  207. jobClassData.add("不限");
  208. for (var i = 0; i < jobClass.length; i++) {
  209. jobClassData.add(jobClass[i].value);
  210. }
  211. new Picker(
  212. // selecteds:[0],
  213. cancelText:"取消",
  214. confirmText:"确认",
  215. adapter: PickerDataAdapter<String>(
  216. pickerdata: jobClassData,
  217. ),
  218. changeToFirst: true,
  219. hideHeader: false,
  220. onConfirm: (Picker picker, List value) {
  221. if (value[0] == 0) {
  222. jobSelected = null;
  223. } else {
  224. jobSelected = picker.getSelectedValues()[0];
  225. print(jobSelected);
  226. }
  227. categoryList[1]['label'] = picker.getSelectedValues()[0];
  228. _onRefresh();
  229. setState(() {});
  230. },
  231. ).showModal(this.context);
  232. }
  233. List salaryRange = [
  234. {
  235. "title": "不限",
  236. "min": null,
  237. "max": null,
  238. },
  239. {
  240. "title": "3K以下",
  241. "min": 0,
  242. "max": 3000,
  243. },
  244. {
  245. "title": "3-5k",
  246. "min": 3000,
  247. "max": 5000,
  248. },
  249. {
  250. "title": "5-10k",
  251. "min": 5000,
  252. "max": 10000,
  253. },
  254. {
  255. "title": "10-20k",
  256. "min": 10000,
  257. "max": 20000,
  258. },
  259. {
  260. "title": "20-50k",
  261. "min": 20000,
  262. "max": 50000,
  263. },
  264. {
  265. "title": "50K以上",
  266. "min": 50000,
  267. "max": null,
  268. }
  269. ];
  270. // 薪资范围
  271. List moneyList;
  272. List salaryRangeData = [];
  273. int minSalary;
  274. int maxSalary;
  275. showSalaryModal(BuildContext context) {
  276. salaryRangeData.clear();
  277. for (var i = 0; i < salaryRange.length; i++) {
  278. salaryRangeData.add(salaryRange[i]["title"]);
  279. }
  280. new Picker(
  281. selectedTextStyle:TextStyle(
  282. color: Colors.black
  283. ),
  284. selecteds:moneyList,
  285. cancelText:"取消",
  286. confirmText:"确认",
  287. adapter: PickerDataAdapter<String>(
  288. pickerdata: salaryRangeData,
  289. ),
  290. changeToFirst: true,
  291. hideHeader: false,
  292. onConfirm: (Picker picker, List value) {
  293. print(12389);
  294. print(value);
  295. moneyList = value;
  296. int index = value[0];
  297. minSalary = salaryRange[index]['min'];
  298. maxSalary = salaryRange[index]['max'];
  299. categoryList[2]['label'] = salaryRange[index]["title"];
  300. _onRefresh();
  301. setState(() {});
  302. },
  303. ).showModal(this.context);
  304. }
  305. @override
  306. Widget build(BuildContext context) {
  307. double width = MediaQuery.of(context).size.width;
  308. double height = MediaQuery.of(context).size.height;
  309. return ChangeNotifierProvider<BaseListProvider<Records>>(
  310. create: (_) => provider,
  311. child: Scaffold(
  312. appBar: SearchAppBar2(
  313. onPressed: (text) {
  314. jobSelected = text;
  315. _onRefresh();
  316. },
  317. ),
  318. body: Container(
  319. child: Stack(
  320. children: <Widget>[
  321. Column(
  322. children: <Widget>[
  323. Container(
  324. width: width,
  325. height: ScreenUtil().setWidth(50),
  326. decoration: BoxDecoration(
  327. border: Border(
  328. bottom: BorderSide(width: 0.5, color: Colours.line),
  329. ),
  330. ),
  331. child: ListView(
  332. scrollDirection: Axis.horizontal,
  333. children: <Widget>[
  334. SizedBox(width: ScreenUtil().setWidth(15)),
  335. TopTitle(
  336. categoryList: categoryList,
  337. fun: changTypeClass,
  338. )
  339. ],
  340. )),
  341. Expanded(
  342. flex: 1,
  343. child: Consumer<BaseListProvider<Records>>(
  344. builder: (_, provider, __) {
  345. return MyListView(
  346. key: Key('position_list'),
  347. itemCount: provider.list.length,
  348. stateType: provider.stateType,
  349. onRefresh: _onRefresh,
  350. loadMore: _loadMore,
  351. hasMore: provider.hasMore,
  352. itemBuilder: (_, index) {
  353. return GestureDetector(
  354. child: Container(
  355. padding: EdgeInsets.only(
  356. left: ScreenUtil().setWidth(15),
  357. right: ScreenUtil().setWidth(15),
  358. top: ScreenUtil().setHeight(10),
  359. bottom: ScreenUtil().setHeight(10)),
  360. decoration: BoxDecoration(
  361. border: Border(
  362. bottom: BorderSide(
  363. width: 0.5, color: Colours.line),
  364. ),
  365. ),
  366. child: Column(
  367. // crossAxisAlignment: CrossAxisAlignment.start,
  368. children: <Widget>[
  369. Container(
  370. padding: EdgeInsets.only(
  371. bottom: ScreenUtil().setHeight(5)),
  372. child: Row(
  373. mainAxisAlignment:
  374. MainAxisAlignment.spaceBetween,
  375. children: <Widget>[
  376. Container(
  377. width: width*0.4,
  378. child: Text(
  379. provider.list[index].job ?? '',
  380. textAlign: TextAlign.left,
  381. style: TextStyle(
  382. fontSize:
  383. ScreenUtil().setSp(17),
  384. ),
  385. overflow: TextOverflow.ellipsis,
  386. ),
  387. ),
  388. Container(
  389. width:width*0.4,
  390. child:Text(
  391. // 'jiage',
  392. "¥" +
  393. provider
  394. .list[index].lowerSalary
  395. .toString() +
  396. "-" +
  397. provider
  398. .list[index].upperSalary
  399. .toString(),
  400. textAlign: TextAlign.right,
  401. style: TextStyle(
  402. fontSize:
  403. ScreenUtil().setSp(17),
  404. color: Color(0xffff0000),
  405. ),
  406. overflow: TextOverflow.ellipsis,
  407. ),
  408. )
  409. ],
  410. ),
  411. ),
  412. Row(
  413. mainAxisAlignment:
  414. MainAxisAlignment.spaceBetween,
  415. children: <Widget>[
  416. Container(
  417. width: width*0.5,
  418. child: Text(
  419. provider.list[index].company
  420. .name ??
  421. '',
  422. textAlign: TextAlign.left,
  423. overflow: TextOverflow.ellipsis,
  424. style: TextStyle(
  425. fontSize:
  426. ScreenUtil().setSp(14),
  427. color: Color(0xff999999),
  428. ),
  429. ),
  430. ),
  431. provider.list[index]
  432. .provinceName !=
  433. null?Container(
  434. width: width*0.35,
  435. child: Text(
  436. (provider.list[index]
  437. .provinceName !=
  438. null
  439. ? provider
  440. .list[index].provinceName
  441. : '') +
  442. "-" +
  443. (provider.list[index]
  444. .cityName !=
  445. null
  446. ? provider
  447. .list[index].cityName
  448. : ''),
  449. textAlign: TextAlign.right,
  450. overflow: TextOverflow.ellipsis,
  451. style: TextStyle(
  452. fontSize:
  453. ScreenUtil().setSp(14),
  454. color: Color(0xff999999),
  455. ),
  456. ),
  457. ):Container(child:null),
  458. ],
  459. ),
  460. Row(
  461. mainAxisAlignment:
  462. MainAxisAlignment.spaceBetween,
  463. children: <Widget>[
  464. Container(
  465. width: width * 0.65,
  466. child: Text(
  467. provider.list[index].info ?? '',
  468. textAlign: TextAlign.left,
  469. style: TextStyle(
  470. fontSize:
  471. ScreenUtil().setSp(14),
  472. color: Color(0xff999999),
  473. ),
  474. overflow: TextOverflow.ellipsis,
  475. ),
  476. ),
  477. Text(
  478. DateUtils.instance.getFormartData(
  479. timeSamp: provider
  480. .list[index].createTime,
  481. format: "yyyy-MM-dd"),
  482. textAlign: TextAlign.left,
  483. style: TextStyle(
  484. fontSize: ScreenUtil().setSp(14),
  485. color: Color(0xff999999),
  486. ),
  487. ),
  488. ],
  489. ),
  490. ]),
  491. ),
  492. onTap: () {
  493. NavigatorUtils.push(context,
  494. "${BbsRouter.positionDetail}?id=${provider.list[index].id.toString()}");
  495. },
  496. );
  497. },
  498. );
  499. }))
  500. ],
  501. ),
  502. ],
  503. ),
  504. ),
  505. ),
  506. );
  507. }
  508. Future _onRefresh() async {
  509. _page = 1;
  510. await presenter.getPositionList(
  511. _page,
  512. provinceName: provinceName,
  513. cityName: cityName,
  514. minSalary: minSalary,
  515. maxSalary: maxSalary,
  516. job: jobSelected,
  517. );
  518. }
  519. Future _loadMore() async {
  520. _page++;
  521. await presenter.getPositionList(
  522. _page,
  523. provinceName: provinceName,
  524. cityName: cityName,
  525. minSalary: minSalary,
  526. maxSalary: maxSalary,
  527. job: jobSelected,
  528. );
  529. }
  530. @override
  531. PositionListPresenterSeconds createPresenter() {
  532. return PositionListPresenterSeconds();
  533. }
  534. }
  535. class TopTitle extends StatelessWidget {
  536. TopTitle({Key key, this.categoryList, this.fun}) : super(key: key);
  537. List<dynamic> categoryList;
  538. Function fun;
  539. List<Widget> listWidget(context) => categoryList.asMap().keys.map((index) {
  540. return index!=1?GestureDetector(
  541. onTap: () {
  542. fun(categoryList[index], index);
  543. },
  544. child: Container(
  545. child: Row(children: <Widget>[
  546. Row(
  547. children: <Widget>[
  548. Text(
  549. categoryList[index]['label'] ?? '',
  550. style: TextStyle(
  551. fontSize: ScreenUtil().setSp(16)),
  552. textAlign: TextAlign.start,
  553. ),
  554. Container(
  555. padding: EdgeInsets.only(top: 3),
  556. child: Icon(
  557. Icons.keyboard_arrow_down,
  558. size: 26.0,
  559. ),
  560. )
  561. ],
  562. ),
  563. SizedBox(width: ScreenUtil().setWidth(15)),
  564. ]),
  565. ),
  566. ):Container(child:null);
  567. }).toList();
  568. @override
  569. Widget build(BuildContext context) {
  570. return Container(
  571. child: Row(children: listWidget(context)),
  572. );
  573. }
  574. }