position_apply.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:flustars/flustars.dart' as FlutterStars;
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. import 'package:liftmanager/common/common.dart';
  7. import 'package:liftmanager/internal/bbs/page/tab/position/label_collection.dart';
  8. import 'package:liftmanager/net/api_service.dart';
  9. import 'package:liftmanager/res/iconfont.dart';
  10. import 'package:liftmanager/routers/fluro_navigator.dart';
  11. import 'package:liftmanager/utils/fast_notification.dart';
  12. import 'package:liftmanager/utils/toast.dart';
  13. import 'package:liftmanager/widgets/app_bar.dart';
  14. import 'package:liftmanager/widgets/bbs_content.dart';
  15. import 'package:liftmanager/widgets/text_field_item.dart';
  16. import 'package:umeng_common_sdk/umeng_common_sdk.dart';
  17. class PositionApply extends StatefulWidget {
  18. PositionApply(this.id);
  19. final String id;
  20. @override
  21. State<StatefulWidget> createState() {
  22. return PositionApplyState();
  23. }
  24. }
  25. class PositionApplyState extends State<PositionApply> {
  26. List<File> images = [];
  27. String sexChiose = "";
  28. int sexChioseValue;
  29. List<String> sexListChiose = ['男', '女'];
  30. List<int> sexListValue = [1, 2];
  31. List experienceRangeList = ['1年以下', '1年-3年', '3年-5年', '5年-10年', '10年以上'];
  32. String experienceRangeSelected = '';
  33. List<String> salaryRangeList = [
  34. '1千以下',
  35. '1千-2千',
  36. '2千-4千',
  37. '4千-6千',
  38. '6千-8千',
  39. '8千-1万',
  40. '1万-1.5万',
  41. '1.5万以上'
  42. ];
  43. String salaryRangeSelected = '';
  44. String birthdaySelected = '';
  45. List<String> selectedLabels = [];
  46. // 焦点控制
  47. FocusNode _focusNode1 = new FocusNode();
  48. GlobalKey _formKey = new GlobalKey<FormState>();
  49. TextEditingController _usernameController = TextEditingController();
  50. TextEditingController _telController = TextEditingController();
  51. TextEditingController _wechatController = TextEditingController();
  52. TextEditingController _evaluationController = TextEditingController();
  53. @override
  54. void initState() {
  55. UmengCommonSdk.onPageStart("申请职位");
  56. super.initState();
  57. NewApiService().getResume(
  58. onError: (code, msg) {},
  59. onSuccess: (res) {
  60. setState(() {
  61. try {
  62. _usernameController.text = res.name;
  63. sexChioseValue = res.gender;
  64. sexChiose = sexListChiose[sexChioseValue - 1];
  65. birthdaySelected = res.birthday ?? '';
  66. _telController.text = res.telephone;
  67. _wechatController.text = res.wechat;
  68. experienceRangeSelected = res.workingTime ?? '';
  69. salaryRangeSelected = res.salary ?? '';
  70. _evaluationController.text = res.intro;
  71. selectedLabels.addAll(
  72. (json.decode(res.ability) as List<dynamic>).cast<String>());
  73. } catch (e) {
  74. print(e);
  75. }
  76. });
  77. });
  78. }
  79. @override
  80. void dispose() {
  81. UmengCommonSdk.onPageEnd("申请职位");
  82. super.dispose();
  83. }
  84. @override
  85. Widget build(BuildContext context) {
  86. double width = MediaQuery.of(context).size.width;
  87. return Scaffold(
  88. resizeToAvoidBottomPadding: false, //不让键盘弹上去
  89. appBar: MyAppBar(
  90. centerTitle: "申请职位",
  91. ),
  92. body: GestureDetector(
  93. onTap: () {
  94. // 点击空白页面关闭键盘
  95. FocusScope.of(context).requestFocus(_focusNode1);
  96. },
  97. child: Stack(
  98. children: <Widget>[
  99. Container(
  100. child: ListView(children: <Widget>[
  101. Form(
  102. key: _formKey, //设置globalKey,用于后面获取FormState
  103. // autovalidate: true, //开启自动校验
  104. child: Column(
  105. crossAxisAlignment: CrossAxisAlignment.start,
  106. children: <Widget>[
  107. TextFieldItem(
  108. title: "姓名",
  109. content: "",
  110. isMust: true,
  111. controller: _usernameController,
  112. hintText: "请输入",
  113. onChanged: (res) {
  114. // setState(() {});
  115. },
  116. ),
  117. ChioseThis(
  118. list: sexListChiose,
  119. label: "性别",
  120. isMust: true,
  121. value: sexChiose,
  122. fun: (index) {
  123. setState(() {
  124. sexChiose = sexListChiose[index];
  125. sexChioseValue = sexListValue[index];
  126. });
  127. Navigator.maybePop(context);
  128. FocusScope.of(context).requestFocus(FocusNode());
  129. }),
  130. DatePickerInputField(
  131. label: '出生年月',
  132. value: birthdaySelected,
  133. onSelectionConfirmed: (value) {
  134. setState(() {
  135. birthdaySelected = value;
  136. });
  137. },
  138. ),
  139. TextFieldItem(
  140. title: "联系电话",
  141. content: "",
  142. isMust: true,
  143. controller: _telController,
  144. hintText: "请输入",
  145. keyboardType: TextInputType.number,
  146. onChanged: (res) {
  147. // setState(() {});
  148. },
  149. ),
  150. TextFieldItem(
  151. title: "微信号",
  152. content: "",
  153. controller: _wechatController,
  154. hintText: "请输入",
  155. keyboardType: TextInputType.text,
  156. onChanged: (res) {
  157. // setState(() {});
  158. },
  159. ),
  160. ChiosePicker(
  161. range: experienceRangeList,
  162. label: "从业时间",
  163. value: experienceRangeSelected,
  164. onConfirm: (value, index) {
  165. setState(() {
  166. experienceRangeSelected = value;
  167. });
  168. Navigator.maybePop(context);
  169. FocusScope.of(context).requestFocus(FocusNode());
  170. }),
  171. ChiosePicker(
  172. range: salaryRangeList,
  173. label: '期望薪资',
  174. isMust: true,
  175. value: salaryRangeSelected,
  176. onConfirm: (value, index) {
  177. setState(() {
  178. salaryRangeSelected = value;
  179. });
  180. Navigator.maybePop(context);
  181. FocusScope.of(context).requestFocus(FocusNode());
  182. },
  183. ),
  184. SizedBox(
  185. height: 10,
  186. ),
  187. CommonSectionHeader(
  188. title: '个人标签',
  189. fontSize: 14,
  190. ),
  191. SizedBox(
  192. height: 10,
  193. ),
  194. Container(
  195. // height: 120,
  196. padding: EdgeInsets.only(
  197. left: ScreenUtil().setWidth(15),
  198. right: ScreenUtil().setWidth(15),
  199. bottom: ScreenUtil().setWidth(20)),
  200. child: labelSection(),
  201. ),
  202. SizedBox(
  203. height: 1,
  204. child: Container(color: Color(0xFFF1F4FC)),
  205. ),
  206. SizedBox(
  207. height: 10,
  208. ),
  209. CommonSectionHeader(
  210. title: '其他介绍',
  211. isMust: true,
  212. fontSize: 14,
  213. ),
  214. SizedBox(
  215. height: 10,
  216. ),
  217. Container(
  218. height: ScreenUtil().setWidth(120),
  219. padding: EdgeInsets.only(
  220. left: ScreenUtil().setWidth(15),
  221. right: ScreenUtil().setWidth(15),
  222. bottom: ScreenUtil().setWidth(20)),
  223. child: TextFormField(
  224. // autofocus: true,
  225. maxLength: 50,
  226. cursorColor: Color(0xffcccccc),
  227. controller: _evaluationController,
  228. maxLines: 5,
  229. decoration: InputDecoration(
  230. contentPadding: EdgeInsets.all(0),
  231. hintText: '请输入',
  232. hintStyle: TextStyle(
  233. color: Color(0xffcccccc),
  234. fontSize: 13,
  235. ),
  236. focusedBorder: InputBorder.none,
  237. border: InputBorder.none,
  238. ),
  239. // 校验
  240. validator: (val) {
  241. return val.trim().length > 0 ? null : "不能为空";
  242. }),
  243. ),
  244. SizedBox(
  245. height: 1,
  246. child: Container(color: Color(0xFFF1F4FC)),
  247. ),
  248. SizedBox(
  249. height: ScreenUtil().setWidth(80),
  250. ),
  251. ],
  252. ),
  253. )
  254. ])),
  255. Positioned(
  256. bottom: 0,
  257. left: 0,
  258. child: Container(
  259. width: width,
  260. color: Colors.white,
  261. padding: EdgeInsets.only(
  262. top: ScreenUtil().setWidth(15),
  263. bottom: ScreenUtil().setWidth(15),
  264. left: ScreenUtil().setWidth(10),
  265. right: ScreenUtil().setWidth(10),
  266. ),
  267. child: Container(
  268. height: ScreenUtil().setWidth(44),
  269. decoration: BoxDecoration(
  270. borderRadius:
  271. BorderRadius.circular(ScreenUtil().setWidth(22)),
  272. color: Color(0xff5589FF),
  273. ),
  274. child: FlatButton(
  275. // padding: EdgeInsets.all(15.0),
  276. child: Text("提交申请", style: TextStyle(fontSize: 16)),
  277. textColor: Colors.white,
  278. onPressed: () {
  279. /*
  280. * 如果:context不对。可以使用GlobalKey,
  281. * 通过_formKey.currentState 获取FormState后,
  282. * 调用validate()方法校验用户名密码是否合法,校验
  283. * 通过后再提交数据。
  284. */
  285. if (_usernameController.text == null ||
  286. _usernameController.text.trim() == "") {
  287. toasts("请输入姓名");
  288. return;
  289. }
  290. if (sexChioseValue == null) {
  291. toasts("请选择性别");
  292. return;
  293. }
  294. if (salaryRangeSelected == null ||
  295. salaryRangeSelected.isEmpty) {
  296. toasts("请输入期望薪资");
  297. return;
  298. }
  299. if (_telController.text == null ||
  300. _telController.text.trim() == "") {
  301. toasts("请输入联系电话");
  302. return;
  303. }
  304. // if (_skillController.text == null ||
  305. // _skillController.text.trim() == "") {
  306. // toasts("请输入个人技能");
  307. // return;
  308. // }
  309. if (_evaluationController.text == null ||
  310. _evaluationController.text.trim() == "") {
  311. toasts("请输入其他介绍");
  312. return;
  313. }
  314. RegExp exp = RegExp(r'^1[34578]\d{9}$');
  315. RegExp expEmail = RegExp(
  316. r"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
  317. if (!exp.hasMatch(_telController.text)) {
  318. toasts("请输入正确的手机号");
  319. return;
  320. }
  321. if ((_formKey.currentState as FormState).validate()) {
  322. var form = {
  323. "infoId": int.parse(widget.id),
  324. "userId":
  325. FlutterStars.SpUtil.getString(Constant.userId),
  326. "name": _usernameController.text,
  327. "gender": sexChioseValue,
  328. "birthday": birthdaySelected,
  329. "telephone": _telController.text,
  330. "wechat": _wechatController.text,
  331. "workingTime": experienceRangeSelected,
  332. "salary": salaryRangeSelected,
  333. "ability": json.encode(selectedLabels),
  334. "intro": _evaluationController.text,
  335. };
  336. NewApiService().applyJob(form, onSuccess: (res) {
  337. toasts("职位申请成功");
  338. NavigatorUtils.goBackWithParams(context, true);
  339. bool isApply = true;
  340. FastNotification.push("apply", isApply);
  341. setState(() {});
  342. }, onError: (code, msg) {
  343. toasts(msg);
  344. });
  345. }
  346. },
  347. ),
  348. ),
  349. ))
  350. ],
  351. ),
  352. ),
  353. );
  354. }
  355. Widget labelSection() {
  356. var labels = selectedLabels
  357. .map(
  358. (e) => Container(
  359. padding: EdgeInsets.symmetric(horizontal: 10),
  360. height: 31,
  361. decoration: BoxDecoration(
  362. color: Color(0xffF4F8FA),
  363. borderRadius: BorderRadius.circular(20),
  364. ),
  365. child: Row(
  366. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  367. mainAxisSize: MainAxisSize.min,
  368. children: [
  369. Text(
  370. e,
  371. style: TextStyle(
  372. fontSize: 13,
  373. color: Color(0xff5589FF),
  374. ),
  375. ),
  376. SizedBox(
  377. width: 10,
  378. ),
  379. GestureDetector(
  380. onTap: () {
  381. setState(() {
  382. selectedLabels.remove(e);
  383. });
  384. },
  385. child: Icon(
  386. Iconfont.shanchu_shuzimianbanbianjitai,
  387. color: Colors.grey,
  388. size: 15,
  389. ),
  390. )
  391. ],
  392. ),
  393. ),
  394. )
  395. .toList();
  396. labels.add(
  397. Container(
  398. width: 75,
  399. height: 31,
  400. decoration: BoxDecoration(
  401. color: Color(0xffF4F8FA),
  402. borderRadius: BorderRadius.circular(20),
  403. ),
  404. child: GestureDetector(
  405. onTap: () async {
  406. Navigator.push(
  407. context,
  408. MaterialPageRoute(
  409. builder: (_) => LabelCollection(
  410. selectedLabels: selectedLabels,
  411. ),
  412. ),
  413. );
  414. setState(() {
  415. // selectedLabels = updatedLabels;
  416. });
  417. },
  418. child: Row(
  419. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  420. children: [
  421. Icon(
  422. Iconfont.tianjia9,
  423. size: 15,
  424. color: Colors.grey,
  425. ),
  426. Text(
  427. '标签',
  428. style: TextStyle(fontSize: 13, color: Color(0xffCCCCCC)),
  429. ),
  430. ],
  431. ),
  432. ),
  433. ),
  434. );
  435. return Wrap(
  436. spacing: 5,
  437. runSpacing: 5,
  438. children: labels.toList(),
  439. );
  440. }
  441. }