wallet_page.dart 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. import 'dart:convert';
  2. import 'dart:math' as math;
  3. import 'package:bbyyy/beans/flow_bean_entity.dart';
  4. import 'package:bbyyy/beans/store_bean_entity.dart';
  5. import 'package:bbyyy/beans/user_balance_entity.dart';
  6. import 'package:bbyyy/https/MyDio.dart';
  7. import 'package:bbyyy/https/url.dart';
  8. import 'package:bbyyy/my_tools/const.dart';
  9. import 'package:bbyyy/my_tools/dims.dart';
  10. import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
  11. import 'package:bbyyy/my_tools/my_colors.dart';
  12. import 'package:bbyyy/my_tools/my_cookie.dart';
  13. import 'package:bbyyy/my_tools/my_tools.dart';
  14. import 'package:bbyyy/my_tools/my_views.dart';
  15. import 'package:bbyyy/pay/pay_tools.dart';
  16. import 'package:flutter/material.dart';
  17. import 'package:flutter_svg/svg.dart';
  18. import 'package:pull_to_refresh/pull_to_refresh.dart';
  19. class WalletPage extends StatefulWidget {
  20. @override
  21. _WalletPageState createState() => _WalletPageState();
  22. }
  23. class _WalletPageState extends State<WalletPage> {
  24. int sTab = 0;
  25. List<FlowBeanDataDataRecords> flow = [];
  26. int page = 1;
  27. RefreshController controller = RefreshController(initialRefresh: true);
  28. int total = 0;
  29. double totalAmount = 0.0;
  30. @override
  31. void initState() {
  32. super.initState();
  33. for(int i =0;i<types.length;i++){
  34. tId[types[i]] = typesID[i];
  35. }
  36. Future.delayed(Duration.zero,(){
  37. EasyLoading.show();
  38. getUserWalletBalance((re, hE) {
  39. if (!hE) {
  40. UserBalanceEntity balance =
  41. UserBalanceEntity.fromJson(json.decode(re.data.toString()));
  42. MyCookie().balance = balance.data;
  43. setState(() {
  44. EasyLoading.dismiss();
  45. });
  46. }
  47. }, (e) {
  48. EasyLoading.dismiss();
  49. }, context);
  50. });
  51. }
  52. @override
  53. Widget build(BuildContext context) {
  54. return Scaffold(
  55. body: Column(
  56. children: [
  57. Stack(
  58. children: [
  59. Container(
  60. decoration: BoxDecoration(
  61. gradient: LinearGradient(colors: MyColors.lg),
  62. ),
  63. height: 200,
  64. ),
  65. Column(
  66. children: [
  67. SafeArea(
  68. bottom: false,
  69. child: Container(
  70. height: 45,
  71. width: double.infinity,
  72. color: Colors.transparent,
  73. child: Stack(
  74. children: [
  75. Text(
  76. '资金流水',
  77. style: TextStyle(color: Colors.white, fontSize: 16),
  78. ),
  79. Positioned(
  80. left: 0,
  81. child: GestureDetector(
  82. onTap: () {
  83. Navigator.pop(context);
  84. },
  85. behavior: HitTestBehavior.translucent,
  86. child: Transform.rotate(
  87. angle: math.pi,
  88. child: Padding(
  89. padding: EdgeInsets.only(
  90. left: 16, right: 16, top: 8, bottom: 8),
  91. child: SvgPicture.asset(
  92. 'images/svg/箭头.svg',
  93. color: Colors.white,
  94. height: 14,
  95. ),
  96. ),
  97. ),
  98. ),
  99. ),
  100. Row(
  101. children: [
  102. GestureDetector(
  103. onTap: () {
  104. showSelect();
  105. },
  106. behavior: HitTestBehavior.translucent,
  107. child: Container(
  108. padding: EdgeInsets.symmetric(
  109. vertical: 8, horizontal: 16),
  110. child: Text(
  111. '筛选',
  112. style: TextStyle(
  113. color: Colors.white, fontSize: 16),
  114. ),
  115. ),
  116. ),
  117. ],
  118. mainAxisAlignment: MainAxisAlignment.end,
  119. )
  120. ],
  121. alignment: Alignment.center,
  122. ),
  123. ),
  124. ),
  125. // Container(
  126. // decoration: BoxDecoration(
  127. // border: Border.all(color: Colors.white, width: 1),
  128. // borderRadius: BorderRadius.all(Radius.circular(20))),
  129. // height: 40,
  130. // width: double.infinity,
  131. // margin: EdgeInsets.symmetric(horizontal: 33, vertical: 7),
  132. // child: Row(
  133. // children: [
  134. // Expanded(
  135. // child: GestureDetector(
  136. // onTap: () {
  137. // setState(() {
  138. // sTab = 0;
  139. // controller.requestRefresh();
  140. // });
  141. // },
  142. // behavior: HitTestBehavior.translucent,
  143. // child: Container(
  144. // height: 40,
  145. // decoration: BoxDecoration(
  146. // borderRadius: BorderRadius.only(
  147. // topLeft: Radius.circular(20),
  148. // bottomLeft: Radius.circular(20),
  149. // ),
  150. // color: sTab == 0
  151. // ? Colors.white
  152. // : Colors.transparent),
  153. // child: Text(
  154. // '我的收入',
  155. // style: TextStyle(
  156. // color: sTab == 0
  157. // ? MyColors.cFF4233
  158. // : Colors.white),
  159. // ),
  160. // alignment: Alignment.center,
  161. // ),
  162. // ),
  163. // ),
  164. // Expanded(
  165. // child: GestureDetector(
  166. // onTap: () {
  167. // setState(() {
  168. // sTab = 1;
  169. // controller.requestRefresh();
  170. // });
  171. // },
  172. // behavior: HitTestBehavior.translucent,
  173. // child: Container(
  174. // height: 40,
  175. // decoration: BoxDecoration(
  176. // borderRadius: BorderRadius.only(
  177. // topRight: Radius.circular(20),
  178. // bottomRight: Radius.circular(20),
  179. // ),
  180. // color: sTab == 1
  181. // ? Colors.white
  182. // : Colors.transparent),
  183. // child: Text(
  184. // '我的支出',
  185. // style: TextStyle(
  186. // color: sTab == 1
  187. // ? MyColors.cFF4233
  188. // : Colors.white),
  189. // ),
  190. // alignment: Alignment.center,
  191. // ),
  192. // ),
  193. // )
  194. // ],
  195. // ),
  196. // ),
  197. Container(
  198. margin: EdgeInsets.only(top: 10),
  199. child: Row(
  200. children: [
  201. ClipRRect(
  202. child: MyViews()
  203. .netImg(imgURL(MyCookie().getPic()), 36, 36),
  204. borderRadius: BorderRadius.circular(18),
  205. ),
  206. Container(
  207. margin: EdgeInsets.only(left: 10),
  208. child: Text(
  209. '${MyCookie().getName()}(${MyCookie().getUID()})',
  210. style: TextStyle(color: Colors.white, fontSize: 15),
  211. ),
  212. ),
  213. ],
  214. mainAxisAlignment: MainAxisAlignment.center,
  215. ),
  216. alignment: Alignment.center,
  217. ),
  218. Container(
  219. margin: EdgeInsets.only(top: 25),
  220. child: Center(
  221. child: Text(
  222. '共$total笔',
  223. style: TextStyle(color: Colors.white, fontSize: 20),
  224. ),
  225. ),
  226. ),
  227. // Container(
  228. // height: 22,
  229. // child: Row(
  230. // children: [
  231. // Text(
  232. // '$total笔数',
  233. // style: TextStyle(color: Colors.white, fontSize: 14),
  234. // ),
  235. // // Visibility(
  236. // // visible: sTab == 0,
  237. // // child: GestureDetector(
  238. // // onTap: () {
  239. // // if (MyCookie().userBean.aliPayAccount.isEmpty) {
  240. // // MyTools().toPage(context, SetAlipayPage(),
  241. // // (then) {
  242. // // if (MyCookie()
  243. // // .userBean
  244. // // .aliPayAccount
  245. // // .isNotEmpty) {
  246. // // MyTools().toPage(context, WithdrawPage(),
  247. // // (then) {
  248. // // controller.requestRefresh();
  249. // // });
  250. // // }
  251. // // });
  252. // // } else {
  253. // // MyTools().toPage(context, WithdrawPage(),
  254. // // (then) {
  255. // // controller.requestRefresh();
  256. // // });
  257. // // }
  258. // // },
  259. // // behavior: HitTestBehavior.translucent,
  260. // // child: Container(
  261. // // decoration: BoxDecoration(
  262. // // color: MyColors.cFFCD00,
  263. // // borderRadius:
  264. // // BorderRadius.all(Radius.circular(15)),
  265. // // ),
  266. // // height: 30,
  267. // // width: 70,
  268. // // child: Text(
  269. // // '申请提现',
  270. // // style: TextStyle(
  271. // // color: Colors.white, fontSize: 13),
  272. // // ),
  273. // // alignment: Alignment.center,
  274. // // padding: EdgeInsets.only(bottom: 1),
  275. // // ),
  276. // // ),
  277. // // )
  278. // ],
  279. // mainAxisAlignment: MainAxisAlignment.spaceBetween,
  280. // ),
  281. // alignment: Alignment.centerLeft,
  282. // margin: EdgeInsets.only(top: 25, left: 15, right: 17),
  283. // ),
  284. // Container(
  285. // child: Text(
  286. // '¥${NumUtil.multiply(totalAmount, 1)}',
  287. // style: TextStyle(color: Colors.white, fontSize: 24),
  288. // ),
  289. // alignment: Alignment.center,
  290. // margin: EdgeInsets.only(top: 2),
  291. // ),
  292. ],
  293. )
  294. ],
  295. ),
  296. Expanded(
  297. child: SmartRefresher(
  298. controller: controller,
  299. onRefresh: onRefresh,
  300. onLoading: onLoading,
  301. enablePullDown: true,
  302. enablePullUp: true,
  303. child: flow.length == 0
  304. ? SingleChildScrollView(child: noData())
  305. : ListView.builder(
  306. itemBuilder: (c, index) {
  307. return MyViews().getWalletItem(flow[index], context);
  308. },
  309. padding: EdgeInsets.only(top: 13),
  310. itemCount: flow.length,
  311. ),
  312. ),
  313. ),
  314. ],
  315. ),
  316. );
  317. }
  318. StateSetter ss;
  319. List<String> types = ['全部', '订单', '佣金', '提现', '缴费'];
  320. var typesID = [
  321. [],
  322. [
  323. flowTypeOrderCommodity,
  324. flowTypeOrderAnnualFee,
  325. flowTypeOrderVirtualProduct,
  326. flowTypeOrderThirdPlatform,
  327. flowTypeOrderOfflineTransfer,
  328. flowTypeScancodeAilyPay
  329. ],
  330. [flowTypeShopCommission],
  331. [flowTypeWithdraw],
  332. [flowTypePlatformFee]
  333. ];
  334. int typeIndex = 0;
  335. Map tId = Map();
  336. // List<String> times = ['全部', '今天', '昨天', '本周', '上周', '本月'];
  337. List<String> times = ['今天', '昨天', '本周', '上周'];
  338. int timeIndex = -1;
  339. void showSelect() {
  340. showModalBottomSheet(
  341. backgroundColor: Colors.transparent,
  342. context: context,
  343. builder: (context) {
  344. return StatefulBuilder(builder: (c, s) {
  345. ss = s;
  346. return Container(
  347. color: Colors.transparent,
  348. height: 240 +
  349. (MediaQuery.of(context).size.width / 3 / 2.5) *
  350. ((types.length / 3).ceil()),
  351. child: Column(
  352. children: [
  353. Container(
  354. padding:
  355. EdgeInsets.only(left: 10, right: 10, top: 3, bottom: 0),
  356. decoration: BoxDecoration(
  357. color: Colors.white,
  358. borderRadius: BorderRadius.only(
  359. topLeft: Radius.circular(8),
  360. topRight: Radius.circular(8))),
  361. child: Row(
  362. children: [
  363. GestureDetector(
  364. onTap: () {
  365. Navigator.pop(context);
  366. },
  367. behavior: HitTestBehavior.translucent,
  368. child: Padding(
  369. padding: const EdgeInsets.all(8.0),
  370. child: Text(
  371. '取消',
  372. style: TextStyle(
  373. color: MyColors.cFF4233, fontSize: 14),
  374. ),
  375. ),
  376. ),
  377. Text(
  378. '类型筛选',
  379. style:
  380. TextStyle(color: MyColors.c333333, fontSize: 16),
  381. ),
  382. GestureDetector(
  383. child: Padding(
  384. padding: const EdgeInsets.all(8.0),
  385. child: Text(
  386. '确定',
  387. style: TextStyle(
  388. color: MyColors.cFF4233, fontSize: 14),
  389. ),
  390. ),
  391. behavior: HitTestBehavior.translucent,
  392. onTap: () {
  393. Navigator.pop(context);
  394. controller.requestRefresh();
  395. },
  396. ),
  397. ],
  398. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  399. ),
  400. height: 39.5,
  401. ),
  402. Container(
  403. height: 0.5,
  404. color: MyColors.cF5F5F5,
  405. ),
  406. Expanded(
  407. child: Container(
  408. color: Colors.white,
  409. child: SingleChildScrollView(
  410. child: Column(
  411. children: [
  412. Visibility(
  413. visible: types.length > 1,
  414. child: Container(
  415. height: 20 +
  416. (MediaQuery.of(context).size.width /
  417. 3 /
  418. 2.5) *
  419. ((types.length / 3).ceil()),
  420. color: Colors.white,
  421. child: Column(
  422. children: [
  423. Container(
  424. child: Text(
  425. '类型筛选',
  426. style: TextStyle(
  427. color: MyColors.c333333,
  428. fontSize: 15),
  429. ),
  430. margin: EdgeInsets.only(
  431. left: 18, top: 5, bottom: 5),
  432. height: 20,
  433. ),
  434. Expanded(
  435. child: GridView(
  436. gridDelegate:
  437. SliverGridDelegateWithFixedCrossAxisCount(
  438. crossAxisCount: 3,
  439. childAspectRatio: 3),
  440. children: getTypeItems(),
  441. physics: NeverScrollableScrollPhysics(),
  442. ),
  443. )
  444. ],
  445. crossAxisAlignment: CrossAxisAlignment.start,
  446. ),
  447. ),
  448. ),
  449. Visibility(
  450. visible: times.length > 1,
  451. child: Container(
  452. height: 20 +
  453. (MediaQuery.of(context).size.width /
  454. 3 /
  455. 2.5) *
  456. ((times.length / 3).ceil()),
  457. color: Colors.white,
  458. child: Column(
  459. children: [
  460. Container(
  461. child: Text(
  462. '时间筛选',
  463. style: TextStyle(
  464. color: MyColors.c333333,
  465. fontSize: 15),
  466. ),
  467. margin: EdgeInsets.only(
  468. left: 18, top: 5, bottom: 5),
  469. height: 20,
  470. ),
  471. Expanded(
  472. child: GridView(
  473. gridDelegate:
  474. SliverGridDelegateWithFixedCrossAxisCount(
  475. crossAxisCount: 3,
  476. childAspectRatio: 3),
  477. children: getTimeItems(),
  478. physics: NeverScrollableScrollPhysics(),
  479. ),
  480. )
  481. ],
  482. crossAxisAlignment: CrossAxisAlignment.start,
  483. ),
  484. ),
  485. ),
  486. ],
  487. crossAxisAlignment: CrossAxisAlignment.start,
  488. ),
  489. ),
  490. ),
  491. )
  492. ],
  493. ),
  494. );
  495. });
  496. });
  497. }
  498. getTypeItems() {
  499. List<Widget> item = [];
  500. for (int i = 0; i < types.length; i++) {
  501. item.add(GestureDetector(
  502. onTap: () {
  503. ss(() {
  504. if (typeIndex == i) {
  505. typeIndex = -1;
  506. } else {
  507. typeIndex = i;
  508. }
  509. });
  510. // getTime(timeIndex);
  511. },
  512. behavior: HitTestBehavior.translucent,
  513. child: Container(
  514. alignment: Alignment.center,
  515. child: Container(
  516. decoration: BoxDecoration(
  517. color: i == typeIndex ? MyColors.cFFECEB : MyColors.cEDEDED,
  518. borderRadius: BorderRadius.all(Radius.circular(4))),
  519. height: 34,
  520. width: 100,
  521. child: Text(
  522. types[i],
  523. style: TextStyle(
  524. color: i == typeIndex ? MyColors.cFF4233 : MyColors.c666666,
  525. fontSize: 14),
  526. ),
  527. alignment: Alignment.center,
  528. ),
  529. ),
  530. ));
  531. }
  532. return item;
  533. }
  534. getTimeItems() {
  535. List<Widget> item = [];
  536. for (int i = 0; i < times.length; i++) {
  537. item.add(GestureDetector(
  538. onTap: () {
  539. ss(() {
  540. if (timeIndex == i) {
  541. timeIndex = -1;
  542. } else {
  543. timeIndex = i;
  544. }
  545. });
  546. if (timeIndex != -1) {
  547. getTime(timeIndex);
  548. }
  549. },
  550. behavior: HitTestBehavior.translucent,
  551. child: Container(
  552. alignment: Alignment.center,
  553. child: Container(
  554. decoration: BoxDecoration(
  555. color: i == timeIndex ? MyColors.cFFECEB : MyColors.cEDEDED,
  556. borderRadius: BorderRadius.all(Radius.circular(4))),
  557. height: 34,
  558. width: 100,
  559. child: Text(
  560. times[i],
  561. style: TextStyle(
  562. color: i == timeIndex ? MyColors.cFF4233 : MyColors.c666666,
  563. fontSize: 14),
  564. ),
  565. alignment: Alignment.center,
  566. ),
  567. ),
  568. ));
  569. }
  570. return item;
  571. }
  572. void myFlow() {
  573. getUserWalletBalance((re, hE) {
  574. if (!hE) {
  575. UserBalanceEntity balance =
  576. UserBalanceEntity.fromJson(json.decode(re.data.toString()));
  577. MyCookie().balance = balance.data;
  578. setState(() {});
  579. }
  580. }, (e) {}, context);
  581. var conditions = [
  582. "user_uid==${MyCookie().getUID()}",
  583. // "paid_amount ${sTab == 0 ? '>' : '<'} 0"
  584. ];
  585. if (typeIndex != 0 && typeIndex != -1) {
  586. conditions.add('type IN ${tId[types[typeIndex]]}');
  587. // switch (typeIndex) {
  588. // case 1:
  589. // conditions.add('type IN ${[
  590. // flowTypeOrderCommodity,
  591. // flowTypeOrderAnnualFee,
  592. // flowTypeOrderVirtualProduct,
  593. // flowTypeOrderThirdPlatform,
  594. // flowTypeOrderOfflineTransfer,
  595. // flowTypeScancodeAilyPay
  596. // ]}');
  597. // break;
  598. // case 2:
  599. // conditions.add('type IN ${[flowTypeShopCommission]}');
  600. // break;
  601. // case 3:
  602. // conditions.add('type IN ${[flowTypeWithdraw]}');
  603. // break;
  604. // case 4:
  605. // conditions.add('type IN ${[flowTypePlatformFee]}');
  606. // break;
  607. // }
  608. // conditions.add("type IN ${typeIndex == 1 ? [
  609. // flowTypeOrderCommodity,
  610. // flowTypeOrderAnnualFee,
  611. // flowTypeOrderVirtualProduct,
  612. // flowTypeOrderThirdPlatform,
  613. // flowTypeOrderOfflineTransfer,
  614. // flowTypeScancodeAilyPay
  615. // ] : [flowTypeShopCommission]}");
  616. }
  617. if (timeIndex != -1) {
  618. conditions.add("pay_time between ${getTime(timeIndex)}");
  619. } else {
  620. conditions.add("pay_time between ${getTime(6)}");
  621. }
  622. MyDio().query({
  623. "key": "flow",
  624. "filters": {"conditions": conditions},
  625. "dims": flowDims,
  626. "order_by": ["id,DESC"],
  627. "paging": [page, 50]
  628. }, (response, hasError) {
  629. if (!hasError) {
  630. FlowBeanEntity entity =
  631. FlowBeanEntity.fromJson(json.decode(response.data.toString()));
  632. total = entity.data.total;
  633. totalAmount = entity.data.data.totalAmount;
  634. if (page == 1) {
  635. flow.clear();
  636. }
  637. try {
  638. flow.addAll(entity.data.data.records);
  639. } catch (e) {}
  640. setState(() {});
  641. }
  642. endRe(controller);
  643. }, (error) {});
  644. }
  645. void onRefresh() {
  646. page = 1;
  647. checkIfYouAreTheOwner();
  648. myFlow();
  649. }
  650. void onLoading() {
  651. page++;
  652. myFlow();
  653. }
  654. void checkIfYouAreTheOwner() {
  655. MyDio().query({
  656. "key": "shop",
  657. "filters": {
  658. "conditions": ["owner_uid == ${MyCookie().getUID()}"]
  659. },
  660. "dims": shopDims,
  661. "paging": [1, 5000]
  662. }, (response, hasError) {
  663. if (!hasError) {
  664. StoreBeanEntity entity =
  665. StoreBeanEntity.fromJson(json.decode(response.data.toString()));
  666. if (entity.data.data.length == 0) {
  667. types.remove('佣金');
  668. types.remove('缴费');
  669. }
  670. setState(() {});
  671. }
  672. endRe(controller);
  673. }, (error) {});
  674. }
  675. }