position_apply.dart 17 KB

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