referrer_flow_page.dart 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. import 'dart:convert';
  2. import 'package:bbyyy/beans/flow_bean_entity.dart';
  3. import 'package:bbyyy/beans/my_shop_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/https/url.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. import 'dart:math' as math;
  19. class ReferrerFlowPage extends StatefulWidget {
  20. MyShopBeanDataData data;
  21. ReferrerFlowPage(this.data);
  22. @override
  23. _ReferrerFlowPageState createState() => _ReferrerFlowPageState();
  24. }
  25. class _ReferrerFlowPageState extends State<ReferrerFlowPage> {
  26. int page = 1;
  27. int total = 0;
  28. double totalAmount = 0.0;
  29. RefreshController controller = RefreshController(initialRefresh: true);
  30. List<FlowBeanDataDataRecords> flow = [];
  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: 220,
  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. margin: EdgeInsets.only(top: 10),
  106. child: Row(
  107. children: [
  108. ClipRRect(
  109. child: MyViews()
  110. .netImg(imgURL(widget.data.recommenderPic), 36, 36),
  111. borderRadius: BorderRadius.circular(18),
  112. ),
  113. Container(
  114. margin: EdgeInsets.only(left: 10),
  115. child: Text(
  116. '${widget.data.recommenderName}(${hideUID(widget.data.recommenderUid.toString())})',
  117. style: TextStyle(color: Colors.white, fontSize: 15),
  118. ),
  119. ),
  120. ],
  121. mainAxisAlignment: MainAxisAlignment.center,
  122. ),
  123. alignment: Alignment.center,
  124. ),
  125. // Container(
  126. // margin: EdgeInsets.only(top: 10),
  127. // child: Center(
  128. // child: Text(
  129. // '总额:$totalAmount',
  130. // style: TextStyle(color: Colors.white, fontSize: 20),
  131. // ),
  132. // ),
  133. // ),
  134. Container(
  135. margin: EdgeInsets.only(top: 10),
  136. child: Center(
  137. child: Text(
  138. '共$total笔',
  139. style: TextStyle(color: Colors.white, fontSize: 20),
  140. ),
  141. ),
  142. ),
  143. ],
  144. )
  145. ],
  146. ),
  147. Expanded(
  148. child: SmartRefresher(
  149. controller: controller,
  150. onRefresh: onRefresh,
  151. onLoading: onLoading,
  152. enablePullDown: true,
  153. enablePullUp: true,
  154. child: flow.length == 0
  155. ? SingleChildScrollView(child: noData())
  156. : ListView.builder(
  157. itemBuilder: (c, index) {
  158. return MyViews().getWalletItem(flow[index], context);
  159. },
  160. padding: EdgeInsets.only(top: 13),
  161. itemCount: flow.length,
  162. ),
  163. ),
  164. ),
  165. ],
  166. ),
  167. );
  168. }
  169. StateSetter ss;
  170. List<String> types = ['全部', '订单', '佣金','缴费'];
  171. int typeIndex = 0;
  172. // List<String> times = ['全部', '今天', '昨天', '本周', '上周', '本月'];
  173. List<String> times = ['今天', '昨天', '本周', '上周'];
  174. int timeIndex = -1;
  175. void showSelect() {
  176. showModalBottomSheet(
  177. backgroundColor: Colors.transparent,
  178. context: context,
  179. builder: (context) {
  180. return StatefulBuilder(builder: (c, s) {
  181. ss = s;
  182. return Container(
  183. color: Colors.transparent,
  184. height: 240 +
  185. (MediaQuery.of(context).size.width / 3 / 2.5) *
  186. ((types.length / 3).ceil()),
  187. child: Column(
  188. children: [
  189. Container(
  190. padding:
  191. EdgeInsets.only(left: 10, right: 10, top: 3, bottom: 0),
  192. decoration: BoxDecoration(
  193. color: Colors.white,
  194. borderRadius: BorderRadius.only(
  195. topLeft: Radius.circular(8),
  196. topRight: Radius.circular(8))),
  197. child: Row(
  198. children: [
  199. GestureDetector(
  200. onTap: () {
  201. Navigator.pop(context);
  202. },
  203. behavior: HitTestBehavior.translucent,
  204. child: Padding(
  205. padding: const EdgeInsets.all(8.0),
  206. child: Text(
  207. '取消',
  208. style: TextStyle(
  209. color: MyColors.cFF4233, fontSize: 14),
  210. ),
  211. ),
  212. ),
  213. Text(
  214. '类型筛选',
  215. style:
  216. TextStyle(color: MyColors.c333333, fontSize: 16),
  217. ),
  218. GestureDetector(
  219. child: Padding(
  220. padding: const EdgeInsets.all(8.0),
  221. child: Text(
  222. '确定',
  223. style: TextStyle(
  224. color: MyColors.cFF4233, fontSize: 14),
  225. ),
  226. ),
  227. behavior: HitTestBehavior.translucent,
  228. onTap: () {
  229. Navigator.pop(context);
  230. controller.requestRefresh();
  231. },
  232. ),
  233. ],
  234. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  235. ),
  236. height: 39.5,
  237. ),
  238. Container(
  239. height: 0.5,
  240. color: MyColors.cF5F5F5,
  241. ),
  242. Expanded(
  243. child: Container(
  244. color: Colors.white,
  245. child: SingleChildScrollView(
  246. child: Column(
  247. children: [
  248. Visibility(
  249. visible: types.length > 1,
  250. child: Container(
  251. height: 20 +
  252. (MediaQuery.of(context).size.width /
  253. 3 /
  254. 2.5) *
  255. ((types.length / 3).ceil()),
  256. color: Colors.white,
  257. child: Column(
  258. children: [
  259. Container(
  260. child: Text(
  261. '类型筛选',
  262. style: TextStyle(
  263. color: MyColors.c333333,
  264. fontSize: 15),
  265. ),
  266. margin: EdgeInsets.only(
  267. left: 18, top: 5, bottom: 5),
  268. height: 20,
  269. ),
  270. Expanded(
  271. child: GridView(
  272. gridDelegate:
  273. SliverGridDelegateWithFixedCrossAxisCount(
  274. crossAxisCount: 3,
  275. childAspectRatio: 3),
  276. children: getTypeItems(),
  277. physics: NeverScrollableScrollPhysics(),
  278. ),
  279. )
  280. ],
  281. crossAxisAlignment: CrossAxisAlignment.start,
  282. ),
  283. ),
  284. ),
  285. Visibility(
  286. visible: times.length > 1,
  287. child: Container(
  288. height: 20 +
  289. (MediaQuery.of(context).size.width /
  290. 3 /
  291. 2.5) *
  292. ((times.length / 3).ceil()),
  293. color: Colors.white,
  294. child: Column(
  295. children: [
  296. Container(
  297. child: Text(
  298. '时间筛选',
  299. style: TextStyle(
  300. color: MyColors.c333333,
  301. fontSize: 15),
  302. ),
  303. margin: EdgeInsets.only(
  304. left: 18, top: 5, bottom: 5),
  305. height: 20,
  306. ),
  307. Expanded(
  308. child: GridView(
  309. gridDelegate:
  310. SliverGridDelegateWithFixedCrossAxisCount(
  311. crossAxisCount: 3,
  312. childAspectRatio: 3),
  313. children: getTimeItems(),
  314. physics: NeverScrollableScrollPhysics(),
  315. ),
  316. )
  317. ],
  318. crossAxisAlignment: CrossAxisAlignment.start,
  319. ),
  320. ),
  321. ),
  322. ],
  323. crossAxisAlignment: CrossAxisAlignment.start,
  324. ),
  325. ),
  326. ),
  327. )
  328. ],
  329. ),
  330. );
  331. });
  332. });
  333. }
  334. getTypeItems() {
  335. List<Widget> item = [];
  336. for (int i = 0; i < types.length; i++) {
  337. item.add(GestureDetector(
  338. onTap: () {
  339. ss(() {
  340. if (typeIndex == i) {
  341. typeIndex = -1;
  342. } else {
  343. typeIndex = i;
  344. }
  345. });
  346. // getTime(timeIndex);
  347. },
  348. behavior: HitTestBehavior.translucent,
  349. child: Container(
  350. alignment: Alignment.center,
  351. child: Container(
  352. decoration: BoxDecoration(
  353. color: i == typeIndex ? MyColors.cFFECEB : MyColors.cEDEDED,
  354. borderRadius: BorderRadius.all(Radius.circular(4))),
  355. height: 34,
  356. width: 100,
  357. child: Text(
  358. types[i],
  359. style: TextStyle(
  360. color: i == typeIndex ? MyColors.cFF4233 : MyColors.c666666,
  361. fontSize: 14),
  362. ),
  363. alignment: Alignment.center,
  364. ),
  365. ),
  366. ));
  367. }
  368. return item;
  369. }
  370. getTimeItems() {
  371. List<Widget> item = [];
  372. for (int i = 0; i < times.length; i++) {
  373. item.add(GestureDetector(
  374. onTap: () {
  375. ss(() {
  376. if (timeIndex == i) {
  377. timeIndex = -1;
  378. } else {
  379. timeIndex = i;
  380. }
  381. });
  382. if (timeIndex != -1) {
  383. getTime(timeIndex);
  384. }
  385. },
  386. behavior: HitTestBehavior.translucent,
  387. child: Container(
  388. alignment: Alignment.center,
  389. child: Container(
  390. decoration: BoxDecoration(
  391. color: i == timeIndex ? MyColors.cFFECEB : MyColors.cEDEDED,
  392. borderRadius: BorderRadius.all(Radius.circular(4))),
  393. height: 34,
  394. width: 100,
  395. child: Text(
  396. times[i],
  397. style: TextStyle(
  398. color: i == timeIndex ? MyColors.cFF4233 : MyColors.c666666,
  399. fontSize: 14),
  400. ),
  401. alignment: Alignment.center,
  402. ),
  403. ),
  404. ));
  405. }
  406. return item;
  407. }
  408. void myFlow() {
  409. var conditions = [
  410. // "user_uid==${MyCookie().getUID()}",
  411. 'recommender_uid == ${widget.data.recommenderUid}',
  412. 'paid_amount > 0 '
  413. // "paid_amount ${sTab == 0 ? '>' : '<'} 0"
  414. ];
  415. if (typeIndex != 0 && typeIndex != -1) {
  416. switch (typeIndex){
  417. case 1:
  418. conditions.add("type IN ${[
  419. flowTypeOrderCommodity,
  420. flowTypeOrderAnnualFee,
  421. flowTypeOrderVirtualProduct,
  422. flowTypeOrderThirdPlatform,
  423. flowTypeOrderOfflineTransfer,
  424. flowTypeScancodeAilyPay
  425. ]}");
  426. break;
  427. case 2:
  428. conditions.add("type IN ${ [flowTypeShopCommission]}");
  429. break;
  430. case 3:
  431. conditions.add("type IN ${ [flowTypePlatformFee]}");
  432. break;
  433. }
  434. }
  435. if (timeIndex != -1) {
  436. conditions.add("pay_time between ${getTime(timeIndex)}");
  437. }else{
  438. conditions.add("pay_time between ${getTime(6)}");
  439. }
  440. MyDio().query({
  441. "key": "flow",
  442. "filters": {"conditions": conditions},
  443. "dims": flowDims,
  444. "order_by": ["id,DESC"],
  445. "paging": [page, 50]
  446. }, (response, hasError) {
  447. if (!hasError) {
  448. FlowBeanEntity entity =
  449. FlowBeanEntity().fromJson(json.decode(response.data.toString()));
  450. total = entity.data.total;
  451. totalAmount = entity.data.data.totalAmount;
  452. if (page == 1) {
  453. flow.clear();
  454. }
  455. try {
  456. flow.addAll(entity.data.data.records);
  457. } catch (e) {}
  458. setState(() {});
  459. }
  460. endRe(controller);
  461. }, (error) {});
  462. }
  463. void onRefresh() {
  464. page = 1;
  465. checkIfYouAreTheOwner();
  466. myFlow();
  467. }
  468. void onLoading() {
  469. page++;
  470. myFlow();
  471. }
  472. void checkIfYouAreTheOwner() {
  473. MyDio().query({
  474. "key": "shop",
  475. "filters": {
  476. "conditions": ["owner_uid == ${MyCookie().getUID()}"]
  477. },
  478. "dims": shopDims,
  479. "paging": [1, 5000]
  480. }, (response, hasError) {
  481. if (!hasError) {
  482. StoreBeanEntity entity =
  483. StoreBeanEntity().fromJson(json.decode(response.data.toString()));
  484. if (entity.data.data.length == 0) {
  485. types.remove('佣金');
  486. }
  487. setState(() {});
  488. }
  489. endRe(controller);
  490. }, (error) {});
  491. }
  492. }