position_detail.dart 19 KB

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