position_detail.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. import 'dart:math';
  2. import 'package:flustars/flustars.dart' as FlutterStars;
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:fluwx/fluwx.dart' as fluwx;
  6. import 'package:liftmanager/common/common.dart';
  7. import 'package:liftmanager/internal/account/account_router.dart';
  8. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  9. import 'package:liftmanager/internal/bbs/model/position_model.dart';
  10. import 'package:liftmanager/net/api_service.dart';
  11. import 'package:liftmanager/res/iconfont.dart';
  12. import 'package:liftmanager/routers/fluro_navigator.dart';
  13. import 'package:liftmanager/utils/fast_notification.dart';
  14. import 'package:liftmanager/utils/theme_utils.dart';
  15. import 'package:liftmanager/utils/time_format.dart';
  16. import 'package:liftmanager/utils/toast.dart';
  17. import 'package:liftmanager/utils/url.dart';
  18. import 'package:liftmanager/widgets/app_bar.dart';
  19. import 'package:liftmanager/widgets/bbs_content.dart';
  20. import 'package:liftmanager/widgets/my_card.dart';
  21. class PositionDetail extends StatefulWidget {
  22. PositionDetail(this.id);
  23. final String id;
  24. @override
  25. State<StatefulWidget> createState() {
  26. return PositionDetailState();
  27. }
  28. }
  29. class PositionDetailState extends State<PositionDetail> {
  30. bool positionFavorited = false;
  31. @override
  32. void initState() {
  33. super.initState();
  34. getPositionDetail();
  35. FastNotification.addListener("apply", (isApply) {
  36. if (isApply == true) {
  37. getPositionDetail();
  38. }
  39. setState(() {});
  40. });
  41. }
  42. bool _hasData = false;
  43. PositionDetailModel detailObj;
  44. Future getPositionDetail() async {
  45. await NewApiService().getPositionDetail(int.parse(widget.id),
  46. onSuccess: (res) {
  47. if (res != null) {
  48. detailObj = res;
  49. positionFavorited = res.isFavorite == 1;
  50. _hasData = true;
  51. setState(() {});
  52. }
  53. }, onError: (code, msg) {
  54. toasts(msg);
  55. });
  56. }
  57. Future changeFavorite() async {
  58. showLoading(context);
  59. print(detailObj.isFavorite);
  60. if (detailObj.isFavorite == 0) {
  61. await NewApiService().insertRecruitmentOperates(
  62. detailObj.id,
  63. 3,
  64. onSuccess: (res) {
  65. print(res);
  66. dismissLoading(context);
  67. initCollect();
  68. this.getPositionDetail();
  69. setState(() {
  70. positionFavorited = true;
  71. });
  72. },
  73. onError: (code, msg) {
  74. dismissLoading(context);
  75. toasts(msg);
  76. },
  77. );
  78. } else {
  79. await NewApiService().deleteRecruitmentOperates(
  80. detailObj.favoriteId,
  81. onSuccess: (res) {
  82. print(res);
  83. dismissLoading(context);
  84. initCollect();
  85. this.getPositionDetail();
  86. setState(() {
  87. positionFavorited = false;
  88. });
  89. },
  90. onError: (code, msg) {
  91. dismissLoading(context);
  92. toasts(msg);
  93. },
  94. );
  95. }
  96. }
  97. showAlertEvent() {
  98. showAlert(
  99. context,
  100. "提示",
  101. "确定登录?",
  102. "确定",
  103. () {
  104. NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
  105. },
  106. txt2: "取消",
  107. onPre2: () {
  108. NavigatorUtils.goBack(context);
  109. },
  110. );
  111. }
  112. initCollect() {
  113. String collectInit = randomInt(1111, 9999).toString() +
  114. DateTime.now().millisecondsSinceEpoch.toString();
  115. FastNotification.push("collectAction", collectInit);
  116. }
  117. randomInt(int min, int max) {
  118. return new Random().nextInt(max) % (max - min + 1) + min;
  119. }
  120. @override
  121. Widget build(BuildContext context) {
  122. double width = MediaQuery.of(context).size.width;
  123. return Scaffold(
  124. resizeToAvoidBottomPadding: false, //不让键盘弹上去
  125. appBar: MyAppBar(
  126. centerTitle: "职位详情",
  127. ),
  128. body: _hasData
  129. ? Stack(
  130. children: <Widget>[
  131. Container(
  132. child: ListView(
  133. children: <Widget>[
  134. SizedBox(
  135. height: 10,
  136. ),
  137. Container(
  138. child: Column(
  139. mainAxisAlignment: MainAxisAlignment.start,
  140. crossAxisAlignment: CrossAxisAlignment.start,
  141. children: <Widget>[
  142. Padding(
  143. padding: EdgeInsets.symmetric(horizontal: 10),
  144. child: MyCard(
  145. child: Container(
  146. color: Colors.white,
  147. padding: EdgeInsets.all(10),
  148. child: Column(
  149. crossAxisAlignment:
  150. CrossAxisAlignment.start,
  151. children: <Widget>[
  152. Container(
  153. padding: EdgeInsets.only(
  154. bottom:
  155. ScreenUtil().setWidth(10)),
  156. child: Row(
  157. crossAxisAlignment:
  158. CrossAxisAlignment.start,
  159. mainAxisAlignment:
  160. MainAxisAlignment.spaceBetween,
  161. children: <Widget>[
  162. Expanded(
  163. child: Text(
  164. detailObj.job ?? '',
  165. style: TextStyle(
  166. fontSize: 15,
  167. color: Color(0xff333333),
  168. ),
  169. textAlign: TextAlign.start,
  170. ),
  171. ),
  172. Container(
  173. padding:
  174. EdgeInsets.only(top: 5),
  175. child: Text(
  176. DateUtils.instance
  177. .getFormartData(
  178. timeSamp: detailObj
  179. .createTime,
  180. format: "yyyy-MM-dd"),
  181. style: TextStyle(
  182. color: Color(0xff999999),
  183. fontSize: 12,
  184. ),
  185. textAlign: TextAlign.start,
  186. ),
  187. )
  188. ],
  189. ),
  190. ),
  191. Container(
  192. child: Text(
  193. "${detailObj.lowerSalary.toInt()}-${detailObj.upperSalary.toInt()}/月",
  194. style: TextStyle(
  195. color: Color(0xffFF5B00),
  196. fontSize: 14,
  197. ),
  198. textAlign: TextAlign.start,
  199. ),
  200. ),
  201. SizedBox(
  202. height: 10,
  203. ),
  204. Row(
  205. children: [
  206. Icon(
  207. Iconfont.xueli,
  208. color: Colors.grey,
  209. size: 12,
  210. ),
  211. SizedBox(
  212. width: 10,
  213. ),
  214. Text(
  215. (detailObj.eduName != '' &&
  216. detailObj.eduName != null)
  217. ? detailObj.eduName
  218. : "不限学历",
  219. style: TextStyle(
  220. color: Color(0xff999999),
  221. fontSize: 12,
  222. ),
  223. overflow: TextOverflow.ellipsis,
  224. textAlign: TextAlign.start,
  225. ),
  226. SizedBox(
  227. width: 10,
  228. ),
  229. Icon(Iconfont.nianxian,
  230. size: 12, color: Colors.grey),
  231. SizedBox(
  232. width: 10,
  233. ),
  234. Text(
  235. (detailObj.upperWorking != null &&
  236. detailObj
  237. .lowerWorking !=
  238. null
  239. ? detailObj.lowerWorking
  240. .toString() +
  241. "-" +
  242. detailObj.upperWorking
  243. .toString()
  244. : '0') +
  245. "年",
  246. style: TextStyle(
  247. color: Color(0xff999999),
  248. fontSize: 12,
  249. ),
  250. ),
  251. ],
  252. ),
  253. SizedBox(
  254. height: 10,
  255. ),
  256. Divider(
  257. thickness: 0.5,
  258. ),
  259. SizedBox(
  260. height: 10,
  261. ),
  262. Row(
  263. children: [
  264. Icon(
  265. Iconfont.dizhi,
  266. color: Colors.grey,
  267. size: 12,
  268. ),
  269. SizedBox(
  270. width: 10,
  271. ),
  272. Expanded(
  273. child: Text(
  274. (detailObj.provinceName ?? '') +
  275. (detailObj.cityName ?? '') +
  276. (detailObj.address ?? ''),
  277. style: TextStyle(
  278. color: Color(0xff999999),
  279. fontSize: 12,
  280. ),
  281. softWrap: true,
  282. textAlign: TextAlign.left,
  283. ),
  284. ),
  285. ],
  286. ),
  287. ],
  288. ),
  289. ),
  290. ),
  291. ),
  292. SizedBox(
  293. height: ScreenUtil().setWidth(20),
  294. ),
  295. CommonSectionHeader(title: '公司信息'),
  296. SizedBox(
  297. height: 10,
  298. ),
  299. ]),
  300. ),
  301. Container(
  302. padding: EdgeInsets.symmetric(horizontal: 10),
  303. width: width,
  304. decoration: BoxDecoration(
  305. border: Border(
  306. bottom: BorderSide(
  307. width: 5,
  308. color: ThemeUtils.getDialogTextFieldColor(
  309. context)),
  310. ),
  311. ),
  312. child: Column(
  313. crossAxisAlignment: CrossAxisAlignment.start,
  314. children: <Widget>[
  315. Container(
  316. child: Text(
  317. detailObj.company?.name == null
  318. ? ''
  319. : detailObj.company.name,
  320. style: TextStyle(
  321. color: Color(0xff333333),
  322. fontSize: 13,
  323. ),
  324. textAlign: TextAlign.left,
  325. ),
  326. ),
  327. SizedBox(
  328. height: ScreenUtil().setWidth(10),
  329. ),
  330. Text(
  331. '${detailObj?.company?.corporator ?? ""} ${detailObj?.company?.telephone ?? ""}',
  332. style: TextStyle(
  333. color: Color(0xff666666),
  334. fontSize: 11,
  335. ),
  336. textAlign: TextAlign.left,
  337. ),
  338. SizedBox(
  339. height: ScreenUtil().setWidth(10),
  340. ),
  341. ],
  342. ),
  343. ),
  344. SizedBox(
  345. height: 10,
  346. ),
  347. CommonSectionHeader(title: '职位信息'),
  348. SizedBox(
  349. height: 10,
  350. ),
  351. Container(
  352. padding: EdgeInsets.symmetric(
  353. horizontal: 10,
  354. ),
  355. child: Text(
  356. detailObj.info ?? '',
  357. style: TextStyle(
  358. color: Color(0xff666666),
  359. fontSize: 13,
  360. ),
  361. textAlign: TextAlign.left,
  362. ),
  363. ),
  364. SizedBox(
  365. height: 80,
  366. )
  367. ],
  368. )),
  369. Positioned(
  370. bottom: 0,
  371. left: 0,
  372. child: CommonActionBar(
  373. isFavorited: positionFavorited,
  374. actionText: '申请职位',
  375. onTapFavoriting: () {
  376. if (FlutterStars.SpUtil.getString(Constant.userId) ==
  377. "-1") {
  378. showAlertEvent();
  379. } else {
  380. changeFavorite();
  381. }
  382. },
  383. onTapSharing: () {
  384. if (FlutterStars.SpUtil.getString(Constant.userId) ==
  385. "-1") {
  386. showAlertEvent();
  387. } else {
  388. String initThis = randomInt(1111, 9999).toString() +
  389. DateTime.now().millisecondsSinceEpoch.toString();
  390. fluwx
  391. .shareToWeChat(fluwx.WeChatShareWebPageModel(
  392. scene: fluwx.WeChatScene.SESSION,
  393. webPage:
  394. "$jumpUrl/h5/index.html?num=$initThis&page=/bbs/positionDetail&id=${widget.id}",
  395. title: detailObj.job,
  396. description: detailObj.info,
  397. thumbnail: "",
  398. ))
  399. .then((result) {}, onError: (msg) {});
  400. }
  401. },
  402. onTapAction: () {
  403. if (FlutterStars.SpUtil.getString(Constant.userId) ==
  404. "-1") {
  405. showAlertEvent();
  406. } else {
  407. if (detailObj.isApply == 1) {
  408. toasts("您已经提交申请了哦");
  409. } else {
  410. NavigatorUtils.push(context,
  411. "${BbsRouter.positionApply}?id=${detailObj.id.toString()}");
  412. }
  413. }
  414. },
  415. ),
  416. ),
  417. ],
  418. )
  419. : Center(
  420. child: Text("正在加载..."),
  421. ));
  422. }
  423. }