wallet_page.dart 23 KB

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