position_list.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. import 'dart:async';
  2. import 'dart:io';
  3. import 'package:amap_location_flutter_plugin/amap_location_flutter_plugin.dart';
  4. import 'package:amap_location_flutter_plugin/amap_location_option.dart';
  5. import 'package:city_pickers/city_pickers.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter_picker/flutter_picker.dart';
  8. import 'package:flutter_screenutil/flutter_screenutil.dart';
  9. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  10. import 'package:liftmanager/internal/bbs/model/mix_model.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/wode/model/table_dicts_model.dart';
  14. import 'package:liftmanager/mvp/base_page_state.dart';
  15. import 'package:liftmanager/net/api_service.dart';
  16. import 'package:liftmanager/res/resources.dart';
  17. import 'package:liftmanager/routers/fluro_navigator.dart';
  18. import 'package:liftmanager/utils/toast.dart';
  19. import 'package:liftmanager/widgets/app_search_bar.dart';
  20. import 'package:liftmanager/widgets/bbs_content.dart';
  21. import 'package:liftmanager/widgets/my_refresh_list.dart';
  22. import 'package:liftmanager/widgets/state_layout.dart';
  23. import 'package:permission_handler/permission_handler.dart';
  24. import 'package:provider/provider.dart';
  25. import 'package:umeng_common_sdk/umeng_common_sdk.dart';
  26. class PositionList extends StatefulWidget {
  27. String city;
  28. String provinceName;
  29. PositionList({this.city, this.provinceName});
  30. @override
  31. PositionListState createState() => PositionListState();
  32. }
  33. class PositionListState
  34. extends BasePageState<PositionList, PositionListPresenterSeconds> {
  35. // Map<String, Object> _locationResult;
  36. // StreamSubscription<Map<String, Object>> _locationListener;
  37. // AmapLocationFlutterPlugin _locationPlugin = new AmapLocationFlutterPlugin();
  38. BaseListProvider<Records> provider = BaseListProvider<Records>();
  39. int _page = 1;
  40. List<dynamic> categoryList = [
  41. {"title": "地址", "label": "地点"},
  42. {"title": "所属职位", "label": "所属职位"},
  43. {"title": "薪资范围", "label": "薪资范围"}
  44. ];
  45. ScrollController _scrollController = new ScrollController();
  46. @override
  47. void initState() {
  48. UmengCommonSdk.onPageStart("招聘求职");
  49. provider.setStateTypeNotNotify(StateType.loading);
  50. super.initState();
  51. cityName = widget.city;
  52. provinceName = widget.provinceName;
  53. categoryList[0]['label'] = widget.city;
  54. _onRefresh();
  55. ///移除定位监听
  56. // if (null != _locationListener) {
  57. // _locationListener.cancel();
  58. // }
  59. // ///销毁定位
  60. // if (null != _locationPlugin) {
  61. // _locationPlugin.destroy();
  62. // }
  63. // _locationListener = _locationPlugin
  64. // .onLocationChanged()
  65. // .listen((Map<String, Object> result) {
  66. // setState(() {
  67. // _locationPlugin.stopLocation();
  68. // _locationResult = result;
  69. // print(_locationResult["city"]);
  70. // print(_locationResult["province"]);
  71. // // address latitude longitude
  72. // provinceName = _locationResult["province"];
  73. // categoryList[0]['label'] = _locationResult["city"];
  74. // _onRefresh();
  75. // setState(() {});
  76. // });
  77. // });
  78. // getInitLocation();
  79. getJobClass();
  80. }
  81. // // 获取定位权限
  82. // Future<bool> requestPermission() async {
  83. // final permissions = await PermissionHandler()
  84. // .requestPermissions([PermissionGroup.location]);
  85. // if (permissions[PermissionGroup.location] == PermissionStatus.granted) {
  86. // return true;
  87. // } else {
  88. // toasts('需要定位权限!');
  89. // _onRefresh();
  90. // setState(() {});
  91. // return false;
  92. // }
  93. // }
  94. // getInitLocation() async {
  95. // if (await requestPermission()) {
  96. // if (null != _locationPlugin) {
  97. // ///开始定位之前设置定位参数
  98. // _setLocationOption();
  99. // // _locationPlugin.getSystemAccuracyAuthorization();
  100. // _locationPlugin.startLocation();
  101. // }
  102. // }
  103. // }
  104. // void _setLocationOption() {
  105. // if (null != _locationPlugin) {
  106. // AMapLocationOption locationOption = new AMapLocationOption();
  107. // ///是否单次定位
  108. // locationOption.onceLocation = true;
  109. // ///是否需要返回逆地理信息
  110. // locationOption.needAddress = true;
  111. // ///逆地理信息的语言类型
  112. // locationOption.geoLanguage = GeoLanguage.DEFAULT;
  113. // ///设置Android端连续定位的定位间隔
  114. // locationOption.locationInterval = 20000;
  115. // locationOption.desiredLocationAccuracyAuthorizationMode =
  116. // AMapLocationAccuracyAuthorizationMode.ReduceAccuracy;
  117. // ///设置Android端的定位模式<br>
  118. // ///可选值:<br>
  119. // ///<li>[AMapLocationMode.Battery_Saving]</li>
  120. // ///<li>[AMapLocationMode.Device_Sensors]</li>
  121. // ///<li>[AMapLocationMode.Hight_Accuracy]</li>
  122. // locationOption.locationMode = AMapLocationMode.Hight_Accuracy;
  123. // // locationOption.requestAccuracyAuthorization();
  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.Best;
  134. // ///设置iOS端是否允许系统暂停定位
  135. // locationOption.pausesLocationUpdatesAutomatically = false;
  136. // ///将定位参数设置给定位插件
  137. // _locationPlugin.setLocationOption(locationOption);
  138. // }
  139. // }
  140. @override
  141. void dispose() {
  142. UmengCommonSdk.onPageEnd("招聘求职");
  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. cancelWidget: GestureDetector(
  174. onTap: () {
  175. provinceName = null;
  176. cityName = null;
  177. categoryList[0]['label'] = "不限地区";
  178. Navigator.pop(context);
  179. _onRefresh();
  180. setState(() {});
  181. },
  182. child: Text(
  183. "不限地区",
  184. style: TextStyle(
  185. color: Color(0xffff0000),
  186. ),
  187. ),
  188. ),
  189. locationCode: addressResult != null
  190. ? addressResult.areaId ??
  191. addressResult.cityId ??
  192. addressResult.provinceId
  193. : null, // 初始化地址信息
  194. );
  195. if (tempResult != null) {
  196. print(tempResult);
  197. addressResult = tempResult;
  198. if (tempResult.cityName == "市辖区") {
  199. cityName = "重庆城区";
  200. } else {
  201. cityName = tempResult.cityName;
  202. }
  203. provinceName = tempResult.provinceName;
  204. if (cityName == "县") {
  205. categoryList[0]['label'] = "重庆市-县";
  206. } else {
  207. categoryList[0]['label'] = cityName;
  208. }
  209. _onRefresh();
  210. setState(() {});
  211. }
  212. }
  213. changTypeClass(item, index) {
  214. if (index == 0) {
  215. // 选择地址
  216. _clickEventFunc();
  217. } else if (index == 1) {
  218. // 所属职位
  219. showPositionModal(context);
  220. } else if (index == 2) {
  221. // 薪资范围
  222. showSalaryModal(context);
  223. }
  224. setState(() {});
  225. }
  226. // 所属职位
  227. List jobClassData = [];
  228. String jobSelected;
  229. showPositionModal(BuildContext context) {
  230. jobClassData.clear();
  231. jobClassData.add("不限");
  232. for (var i = 0; i < jobClass.length; i++) {
  233. jobClassData.add(jobClass[i].value);
  234. }
  235. new Picker(
  236. // selecteds:[0],
  237. cancelText: "取消",
  238. confirmText: "确认",
  239. adapter: PickerDataAdapter<String>(
  240. pickerdata: jobClassData,
  241. ),
  242. changeToFirst: true,
  243. hideHeader: false,
  244. onConfirm: (Picker picker, List value) {
  245. if (value[0] == 0) {
  246. jobSelected = null;
  247. } else {
  248. jobSelected = picker.getSelectedValues()[0];
  249. print(jobSelected);
  250. }
  251. categoryList[1]['label'] = picker.getSelectedValues()[0];
  252. _onRefresh();
  253. setState(() {});
  254. },
  255. ).showModal(this.context);
  256. }
  257. List salaryRange = [
  258. {
  259. "title": "不限",
  260. "min": null,
  261. "max": null,
  262. },
  263. {
  264. "title": "3K以下",
  265. "min": 0,
  266. "max": 3000,
  267. },
  268. {
  269. "title": "3-5k",
  270. "min": 3000,
  271. "max": 5000,
  272. },
  273. {
  274. "title": "5-10k",
  275. "min": 5000,
  276. "max": 10000,
  277. },
  278. {
  279. "title": "10-20k",
  280. "min": 10000,
  281. "max": 20000,
  282. },
  283. {
  284. "title": "20-50k",
  285. "min": 20000,
  286. "max": 50000,
  287. },
  288. {
  289. "title": "50K以上",
  290. "min": 50000,
  291. "max": null,
  292. }
  293. ];
  294. // 薪资范围
  295. List moneyList;
  296. List salaryRangeData = [];
  297. int minSalary;
  298. int maxSalary;
  299. showSalaryModal(BuildContext context) {
  300. salaryRangeData.clear();
  301. for (var i = 0; i < salaryRange.length; i++) {
  302. salaryRangeData.add(salaryRange[i]["title"]);
  303. }
  304. new Picker(
  305. selectedTextStyle: TextStyle(color: Colors.black),
  306. selecteds: moneyList,
  307. cancelText: "取消",
  308. confirmText: "确认",
  309. adapter: PickerDataAdapter<String>(
  310. pickerdata: salaryRangeData,
  311. ),
  312. changeToFirst: true,
  313. hideHeader: false,
  314. onConfirm: (Picker picker, List value) {
  315. print(12389);
  316. print(value);
  317. moneyList = value;
  318. int index = value[0];
  319. minSalary = salaryRange[index]['min'];
  320. maxSalary = salaryRange[index]['max'];
  321. categoryList[2]['label'] = salaryRange[index]["title"];
  322. _onRefresh();
  323. setState(() {});
  324. },
  325. ).showModal(this.context);
  326. }
  327. @override
  328. Widget build(BuildContext context) {
  329. double width = MediaQuery.of(context).size.width;
  330. return ChangeNotifierProvider<BaseListProvider<Records>>(
  331. create: (_) => provider,
  332. child: Scaffold(
  333. appBar: SearchAppBar2(
  334. onPressed: (text) {
  335. jobSelected = text;
  336. _onRefresh();
  337. },
  338. ),
  339. body: Container(
  340. child: Stack(
  341. children: <Widget>[
  342. Column(
  343. children: <Widget>[
  344. Container(
  345. width: width,
  346. height: ScreenUtil().setWidth(50),
  347. decoration: BoxDecoration(
  348. border: Border(
  349. bottom: BorderSide(
  350. width: 5,
  351. color: Color(0xffF9F9F9),
  352. ),
  353. ),
  354. ),
  355. child: TopTitle(
  356. categoryList: categoryList,
  357. fun: changTypeClass,
  358. )),
  359. SizedBox(
  360. height: 10,
  361. ),
  362. Expanded(
  363. flex: 1,
  364. child: Consumer<BaseListProvider<Records>>(
  365. builder: (_, provider, __) {
  366. return MyListView(
  367. key: Key('position_list'),
  368. itemCount: provider.list.length,
  369. stateType: provider.stateType,
  370. onRefresh: _onRefresh,
  371. loadMore: _loadMore,
  372. hasMore: provider.hasMore,
  373. showSeparator: false,
  374. itemBuilder: (_, index) {
  375. return GestureDetector(
  376. child: Container(
  377. padding: EdgeInsets.symmetric(horizontal: 10),
  378. child: PositionCell(
  379. provider.list[index],
  380. ),
  381. ),
  382. onTap: () {
  383. NavigatorUtils.push(context,
  384. "${BbsRouter.positionDetail}?id=${provider.list[index].id.toString()}");
  385. },
  386. );
  387. },
  388. );
  389. }))
  390. ],
  391. ),
  392. ],
  393. ),
  394. ),
  395. ),
  396. );
  397. }
  398. Future _onRefresh() async {
  399. _page = 1;
  400. await presenter.getPositionList(
  401. _page,
  402. provinceName: provinceName,
  403. cityName: cityName,
  404. minSalary: minSalary,
  405. maxSalary: maxSalary,
  406. job: jobSelected,
  407. );
  408. }
  409. Future _loadMore() async {
  410. _page++;
  411. await presenter.getPositionList(
  412. _page,
  413. provinceName: provinceName,
  414. cityName: cityName,
  415. minSalary: minSalary,
  416. maxSalary: maxSalary,
  417. job: jobSelected,
  418. );
  419. }
  420. @override
  421. PositionListPresenterSeconds createPresenter() {
  422. return PositionListPresenterSeconds();
  423. }
  424. }
  425. class TopTitle extends StatelessWidget {
  426. TopTitle({Key key, this.categoryList, this.fun}) : super(key: key);
  427. List<dynamic> categoryList;
  428. Function fun;
  429. List<Widget> listWidget(context) => categoryList.asMap().keys.map((index) {
  430. return index != 1
  431. ? GestureDetector(
  432. onTap: () {
  433. fun(categoryList[index], index);
  434. },
  435. child: Container(
  436. child: Row(children: <Widget>[
  437. Row(
  438. children: <Widget>[
  439. Text(
  440. categoryList[index]['label'] ?? '',
  441. style: TextStyle(
  442. fontSize: 14,
  443. color: Color(0xff333333),
  444. ),
  445. textAlign: TextAlign.start,
  446. ),
  447. Container(
  448. padding: EdgeInsets.only(top: 3),
  449. child: Icon(
  450. Icons.keyboard_arrow_down,
  451. size: 20.0,
  452. ),
  453. )
  454. ],
  455. ),
  456. SizedBox(width: ScreenUtil().setWidth(15)),
  457. ]),
  458. ),
  459. )
  460. : Container(child: null);
  461. }).toList();
  462. @override
  463. Widget build(BuildContext context) {
  464. return Container(
  465. child: Row(
  466. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  467. children: listWidget(context),
  468. ),
  469. );
  470. }
  471. }