wallet_page.dart 23 KB

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