referrer_flow_page.dart 17 KB

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