wallet_page.dart 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. import 'dart:convert';
  2. import 'dart:math' as math;
  3. import 'package:bbyyy/beans/flow_bean_entity.dart';
  4. import 'package:bbyyy/beans/my_shop_bean_entity.dart';
  5. import 'package:bbyyy/beans/store_bean_entity.dart';
  6. import 'package:bbyyy/beans/user_balance_entity.dart';
  7. import 'package:bbyyy/https/MyDio.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: 170,
  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: 25),
  180. child: Center(
  181. child: Text(
  182. '共$total笔',
  183. style: TextStyle(color: Colors.white, fontSize: 20),
  184. ),
  185. ),
  186. ),
  187. // Container(
  188. // height: 22,
  189. // child: Row(
  190. // children: [
  191. // Text(
  192. // '$total笔数',
  193. // style: TextStyle(color: Colors.white, fontSize: 14),
  194. // ),
  195. // // Visibility(
  196. // // visible: sTab == 0,
  197. // // child: GestureDetector(
  198. // // onTap: () {
  199. // // if (MyCookie().userBean.aliPayAccount.isEmpty) {
  200. // // MyTools().toPage(context, SetAlipayPage(),
  201. // // (then) {
  202. // // if (MyCookie()
  203. // // .userBean
  204. // // .aliPayAccount
  205. // // .isNotEmpty) {
  206. // // MyTools().toPage(context, WithdrawPage(),
  207. // // (then) {
  208. // // controller.requestRefresh();
  209. // // });
  210. // // }
  211. // // });
  212. // // } else {
  213. // // MyTools().toPage(context, WithdrawPage(),
  214. // // (then) {
  215. // // controller.requestRefresh();
  216. // // });
  217. // // }
  218. // // },
  219. // // behavior: HitTestBehavior.translucent,
  220. // // child: Container(
  221. // // decoration: BoxDecoration(
  222. // // color: MyColors.cFFCD00,
  223. // // borderRadius:
  224. // // BorderRadius.all(Radius.circular(15)),
  225. // // ),
  226. // // height: 30,
  227. // // width: 70,
  228. // // child: Text(
  229. // // '申请提现',
  230. // // style: TextStyle(
  231. // // color: Colors.white, fontSize: 13),
  232. // // ),
  233. // // alignment: Alignment.center,
  234. // // padding: EdgeInsets.only(bottom: 1),
  235. // // ),
  236. // // ),
  237. // // )
  238. // ],
  239. // mainAxisAlignment: MainAxisAlignment.spaceBetween,
  240. // ),
  241. // alignment: Alignment.centerLeft,
  242. // margin: EdgeInsets.only(top: 25, left: 15, right: 17),
  243. // ),
  244. // Container(
  245. // child: Text(
  246. // '¥${NumUtil.multiply(totalAmount, 1)}',
  247. // style: TextStyle(color: Colors.white, fontSize: 24),
  248. // ),
  249. // alignment: Alignment.center,
  250. // margin: EdgeInsets.only(top: 2),
  251. // ),
  252. ],
  253. )
  254. ],
  255. ),
  256. Expanded(
  257. child: SmartRefresher(
  258. controller: controller,
  259. onRefresh: onRefresh,
  260. onLoading: onLoading,
  261. enablePullDown: true,
  262. enablePullUp: true,
  263. child: flow.length == 0
  264. ? SingleChildScrollView(child: noData())
  265. : ListView.builder(
  266. itemBuilder: (c, index) {
  267. return MyViews().getWalletItem(flow[index], context);
  268. },
  269. padding: EdgeInsets.only(top: 13),
  270. itemCount: flow.length,
  271. ),
  272. ),
  273. ),
  274. ],
  275. ),
  276. );
  277. }
  278. StateSetter ss;
  279. List<String> types = ['全部', '订单', '佣金'];
  280. int typeIndex = 0;
  281. List<String> times = ['全部', '今天', '昨天', '本周', '上周', '本月'];
  282. int timeIndex = 0;
  283. void showSelect() {
  284. showModalBottomSheet(
  285. backgroundColor: Colors.transparent,
  286. context: context,
  287. builder: (context) {
  288. return StatefulBuilder(builder: (c, s) {
  289. ss = s;
  290. return Container(
  291. color: Colors.transparent,
  292. height: 240 +
  293. (MediaQuery.of(context).size.width / 3 / 2.5) *
  294. ((types.length / 3).ceil()),
  295. child: Column(
  296. children: [
  297. Container(
  298. padding:
  299. EdgeInsets.only(left: 10, right: 10, top: 3, bottom: 0),
  300. decoration: BoxDecoration(
  301. color: Colors.white,
  302. borderRadius: BorderRadius.only(
  303. topLeft: Radius.circular(8),
  304. topRight: Radius.circular(8))),
  305. child: Row(
  306. children: [
  307. GestureDetector(
  308. onTap: () {
  309. Navigator.pop(context);
  310. },
  311. behavior: HitTestBehavior.translucent,
  312. child: Padding(
  313. padding: const EdgeInsets.all(8.0),
  314. child: Text(
  315. '取消',
  316. style: TextStyle(
  317. color: MyColors.cFF4233, fontSize: 14),
  318. ),
  319. ),
  320. ),
  321. Text(
  322. '类型筛选',
  323. style:
  324. TextStyle(color: MyColors.c333333, fontSize: 16),
  325. ),
  326. GestureDetector(
  327. child: Padding(
  328. padding: const EdgeInsets.all(8.0),
  329. child: Text(
  330. '确定',
  331. style: TextStyle(
  332. color: MyColors.cFF4233, fontSize: 14),
  333. ),
  334. ),
  335. behavior: HitTestBehavior.translucent,
  336. onTap: () {
  337. Navigator.pop(context);
  338. controller.requestRefresh();
  339. },
  340. ),
  341. ],
  342. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  343. ),
  344. height: 39.5,
  345. ),
  346. Container(
  347. height: 0.5,
  348. color: MyColors.cF5F5F5,
  349. ),
  350. Expanded(
  351. child: Container(
  352. color: Colors.white,
  353. child: SingleChildScrollView(
  354. child: Column(
  355. children: [
  356. Visibility(
  357. visible: types.length > 1,
  358. child: Container(
  359. height: 20 +
  360. (MediaQuery.of(context).size.width /
  361. 3 /
  362. 2.5) *
  363. ((types.length / 3).ceil()),
  364. color: Colors.white,
  365. child: Column(
  366. children: [
  367. Container(
  368. child: Text(
  369. '类型筛选',
  370. style: TextStyle(
  371. color: MyColors.c333333,
  372. fontSize: 15),
  373. ),
  374. margin: EdgeInsets.only(
  375. left: 18, top: 5, bottom: 5),
  376. height: 20,
  377. ),
  378. Expanded(
  379. child: GridView(
  380. gridDelegate:
  381. SliverGridDelegateWithFixedCrossAxisCount(
  382. crossAxisCount: 3,
  383. childAspectRatio: 3),
  384. children: getTypeItems(),
  385. physics: NeverScrollableScrollPhysics(),
  386. ),
  387. )
  388. ],
  389. crossAxisAlignment: CrossAxisAlignment.start,
  390. ),
  391. ),
  392. ),
  393. Visibility(
  394. visible: times.length > 1,
  395. child: Container(
  396. height: 20 +
  397. (MediaQuery.of(context).size.width /
  398. 3 /
  399. 2.5) *
  400. ((times.length / 3).ceil()),
  401. color: Colors.white,
  402. child: Column(
  403. children: [
  404. Container(
  405. child: Text(
  406. '时间筛选',
  407. style: TextStyle(
  408. color: MyColors.c333333,
  409. fontSize: 15),
  410. ),
  411. margin: EdgeInsets.only(
  412. left: 18, top: 5, bottom: 5),
  413. height: 20,
  414. ),
  415. Expanded(
  416. child: GridView(
  417. gridDelegate:
  418. SliverGridDelegateWithFixedCrossAxisCount(
  419. crossAxisCount: 3,
  420. childAspectRatio: 3),
  421. children: getTimeItems(),
  422. physics: NeverScrollableScrollPhysics(),
  423. ),
  424. )
  425. ],
  426. crossAxisAlignment: CrossAxisAlignment.start,
  427. ),
  428. ),
  429. ),
  430. ],
  431. crossAxisAlignment: CrossAxisAlignment.start,
  432. ),
  433. ),
  434. ),
  435. )
  436. ],
  437. ),
  438. );
  439. });
  440. });
  441. }
  442. getTypeItems() {
  443. List<Widget> item = [];
  444. for (int i = 0; i < types.length; i++) {
  445. item.add(GestureDetector(
  446. onTap: () {
  447. ss(() {
  448. if (typeIndex == i) {
  449. typeIndex = -1;
  450. } else {
  451. typeIndex = i;
  452. }
  453. });
  454. // getTime(timeIndex);
  455. },
  456. behavior: HitTestBehavior.translucent,
  457. child: Container(
  458. alignment: Alignment.center,
  459. child: Container(
  460. decoration: BoxDecoration(
  461. color: i == typeIndex ? MyColors.cFFECEB : MyColors.cEDEDED,
  462. borderRadius: BorderRadius.all(Radius.circular(4))),
  463. height: 34,
  464. width: 100,
  465. child: Text(
  466. types[i],
  467. style: TextStyle(
  468. color: i == typeIndex ? MyColors.cFF4233 : MyColors.c666666,
  469. fontSize: 14),
  470. ),
  471. alignment: Alignment.center,
  472. ),
  473. ),
  474. ));
  475. }
  476. return item;
  477. }
  478. getTimeItems() {
  479. List<Widget> item = [];
  480. for (int i = 0; i < times.length; i++) {
  481. item.add(GestureDetector(
  482. onTap: () {
  483. ss(() {
  484. if (timeIndex == i) {
  485. timeIndex = -1;
  486. } else {
  487. timeIndex = i;
  488. }
  489. });
  490. if (timeIndex != 0) {
  491. getTime(timeIndex - 1);
  492. }
  493. },
  494. behavior: HitTestBehavior.translucent,
  495. child: Container(
  496. alignment: Alignment.center,
  497. child: Container(
  498. decoration: BoxDecoration(
  499. color: i == timeIndex ? MyColors.cFFECEB : MyColors.cEDEDED,
  500. borderRadius: BorderRadius.all(Radius.circular(4))),
  501. height: 34,
  502. width: 100,
  503. child: Text(
  504. times[i],
  505. style: TextStyle(
  506. color: i == timeIndex ? MyColors.cFF4233 : MyColors.c666666,
  507. fontSize: 14),
  508. ),
  509. alignment: Alignment.center,
  510. ),
  511. ),
  512. ));
  513. }
  514. return item;
  515. }
  516. void myFlow() {
  517. getUserWalletBalance((re, hE) {
  518. if (!hE) {
  519. UserBalanceEntity balance =
  520. UserBalanceEntity().fromJson(json.decode(re.data.toString()));
  521. MyCookie().userBean.balance = balance.data;
  522. setState(() {});
  523. }
  524. }, (e) {}, context);
  525. var conditions = [
  526. "user_uid==${MyCookie().getUID()}",
  527. // "paid_amount ${sTab == 0 ? '>' : '<'} 0"
  528. ];
  529. if (typeIndex != 0 && typeIndex != -1) {
  530. conditions.add("type IN ${typeIndex == 1 ? [
  531. flowTypeOrderCommodity,
  532. flowTypeOrderAnnualFee,
  533. flowTypeOrderVirtualProduct,
  534. flowTypeOrderThirdPlatform,
  535. flowTypeOrderOfflineTransfer,
  536. flowTypeScancodeAilyPay
  537. ] : [flowTypeShopCommission]}");
  538. }
  539. if (timeIndex != 0 && timeIndex != -1) {
  540. conditions.add("pay_time between ${getTime(timeIndex - 1)}");
  541. }
  542. MyDio().query({
  543. "key": "flow",
  544. "filters": {"conditions": conditions},
  545. "dims": flowDims,
  546. "order_by": ["id,DESC"],
  547. "paging": [page, 50]
  548. }, (response, hasError) {
  549. if (!hasError) {
  550. FlowBeanEntity entity =
  551. FlowBeanEntity().fromJson(json.decode(response.data.toString()));
  552. total = entity.data.total;
  553. totalAmount = entity.data.data.totalAmount;
  554. if (page == 1) {
  555. flow.clear();
  556. }
  557. try {
  558. flow.addAll(entity.data.data.records);
  559. } catch (e) {}
  560. setState(() {});
  561. }
  562. endRe(controller);
  563. }, (error) {});
  564. }
  565. void onRefresh() {
  566. page = 1;
  567. checkIfYouAreTheOwner();
  568. myFlow();
  569. }
  570. void onLoading() {
  571. page++;
  572. myFlow();
  573. }
  574. void checkIfYouAreTheOwner() {
  575. MyDio().query({
  576. "key": "shop",
  577. "filters": {
  578. "conditions": ["owner_uid == ${MyCookie().getUID()}"]
  579. },
  580. "dims": shopDims,
  581. "paging": [1, 5000]
  582. }, (response, hasError) {
  583. if (!hasError) {
  584. StoreBeanEntity entity =
  585. StoreBeanEntity().fromJson(json.decode(response.data.toString()));
  586. if (entity.data.data.length == 0) {
  587. types.remove('佣金');
  588. }
  589. setState(() {});
  590. }
  591. endRe(controller);
  592. }, (error) {});
  593. }
  594. }