Hibok
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

1243 行
41 KiB

  1. import 'package:chat/data/UserData.dart';
  2. import 'package:chat/data/WebData.dart';
  3. import 'package:chat/generated/i18n.dart';
  4. import 'package:chat/home/ProfilePage.dart';
  5. import 'package:chat/models/ref_name_provider.dart';
  6. import 'package:chat/utils/CustomUI.dart';
  7. import 'package:chat/utils/HttpUtil.dart';
  8. import 'package:chat/utils/MessageMgr.dart';
  9. import 'package:chat/utils/PicSwiper.dart';
  10. import 'package:chat/utils/TokenMgr.dart';
  11. import 'package:chat/utils/conversation_table.dart';
  12. import 'package:chat/utils/friend_list_mgr.dart';
  13. import 'package:chat/utils/screen.dart';
  14. import 'package:dio/dio.dart';
  15. import 'package:flutter/cupertino.dart';
  16. import 'package:flutter/material.dart';
  17. import 'package:flutter/services.dart';
  18. import 'package:oktoast/oktoast.dart';
  19. import 'package:provider/provider.dart';
  20. import 'package:pull_to_refresh/pull_to_refresh.dart';
  21. import 'package:url_launcher/url_launcher.dart';
  22. import '../data/constants.dart' show AppColors, Constants;
  23. import '../data/conversation.dart';
  24. import 'package:cached_network_image/cached_network_image.dart';
  25. import 'ProgramDetail.dart';
  26. class InfoType {
  27. static const int Apply = 1;
  28. static const int Evaluation = 2;
  29. static const int System = 3;
  30. static const int Radio = 4;
  31. static const int Money = 5;
  32. static const int IncomeMoney = 6;
  33. static const int MyMoney = 7;
  34. }
  35. class _ConversationItem extends StatelessWidget {
  36. const _ConversationItem(
  37. {Key key,
  38. this.conversation,
  39. this.callback,
  40. this.showRight = true,
  41. this.rightButton,
  42. this.applyInfo,
  43. this.bgColor,
  44. this.title})
  45. : assert(conversation != null),
  46. super(key: key);
  47. final Widget rightButton;
  48. final Conversation conversation;
  49. final callback;
  50. final bool showRight;
  51. final title;
  52. final applyInfo;
  53. final bgColor;
  54. @override
  55. Widget build(BuildContext context) {
  56. Widget avatar;
  57. double width = 53;
  58. if (conversation.isAvatarFromNet()) {
  59. avatar = ClipRRect(
  60. borderRadius: BorderRadius.circular(10),
  61. child: CachedNetworkImage(
  62. imageUrl: conversation.avatar,
  63. placeholder: (context, url) => Image.asset(
  64. Constants.DefaultHeadImgUrl,
  65. width: width,
  66. height: width,
  67. ),
  68. fit: BoxFit.cover,
  69. width: width,
  70. height: width,
  71. ));
  72. } else {
  73. avatar = ClipRRect(
  74. borderRadius: BorderRadius.circular(10),
  75. child: Container(
  76. width: width,
  77. height: width,
  78. alignment: Alignment.center,
  79. decoration: BoxDecoration(
  80. gradient: this.bgColor,
  81. borderRadius: BorderRadius.all(Radius.circular(50))),
  82. child: Image.asset(
  83. conversation.avatar,
  84. height: 27,
  85. )));
  86. }
  87. _buildBotton(str, callback) {
  88. return InkWell(
  89. onTap: callback,
  90. child: Container(
  91. padding: EdgeInsets.only(top: 5, left: 15, right: 15, bottom: 5),
  92. decoration: BoxDecoration(
  93. border:
  94. Border.all(color: Constants.ConfrimButtonColor, width: 1),
  95. color: Constants.ConfrimButtonColor,
  96. borderRadius: BorderRadius.all(Radius.circular(5))),
  97. child: fixedText(
  98. str,
  99. fontSize: 12,
  100. color: Colors.white,
  101. ),
  102. ));
  103. }
  104. void doApply(state, callback) async {
  105. Map data = {
  106. "id": applyInfo['applyId'],
  107. "userId": UserData().basicInfo.userId,
  108. "status": state,
  109. };
  110. data['sign'] = TokenMgr().getSign(data);
  111. Response res = await HttpUtil().post('user/handler/apply', data: data);
  112. if (res == null) {
  113. return;
  114. }
  115. var resData = res.data;
  116. if (resData['code'] == 0) {
  117. callback(resData['msg']);
  118. } else {}
  119. }
  120. void doFriendApply(state, callback) async {
  121. Map data = {
  122. "id": applyInfo['applyId'],
  123. "userId": UserData().basicInfo.userId,
  124. "status": state,
  125. };
  126. data['sign'] = TokenMgr().getSign(data);
  127. Response res =
  128. await HttpUtil().post('friendship/handler/apply', data: data);
  129. if (res == null) {
  130. return;
  131. }
  132. var resData = res.data;
  133. if (resData['code'] == 0) {
  134. callback(resData['msg']);
  135. } else {}
  136. }
  137. var bottomWiget = applyInfo == null
  138. ? Container()
  139. : Container(
  140. padding: EdgeInsets.only(left: 0, top: 10),
  141. decoration: BoxDecoration(
  142. color: Color(AppColors.ConversationItemBgColor),
  143. ),
  144. child: Row(
  145. crossAxisAlignment: CrossAxisAlignment.center,
  146. children: applyInfo['type'] == 0 || applyInfo['type'] == 6
  147. ? <Widget>[
  148. CustomUI.buildImgCover(
  149. applyInfo['imgId'],
  150. [
  151. PicSwiperItem(applyInfo['showUrl'],
  152. id: applyInfo['imgId'],
  153. type: applyInfo['type'] == 0
  154. ? PhotoType.destroy.index
  155. : PhotoType.free.index,
  156. isWatch: applyInfo['isWatch'],
  157. userId: applyInfo['userId'])
  158. ],
  159. applyInfo['showUrl'],
  160. 65,
  161. 10,
  162. applyInfo['isWatch'],
  163. context,
  164. applyInfo['type'] == 0
  165. ? PhotoType.destroy.index
  166. : PhotoType.free.index),
  167. Expanded(
  168. child: applyInfo['type'] == 0
  169. ? Container(
  170. alignment: Alignment.centerRight,
  171. padding: EdgeInsets.only(top: 40),
  172. child: applyInfo['state'] == 0
  173. ? Row(
  174. mainAxisAlignment:
  175. MainAxisAlignment.end,
  176. children: <Widget>[
  177. _buildBotton(I18n.of(context).aging,
  178. () {
  179. doApply(1, (msg) {
  180. showToast(msg);
  181. applyInfo['state'] = 1;
  182. MessageMgr()
  183. .emit('do_info_apply');
  184. });
  185. }),
  186. SizedBox(
  187. width: 10,
  188. ),
  189. _buildBotton(I18n.of(context).refuse,
  190. () {
  191. doApply(2, (msg) {
  192. showToast(msg);
  193. applyInfo['state'] = 2;
  194. MessageMgr()
  195. .emit('do_info_apply');
  196. });
  197. }),
  198. ],
  199. )
  200. : Padding(
  201. padding: EdgeInsets.only(right: 0),
  202. child: Text(
  203. applyInfo['state'] == 1
  204. ? I18n.of(context).passed
  205. : I18n.of(context).rejected,
  206. style: TextStyle(
  207. color: Constants.GreyTextColor,
  208. fontSize: 13),
  209. textScaleFactor: 1.0,
  210. ),
  211. ),
  212. )
  213. : Container(),
  214. )
  215. ]
  216. : [
  217. Expanded(child: Container()),
  218. Container(
  219. alignment: Alignment.centerRight,
  220. child: applyInfo['state'] == 0
  221. ? Row(
  222. mainAxisAlignment: MainAxisAlignment.end,
  223. children: <Widget>[
  224. _buildBotton(I18n.of(context).agree, () {
  225. doFriendApply(1, (msg) {
  226. showToast(msg);
  227. applyInfo['state'] = 1;
  228. var friendModel =
  229. FriendModel.fromServerJson({
  230. 'UserId': applyInfo['userId'],
  231. 'ImgUrl': applyInfo['imgUrl'],
  232. 'UserName': applyInfo['name']
  233. });
  234. FriendListMgr().addFriend(friendModel);
  235. MessageMgr().emit('do_info_apply');
  236. MessageMgr().emit('do_friend_apply', {
  237. 'userId': applyInfo['userId'],
  238. 'state': 1
  239. });
  240. MessageMgr().emit('Add friend');
  241. });
  242. }),
  243. SizedBox(
  244. width: 10,
  245. ),
  246. _buildBotton(I18n.of(context).refuse, () {
  247. doFriendApply(2, (msg) {
  248. showToast(msg);
  249. applyInfo['state'] = 2;
  250. MessageMgr().emit('do_info_apply');
  251. MessageMgr().emit('do_friend_apply', {
  252. 'userId': applyInfo['userId'],
  253. 'state': 2
  254. });
  255. });
  256. }),
  257. ],
  258. )
  259. : Padding(
  260. padding: EdgeInsets.only(right: 0),
  261. child: Text(
  262. applyInfo['state'] == 1
  263. ? I18n.of(context).passed
  264. : I18n.of(context).rejected,
  265. style: TextStyle(
  266. color: Constants.GreyTextColor,
  267. fontSize: 13),
  268. textScaleFactor: 1.0,
  269. ),
  270. ),
  271. ),
  272. ],
  273. ),
  274. );
  275. return InkWell(
  276. child: Container(
  277. padding:
  278. const EdgeInsets.only(left: 16.5, top: 11, bottom: 11, right: 14.5),
  279. decoration: BoxDecoration(
  280. color: Color(AppColors.ConversationItemBgColor),
  281. border: Border(
  282. bottom: BorderSide(
  283. color: AppColors.DividerColor,
  284. width: Constants.DividerWidth))),
  285. child: Column(
  286. children: <Widget>[
  287. Row(
  288. crossAxisAlignment: CrossAxisAlignment.start,
  289. children: <Widget>[
  290. avatar,
  291. Container(width: 19.0),
  292. Expanded(
  293. child: Container(
  294. child: Column(
  295. crossAxisAlignment: CrossAxisAlignment.start,
  296. children: <Widget>[
  297. Container(
  298. child: title == null
  299. ? Text(conversation.title,
  300. textScaleFactor: 1.0,
  301. style: TextStyle(
  302. fontSize: 12,
  303. color: Constants.LightGreyTextColor))
  304. : title),
  305. Container(
  306. padding: EdgeInsets.only(top: 5, bottom: 5),
  307. child: Row(
  308. children: <Widget>[
  309. Text(conversation.desc,
  310. textScaleFactor: 1.0,
  311. style: TextStyle(
  312. fontSize: 11,
  313. color: Constants.LightGreyTextColor)),
  314. showRight
  315. ? Expanded(
  316. child: Container(
  317. alignment: Alignment.centerRight,
  318. child: rightButton == null
  319. ? Text(
  320. '${I18n.of(context).go_see}>',
  321. textScaleFactor: 1.0,
  322. style: TextStyle(
  323. fontSize: 11,
  324. color: Constants
  325. .LightGreyTextColor))
  326. : rightButton,
  327. ),
  328. )
  329. : Container()
  330. ],
  331. )),
  332. applyInfo != null && applyInfo['content'] != null
  333. ? Container(
  334. child: Text(applyInfo['content'],
  335. textScaleFactor: 1.0,
  336. style: TextStyle(
  337. fontSize: 14,
  338. color: Constants.LightGreyTextColor)))
  339. : Container(),
  340. ],
  341. ),
  342. )),
  343. ],
  344. ),
  345. bottomWiget
  346. ],
  347. ),
  348. ),
  349. onTap: () {
  350. callback();
  351. },
  352. );
  353. }
  354. }
  355. class TitleItem {
  356. String title = '';
  357. String name = '';
  358. String value = '';
  359. TitleItem({this.title, this.name, this.value});
  360. }
  361. class RichTitle {
  362. static List<InlineSpan> getRichText(TitleItem titleItem,
  363. {titleStyle, nameStyle}) {
  364. if (nameStyle == null) {
  365. nameStyle = TextStyle(
  366. fontWeight: FontWeight.w500, color: Constants.BlackTextColor);
  367. }
  368. if (titleStyle == null) {
  369. titleStyle = TextStyle(color: Constants.GreyTextColor);
  370. }
  371. titleItem.title = titleItem.title == null ? '' : titleItem.title;
  372. List list = titleItem.title.split('/s1');
  373. titleItem.name = titleItem.name == null ? '' : (titleItem.name + ' ');
  374. List<InlineSpan> child;
  375. if (list == null) {
  376. child = [
  377. TextSpan(text: titleItem.title, style: titleStyle),
  378. ];
  379. } else {
  380. child = list.length > 1
  381. ? [
  382. TextSpan(
  383. text: list[0] == '' ? '' : (list[0] + ' '),
  384. style: titleStyle),
  385. TextSpan(text: titleItem.name, style: nameStyle),
  386. TextSpan(text: list[1], style: titleStyle),
  387. ]
  388. : [
  389. TextSpan(text: titleItem.name, style: nameStyle),
  390. TextSpan(text: list[0], style: titleStyle),
  391. ];
  392. }
  393. return child;
  394. }
  395. static String getNormalText(TitleItem titleItem) {
  396. List list = titleItem.title.split('/s1');
  397. titleItem.name = titleItem.name == null ? '' : (titleItem.name + ' ');
  398. String res = '';
  399. if (list == null) {
  400. res = titleItem.title;
  401. } else {
  402. list.length > 1
  403. ? res = (list[0] == '' ? list[0] : (list[0] + ' ')) +
  404. titleItem.name +
  405. list[1]
  406. : res = titleItem.name + list[0];
  407. }
  408. return res;
  409. }
  410. //申请
  411. static TitleItem _delApplyTitle(userInfo, BuildContext context) {
  412. print(userInfo);
  413. bool isMyself = userInfo['ApplyUserId'] == UserData().basicInfo.userId;
  414. String name = isMyself
  415. ? Provider.of<RefNameProvider>(context)
  416. .getRefName(userInfo['UserId'], userInfo['UserName'])
  417. : Provider.of<RefNameProvider>(context)
  418. .getRefName(userInfo['ApplyUserId'], userInfo['ApplyName']);
  419. String title = isMyself
  420. ? userInfo['Status'] == 1
  421. ? I18n.of(context).l15_days
  422. : I18n.of(context).reject_reply
  423. : I18n.of(context).view_application2;
  424. if (userInfo['Type'] == 1) {
  425. title = isMyself
  426. ? I18n.of(context).applyed_friends
  427. : I18n.of(context).apply_friends;
  428. }
  429. return TitleItem(title: title, name: name);
  430. }
  431. //评价
  432. static TitleItem _delEvaluateTitle(userInfo, BuildContext context) {
  433. String name = WebData().getEvaluation(context, userInfo['Value']);
  434. String title = '';
  435. if (userInfo['Status'] == 2) {
  436. title = I18n.of(context).successful_appeal;
  437. } else if (userInfo['Status'] == 3) {
  438. title = I18n.of(context).successful_appeal1;
  439. } else {
  440. title = UserData().isMan()
  441. ? I18n.of(context).received_evaluation
  442. : I18n.of(context).received_evaluation2;
  443. }
  444. return TitleItem(title: title, name: name);
  445. }
  446. //电台
  447. static TitleItem _delRadioTitle(data, BuildContext context) {
  448. bool isProgram = data['ProgramType'] == 0;
  449. String title;
  450. switch (data['Type']) {
  451. case 1:
  452. title = isProgram
  453. ? I18n.of(context).thumbs_up2
  454. : I18n.of(context).thumbs_up;
  455. break;
  456. case 2:
  457. title =
  458. isProgram ? I18n.of(context).comment2 : I18n.of(context).comment1;
  459. break;
  460. case 3:
  461. title = I18n.of(context).signed_up;
  462. break;
  463. case 4:
  464. title = isProgram
  465. ? I18n.of(context).favorite_user
  466. : I18n.of(context).favorite_user2;
  467. break;
  468. case 5:
  469. title = I18n.of(context).replied_comment;
  470. break;
  471. default:
  472. }
  473. return TitleItem(
  474. title: title,
  475. name: Provider.of<RefNameProvider>(context)
  476. .getRefName(data['UserId'], data['UserName']));
  477. }
  478. //系统
  479. static TitleItem _delSystemTitle(data, BuildContext context) {
  480. bool isMyself = data['UserId'] == UserData().basicInfo.userId;
  481. bool isPass = data['Status'] == 1;
  482. String title = '';
  483. String name = Provider.of<RefNameProvider>(context)
  484. .getRefName(data['ReportedUserId'], data['ReportedUserName']);
  485. switch (data['Type']) {
  486. case 1:
  487. title = isPass
  488. ? I18n.of(context).upload_success
  489. : I18n.of(context).re_upload;
  490. break;
  491. case 2:
  492. title = isPass
  493. ? I18n.of(context).successful_authentication
  494. : I18n.of(context).authentication_failed;
  495. break;
  496. case 3:
  497. if (isMyself) {
  498. title = data['Status'] == 1
  499. ? I18n.of(context).report_success
  500. : I18n.of(context).report_failure;
  501. } else {
  502. title = I18n.of(context).coin_returen;
  503. }
  504. break;
  505. case 4:
  506. title = data['Status'] == 1
  507. ? I18n.of(context).successful_application
  508. : I18n.of(context).application_failed;
  509. name = data['Status'] == 1 ? data['Content'].toString() : null;
  510. break;
  511. case 5:
  512. title = '代理会员推送相关';
  513. break;
  514. default:
  515. }
  516. return TitleItem(title: title, name: name);
  517. }
  518. //钱包
  519. static TitleItem _delMoneyTitle(data, BuildContext context) {
  520. String title = '';
  521. bool isMyself = data['UserId'] == UserData().basicInfo.userId;
  522. String name = Provider.of<RefNameProvider>(context)
  523. .getRefName(data['ChangeUserId'], data['UserName']);
  524. switch (data['DetailType'] == 10 ? data['Status'] : data['DetailType']) {
  525. case 1:
  526. title = I18n.of(context).get_coin2;
  527. name = data['Value'].toString();
  528. break;
  529. case 2:
  530. title = I18n.of(context).buy_vip;
  531. name = data['Value'].toString();
  532. break;
  533. case 3:
  534. title = isMyself
  535. ? I18n.of(context)
  536. .paid_you4
  537. .replaceFirst('/s2', data['Value'].toString())
  538. : I18n.of(context)
  539. .paid_you
  540. .replaceFirst('/s2', data['Value'].toString());
  541. break;
  542. case 4:
  543. title = isMyself
  544. ? I18n.of(context)
  545. .paid_you5
  546. .replaceFirst('/s2', data['Value'].toString())
  547. : I18n.of(context)
  548. .paid_you2
  549. .replaceFirst('/s2', data['Value'].toString());
  550. break;
  551. case 5:
  552. title = I18n.of(context).buy_program;
  553. name = data['Value'].toString();
  554. break;
  555. case 6:
  556. if (data['Status'] == 0) {
  557. title = I18n.of(context).del_add_money;
  558. } else if (data['Status'] == 1) {
  559. title = I18n.of(context).adding_money;
  560. } else {
  561. title = I18n.of(context).withdraw_fail;
  562. }
  563. name = data['Value'].toString();
  564. break;
  565. case 7:
  566. title =
  567. isMyself ? I18n.of(context).paid_you6 : I18n.of(context).paid_you3;
  568. break;
  569. case 8:
  570. title = isMyself
  571. ? I18n.of(context)
  572. .give_other_money
  573. .replaceFirst('/s2', data['Value'].toString())
  574. : I18n.of(context)
  575. .get_other_money
  576. .replaceFirst('/s2', data['Value'].toString());
  577. break;
  578. case 9:
  579. title = isMyself
  580. ? I18n.of(context)
  581. .give_red_money
  582. .replaceFirst('/s2', data['Value'].toString())
  583. : I18n.of(context)
  584. .get_red_money
  585. .replaceFirst('/s2', data['Value'].toString());
  586. break;
  587. case 11:
  588. title = I18n.of(context).Redeem;
  589. name = data['Value'].toString();
  590. break;
  591. }
  592. return TitleItem(title: title, name: name);
  593. }
  594. //收入金额
  595. static TitleItem _delInMoneyTitle(data, BuildContext context) {
  596. String title = '';
  597. String name = Provider.of<RefNameProvider>(context)
  598. .getRefName(data['UserId'], data['UserName']);
  599. switch (data['DetailType']) {
  600. case 1:
  601. if (data['Status'] == 0) {
  602. title = I18n.of(context).del_add_money;
  603. } else if (data['Status'] == 1) {
  604. title = I18n.of(context).withdraw_fail;
  605. } else {
  606. title = I18n.of(context).adding_money;
  607. }
  608. name = data['Value'].toString();
  609. break;
  610. case 2:
  611. title = I18n.of(context).change_h_coin;
  612. name = data['Value'].toString();
  613. break;
  614. case 3:
  615. title = I18n.of(context)
  616. .get_other_money
  617. .replaceFirst('/s2', data['Value'].toString());
  618. break;
  619. case 4:
  620. title = I18n.of(context)
  621. .get_red_money
  622. .replaceFirst('/s2', data['Value'].toString());
  623. break;
  624. case 5:
  625. title = I18n.of(context).paid_you3;
  626. break;
  627. case 6:
  628. title = I18n.of(context)
  629. .paid_you
  630. .replaceFirst('/s2', data['Value'].toString());
  631. break;
  632. case 7:
  633. title = I18n.of(context)
  634. .paid_you2
  635. .replaceFirst('/s2', data['Value'].toString());
  636. break;
  637. case 8:
  638. title = I18n.of(context).Representation_succes;
  639. break;
  640. case 9:
  641. title = I18n.of(context).system_give;
  642. break;
  643. case 10:
  644. title = I18n.of(context).exchange_fail;
  645. break;
  646. }
  647. return TitleItem(title: title, name: name);
  648. }
  649. //我的余额
  650. static TitleItem _delMyMoneyTitle(data, BuildContext context) {
  651. String title = '';
  652. String name = Provider.of<RefNameProvider>(context)
  653. .getRefName(data['UserId'], data['UserName']);
  654. switch (data['DetailType']) {
  655. case 1:
  656. title = I18n.of(context).get_coin2;
  657. name = data['Value'].toString();
  658. break;
  659. case 2:
  660. title = I18n.of(context).hibok_exchange;
  661. name = data['Value'].toString();
  662. break;
  663. case 3:
  664. title = I18n.of(context).bind_code_success;
  665. break;
  666. case 4:
  667. title = I18n.of(context)
  668. .give_other_money
  669. .replaceFirst('/s2', data['Value'].toString());
  670. break;
  671. case 5:
  672. title = I18n.of(context)
  673. .give_red_money
  674. .replaceFirst('/s2', data['Value'].toString());
  675. break;
  676. case 6:
  677. title = I18n.of(context)
  678. .paid_you6
  679. .replaceFirst('/s2', data['Value'].toString());
  680. break;
  681. case 7:
  682. title = I18n.of(context)
  683. .paid_you4
  684. .replaceFirst('/s2', data['Value'].toString());
  685. break;
  686. case 8:
  687. title = I18n.of(context)
  688. .paid_you5
  689. .replaceFirst('/s2', data['Value'].toString());
  690. break;
  691. case 9:
  692. title = I18n.of(context).buy_vip;
  693. name = data['Value'].toString();
  694. break;
  695. case 10:
  696. title = I18n.of(context).translate_money;
  697. name = data['Value'].toString();
  698. break;
  699. case 11:
  700. title = I18n.of(context).buy_program;
  701. name = data['Value'].toString();
  702. break;
  703. case 12:
  704. title = I18n.of(context).Representation_succes;
  705. break;
  706. case 13:
  707. title = I18n.of(context).system_back;
  708. break;
  709. case 14:
  710. title = I18n.of(context).system_give;
  711. break;
  712. }
  713. return TitleItem(title: title, name: name);
  714. }
  715. static TitleItem _getTypeTitleItem(userInfo, BuildContext context, int type) {
  716. var tileItem = TitleItem();
  717. switch (type) {
  718. case InfoType.Apply:
  719. tileItem = _delApplyTitle(userInfo, context);
  720. break;
  721. case InfoType.Radio:
  722. tileItem = _delRadioTitle(userInfo, context);
  723. break;
  724. case InfoType.System:
  725. tileItem = _delSystemTitle(userInfo, context);
  726. break;
  727. case InfoType.Money:
  728. tileItem = _delMoneyTitle(userInfo, context);
  729. break;
  730. case InfoType.IncomeMoney:
  731. tileItem = _delInMoneyTitle(userInfo, context);
  732. break;
  733. case InfoType.MyMoney:
  734. tileItem = _delMyMoneyTitle(userInfo, context);
  735. break;
  736. case InfoType.Evaluation:
  737. tileItem = _delEvaluateTitle(userInfo, context);
  738. break;
  739. default:
  740. }
  741. return tileItem;
  742. }
  743. static Widget getRichTitleWidget(userInfo, BuildContext context, int type,
  744. {titleStyle, nameStyle}) {
  745. var tileItem = _getTypeTitleItem(userInfo, context, type);
  746. return RichText(
  747. text: TextSpan(
  748. children: getRichText(tileItem,
  749. titleStyle: titleStyle, nameStyle: nameStyle)));
  750. }
  751. static String normalTitle(userInfo, BuildContext context, int type) {
  752. if (userInfo == null) {
  753. return '';
  754. }
  755. var tileItem = _getTypeTitleItem(userInfo, context, type);
  756. var res = getNormalText(tileItem);
  757. int maxlength = 17;
  758. return res.length > maxlength ? res.substring(0, maxlength) + '...' : res;
  759. }
  760. }
  761. class InfoListPage extends StatefulWidget {
  762. @required
  763. final String title;
  764. @required
  765. final int type;
  766. InfoListPage({Key key, this.title = "", this.type = 1}) : super(key: key);
  767. _InfoListPageState createState() => _InfoListPageState();
  768. }
  769. class _InfoListPageState extends State<InfoListPage>
  770. with SingleTickerProviderStateMixin {
  771. List list = new List(); //列表要展示的数据
  772. RefreshController _refreshController =
  773. RefreshController(initialRefresh: true);
  774. int _page = 1; //加载的页数
  775. int rows = 20;
  776. @override
  777. void initState() {
  778. super.initState();
  779. messageOn();
  780. }
  781. void initList(data) {
  782. list.clear();
  783. if (data != null) {
  784. list.addAll(data);
  785. }
  786. if (mounted) setState(() {});
  787. }
  788. void addList(data) {
  789. if (data == null || data.length == 0) {
  790. _page--;
  791. _refreshController.loadNoData();
  792. } else {
  793. list.addAll(data);
  794. _refreshController.loadComplete();
  795. }
  796. setState(() {});
  797. }
  798. messageApply(data) {
  799. _onRefresh();
  800. }
  801. msgPhoto(id) {
  802. for (int i = 0; i < list.length; i++) {
  803. if (list[i]['ApplyImg'] == id) {
  804. setState(() {
  805. list[i]['IsCheck'] = 1;
  806. });
  807. break;
  808. }
  809. }
  810. }
  811. void messageOn() {
  812. MessageMgr().on('do_info_apply', messageApply);
  813. MessageMgr().on('refresh_photo', msgPhoto);
  814. }
  815. void messageOff() {
  816. MessageMgr().off('do_info_apply', messageApply);
  817. MessageMgr().off('refresh_photo', msgPhoto);
  818. }
  819. getNewData(callback) {
  820. switch (widget.type) {
  821. case InfoType.Apply: //获取申请通知
  822. getData('user/check/realecords', callback);
  823. break;
  824. case InfoType.Evaluation: //获取评价通知
  825. getData('evaluate/user/realecordslist', callback);
  826. break;
  827. case InfoType.System: //获取系统通知
  828. getData('message/center/list', callback);
  829. break;
  830. case InfoType.Radio: //获取电台消息
  831. getData('message/center/cast', callback);
  832. break;
  833. case InfoType.Money: //获取钱包通知
  834. getData('message/wallet/message', callback);
  835. break;
  836. default:
  837. }
  838. }
  839. Future getData(url, callback) async {
  840. Map data = {
  841. "userId": UserData().basicInfo.userId,
  842. };
  843. if (widget.type == InfoType.System) {
  844. data['type'] = UserData().basicInfo.sex;
  845. }
  846. data['sign'] = TokenMgr().getSign(data);
  847. if (widget.type == InfoType.Money) {
  848. data['type'] = 1;
  849. }
  850. data["page"] = _page;
  851. data['rows'] = rows;
  852. Response res = await HttpUtil()
  853. .post(url, data: data, failback: () => Navigator.of(context).pop());
  854. _refreshController.refreshCompleted();
  855. var resData = res.data;
  856. print(resData);
  857. if (resData['code'] == 0) {
  858. callback(resData['data']);
  859. } else {
  860. showToast(resData['msg']);
  861. }
  862. }
  863. /*
  864. * 下拉刷新方法,为list重新赋值
  865. */
  866. Future<Null> _onRefresh() async {
  867. _page = 1;
  868. getNewData(initList);
  869. }
  870. @override
  871. void dispose() {
  872. _refreshController.dispose();
  873. messageOff();
  874. super.dispose();
  875. }
  876. //钱包通知
  877. Widget _buildMoneyInfo(data) {
  878. String imgUrl = data['HeadImg'] == null || data['HeadImg'] == ''
  879. ? 'assets/images/chat/icon4.png'
  880. : data['HeadImg'];
  881. bool showIndex = data['ChangeUserId'] != 0;
  882. return _ConversationItem(
  883. conversation: Conversation(
  884. avatar: imgUrl,
  885. title: '',
  886. desc: WebData().getLoginTime(context, data['CreateTime']),
  887. updateAt: '',
  888. ),
  889. bgColor: Constants.MoneyGradient,
  890. showRight: data['DetailType'] == 10,
  891. title: RichTitle.getRichTitleWidget(data, context, InfoType.Money),
  892. rightButton: Text(I18n.of(context).alreay_back,
  893. style: TextStyle(
  894. fontSize: 12,
  895. fontWeight: FontWeight.normal,
  896. color: Constants.BlackTextColor)),
  897. callback: () {
  898. if (showIndex) {
  899. Navigator.of(context).push(
  900. new MaterialPageRoute(
  901. builder: (context) {
  902. return ProfilePage(
  903. userId: data['UserId'] == UserData().basicInfo.userId
  904. ? data['ChangeUserId']
  905. : data['UserId'],
  906. );
  907. },
  908. ),
  909. );
  910. }
  911. },
  912. );
  913. }
  914. //申请列表
  915. Widget _buildApllayInfo(userInfo) {
  916. bool isMyself = userInfo['ApplyUserId'] == UserData().basicInfo.userId;
  917. String name = isMyself ? userInfo['UserName'] : userInfo['ApplyName'];
  918. String imgUrl = isMyself ? userInfo['UserUrl'] : userInfo['ApplyUrl'];
  919. var applyInfo = {
  920. 'applyId': userInfo['Id'],
  921. 'userId': userInfo['ApplyUserId'],
  922. 'name': name,
  923. 'type': userInfo['Type'],
  924. 'imgUrl': imgUrl,
  925. 'showUrl': userInfo['ImgUrl'],
  926. 'content': userInfo['Content'],
  927. 'imgId': userInfo['ApplyImg'],
  928. 'createTime': userInfo['CreatTime'],
  929. 'isWatch': userInfo['IsCheck'] == 1,
  930. 'state': userInfo['Status'],
  931. };
  932. return _ConversationItem(
  933. conversation: Conversation(
  934. avatar: imgUrl == null || imgUrl == ''
  935. ? Constants.DefaultHeadImgUrl
  936. : imgUrl,
  937. title: '',
  938. desc: WebData().getLoginTime(context, userInfo['CreatTime']),
  939. updateAt: '17:20',
  940. ),
  941. title: RichTitle.getRichTitleWidget(userInfo, context, InfoType.Apply),
  942. applyInfo: isMyself ? null : applyInfo,
  943. callback: () {
  944. Navigator.of(context).push(
  945. new MaterialPageRoute(
  946. builder: (context) {
  947. return ProfilePage(
  948. userId: isMyself ? userInfo['UserId'] : userInfo['ApplyUserId'],
  949. );
  950. },
  951. ),
  952. );
  953. },
  954. );
  955. }
  956. //评价列表
  957. Widget _buildContentInfo(userInfo) {
  958. Widget botton = InkWell(
  959. onTap: () async {
  960. var data = {
  961. "userid": UserData().basicInfo.userId,
  962. "evaluateuserid": userInfo['EvaluateUserId'],
  963. };
  964. data['sign'] = TokenMgr().getSign(data);
  965. Response res =
  966. await HttpUtil().post('evaluate/user/appeal', data: data);
  967. if (res == null) {
  968. return;
  969. }
  970. Map resData = res.data;
  971. if (resData['code'] == 0) {
  972. setState(() {
  973. userInfo['Status'] = 1;
  974. });
  975. }
  976. },
  977. child: Container(
  978. padding: EdgeInsets.only(top: 2, left: 5, right: 5, bottom: 2),
  979. decoration: BoxDecoration(
  980. border:
  981. Border.all(color: Constants.LightBlueButtonColor, width: 1),
  982. color: Constants.LightBlueButtonColor,
  983. borderRadius: BorderRadius.all(Radius.circular(5))),
  984. child: fixedText(
  985. I18n.of(context).appeal,
  986. fontSize: 9,
  987. color: Colors.white,
  988. ),
  989. ));
  990. return _ConversationItem(
  991. conversation: Conversation(
  992. avatar: 'assets/images/chat/icon6.png',
  993. title: '',
  994. desc: WebData().getLoginTime(context, userInfo['CreateTime']),
  995. updateAt: '17:20',
  996. ),
  997. bgColor: Constants.EvaGradient,
  998. rightButton: userInfo['Status'] == 0 || userInfo['Status'] == 3
  999. ? botton
  1000. : Text(userInfo['Status'] == 1 ? I18n.of(context).appealed : "",
  1001. style:
  1002. TextStyle(fontSize: 11, color: Constants.LightGreyTextColor)),
  1003. title:
  1004. RichTitle.getRichTitleWidget(userInfo, context, InfoType.Evaluation),
  1005. callback: () {},
  1006. );
  1007. }
  1008. String getReportTilte(bool isMyself, data) {
  1009. String res = '';
  1010. switch (data['ReportType']) {
  1011. //举报用户
  1012. case 1:
  1013. if (isMyself) {
  1014. res = data['Status'] == 1
  1015. ? I18n.of(context)
  1016. .report_success
  1017. .replaceFirst('/s1', data['ReportedUserName'])
  1018. : I18n.of(context)
  1019. .report_failure
  1020. .replaceFirst('/s1', data['ReportedUserName']);
  1021. } else {
  1022. res = I18n.of(context).coin_returen;
  1023. }
  1024. break;
  1025. //举报节目
  1026. case 2:
  1027. break;
  1028. //举报动态
  1029. case 3:
  1030. break;
  1031. //举报评论
  1032. case 4:
  1033. break;
  1034. default:
  1035. }
  1036. return res;
  1037. }
  1038. //系统通知
  1039. Widget _buildSystemInfo(data) {
  1040. bool isMyself = data['UserId'] == UserData().basicInfo.userId;
  1041. String imgUrl = data['Type'] == 3
  1042. ? (isMyself ? data['HeadImg'] : 'assets/images/chat/icon5.png')
  1043. : 'assets/images/chat/icon5.png';
  1044. var applyInfo = {
  1045. 'applyId': data['Id'],
  1046. 'userId': data['ApplyUserId'],
  1047. 'name': data['Theme'],
  1048. 'type': data['Type'],
  1049. 'imgUrl': imgUrl,
  1050. 'showUrl': data['HeadImg'],
  1051. 'content': data['Content'],
  1052. 'imgId': data['ApplyImg'],
  1053. 'createTime': data['CreatTime'],
  1054. 'isWatch': data['IsCheck'] == 1,
  1055. 'links': data['Links'],
  1056. 'state': data['Status'],
  1057. };
  1058. return _ConversationItem(
  1059. conversation: Conversation(
  1060. avatar: imgUrl,
  1061. title: '',
  1062. desc: WebData().getLoginTime(context, data['CreateTime']),
  1063. updateAt: '17:20',
  1064. ),
  1065. showRight: data['Type'] == 6,
  1066. applyInfo: data['Type'] == 6 ? applyInfo : null, // applyInfo,
  1067. bgColor: Constants.ParkGradient,
  1068. title: data['Type'] == 6
  1069. ? Text(data['Theme'])
  1070. : RichTitle.getRichTitleWidget(data, context, InfoType.System),
  1071. callback: () {
  1072. if (data['Type'] == 4 && data['Status'] == 1) {
  1073. ClipboardData clipboardData =
  1074. new ClipboardData(text: data['Content']);
  1075. Clipboard.setData(clipboardData);
  1076. showToast(I18n.of(context).successful_copy);
  1077. }
  1078. if (data['Type'] == 3) {
  1079. Navigator.of(context).push(
  1080. new MaterialPageRoute(
  1081. builder: (context) {
  1082. return ProfilePage(
  1083. userId: data['ReportedUserId'],
  1084. );
  1085. },
  1086. ),
  1087. );
  1088. }
  1089. if (data['Type'] == 6) {
  1090. launch(applyInfo['links']);
  1091. }
  1092. },
  1093. );
  1094. }
  1095. //电台消息
  1096. Widget _buildRadioInfo(data) {
  1097. String imgUrl = data['HeadImg'] == null || data['HeadImg'] == ''
  1098. ? Constants.DefaultHeadImgUrl
  1099. : data['HeadImg'];
  1100. return _ConversationItem(
  1101. conversation: Conversation(
  1102. avatar: imgUrl,
  1103. title: '',
  1104. desc: WebData().getLoginTime(context, data['CreateTime']),
  1105. updateAt: '17:20',
  1106. ),
  1107. title: RichTitle.getRichTitleWidget(data, context, InfoType.Radio),
  1108. callback: () {
  1109. Navigator.of(context).push(
  1110. new MaterialPageRoute(
  1111. builder: (context) {
  1112. return ProgramDetailPage(
  1113. programId: data['Id'],
  1114. );
  1115. },
  1116. ),
  1117. );
  1118. },
  1119. );
  1120. }
  1121. Widget _renderRow(BuildContext context, int index) {
  1122. if (index < list.length) {
  1123. var userInfo = list[index];
  1124. Widget result = Container();
  1125. switch (widget.type) {
  1126. case InfoType.Apply:
  1127. result = _buildApllayInfo(userInfo);
  1128. break;
  1129. case InfoType.Evaluation:
  1130. result = _buildContentInfo(userInfo);
  1131. break;
  1132. case InfoType.System:
  1133. result = _buildSystemInfo(userInfo);
  1134. break;
  1135. case InfoType.Radio:
  1136. result = _buildRadioInfo(userInfo);
  1137. break;
  1138. case InfoType.Money:
  1139. result = _buildMoneyInfo(userInfo);
  1140. break;
  1141. default:
  1142. }
  1143. if (index == 0) {
  1144. result = Padding(padding: EdgeInsets.only(top: 10), child: result);
  1145. }
  1146. return result;
  1147. }
  1148. return Container();
  1149. }
  1150. void _onLoading() async {
  1151. _page++;
  1152. getNewData(addList);
  1153. }
  1154. @override
  1155. Widget build(BuildContext context) {
  1156. var content = Scaffold(
  1157. appBar: AppBar(
  1158. backgroundColor: AppColors.NewAppbarBgColor,
  1159. title: Text(
  1160. widget.title,
  1161. style: TextStyle(color: AppColors.NewAppbarTextColor),
  1162. ),
  1163. leading: CustomUI.buildCustomLeading(context),
  1164. centerTitle: true,
  1165. ),
  1166. body: SafeArea(
  1167. child: SmartRefresher(
  1168. enablePullDown: true,
  1169. enablePullUp: true,
  1170. header: MaterialClassicHeader(),
  1171. footer: CustomUI.buildLoadingFooter(),
  1172. controller: _refreshController,
  1173. onRefresh: _onRefresh,
  1174. onLoading: _onLoading,
  1175. child: (_refreshController.headerStatus == RefreshStatus.completed &&
  1176. list.length == 0)
  1177. ? CustomUI.buildNoData(context)
  1178. : ListView.builder(
  1179. itemBuilder: _renderRow,
  1180. itemCount: list.length,
  1181. ),
  1182. )));
  1183. return content; // CustomUI.buildPageLoading(context, content, !isLoadingFish);
  1184. }
  1185. }