wallet_page.dart 23 KB

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