position_apply.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/net/api_service.dart';
  3. import 'package:liftmanager/utils/toast.dart';
  4. import 'package:liftmanager/widgets/app_bar.dart';
  5. import 'dart:io';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. import 'package:liftmanager/widgets/text_field_item.dart';
  8. import 'package:liftmanager/widgets/bbs_content.dart';
  9. import 'package:liftmanager/routers/fluro_navigator.dart';
  10. import 'package:liftmanager/utils/fast_notification.dart';
  11. import 'package:liftmanager/common/common.dart';
  12. // import 'package:flustars/flustars.dart';
  13. import 'package:flustars/flustars.dart' as FlutterStars;
  14. import 'package:liftmanager/utils/theme_utils.dart';
  15. class PositionApply extends StatefulWidget {
  16. PositionApply(this.id);
  17. final String id;
  18. @override
  19. State<StatefulWidget> createState() {
  20. return PositionApplyState();
  21. }
  22. }
  23. class PositionApplyState extends State<PositionApply> {
  24. List<File> images = [];
  25. String sexChiose = "";
  26. int sexChioseValue;
  27. List<String> sexListChiose = ['男', '女'];
  28. List<int> sexListValue = [1, 2];
  29. dynamic usreJob = {
  30. "infoId": 0,
  31. "userId": 1,
  32. "ability": "",
  33. "email": "",
  34. "intro": "",
  35. "name": "",
  36. "telephone": "",
  37. "salary": 0,
  38. "gender": 0
  39. };
  40. // 焦点控制
  41. FocusNode _focusNode1 = new FocusNode();
  42. GlobalKey _formKey = new GlobalKey<FormState>();
  43. TextEditingController _usernameController = new TextEditingController();
  44. TextEditingController _salaryController = new TextEditingController();
  45. TextEditingController _telController = new TextEditingController();
  46. TextEditingController _emailController = new TextEditingController();
  47. TextEditingController _skillController = new TextEditingController();
  48. TextEditingController _evaluationController = new TextEditingController();
  49. @override
  50. Widget build(BuildContext context) {
  51. double width = MediaQuery.of(context).size.width;
  52. return Scaffold(
  53. resizeToAvoidBottomPadding: false, //不让键盘弹上去
  54. appBar: MyAppBar(
  55. centerTitle: "申请职位",
  56. ),
  57. body: GestureDetector(
  58. onTap: () {
  59. // 点击空白页面关闭键盘
  60. FocusScope.of(context).requestFocus(_focusNode1);
  61. },
  62. child: Stack(
  63. children: <Widget>[
  64. Container(
  65. child: ListView(children: <Widget>[
  66. Form(
  67. key: _formKey, //设置globalKey,用于后面获取FormState
  68. // autovalidate: true, //开启自动校验
  69. child: Column(
  70. children: <Widget>[
  71. TextFieldItem(
  72. title: "姓名",
  73. content: "",
  74. controller: _usernameController,
  75. // controller: TextEditingController(),
  76. hintText: "请输入您的姓名",
  77. onChanged: (res) {
  78. // setState(() {});
  79. },
  80. ),
  81. ChioseThis(
  82. list: sexListChiose,
  83. label: "性别",
  84. value: sexChiose,
  85. fun: (index) {
  86. setState(() {
  87. sexChiose = sexListChiose[index];
  88. sexChioseValue = sexListValue[index];
  89. });
  90. Navigator.maybePop(context);
  91. FocusScope.of(context)
  92. .requestFocus(FocusNode());
  93. }),
  94. TextFieldItem(
  95. title: "期望薪资(元/月)",
  96. content: "",
  97. controller: _salaryController,
  98. hintText: "请输入您的期望薪资",
  99. keyboardType: TextInputType.number,
  100. // maxLength: 6,
  101. onChanged: (res) {
  102. // setState(() {});
  103. },
  104. // validator: (val) {
  105. // return val.trim().length > 0 ? null : "不能为空";
  106. // },
  107. ),
  108. TextFieldItem(
  109. title: "联系方式",
  110. content: "",
  111. controller: _telController,
  112. hintText: "请输入您的电话",
  113. keyboardType: TextInputType.number,
  114. onChanged: (res) {
  115. // setState(() {});
  116. },
  117. ),
  118. TextFieldItem(
  119. title: "联系邮箱",
  120. content: "",
  121. controller: _emailController,
  122. hintText: "请输入您的邮箱",
  123. onChanged: (res) {
  124. // setState(() {});
  125. },
  126. ),
  127. Row(
  128. crossAxisAlignment: CrossAxisAlignment.start,
  129. mainAxisAlignment: MainAxisAlignment.start,
  130. children: <Widget>[
  131. Container(
  132. padding: EdgeInsets.only(
  133. left: ScreenUtil().setWidth(15),
  134. top: ScreenUtil().setWidth(10),
  135. bottom: ScreenUtil().setWidth(5)),
  136. child: Text(
  137. "个人技能",
  138. style: TextStyle(
  139. color: Color(0xff222222),
  140. // fontSize:ScreenUtil().setSp(14),
  141. ),
  142. textAlign: TextAlign.left,
  143. ),
  144. ),
  145. ],
  146. ),
  147. Container(
  148. height: 120,
  149. padding: EdgeInsets.only(
  150. left: ScreenUtil().setWidth(15),
  151. right: ScreenUtil().setWidth(15),
  152. bottom: ScreenUtil().setWidth(20)),
  153. child: TextFormField(
  154. // autofocus: true,
  155. maxLength: 50,
  156. cursorColor: Color(0xffcccccc),
  157. controller: _skillController,
  158. maxLines: 5,
  159. decoration: InputDecoration(
  160. contentPadding: EdgeInsets.all(0),
  161. hintText: '请输入您的个人技能',
  162. hintStyle: TextStyle(
  163. color: Color(0xffcccccc),
  164. // fontSize: ScreenUtil().setSp(14)
  165. ),
  166. focusedBorder: InputBorder.none,
  167. border: InputBorder.none,
  168. // filled: true, // 背景色
  169. // fillColor: Colors.cyan.withAlpha(35),
  170. // icon: Icon(Icons.person)
  171. ),
  172. // 校验
  173. validator: (val) {
  174. return val.trim().length > 0 ? null : "不能为空";
  175. }),
  176. ),
  177. SizedBox(
  178. height: 6,
  179. child: Container(color: Color(0xFFF1F4FC)),
  180. ),
  181. Row(
  182. crossAxisAlignment: CrossAxisAlignment.start,
  183. mainAxisAlignment: MainAxisAlignment.start,
  184. children: <Widget>[
  185. Container(
  186. padding: EdgeInsets.only(
  187. left: ScreenUtil().setWidth(15),
  188. top: ScreenUtil().setWidth(10),
  189. bottom: ScreenUtil().setWidth(5)),
  190. child: Text(
  191. "自我评价",
  192. style: TextStyle(
  193. color: Color(0xff222222),
  194. // fontSize:ScreenUtil().setSp(14),
  195. ),
  196. textAlign: TextAlign.left,
  197. ),
  198. ),
  199. ],
  200. ),
  201. Container(
  202. height: ScreenUtil().setWidth(120),
  203. padding: EdgeInsets.only(
  204. left: ScreenUtil().setWidth(15),
  205. right: ScreenUtil().setWidth(15),
  206. bottom: ScreenUtil().setWidth(20)),
  207. child: TextFormField(
  208. // autofocus: true,
  209. maxLength: 50,
  210. cursorColor: Color(0xffcccccc),
  211. controller: _evaluationController,
  212. maxLines: 5,
  213. decoration: InputDecoration(
  214. contentPadding: EdgeInsets.all(0),
  215. hintText: '请输入您的自我评价',
  216. hintStyle: TextStyle(
  217. color: Color(0xffcccccc),
  218. // fontSize: ScreenUtil().setSp(14)
  219. ),
  220. focusedBorder: InputBorder.none,
  221. border: InputBorder.none,
  222. // filled: true, // 背景色
  223. // fillColor: Colors.cyan.withAlpha(35),
  224. // icon: Icon(Icons.person)
  225. ),
  226. // 校验
  227. validator: (val) {
  228. return val.trim().length > 0 ? null : "不能为空";
  229. }),
  230. ),
  231. SizedBox(
  232. height: 6,
  233. child: Container(color: Color(0xFFF1F4FC)),
  234. ),
  235. SizedBox(
  236. height: ScreenUtil().setWidth(80),
  237. ),
  238. ],
  239. ),
  240. )
  241. ])),
  242. Positioned(
  243. bottom: 0,
  244. left: 0,
  245. child: Container(
  246. width: width,
  247. padding: EdgeInsets.only(
  248. top: ScreenUtil().setWidth(15),
  249. bottom: ScreenUtil().setWidth(15),
  250. left: ScreenUtil().setWidth(25),
  251. right: ScreenUtil().setWidth(25)),
  252. color: ThemeUtils.getDialogTextFieldColor(context),
  253. child: Container(
  254. height: ScreenUtil().setWidth(44),
  255. decoration: BoxDecoration(
  256. borderRadius:
  257. BorderRadius.circular(ScreenUtil().setWidth(22)),
  258. gradient: const LinearGradient(
  259. colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
  260. ),
  261. child: FlatButton(
  262. // padding: EdgeInsets.all(15.0),
  263. child: Text("提交"),
  264. textColor: Colors.white,
  265. onPressed: () {
  266. /*
  267. * 如果:context不对。可以使用GlobalKey,
  268. * 通过_formKey.currentState 获取FormState后,
  269. * 调用validate()方法校验用户名密码是否合法,校验
  270. * 通过后再提交数据。
  271. */
  272. if(_usernameController.text == null || _usernameController.text.trim()==""){
  273. toasts("请输入姓名");
  274. return;
  275. }
  276. if(sexChioseValue == null){
  277. toasts("请选择性别");
  278. return;
  279. }
  280. if(_salaryController.text == null || _salaryController.text.trim()==""){
  281. toasts("请输入期望薪资");
  282. return;
  283. }
  284. if(_telController.text == null || _telController.text.trim()==""){
  285. toasts("请输入联系方式");
  286. return;
  287. }
  288. if(_emailController.text == null || _emailController.text.trim()==""){
  289. toasts("请输入联系邮箱");
  290. return;
  291. }
  292. if(_skillController.text == null || _skillController.text.trim()==""){
  293. toasts("请输入个人技能");
  294. return;
  295. }
  296. if(_evaluationController.text == null || _evaluationController.text.trim()==""){
  297. toasts("请输入自我评价");
  298. return;
  299. }
  300. RegExp exp = RegExp(r'^1[34578]\d{9}$');
  301. RegExp expEmail = RegExp(r"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
  302. if(!exp.hasMatch(_telController.text)){
  303. toasts("请输入正确的手机号");
  304. return;
  305. }
  306. if(!expEmail.hasMatch(_emailController.text)){
  307. toasts("请输入正确的邮箱");
  308. return;
  309. }
  310. print(_salaryController.text);
  311. if ((_formKey.currentState as FormState).validate()) {
  312. usreJob = {
  313. "infoId": int.parse(widget.id),
  314. "userId":
  315. FlutterStars.SpUtil.getString(Constant.userId),
  316. "ability": _skillController.text,
  317. "email": _emailController.text,
  318. "intro": _evaluationController.text,
  319. "name": _usernameController.text,
  320. "telephone": _telController.text,
  321. "salary": _salaryController.text == ''
  322. ? 0
  323. : int.parse(_salaryController.text),
  324. "gender": sexChioseValue
  325. };
  326. NewApiService().applyJob(usreJob, onSuccess: (res) {
  327. toasts("职位申请成功");
  328. NavigatorUtils.goBackWithParams(context, true);
  329. bool isApply = true;
  330. FastNotification.push("apply", isApply);
  331. setState(() {});
  332. }, onError: (code, msg) {
  333. toasts(msg);
  334. });
  335. }
  336. },
  337. ),
  338. ),
  339. ))
  340. ],
  341. ),
  342. ),
  343. );
  344. }
  345. }