wallet_page.dart 23 KB

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