wallet_page.dart 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. int timeIndex = 0;
  304. void showSelect() {
  305. showModalBottomSheet(
  306. backgroundColor: Colors.transparent,
  307. context: context,
  308. builder: (context) {
  309. return StatefulBuilder(builder: (c, s) {
  310. ss = s;
  311. return Container(
  312. color: Colors.transparent,
  313. height: 240 +
  314. (MediaQuery.of(context).size.width / 3 / 2.5) *
  315. ((types.length / 3).ceil()),
  316. child: Column(
  317. children: [
  318. Container(
  319. padding:
  320. EdgeInsets.only(left: 10, right: 10, top: 3, bottom: 0),
  321. decoration: BoxDecoration(
  322. color: Colors.white,
  323. borderRadius: BorderRadius.only(
  324. topLeft: Radius.circular(8),
  325. topRight: Radius.circular(8))),
  326. child: Row(
  327. children: [
  328. GestureDetector(
  329. onTap: () {
  330. Navigator.pop(context);
  331. },
  332. behavior: HitTestBehavior.translucent,
  333. child: Padding(
  334. padding: const EdgeInsets.all(8.0),
  335. child: Text(
  336. '取消',
  337. style: TextStyle(
  338. color: MyColors.cFF4233, fontSize: 14),
  339. ),
  340. ),
  341. ),
  342. Text(
  343. '类型筛选',
  344. style:
  345. TextStyle(color: MyColors.c333333, fontSize: 16),
  346. ),
  347. GestureDetector(
  348. child: Padding(
  349. padding: const EdgeInsets.all(8.0),
  350. child: Text(
  351. '确定',
  352. style: TextStyle(
  353. color: MyColors.cFF4233, fontSize: 14),
  354. ),
  355. ),
  356. behavior: HitTestBehavior.translucent,
  357. onTap: () {
  358. Navigator.pop(context);
  359. controller.requestRefresh();
  360. },
  361. ),
  362. ],
  363. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  364. ),
  365. height: 39.5,
  366. ),
  367. Container(
  368. height: 0.5,
  369. color: MyColors.cF5F5F5,
  370. ),
  371. Expanded(
  372. child: Container(
  373. color: Colors.white,
  374. child: SingleChildScrollView(
  375. child: Column(
  376. children: [
  377. Visibility(
  378. visible: types.length > 1,
  379. child: Container(
  380. height: 20 +
  381. (MediaQuery.of(context).size.width /
  382. 3 /
  383. 2.5) *
  384. ((types.length / 3).ceil()),
  385. color: Colors.white,
  386. child: Column(
  387. children: [
  388. Container(
  389. child: Text(
  390. '类型筛选',
  391. style: TextStyle(
  392. color: MyColors.c333333,
  393. fontSize: 15),
  394. ),
  395. margin: EdgeInsets.only(
  396. left: 18, top: 5, bottom: 5),
  397. height: 20,
  398. ),
  399. Expanded(
  400. child: GridView(
  401. gridDelegate:
  402. SliverGridDelegateWithFixedCrossAxisCount(
  403. crossAxisCount: 3,
  404. childAspectRatio: 3),
  405. children: getTypeItems(),
  406. physics: NeverScrollableScrollPhysics(),
  407. ),
  408. )
  409. ],
  410. crossAxisAlignment: CrossAxisAlignment.start,
  411. ),
  412. ),
  413. ),
  414. Visibility(
  415. visible: times.length > 1,
  416. child: Container(
  417. height: 20 +
  418. (MediaQuery.of(context).size.width /
  419. 3 /
  420. 2.5) *
  421. ((times.length / 3).ceil()),
  422. color: Colors.white,
  423. child: Column(
  424. children: [
  425. Container(
  426. child: Text(
  427. '时间筛选',
  428. style: TextStyle(
  429. color: MyColors.c333333,
  430. fontSize: 15),
  431. ),
  432. margin: EdgeInsets.only(
  433. left: 18, top: 5, bottom: 5),
  434. height: 20,
  435. ),
  436. Expanded(
  437. child: GridView(
  438. gridDelegate:
  439. SliverGridDelegateWithFixedCrossAxisCount(
  440. crossAxisCount: 3,
  441. childAspectRatio: 3),
  442. children: getTimeItems(),
  443. physics: NeverScrollableScrollPhysics(),
  444. ),
  445. )
  446. ],
  447. crossAxisAlignment: CrossAxisAlignment.start,
  448. ),
  449. ),
  450. ),
  451. ],
  452. crossAxisAlignment: CrossAxisAlignment.start,
  453. ),
  454. ),
  455. ),
  456. )
  457. ],
  458. ),
  459. );
  460. });
  461. });
  462. }
  463. getTypeItems() {
  464. List<Widget> item = [];
  465. for (int i = 0; i < types.length; i++) {
  466. item.add(GestureDetector(
  467. onTap: () {
  468. ss(() {
  469. if (typeIndex == i) {
  470. typeIndex = -1;
  471. } else {
  472. typeIndex = i;
  473. }
  474. });
  475. // getTime(timeIndex);
  476. },
  477. behavior: HitTestBehavior.translucent,
  478. child: Container(
  479. alignment: Alignment.center,
  480. child: Container(
  481. decoration: BoxDecoration(
  482. color: i == typeIndex ? MyColors.cFFECEB : MyColors.cEDEDED,
  483. borderRadius: BorderRadius.all(Radius.circular(4))),
  484. height: 34,
  485. width: 100,
  486. child: Text(
  487. types[i],
  488. style: TextStyle(
  489. color: i == typeIndex ? MyColors.cFF4233 : MyColors.c666666,
  490. fontSize: 14),
  491. ),
  492. alignment: Alignment.center,
  493. ),
  494. ),
  495. ));
  496. }
  497. return item;
  498. }
  499. getTimeItems() {
  500. List<Widget> item = [];
  501. for (int i = 0; i < times.length; i++) {
  502. item.add(GestureDetector(
  503. onTap: () {
  504. ss(() {
  505. if (timeIndex == i) {
  506. timeIndex = -1;
  507. } else {
  508. timeIndex = i;
  509. }
  510. });
  511. if (timeIndex != 0) {
  512. getTime(timeIndex - 1);
  513. }
  514. },
  515. behavior: HitTestBehavior.translucent,
  516. child: Container(
  517. alignment: Alignment.center,
  518. child: Container(
  519. decoration: BoxDecoration(
  520. color: i == timeIndex ? MyColors.cFFECEB : MyColors.cEDEDED,
  521. borderRadius: BorderRadius.all(Radius.circular(4))),
  522. height: 34,
  523. width: 100,
  524. child: Text(
  525. times[i],
  526. style: TextStyle(
  527. color: i == timeIndex ? MyColors.cFF4233 : MyColors.c666666,
  528. fontSize: 14),
  529. ),
  530. alignment: Alignment.center,
  531. ),
  532. ),
  533. ));
  534. }
  535. return item;
  536. }
  537. void myFlow() {
  538. getUserWalletBalance((re, hE) {
  539. if (!hE) {
  540. UserBalanceEntity balance =
  541. UserBalanceEntity().fromJson(json.decode(re.data.toString()));
  542. MyCookie().userBean.balance = balance.data;
  543. setState(() {});
  544. }
  545. }, (e) {}, context);
  546. var conditions = [
  547. "user_uid==${MyCookie().getUID()}",
  548. // "paid_amount ${sTab == 0 ? '>' : '<'} 0"
  549. ];
  550. if (typeIndex != 0 && typeIndex != -1) {
  551. switch(typeIndex){
  552. case 1:
  553. conditions.add('type IN ${[
  554. flowTypeOrderCommodity,
  555. flowTypeOrderAnnualFee,
  556. flowTypeOrderVirtualProduct,
  557. flowTypeOrderThirdPlatform,
  558. flowTypeOrderOfflineTransfer,
  559. flowTypeScancodeAilyPay
  560. ]}');
  561. break;
  562. case 2:
  563. conditions.add('type IN ${[
  564. flowTypeShopCommission
  565. ]}');
  566. break;
  567. case 3:
  568. conditions.add('type IN ${[
  569. flowTypeWithdraw
  570. ]}');
  571. break;
  572. }
  573. // conditions.add("type IN ${typeIndex == 1 ? [
  574. // flowTypeOrderCommodity,
  575. // flowTypeOrderAnnualFee,
  576. // flowTypeOrderVirtualProduct,
  577. // flowTypeOrderThirdPlatform,
  578. // flowTypeOrderOfflineTransfer,
  579. // flowTypeScancodeAilyPay
  580. // ] : [flowTypeShopCommission]}");
  581. }
  582. if (timeIndex != 0 && timeIndex != -1) {
  583. conditions.add("pay_time between ${getTime(timeIndex - 1)}");
  584. }
  585. MyDio().query({
  586. "key": "flow",
  587. "filters": {"conditions": conditions},
  588. "dims": flowDims,
  589. "order_by": ["id,DESC"],
  590. "paging": [page, 50]
  591. }, (response, hasError) {
  592. if (!hasError) {
  593. FlowBeanEntity entity =
  594. FlowBeanEntity().fromJson(json.decode(response.data.toString()));
  595. total = entity.data.total;
  596. totalAmount = entity.data.data.totalAmount;
  597. if (page == 1) {
  598. flow.clear();
  599. }
  600. try {
  601. flow.addAll(entity.data.data.records);
  602. } catch (e) {}
  603. setState(() {});
  604. }
  605. endRe(controller);
  606. }, (error) {});
  607. }
  608. void onRefresh() {
  609. page = 1;
  610. checkIfYouAreTheOwner();
  611. myFlow();
  612. }
  613. void onLoading() {
  614. page++;
  615. myFlow();
  616. }
  617. void checkIfYouAreTheOwner() {
  618. MyDio().query({
  619. "key": "shop",
  620. "filters": {
  621. "conditions": ["owner_uid == ${MyCookie().getUID()}"]
  622. },
  623. "dims": shopDims,
  624. "paging": [1, 5000]
  625. }, (response, hasError) {
  626. if (!hasError) {
  627. StoreBeanEntity entity =
  628. StoreBeanEntity().fromJson(json.decode(response.data.toString()));
  629. if (entity.data.data.length == 0) {
  630. types.remove('佣金');
  631. }
  632. setState(() {});
  633. }
  634. endRe(controller);
  635. }, (error) {});
  636. }
  637. }