wode_page.dart 27 KB

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