referrer_flow_page.dart 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  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}(${widget.data.recommenderUid})',
  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. int timeIndex = 0;
  174. void showSelect() {
  175. showModalBottomSheet(
  176. backgroundColor: Colors.transparent,
  177. context: context,
  178. builder: (context) {
  179. return StatefulBuilder(builder: (c, s) {
  180. ss = s;
  181. return Container(
  182. color: Colors.transparent,
  183. height: 240 +
  184. (MediaQuery.of(context).size.width / 3 / 2.5) *
  185. ((types.length / 3).ceil()),
  186. child: Column(
  187. children: [
  188. Container(
  189. padding:
  190. EdgeInsets.only(left: 10, right: 10, top: 3, bottom: 0),
  191. decoration: BoxDecoration(
  192. color: Colors.white,
  193. borderRadius: BorderRadius.only(
  194. topLeft: Radius.circular(8),
  195. topRight: Radius.circular(8))),
  196. child: Row(
  197. children: [
  198. GestureDetector(
  199. onTap: () {
  200. Navigator.pop(context);
  201. },
  202. behavior: HitTestBehavior.translucent,
  203. child: Padding(
  204. padding: const EdgeInsets.all(8.0),
  205. child: Text(
  206. '取消',
  207. style: TextStyle(
  208. color: MyColors.cFF4233, fontSize: 14),
  209. ),
  210. ),
  211. ),
  212. Text(
  213. '类型筛选',
  214. style:
  215. TextStyle(color: MyColors.c333333, fontSize: 16),
  216. ),
  217. GestureDetector(
  218. child: Padding(
  219. padding: const EdgeInsets.all(8.0),
  220. child: Text(
  221. '确定',
  222. style: TextStyle(
  223. color: MyColors.cFF4233, fontSize: 14),
  224. ),
  225. ),
  226. behavior: HitTestBehavior.translucent,
  227. onTap: () {
  228. Navigator.pop(context);
  229. controller.requestRefresh();
  230. },
  231. ),
  232. ],
  233. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  234. ),
  235. height: 39.5,
  236. ),
  237. Container(
  238. height: 0.5,
  239. color: MyColors.cF5F5F5,
  240. ),
  241. Expanded(
  242. child: Container(
  243. color: Colors.white,
  244. child: SingleChildScrollView(
  245. child: Column(
  246. children: [
  247. Visibility(
  248. visible: types.length > 1,
  249. child: Container(
  250. height: 20 +
  251. (MediaQuery.of(context).size.width /
  252. 3 /
  253. 2.5) *
  254. ((types.length / 3).ceil()),
  255. color: Colors.white,
  256. child: Column(
  257. children: [
  258. Container(
  259. child: Text(
  260. '类型筛选',
  261. style: TextStyle(
  262. color: MyColors.c333333,
  263. fontSize: 15),
  264. ),
  265. margin: EdgeInsets.only(
  266. left: 18, top: 5, bottom: 5),
  267. height: 20,
  268. ),
  269. Expanded(
  270. child: GridView(
  271. gridDelegate:
  272. SliverGridDelegateWithFixedCrossAxisCount(
  273. crossAxisCount: 3,
  274. childAspectRatio: 3),
  275. children: getTypeItems(),
  276. physics: NeverScrollableScrollPhysics(),
  277. ),
  278. )
  279. ],
  280. crossAxisAlignment: CrossAxisAlignment.start,
  281. ),
  282. ),
  283. ),
  284. Visibility(
  285. visible: times.length > 1,
  286. child: Container(
  287. height: 20 +
  288. (MediaQuery.of(context).size.width /
  289. 3 /
  290. 2.5) *
  291. ((times.length / 3).ceil()),
  292. color: Colors.white,
  293. child: Column(
  294. children: [
  295. Container(
  296. child: Text(
  297. '时间筛选',
  298. style: TextStyle(
  299. color: MyColors.c333333,
  300. fontSize: 15),
  301. ),
  302. margin: EdgeInsets.only(
  303. left: 18, top: 5, bottom: 5),
  304. height: 20,
  305. ),
  306. Expanded(
  307. child: GridView(
  308. gridDelegate:
  309. SliverGridDelegateWithFixedCrossAxisCount(
  310. crossAxisCount: 3,
  311. childAspectRatio: 3),
  312. children: getTimeItems(),
  313. physics: NeverScrollableScrollPhysics(),
  314. ),
  315. )
  316. ],
  317. crossAxisAlignment: CrossAxisAlignment.start,
  318. ),
  319. ),
  320. ),
  321. ],
  322. crossAxisAlignment: CrossAxisAlignment.start,
  323. ),
  324. ),
  325. ),
  326. )
  327. ],
  328. ),
  329. );
  330. });
  331. });
  332. }
  333. getTypeItems() {
  334. List<Widget> item = [];
  335. for (int i = 0; i < types.length; i++) {
  336. item.add(GestureDetector(
  337. onTap: () {
  338. ss(() {
  339. if (typeIndex == i) {
  340. typeIndex = -1;
  341. } else {
  342. typeIndex = i;
  343. }
  344. });
  345. // getTime(timeIndex);
  346. },
  347. behavior: HitTestBehavior.translucent,
  348. child: Container(
  349. alignment: Alignment.center,
  350. child: Container(
  351. decoration: BoxDecoration(
  352. color: i == typeIndex ? MyColors.cFFECEB : MyColors.cEDEDED,
  353. borderRadius: BorderRadius.all(Radius.circular(4))),
  354. height: 34,
  355. width: 100,
  356. child: Text(
  357. types[i],
  358. style: TextStyle(
  359. color: i == typeIndex ? MyColors.cFF4233 : MyColors.c666666,
  360. fontSize: 14),
  361. ),
  362. alignment: Alignment.center,
  363. ),
  364. ),
  365. ));
  366. }
  367. return item;
  368. }
  369. getTimeItems() {
  370. List<Widget> item = [];
  371. for (int i = 0; i < times.length; i++) {
  372. item.add(GestureDetector(
  373. onTap: () {
  374. ss(() {
  375. if (timeIndex == i) {
  376. timeIndex = -1;
  377. } else {
  378. timeIndex = i;
  379. }
  380. });
  381. if (timeIndex != 0) {
  382. getTime(timeIndex - 1);
  383. }
  384. },
  385. behavior: HitTestBehavior.translucent,
  386. child: Container(
  387. alignment: Alignment.center,
  388. child: Container(
  389. decoration: BoxDecoration(
  390. color: i == timeIndex ? MyColors.cFFECEB : MyColors.cEDEDED,
  391. borderRadius: BorderRadius.all(Radius.circular(4))),
  392. height: 34,
  393. width: 100,
  394. child: Text(
  395. times[i],
  396. style: TextStyle(
  397. color: i == timeIndex ? MyColors.cFF4233 : MyColors.c666666,
  398. fontSize: 14),
  399. ),
  400. alignment: Alignment.center,
  401. ),
  402. ),
  403. ));
  404. }
  405. return item;
  406. }
  407. void myFlow() {
  408. var conditions = [
  409. // "user_uid==${MyCookie().getUID()}",
  410. 'recommender_uid == ${widget.data.recommenderUid}',
  411. 'paid_amount > 0 '
  412. // "paid_amount ${sTab == 0 ? '>' : '<'} 0"
  413. ];
  414. if (typeIndex != 0 && typeIndex != -1) {
  415. conditions.add("type IN ${typeIndex == 1 ? [
  416. flowTypeOrderCommodity,
  417. flowTypeOrderAnnualFee,
  418. flowTypeOrderVirtualProduct,
  419. flowTypeOrderThirdPlatform,
  420. flowTypeOrderOfflineTransfer,
  421. flowTypeScancodeAilyPay
  422. ] : [flowTypeShopCommission]}");
  423. }
  424. if (timeIndex != 0 && timeIndex != -1) {
  425. conditions.add("pay_time between ${getTime(timeIndex - 1)}");
  426. }
  427. MyDio().query({
  428. "key": "flow",
  429. "filters": {"conditions": conditions},
  430. "dims": flowDims,
  431. "order_by": ["id,DESC"],
  432. "paging": [page, 50]
  433. }, (response, hasError) {
  434. if (!hasError) {
  435. FlowBeanEntity entity =
  436. FlowBeanEntity().fromJson(json.decode(response.data.toString()));
  437. total = entity.data.total;
  438. totalAmount = entity.data.data.totalAmount;
  439. if (page == 1) {
  440. flow.clear();
  441. }
  442. try {
  443. flow.addAll(entity.data.data.records);
  444. } catch (e) {}
  445. setState(() {});
  446. }
  447. endRe(controller);
  448. }, (error) {});
  449. }
  450. void onRefresh() {
  451. page = 1;
  452. checkIfYouAreTheOwner();
  453. myFlow();
  454. }
  455. void onLoading() {
  456. page++;
  457. myFlow();
  458. }
  459. void checkIfYouAreTheOwner() {
  460. MyDio().query({
  461. "key": "shop",
  462. "filters": {
  463. "conditions": ["owner_uid == ${MyCookie().getUID()}"]
  464. },
  465. "dims": shopDims,
  466. "paging": [1, 5000]
  467. }, (response, hasError) {
  468. if (!hasError) {
  469. StoreBeanEntity entity =
  470. StoreBeanEntity().fromJson(json.decode(response.data.toString()));
  471. if (entity.data.data.length == 0) {
  472. types.remove('佣金');
  473. }
  474. setState(() {});
  475. }
  476. endRe(controller);
  477. }, (error) {});
  478. }
  479. }