Hibok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

344 lines
12 KiB

  1. import 'package:chat/data/UserData.dart';
  2. import 'package:chat/data/WebData.dart';
  3. import 'package:chat/data/constants.dart';
  4. import 'package:chat/generated/i18n.dart';
  5. import 'package:chat/utils/CustomUI.dart';
  6. import 'package:chat/utils/HttpUtil.dart';
  7. import 'package:chat/utils/TokenMgr.dart';
  8. import 'package:chat/utils/screen.dart';
  9. import 'package:dio/dio.dart';
  10. import 'package:flutter/material.dart';
  11. import 'package:image_picker/image_picker.dart';
  12. import 'package:oktoast/oktoast.dart';
  13. import 'InformUser.dart';
  14. class ApplyContent extends StatefulWidget {
  15. final userInfo;
  16. final userId;
  17. final bool isMan;
  18. ApplyContent({Key key, this.userInfo, this.userId, this.isMan = false})
  19. : super(key: key);
  20. _ApplyContentState createState() => _ApplyContentState();
  21. }
  22. class _ApplyContentState extends State<ApplyContent> {
  23. int friendly = 0;
  24. int interesting = 0;
  25. int refreshing = 0;
  26. int patience = 0;
  27. int hello = 0;
  28. int unfriendly = 0;
  29. bool isPost = false;
  30. Set select = new Set();
  31. String evilImg1 = ''; //恶意差评1
  32. String evilImg2 = ''; //恶意差评2
  33. @override
  34. Widget build(BuildContext context) {
  35. String tip = isPost
  36. ? I18n.of(context).anonymous_evaluation
  37. : (widget.isMan
  38. ? I18n.of(context).his_evaluation
  39. : I18n.of(context).her_evaluation);
  40. return CustomUI.buildTipContent(
  41. context, tip, _buildContent(widget.userInfo));
  42. }
  43. @override
  44. void initState() {
  45. super.initState();
  46. friendly = widget.userInfo['Friendly'];
  47. interesting = widget.userInfo['Interesting'];
  48. refreshing = widget.userInfo['Refreshing'];
  49. patience = widget.userInfo['Patience'];
  50. hello = widget.userInfo['Hello'];
  51. unfriendly = widget.userInfo['Unfriendly'];
  52. }
  53. void doContext(callback) async {
  54. Map data = {
  55. "userid": widget.userId,
  56. "evaluateuserid": UserData().basicInfo.userId,
  57. };
  58. String str = '';
  59. select.forEach((s) {
  60. str += (str == '' ? s : '|$s');
  61. });
  62. if (str == '') {
  63. showToast(I18n.of(context).click_select);
  64. return;
  65. }
  66. data['sign'] = TokenMgr().getSign(data);
  67. data['value'] = str;
  68. data['evilImg'] = '$evilImg1|$evilImg2';
  69. Response res = await HttpUtil().post('evaluate/user/insert', data: data);
  70. var resData = res.data;
  71. if (resData['code'] == 0) {
  72. select.forEach((s) {
  73. switch (s) {
  74. case 'Friendly':
  75. friendly++;
  76. break;
  77. case 'Interesting':
  78. interesting++;
  79. break;
  80. case 'Refreshing':
  81. refreshing++;
  82. break;
  83. case 'Patience':
  84. patience++;
  85. break;
  86. case 'Hello':
  87. hello++;
  88. break;
  89. case 'Unfriendly':
  90. unfriendly++;
  91. break;
  92. default:
  93. }
  94. });
  95. showToast(resData['msg']);
  96. callback();
  97. } else {
  98. showToast(resData['msg']);
  99. }
  100. }
  101. void _sendPicture(callback) async {
  102. if (await CustomUI.showPhotoPermissionSetting(context)) {
  103. var tempFile = await ImagePicker.pickImage(source: ImageSource.gallery);
  104. if (tempFile != null) {
  105. Map data = {"type": 4, "userId": UserData().basicInfo.userId};
  106. data['sign'] = TokenMgr().getSign(data);
  107. Response res = await HttpUtil().uploadFile(
  108. tempFile, data, 'upload/file/postflie', 'image',
  109. isShowLoading: true);
  110. var resData = res.data;
  111. if (resData['code'] == 0) {
  112. Navigator.of(context).pop();
  113. callback(WebData().deleteDemain(resData['msg']));
  114. }
  115. }
  116. }
  117. }
  118. Widget _buildBox(str, value, callback) {
  119. bool isSelect = select.contains(value);
  120. return InkWell(
  121. onTap: callback,
  122. child: Container(
  123. alignment: Alignment.center,
  124. margin: EdgeInsets.only(top: 10, bottom: 21, left: 5, right: 5),
  125. width: (Screen.width - 70) / 3,
  126. height: 28,
  127. decoration: BoxDecoration(
  128. color: isSelect ? Colors.blue : Colors.grey[200],
  129. borderRadius:
  130. BorderRadius.circular(Constants.LittleButtonRadius)),
  131. child: Text(
  132. str,
  133. textScaleFactor: 1.0,
  134. style: TextStyle(
  135. fontSize: 14,
  136. color: isSelect ? Colors.white : Constants.BlackTextColor),
  137. ),
  138. ));
  139. }
  140. Widget _buildContext(nums, str) {
  141. return InkWell(
  142. onTap: () {
  143. if (widget.userInfo['Statu'] == 1) {
  144. showToast(I18n.of(context).has_eva);
  145. return;
  146. }
  147. if (widget.userInfo['IsComment'] == 0) {
  148. showToast(!widget.isMan
  149. ? I18n.of(context).cant_evaluate
  150. : I18n.of(context).cant_evaluate2);
  151. return;
  152. }
  153. setState(() {
  154. isPost = !isPost;
  155. });
  156. },
  157. child: CustomUI.buildBox(nums, str));
  158. }
  159. Widget _buildContent(data) {
  160. var evaluation1 =
  161. widget.isMan ? I18n.of(context).courtesy : I18n.of(context).friendly;
  162. var evaluation2 = I18n.of(context).interesting;
  163. var evaluation3 = I18n.of(context).readily;
  164. var evaluation4 =
  165. widget.isMan ? I18n.of(context).generous : I18n.of(context).patient;
  166. var evaluation5 =
  167. widget.isMan ? I18n.of(context).lie : I18n.of(context).indifferent;
  168. var evaluation6 = widget.isMan
  169. ? I18n.of(context).unfriendly
  170. : I18n.of(context).bad_temper;
  171. return Container(
  172. padding: EdgeInsets.only(top: 10),
  173. child: Column(
  174. children: <Widget>[
  175. Row(
  176. crossAxisAlignment: CrossAxisAlignment.center,
  177. mainAxisAlignment: MainAxisAlignment.center,
  178. children: <Widget>[
  179. isPost
  180. ? _buildBox(evaluation1, 'Friendly', () {
  181. select.contains('Friendly')
  182. ? select.remove('Friendly')
  183. : select.add('Friendly');
  184. setState(() {});
  185. })
  186. : _buildContext(friendly, evaluation1),
  187. isPost
  188. ? _buildBox(evaluation2, 'Interesting', () {
  189. select.contains('Interesting')
  190. ? select.remove('Interesting')
  191. : select.add('Interesting');
  192. setState(() {});
  193. })
  194. : _buildContext(interesting, evaluation2),
  195. isPost
  196. ? _buildBox(evaluation3, 'Refreshing', () {
  197. select.contains('Refreshing')
  198. ? select.remove('Refreshing')
  199. : select.add('Refreshing');
  200. setState(() {});
  201. })
  202. : _buildContext(refreshing, evaluation3),
  203. ],
  204. ),
  205. Row(
  206. crossAxisAlignment: CrossAxisAlignment.center,
  207. mainAxisAlignment: MainAxisAlignment.center,
  208. children: <Widget>[
  209. isPost
  210. ? _buildBox(evaluation4, 'Patience', () {
  211. select.contains('Patience')
  212. ? select.remove('Patience')
  213. : select.add('Patience');
  214. setState(() {});
  215. })
  216. : _buildContext(patience, evaluation4),
  217. isPost
  218. ? _buildBox(evaluation5, 'Hello', () {
  219. if (select.contains('Hello')) {
  220. select.remove('Hello');
  221. evilImg1 = '';
  222. setState(() {});
  223. } else {
  224. CustomUI.buildOneConfirm(
  225. context,
  226. I18n.of(context).bad_evaluate,
  227. I18n.of(context).determine, () {
  228. _sendPicture((url) {
  229. evilImg1 = url;
  230. select.add('Hello');
  231. setState(() {});
  232. });
  233. });
  234. }
  235. })
  236. : _buildContext(hello, evaluation5),
  237. isPost
  238. ? _buildBox(evaluation6, 'Unfriendly', () {
  239. if (select.contains('Unfriendly')) {
  240. select.remove('Unfriendly');
  241. evilImg2 = '';
  242. setState(() {});
  243. } else {
  244. CustomUI.buildOneConfirm(
  245. context,
  246. I18n.of(context).bad_evaluate,
  247. I18n.of(context).determine, () {
  248. _sendPicture((url) {
  249. evilImg2 = url;
  250. select.add('Unfriendly');
  251. setState(() {});
  252. });
  253. });
  254. }
  255. })
  256. : _buildContext(unfriendly, evaluation6),
  257. ],
  258. ),
  259. InkWell(
  260. onTap: () {
  261. if (!isPost && widget.userInfo['Statu'] == 1) {
  262. showToast(I18n.of(context).has_eva);
  263. return;
  264. }
  265. if (widget.userInfo['IsComment'] == 0) {
  266. showToast(!widget.isMan
  267. ? I18n.of(context).cant_evaluate
  268. : I18n.of(context).cant_evaluate2);
  269. return;
  270. }
  271. if (isPost) {
  272. doContext(() {
  273. isPost = !isPost;
  274. widget.userInfo['Statu'] = 1;
  275. setState(() {});
  276. });
  277. } else {
  278. isPost = !isPost;
  279. setState(() {});
  280. }
  281. },
  282. child: Container(
  283. margin: EdgeInsets.only(top: 20, left: 80, right: 80),
  284. width: double.infinity,
  285. alignment: Alignment.center,
  286. padding: EdgeInsets.only(top: 8, bottom: 8),
  287. decoration: BoxDecoration(
  288. border:
  289. Border.all(color: const Color(0xFF2D81FF), width: 1),
  290. color: const Color(0xFF2D81FF),
  291. borderRadius: BorderRadius.all(
  292. Radius.circular(Constants.LittleButtonRadius))),
  293. child: Text(
  294. isPost
  295. ? I18n.of(context).submit
  296. : I18n.of(context).anonymous_evaluation,
  297. textScaleFactor: 1.0,
  298. style: TextStyle(color: Colors.white),
  299. ),
  300. )),
  301. InkWell(
  302. onTap: () {
  303. Navigator.of(context).push(
  304. new MaterialPageRoute(
  305. builder: (context) {
  306. return InformUserPage(
  307. isMan: widget.isMan,
  308. userId: widget.userId,
  309. );
  310. },
  311. ),
  312. );
  313. },
  314. child: Container(
  315. margin: EdgeInsets.only(top: 5),
  316. child: Text(
  317. I18n.of(context).anonymous_report,
  318. textScaleFactor: 1.0,
  319. style: TextStyle(color: Colors.red, fontSize: 12),
  320. ),
  321. ))
  322. ],
  323. ));
  324. }
  325. }