order_page.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. import 'dart:convert';
  2. import 'package:bbyyy/beans/my_shop_bean_entity.dart';
  3. import 'package:bbyyy/beans/smart_order_bean_entity.dart';
  4. import 'package:bbyyy/https/MyDio.dart';
  5. import 'package:bbyyy/https/my_request.dart';
  6. import 'package:bbyyy/my_tools/const.dart';
  7. import 'package:bbyyy/my_tools/dims.dart';
  8. import 'package:bbyyy/my_tools/event_bus.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:flutter/material.dart';
  14. import 'package:flutter_slidable/flutter_slidable.dart';
  15. import 'package:flutter_svg/svg.dart';
  16. import 'package:pull_to_refresh/pull_to_refresh.dart';
  17. class OrderPage extends StatefulWidget {
  18. int index;
  19. OrderPage({this.index = 0});
  20. @override
  21. _OrderPageState createState() => _OrderPageState();
  22. }
  23. class _OrderPageState extends State<OrderPage> {
  24. int selectedIndex = 0;
  25. List<SmartOrderBeanDataData> orders = [];
  26. RefreshController controller = RefreshController(initialRefresh: true);
  27. int page = 1;
  28. List<int> myShopUIDs = [];
  29. @override
  30. void initState() {
  31. // TODO: implement initState
  32. super.initState();
  33. EventBus().on('刷新未付订单', (arg) {
  34. controller.requestRefresh();
  35. });
  36. selectedIndex = widget.index;
  37. }
  38. @override
  39. void dispose() {
  40. // TODO: implement dispose
  41. super.dispose();
  42. EventBus().off('刷新未付订单');
  43. checkUnpaidThirdPartyOrders();
  44. }
  45. @override
  46. Widget build(BuildContext context) {
  47. return Scaffold(
  48. backgroundColor: MyColors.cE7E7E7,
  49. body: Column(
  50. children: [
  51. MyViews().myAppBar('订单', context, []),
  52. Container(
  53. height: 40,
  54. color: Colors.white,
  55. child: Row(
  56. children: [
  57. GestureDetector(
  58. onTap: () {
  59. setState(() {
  60. selectedIndex = 0;
  61. page = 1;
  62. controller.requestRefresh();
  63. });
  64. },
  65. behavior: HitTestBehavior.translucent,
  66. child: Padding(
  67. padding: EdgeInsets.only(left: 10, right: 10),
  68. child: Column(
  69. children: [
  70. Text(
  71. '未收',
  72. style: TextStyle(
  73. color: selectedIndex == 0
  74. ? MyColors.cFF4233
  75. : MyColors.c666666,
  76. fontSize: 15),
  77. ),
  78. Container(
  79. height: 10,
  80. child: Visibility(
  81. child: SvgPicture.asset('images/svg/tab.svg'),
  82. visible: selectedIndex == 0,
  83. ),
  84. )
  85. ],
  86. mainAxisAlignment: MainAxisAlignment.end,
  87. ),
  88. ),
  89. ),
  90. GestureDetector(
  91. onTap: () {
  92. setState(() {
  93. selectedIndex = 1;
  94. page = 1;
  95. controller.requestRefresh();
  96. });
  97. },
  98. behavior: HitTestBehavior.translucent,
  99. child: Padding(
  100. padding: EdgeInsets.only(left: 10, right: 10),
  101. child: Column(
  102. children: [
  103. Text(
  104. '已收',
  105. style: TextStyle(
  106. color: selectedIndex == 1
  107. ? MyColors.cFF4233
  108. : MyColors.c666666,
  109. fontSize: 15),
  110. ),
  111. Container(
  112. height: 10,
  113. child: Visibility(
  114. child: SvgPicture.asset('images/svg/tab.svg'),
  115. visible: selectedIndex == 1,
  116. ),
  117. )
  118. ],
  119. mainAxisAlignment: MainAxisAlignment.end,
  120. ),
  121. ),
  122. ),
  123. GestureDetector(
  124. onTap: () {
  125. setState(() {
  126. selectedIndex = 2;
  127. page = 1;
  128. controller.requestRefresh();
  129. });
  130. },
  131. behavior: HitTestBehavior.translucent,
  132. child: Padding(
  133. padding: EdgeInsets.only(left: 10, right: 10),
  134. child: Column(
  135. children: [
  136. Text(
  137. '未付',
  138. style: TextStyle(
  139. color: selectedIndex == 2
  140. ? MyColors.cFF4233
  141. : MyColors.c666666,
  142. fontSize: 15),
  143. ),
  144. Container(
  145. height: 10,
  146. child: Visibility(
  147. child: SvgPicture.asset('images/svg/tab.svg'),
  148. visible: selectedIndex == 2,
  149. ),
  150. )
  151. ],
  152. mainAxisAlignment: MainAxisAlignment.end,
  153. ),
  154. ),
  155. )
  156. ],
  157. mainAxisAlignment: MainAxisAlignment.spaceAround,
  158. ),
  159. ),
  160. Expanded(
  161. child: SmartRefresher(
  162. controller: controller,
  163. onLoading: onLoading,
  164. onRefresh: onRefresh,
  165. enablePullUp: true,
  166. enablePullDown: true,
  167. child: orders.length == 0
  168. ? SingleChildScrollView(child: noData())
  169. : ListView.builder(
  170. itemBuilder: (c, index) {
  171. return Slidable(
  172. child: MyViews().getNoPayGoodsItem(
  173. orders[index], context, -1, -1),
  174. actionPane: SlidableDrawerActionPane(),
  175. enabled: selectedIndex == 0 ||
  176. (orders[index].type == orderTypeOfflineTransfer &&
  177. orders[index].buyerUid ==
  178. MyCookie().getUID()) ||
  179. orders[index].buyerUid == MyCookie().getUID(),
  180. actionExtentRatio: 0.25,
  181. secondaryActions: <Widget>[
  182. SlideAction(
  183. child: Container(
  184. child: Container(
  185. decoration: BoxDecoration(
  186. borderRadius: BorderRadius.circular(30),
  187. color: MyColors.cFF4233,
  188. ),
  189. height: 60,
  190. width: 60,
  191. child: SvgPicture.asset(
  192. 'images/svg/del.svg',
  193. height: 40,
  194. width: 40,
  195. ),
  196. alignment: Alignment.center,
  197. ),
  198. ),
  199. onTap: () {
  200. showSimpleDialog(
  201. '将删除订单(${orders[index].uid})', context, () {
  202. Navigator.pop(context);
  203. deleteOrder(orders[index]);
  204. });
  205. },
  206. )
  207. ],
  208. );
  209. },
  210. itemCount: orders.length,
  211. padding: EdgeInsets.only(top: 10),
  212. ),
  213. ),
  214. ),
  215. ],
  216. ),
  217. );
  218. }
  219. void onLoading() {
  220. page++;
  221. checkMyStore();
  222. }
  223. void onRefresh() {
  224. page = 1;
  225. checkMyStore();
  226. }
  227. checkingOrder() {
  228. var conditions = [];
  229. if (selectedIndex == 0) {
  230. conditions.add("state == $orderStateUnpaid");
  231. conditions.add('seller_uid == ${MyCookie().getUID()}');
  232. } else if (selectedIndex == 1) {
  233. conditions.add("state == $orderStatePaid");
  234. conditions.add('seller_uid == ${MyCookie().getUID()}');
  235. } else {
  236. conditions.add("state == $orderStateUnpaid");
  237. conditions.add('buyer_uid==0');
  238. conditions.add('buyer_name LIKE ${MyCookie().getName()}');
  239. conditions.add('shop_uid IN $myShopUIDs');
  240. }
  241. var filters;
  242. if (selectedIndex == 2) {
  243. filters = {
  244. "conditions": conditions,
  245. "or": true,
  246. "filters": [
  247. {
  248. "conditions": [
  249. "state == $orderStateUnpaid",
  250. 'buyer_uid==${MyCookie().getUID()}'
  251. ]
  252. }
  253. ]
  254. };
  255. } else {
  256. filters = {"conditions": conditions};
  257. }
  258. MyDio().query({
  259. "key": "order",
  260. "filters": filters,
  261. "dims": orderDims,
  262. "paging": [page, 20],
  263. "order_by": ["create_time,DESC"]
  264. }, (response, hasError) {
  265. if (!hasError) {
  266. SmartOrderBeanEntity entity = SmartOrderBeanEntity()
  267. .fromJson(json.decode(response.data.toString()));
  268. if (page == 1) {
  269. orders.clear();
  270. }
  271. orders.addAll(entity.data.data);
  272. setState(() {});
  273. }
  274. endRe(controller);
  275. }, (error) {});
  276. }
  277. checkMyStore() {
  278. var dJson;
  279. var conditions1 = [
  280. "role!=$shopUserOwner",
  281. "user_uid==${MyCookie().getUID()}",
  282. "review_state==1"
  283. ];
  284. var conditions2 = [
  285. "role==$shopUserOwner",
  286. "user_uid==${MyCookie().getUID()}"
  287. ];
  288. conditions1.add('private_shop==true');
  289. dJson = {
  290. "key": "shop_user",
  291. "filters": {
  292. "or": true,
  293. "conditions": conditions1,
  294. "filters": [
  295. {"conditions": conditions2}
  296. ]
  297. },
  298. "dims": shopUserDims,
  299. "paging": [page, 1000],
  300. "order_by": ["shop_name,DESC"]
  301. };
  302. MyDio().query(dJson, (response, hasError) {
  303. if (!hasError) {
  304. MyShopBeanEntity entity =
  305. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  306. myShopUIDs.clear();
  307. entity.data.data.forEach((element) {
  308. myShopUIDs.add(element.shopUid);
  309. });
  310. if(myShopUIDs.length==0){
  311. return;
  312. }
  313. checkingOrder();
  314. }
  315. }, (error) {});
  316. }
  317. void deleteOrder(SmartOrderBeanDataData order) {
  318. MyDio().del({
  319. 'key': 'order',
  320. 'ids': [order.id]
  321. }, (response, hasError) {
  322. if (!hasError) {
  323. orders.remove(order);
  324. setState(() {});
  325. }
  326. }, (error) {});
  327. }
  328. }