wode_page.dart 28 KB

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