position_list.dart 22 KB

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