wode_page.dart 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:liftmanager/common/common.dart';
  6. import 'package:liftmanager/internal/account/account_router.dart';
  7. import 'package:liftmanager/internal/account/model/user_info_entity.dart';
  8. import 'package:liftmanager/internal/account/provider/user_provider.dart';
  9. import 'package:liftmanager/internal/wode/wode_router.dart';
  10. import 'package:liftmanager/net/api_service.dart';
  11. import 'package:liftmanager/routers/fluro_navigator.dart';
  12. import 'package:liftmanager/utils/image_utils.dart';
  13. import 'package:liftmanager/widgets/app_bar.dart';
  14. import 'package:liftmanager/widgets/click_item.dart';
  15. import 'package:liftmanager/widgets/load_image.dart';
  16. import 'package:liftmanager/widgets/my_button.dart';
  17. import 'package:provider/provider.dart';
  18. import 'package:liftmanager/widgets/bbs_content.dart';
  19. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  20. import 'package:flutter_screenutil/flutter_screenutil.dart';
  21. import 'package:image_picker/image_picker.dart';
  22. import 'package:liftmanager/utils/toast.dart';
  23. import 'package:liftmanager/utils/utils.dart';
  24. import 'package:barcode_scan/barcode_scan.dart';
  25. import 'package:flutter/services.dart';
  26. import 'package:flustars/flustars.dart' as FlutterStars;
  27. import 'package:liftmanager/utils/fast_notification.dart';
  28. import 'dart:async';
  29. import 'package:liftmanager/utils/theme_utils.dart';
  30. class WodePage extends StatefulWidget {
  31. //1用户 2专家
  32. String type = "2";
  33. @override
  34. State<StatefulWidget> createState() {
  35. return WodePageState();
  36. }
  37. }
  38. class WodePageState extends State<WodePage> with AutomaticKeepAliveClientMixin {
  39. UserProvider provider = UserProvider();
  40. @override
  41. void initState() {
  42. super.initState();
  43. getUserInfo();
  44. getCoupon();
  45. FastNotification.addListener("initUserMoney", (initThisUserMoney) {
  46. if (mounted) {
  47. getCoupon();
  48. setState(() {
  49. });
  50. }
  51. });
  52. FastNotification.addListener("initUserInfomation", (initThisUserInfomation) {
  53. if (mounted) {
  54. getUserInfo();
  55. setState(() {
  56. });
  57. }
  58. });
  59. }
  60. String indexNow;
  61. final _cancelController = TextEditingController(text: "取消");
  62. Map<String, dynamic> detailOj = {
  63. "couponNum": 0,
  64. "balance": 0.0,
  65. "hongBaoNum": 0,
  66. "memberDays": "",
  67. };
  68. int isVip = 1;
  69. ///获取用户信息
  70. void getUserInfo() {
  71. ApiService(context: context).userInfo(
  72. onSuccess: (data) {
  73. setUser(data);
  74. print(data.showWhichName);
  75. indexNow = data.showWhichName.toString();
  76. },
  77. onError: (code, msg) {},
  78. );
  79. }
  80. Future scan() async {
  81. try {
  82. // 此处为扫码结果,barcode为二维码的内容
  83. String barcode = await BarcodeScanner.scan();
  84. print(barcode);
  85. // return;
  86. // print('扫码结果: ' + jsonDecode(barcode)["url"]);
  87. Uri u = Uri.parse(barcode);
  88. String id = u.queryParameters['id'];
  89. print('扫码结果: ' + id);
  90. // print('扫码结果: ' + jsonDecode(barcode)["userId"].toString());
  91. NewApiService().getUserRebates(id,
  92. onSuccess: (res) {
  93. toastsF(context,"你已成功接受${res!=null?res.toString():''}的邀请,立即成为会员!",timeInSecForIos:3);
  94. // toasts("您已成为${res!=null?res.toString():''}的下级用户");
  95. NavigatorUtils.push(context, "${WodeRouter.vip}?id=");
  96. }, onError: (code, msg) {
  97. toasts(msg);
  98. });
  99. } on PlatformException catch (e) {
  100. if (e.code == BarcodeScanner.CameraAccessDenied) {
  101. // 未授予APP相机权限
  102. print('未授予APP相机权限');
  103. } else {
  104. // 扫码错误
  105. print('扫码错误: $e');
  106. }
  107. } on FormatException {
  108. // 进入扫码页面后未扫码就返回
  109. print('进入扫码页面后未扫码就返回');
  110. } catch (e) {
  111. // 扫码错误
  112. print('扫码错误: $e');
  113. }
  114. }
  115. Future getCoupon() async {
  116. await NewApiService().getUserCoupons(onSuccess: (res) {
  117. if (res != null) {
  118. detailOj["couponNum"] = res["couponNum"];
  119. detailOj["balance"] = res["balance"];
  120. detailOj["hongBaoNum"] = res["hongBaoNum"];
  121. detailOj["memberDays"] = res["memberDays"];
  122. isVip = res["isVip"];
  123. FlutterStars.SpUtil.putInt('isVip', isVip);
  124. setState(() {});
  125. print(6666544);
  126. }
  127. }, onError: (code, msg) {
  128. toasts(msg);
  129. });
  130. }
  131. void setUser(UserInfoEntity user) {
  132. provider.setUser(user);
  133. }
  134. ///选择图片
  135. void selectPicker() {
  136. showDialog(
  137. context: context,
  138. builder: (BuildContext context) {
  139. return SimpleDialog(
  140. title: Text("修改头像"),
  141. children: ["拍照", '从手机相册选择'].map((String value) {
  142. print("$value");
  143. return SimpleDialogOption(
  144. child: Text(
  145. "${value}",
  146. style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
  147. ),
  148. onPressed: () {
  149. _getImage(value == '拍照' ? 1 : 0);
  150. Navigator.of(context).pop();
  151. },
  152. );
  153. }).toList(),
  154. );
  155. },
  156. );
  157. }
  158. void _getImage(int key) async {
  159. try {
  160. var _imageFile = await ImagePicker.pickImage(
  161. source: key == 1 ? ImageSource.camera : ImageSource.gallery,
  162. maxWidth: 800,
  163. imageQuality: 95);
  164. if (_imageFile != null) {
  165. updateAvatar(_imageFile);
  166. setState(() {});
  167. }
  168. } catch (e) {
  169. toasts("没有权限,无法打开相册!");
  170. }
  171. }
  172. void updateAvatar(File imageFile) {
  173. List<File> list = [imageFile];
  174. ApiService(context: context).uploadMore(list, onSuccess: (imgs) {
  175. ApiService(context: context).modifyAvatar(imgs[0], onSuccess: (res) {
  176. if (res != null) {
  177. getUserInfo();
  178. }
  179. }, onError: (code, msg) {
  180. toasts(msg);
  181. });
  182. });
  183. }
  184. void _updateUserInfo(value) {
  185. ApiService(context: context).modifyName(value, onSuccess: (res) {
  186. if (res != null) {
  187. getUserInfo();
  188. }
  189. }, onError: (code, msg) {
  190. toasts(msg);
  191. });
  192. }
  193. @override
  194. void dispose() {
  195. // provider.dispose();
  196. super.dispose();
  197. }
  198. static const OrderTypeList = [
  199. {
  200. "title": "待付款",
  201. "img": "wode/order_1",
  202. },
  203. {
  204. "title": "待确认",
  205. "img": "wode/order_3",
  206. },
  207. {
  208. "title": "待评价",
  209. "img": "wode/order_2",
  210. },
  211. {
  212. "title": "申诉",
  213. "img": "wode/order_4",
  214. },
  215. ];
  216. @override
  217. Widget build(BuildContext context) {
  218. return
  219. // Center(child:new Text("个人中心"));
  220. ChangeNotifierProvider<UserProvider>(
  221. create: (_) => provider,
  222. child: Scaffold(
  223. appBar: MyAppBar(
  224. // centerTitle: "个人中心",
  225. isBack: false,
  226. actions: <Widget>[
  227. IconButton(
  228. onPressed: () {
  229. NavigatorUtils.push(context, "${WodeRouter.settingPage}?indexNow=$indexNow");
  230. },
  231. icon: LoadAssetImage(
  232. "icon_setting",
  233. key: const Key('add'),
  234. width: ScreenUtil().setWidth(24),
  235. height: ScreenUtil().setWidth(24),
  236. color: Colors.white,
  237. ),
  238. )
  239. ],
  240. ),
  241. body:
  242. RefreshIndicator(
  243. onRefresh:()async{
  244. setState(() {
  245. getUserInfo();
  246. getCoupon();
  247. });
  248. },
  249. child: Consumer<UserProvider>(
  250. builder: (_, provider, __) {
  251. return ListView(
  252. padding: EdgeInsets.all(0.0),
  253. children: <Widget>[
  254. Container(
  255. decoration: BoxDecoration(
  256. gradient: const LinearGradient(
  257. colors: [Color(0xFF00D9FF), Color(0xFF0287FF)],
  258. ),
  259. ),
  260. height: ScreenUtil().setWidth(130),
  261. child: Column(
  262. children: <Widget>[
  263. Row(
  264. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  265. crossAxisAlignment: CrossAxisAlignment.start,
  266. children: <Widget>[
  267. GestureDetector(
  268. onTap: () {
  269. NavigatorUtils.push(
  270. context, WodeRouter.personalPage);
  271. },
  272. child: Container(
  273. padding: EdgeInsets.only(
  274. left: ScreenUtil().setWidth(25),
  275. bottom: ScreenUtil().setWidth(25),
  276. ),
  277. child: Row(
  278. children: <Widget>[
  279. Container(
  280. padding: EdgeInsets.only(
  281. right: ScreenUtil().setWidth(10),
  282. ),
  283. child:
  284. // CircleAvatar(
  285. // radius: 24,
  286. // backgroundColor: Colors.transparent,
  287. // backgroundImage:
  288. // ImageUtils.getImageProvider(
  289. // provider.user?.avatarUrl),
  290. // ),
  291. ClipRRect(
  292. borderRadius:
  293. BorderRadius.circular(
  294. ScreenUtil()
  295. .setWidth(25)),
  296. child: Container(
  297. child: LoadNetworkImage(
  298. provider.user?.avatarUrl,
  299. // fit: BoxFit.fitWidth,
  300. width: ScreenUtil()
  301. .setWidth(50),
  302. height: ScreenUtil()
  303. .setWidth(50),
  304. ),
  305. ))
  306. ),
  307. Column(
  308. mainAxisAlignment: MainAxisAlignment.start,
  309. crossAxisAlignment:
  310. CrossAxisAlignment.start,
  311. children: <Widget>[
  312. Container(
  313. child: Text(
  314. provider.user?.showWhichName==1?(provider.user?.nickName ?? ""):(provider.user?.userName ?? ""),
  315. textAlign: TextAlign.left,
  316. style: TextStyle(
  317. fontSize: ScreenUtil().setSp(18),
  318. color: Color(0xffffffff),
  319. ),
  320. ),
  321. ),
  322. SizedBox(height: 3),
  323. Row(
  324. children: <Widget>[
  325. GestureDetector(
  326. onTap: () {
  327. // print(provider.user.userLevel);
  328. NavigatorUtils.push(context, "${WodeRouter.vip}?id=");
  329. },
  330. child: Container(
  331. padding: EdgeInsets.only(
  332. left: 6,
  333. right: 6,
  334. top: 2,
  335. bottom: 2,
  336. ),
  337. decoration: BoxDecoration(
  338. borderRadius:
  339. BorderRadius.circular(10.0),
  340. color: Colors.white,
  341. ),
  342. child: Row(
  343. children: <Widget>[
  344. Container(
  345. child: LoadAssetImage(
  346. // image: AssetImage(i['img']),
  347. 'wode/zuan',
  348. height: ScreenUtil()
  349. .setWidth(11),
  350. width: ScreenUtil()
  351. .setWidth(12),
  352. fit: BoxFit.cover,
  353. // alignment: Alignment.centerLeft,
  354. ),
  355. ),
  356. SizedBox(width: 3),
  357. Text(
  358. provider.user
  359. ?.userLevelName!=null&&provider.user
  360. ?.userLevelName!='' ?provider.user
  361. ?.userLevelName:
  362. "成为会员",
  363. textAlign: TextAlign.left,
  364. style: TextStyle(
  365. fontSize: ScreenUtil()
  366. .setSp(11),
  367. color: Color(0xff0288FF),
  368. ),
  369. ),
  370. ],
  371. ),
  372. ),
  373. ),
  374. SizedBox(
  375. width: 10,
  376. ),
  377. Container(
  378. child: Text(
  379. detailOj["memberDays"] ?? "",
  380. textAlign: TextAlign.left,
  381. style: TextStyle(
  382. fontSize:
  383. ScreenUtil().setSp(14),
  384. color: Color(0xffffffff),
  385. ),
  386. ),
  387. )
  388. ],
  389. )
  390. ],
  391. ),
  392. ],
  393. ),
  394. ),
  395. ),
  396. ],
  397. ),
  398. Container(
  399. child: Row(
  400. mainAxisAlignment: MainAxisAlignment.spaceAround,
  401. children: <Widget>[
  402. GestureDetector(
  403. child: Container(
  404. child: Column(
  405. crossAxisAlignment: CrossAxisAlignment.center,
  406. children: <Widget>[
  407. Text(
  408. detailOj["balance"] != null
  409. ? detailOj["balance"].toString()
  410. : "0.0",
  411. textAlign: TextAlign.left,
  412. style: TextStyle(
  413. fontSize: ScreenUtil().setSp(18),
  414. color: Color(0xffffffff),
  415. ),
  416. ),
  417. Text(
  418. '我的钱包',
  419. textAlign: TextAlign.left,
  420. style: TextStyle(
  421. fontSize: ScreenUtil().setSp(15),
  422. color: Color(0xffffffff),
  423. ),
  424. ),
  425. ],
  426. ),
  427. ),
  428. onTap: () {
  429. NavigatorUtils.push(
  430. context, WodeRouter.walletPage);
  431. },
  432. ),
  433. GestureDetector(
  434. child: Container(
  435. child: Column(
  436. crossAxisAlignment: CrossAxisAlignment.center,
  437. children: <Widget>[
  438. Text(
  439. detailOj["couponNum"] != null
  440. ? detailOj["couponNum"].toString()
  441. : "0",
  442. textAlign: TextAlign.left,
  443. style: TextStyle(
  444. fontSize: ScreenUtil().setSp(18),
  445. color: Color(0xffffffff),
  446. ),
  447. ),
  448. Text(
  449. '优惠券(张)',
  450. textAlign: TextAlign.left,
  451. style: TextStyle(
  452. fontSize: ScreenUtil().setSp(15),
  453. color: Color(0xffffffff),
  454. ),
  455. ),
  456. ],
  457. ),
  458. ),
  459. onTap: () {
  460. NavigatorUtils.push(
  461. context, WodeRouter.couponPage);
  462. },
  463. ),
  464. GestureDetector(
  465. child: Container(
  466. child: Column(
  467. crossAxisAlignment: CrossAxisAlignment.center,
  468. children: <Widget>[
  469. Text(
  470. detailOj["hongBaoNum"] != null
  471. ? detailOj["hongBaoNum"].toString()
  472. : "0",
  473. textAlign: TextAlign.left,
  474. style: TextStyle(
  475. fontSize: ScreenUtil().setSp(18),
  476. color: Color(0xffffffff),
  477. ),
  478. ),
  479. Text(
  480. '红包(张)',
  481. textAlign: TextAlign.left,
  482. style: TextStyle(
  483. fontSize: ScreenUtil().setSp(15),
  484. color: Color(0xffffffff),
  485. ),
  486. ),
  487. ],
  488. ),
  489. ),
  490. onTap: () {
  491. NavigatorUtils.push(
  492. context, WodeRouter.redbaoPage);
  493. },
  494. ),
  495. ],
  496. ),
  497. ),
  498. ],
  499. ),
  500. ),
  501. LableTitle(
  502. title: "我的订单",
  503. hasArrow: true,
  504. isMore: false,
  505. userTap: () {
  506. NavigatorUtils.push(
  507. context, "${WodeRouter.orderPage}?checkType=0");
  508. },
  509. ),
  510. Container(
  511. padding: EdgeInsets.only(
  512. bottom: ScreenUtil().setWidth(5),
  513. top: ScreenUtil().setWidth(5),
  514. ),
  515. child: OrderType(initList: OrderTypeList),
  516. ),
  517. Container(
  518. color: ThemeUtils.getDialogTextFieldColor(context),
  519. height: ScreenUtil().setWidth(5),
  520. ),
  521. Utils.getAuthByRouter(context,"master_order", false)
  522. ? ClickItem(
  523. title: "我的接单",
  524. hasPic: "wode/user_order",
  525. content: "",
  526. onTap: () {
  527. NavigatorUtils.push(context,
  528. "${WodeRouter.orderPageMaster}?checkType=0");
  529. },
  530. )
  531. : Container(),
  532. Utils.getAuthByRouter(context,"master_order", false)
  533. ? Container(
  534. color: ThemeUtils.getDialogTextFieldColor(context),
  535. height: ScreenUtil().setWidth(5),
  536. )
  537. : Container(),
  538. ClickItem(
  539. title: "我的视频",
  540. hasPic: "wode/shipin",
  541. content: "",
  542. onTap: () {
  543. NavigatorUtils.push(context, WodeRouter.myVideo);
  544. },
  545. ),
  546. ClickItem(
  547. title: "我的收藏",
  548. hasPic: "wode/shoucang",
  549. content: "",
  550. onTap: () {
  551. NavigatorUtils.push(context, WodeRouter.collectPage);
  552. },
  553. ),
  554. ClickItem(
  555. title: "消息中心",
  556. hasPic: "wode/xiaoxi",
  557. content: "",
  558. onTap: () {
  559. NavigatorUtils.push(context, WodeRouter.noticeList);
  560. },
  561. ),
  562. ClickItem(
  563. title: "发票中心",
  564. hasPic: "wode/piao",
  565. content: "",
  566. onTap: () {
  567. NavigatorUtils.push(context, WodeRouter.piaoCenter);
  568. },
  569. ),
  570. ClickItem(
  571. title: "扫码成为会员",
  572. hasPic: "wode/qr",
  573. content: "",
  574. onTap: () {
  575. scan();
  576. },
  577. ),
  578. Utils.getAuthByRouter(context,'punishment_record',false)?
  579. ClickItem(
  580. title: "违规记录",
  581. hasPic: "wode/wr",
  582. content: "",
  583. onTap: () {
  584. NavigatorUtils.push(context, WodeRouter.errorRecordList);
  585. },
  586. )
  587. :Container(child: null,),
  588. ],
  589. );
  590. },
  591. ),
  592. )
  593. ,
  594. ),
  595. );
  596. }
  597. @override
  598. bool get wantKeepAlive => true;
  599. }
  600. class OrderType extends StatelessWidget {
  601. OrderType({Key key, this.initList}) : super(key: key);
  602. List<dynamic> initList;
  603. List<Widget> brandList(context) => initList.asMap().keys.map(
  604. (item) {
  605. double width = MediaQuery.of(context).size.width;
  606. return Container(
  607. // color:Colors.yellow,
  608. width: width / 4,
  609. child: FlatButton(
  610. padding: EdgeInsets.all(0),
  611. highlightColor: Colors.white,
  612. splashColor: Colors.white,
  613. child: Container(
  614. // width: 90,
  615. height: ScreenUtil().setWidth(80),
  616. // color: Colors.red,
  617. padding: EdgeInsets.only(
  618. left: ScreenUtil().setWidth(10),
  619. right: ScreenUtil().setWidth(10),
  620. top: ScreenUtil().setWidth(10)),
  621. child: Column(
  622. mainAxisAlignment: MainAxisAlignment.start,
  623. children: <Widget>[
  624. Container(
  625. // height: 70,
  626. // color: Colors.red,
  627. child: LoadAssetImage(
  628. // image: AssetImage(i['img']),
  629. initList[item]['img'],
  630. width: ScreenUtil().setWidth(50),
  631. height: ScreenUtil().setWidth(30),
  632. // alignment: Alignment.centerLeft,
  633. ),
  634. ),
  635. SizedBox(height: ScreenUtil().setWidth(10)),
  636. Container(
  637. child: Text(
  638. initList[item]["title"],
  639. style: TextStyle(
  640. color: Color(0xff666666),
  641. fontSize: ScreenUtil().setSp(15)),
  642. textAlign: TextAlign.start,
  643. ),
  644. ),
  645. ]),
  646. ),
  647. onPressed: () {
  648. int nums = item + 1;
  649. String index = nums.toString();
  650. NavigatorUtils.push(
  651. context, "${WodeRouter.orderPage}?checkType=$index");
  652. },
  653. ),
  654. );
  655. },
  656. ).toList();
  657. @override
  658. Widget build(BuildContext context) {
  659. return Container(
  660. padding: EdgeInsets.only(top: ScreenUtil().setWidth(5)),
  661. child: Wrap(
  662. // spacing: 26,
  663. alignment: WrapAlignment.spaceBetween,
  664. crossAxisAlignment: WrapCrossAlignment.center,
  665. children: brandList(context),
  666. ),
  667. );
  668. }
  669. }