position_list.dart 23 KB

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