wallet_page.dart 25 KB

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