wallet_page.dart 23 KB

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