index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. var app = getApp();
  2. var token = wx.getStorageSync('token');
  3. let touchDotX = 0; //X按下时坐标
  4. let touchDotY = 0; //y按下时坐标
  5. let interval; //计时器
  6. let time = 0;
  7. Page({
  8. data: {
  9. current: 2,
  10. option1: [{
  11. text: '全部区域',
  12. value: 0,
  13. areaID: ''
  14. }],
  15. value1: 0, //第一个显示什么
  16. active: 0, //当前tab切换的下标
  17. bike: [], //车辆
  18. work_order: [], //工单
  19. user: [], //用户
  20. orderProfit: [], //收益
  21. order: [], //订单
  22. bikeList: [], //车辆
  23. work_orderList: [], //工单
  24. userList: [], //用户
  25. orderProfitList: [], //收益
  26. orderList: [], //订单
  27. areaID: '', //首页的区域变量
  28. page: 1, //当前页数
  29. name: '', //车辆管理的局部筛选
  30. // curPage: 1, //默认显示普通订单
  31. userUrl: '',
  32. screenHeight: '', //屏幕可视高度
  33. },
  34. // 触摸开始事件
  35. touchStart: function(e) {
  36. let that = this;
  37. touchDotX = e.touches[0].pageX; // 获取触摸时的原点
  38. touchDotY = e.touches[0].pageY;
  39. // 使用js计时器记录时间
  40. interval = setInterval(function() {
  41. that.setData({
  42. curPage: 1, //默认显示普通订单
  43. userUrl: ''
  44. })
  45. }, 1000)
  46. },
  47. // 触摸结束事件
  48. touchEnd: function(e) {
  49. var that = this;
  50. let touchMoveX = e.changedTouches[0].pageX;
  51. let touchMoveY = e.changedTouches[0].pageY;
  52. let tmX = touchMoveX - touchDotX;
  53. let tmY = touchMoveY - touchDotY;
  54. if (time < 20) {
  55. let absX = Math.abs(tmX);
  56. let absY = Math.abs(tmY);
  57. if (absX > 2 * absY) {
  58. if (tmX < 0) {
  59. console.log(that.data.active)
  60. if (that.data.active >= 4) return
  61. that.setData({
  62. active: that.data.active + 1
  63. })
  64. that.goTop();
  65. that.screen();
  66. } else {
  67. console.log(that.data.active)
  68. if (that.data.active <= 0) return
  69. that.setData({
  70. active: that.data.active - 1
  71. })
  72. that.goTop();
  73. that.screen()
  74. }
  75. }
  76. }
  77. clearInterval(interval); // 清除setInterval
  78. time = 0;
  79. },
  80. goTop: function(e) { // 一键回到顶部
  81. if (wx.pageScrollTo) {
  82. wx.pageScrollTo({
  83. scrollTop: 0
  84. })
  85. }
  86. },
  87. onLoad: function(options) {
  88. var that = this;
  89. that.setData({
  90. screenHeight: app.globalData.screenHeight
  91. })
  92. app.request('index', '', 'GET').then(res => {
  93. console.log(res.data)
  94. var data = res.data
  95. for (var i = 0; i < data.wx_area.length; i++) {
  96. data.wx_area[i].value = i + 1
  97. }
  98. console.log(data)
  99. that.setData({
  100. option1: that.data.option1.concat(data.wx_area)
  101. })
  102. })
  103. this.tongji();
  104. this.list()
  105. },
  106. scanCode() {
  107. wx.redirectTo({
  108. url: '/pages/logs/logs?scan=' + 1,
  109. })
  110. // wx.setStorageSync('scan', 1)
  111. },
  112. //点击手机号拨打用户电话
  113. phoneCall(e) {
  114. console.log(33333)
  115. wx.makePhoneCall({
  116. phoneNumber: e.currentTarget.dataset.phone
  117. })
  118. },
  119. choose(e) {
  120. var that = this;
  121. this.setData({
  122. curPage: e.currentTarget.dataset.idx
  123. })
  124. },
  125. // choose(e) {
  126. // var that = this;
  127. // this.setData({
  128. // curPage: e.currentTarget.dataset.idx
  129. // })
  130. // if (e.currentTarget.dataset.idx == 1) {
  131. // app.request('order/list/?page=1', '', 'GET').then(res => {
  132. // console.log(res, '订单')
  133. // that.setData({
  134. // orderList: res.data.data
  135. // })
  136. // })
  137. // } else {
  138. // app.request('orderRent/list/?page=1', '', 'GET').then(res => {
  139. // console.log(res, '日租订单')
  140. // that.setData({
  141. // orderList: res.data.data
  142. // })
  143. // })
  144. // }
  145. // },
  146. tongji: function() {
  147. var that = this;
  148. var areaId = ''
  149. if (that.data.areaID != '') {
  150. areaId = '?put_area_id=' + that.data.areaID
  151. }
  152. app.request('user/userStatistics' + areaId, '', 'GET').then(res => {
  153. //用户统计
  154. console.log(res)
  155. that.setData({
  156. user: res.data
  157. })
  158. })
  159. app.request('bike/statistics' + areaId, '', 'GET').then(res => {
  160. console.log(res)
  161. //车辆统计
  162. that.setData({
  163. bike: res.data
  164. })
  165. })
  166. app.request('order/orderStatistics' + areaId, '', 'GET').then(res => {
  167. //订单统计
  168. console.log(res)
  169. that.setData({
  170. order: res.data
  171. })
  172. })
  173. app.request('work_order/workOrderStatistics' + areaId, '', 'POST').then(res => {
  174. //工单统计
  175. console.log(res)
  176. that.setData({
  177. work_order: res.data
  178. })
  179. })
  180. app.request('order/orderProfitStatistics' + areaId, '', 'GET').then(res => {
  181. //收益统计
  182. console.log(res)
  183. that.setData({
  184. orderProfit: res.data
  185. })
  186. })
  187. },
  188. list: function() {
  189. //获取所有tab切换的值
  190. var that = this;
  191. app.request('user/list/?page=1', '', 'GET').then(res => {
  192. console.log(res, '用户')
  193. that.setData({
  194. userList: res.data.data
  195. })
  196. })
  197. app.request('bike/list/?page=1', '', 'GET').then(res => {
  198. console.log(res, '车辆')
  199. that.setData({
  200. bikeList: res.data.data
  201. })
  202. })
  203. app.request('order/list/?page=1', '', 'GET').then(res => {
  204. console.log(res, '订单')
  205. that.setData({
  206. orderList: res.data.data
  207. })
  208. })
  209. app.request('work_order/list?page=1', '', 'GET').then(res => {
  210. console.log(res, '工单')
  211. that.setData({
  212. work_orderList: res.data.data
  213. })
  214. })
  215. },
  216. localscreen: function(e) {
  217. //车辆管理的局部筛选
  218. this.setData({
  219. name: e.currentTarget.dataset.name
  220. });
  221. this.screen();
  222. },
  223. //切换tab按钮
  224. onChange(event) {
  225. var that = this;
  226. console.log(that.data.areaID)
  227. that.setData({
  228. active: event.detail.name,
  229. page: 1
  230. })
  231. that.goTop();
  232. that.screen();
  233. if (event.detail.name == 4) {
  234. app.request('work_order/list?page=1', '', 'GET').then(res => {
  235. console.log(res, '工单')
  236. that.setData({
  237. work_orderList: res.data.data
  238. })
  239. })
  240. }
  241. },
  242. screen1: function(e) {
  243. console.log(e)
  244. var index = Number(e.currentTarget.dataset.index)
  245. this.setData({
  246. active: index,
  247. page: 1
  248. })
  249. },
  250. skipNext() {
  251. wx.navigateTo({
  252. url: '/pages/statistics/statistics',
  253. })
  254. },
  255. //选择区域事件
  256. change(event) {
  257. var that = this;
  258. this.setData({
  259. page: 1
  260. })
  261. var options = this.data.option1;
  262. var areaId = options[event.detail].areaID
  263. var url = '';
  264. this.setData({
  265. areaID: areaId
  266. })
  267. if (this.data.active == 0) {
  268. that.tongji()
  269. } else if (this.data.active == 1) {
  270. url = 'user/userStatistics?put_area_id=' + areaId
  271. } else if (this.data.active == 2) {
  272. url = 'bike/statistics?put_area_id=' + areaId
  273. } else if (this.data.active == 3) {
  274. url = 'order/orderStatistics?put_area_id=' + areaId
  275. } else if (this.data.active == 4) {
  276. url = {
  277. put_area_id: areaId
  278. }
  279. app.request('work_order/workOrderStatistics', url, 'POST').then(res => {
  280. //工单统计
  281. console.log(res)
  282. that.setData({
  283. work_order: res.data
  284. })
  285. })
  286. }
  287. that.screen()
  288. if (that.data.active == 1 || that.data.active == 2 || that.data.active == 3) {
  289. app.request(url, '', 'GET').then(res => {
  290. //用户统计
  291. console.log(res)
  292. if (this.data.active == 1) {
  293. that.setData({
  294. user: res.data
  295. })
  296. } else if (this.data.active == 2) {
  297. that.setData({
  298. bike: res.data
  299. })
  300. } else if (this.data.active == 3) {
  301. that.setData({
  302. order: res.data
  303. })
  304. }
  305. })
  306. }
  307. },
  308. screen: function() {
  309. //点击筛选 点击区域 上拉刷新的公共方法
  310. var that = this;
  311. var active = that.data.active;
  312. if (active == 0) {
  313. //当前是全部管理不需要加载
  314. return;
  315. }
  316. wx.showLoading({
  317. title: '加载中...',
  318. })
  319. var url = '';
  320. var data = '';
  321. var name = '';
  322. if (that.data.name != '') {
  323. name = '&' + that.data.name
  324. }
  325. if (active == 1) {
  326. //用户管理
  327. if (that.data.areaID != '') {
  328. data = '&put_area_id=' + that.data.areaID
  329. }
  330. url = 'user/list?page=1' + that.data.userUrl;
  331. } else if (active == 2) {
  332. //车辆管理
  333. if (that.data.areaID != '') {
  334. data = '&put_area_id=' + that.data.areaID
  335. }
  336. url = 'bike/list?page=1';
  337. } else if (active == 3) {
  338. //订单管理
  339. if (that.data.areaID != '') {
  340. data = '&put_area_id=' + that.data.areaID
  341. }
  342. url = 'order/list?page=';
  343. // if (that.data.curPage == 1) {
  344. // url = 'order/list?page=';
  345. // } else {
  346. // url = 'orderRent/list?page=';
  347. // }
  348. } else if (active == 4) {
  349. //工单管理
  350. if (that.data.areaID != '') {
  351. data = '&put_area_id=' + that.data.areaID
  352. }
  353. url = 'work_order/list?page=1';
  354. }
  355. app.request(url + data + name, '', 'GET').then(res => {
  356. console.log(res)
  357. if (res.statusCode == 200) {
  358. wx.hideLoading()
  359. if (active == 1) {
  360. that.setData({
  361. userList: res.data.data
  362. })
  363. } else if (active == 2) {
  364. that.setData({
  365. bikeList: res.data.data
  366. })
  367. } else if (active == 3) {
  368. that.setData({
  369. orderList: res.data.data
  370. })
  371. } else if (active == 4) {
  372. that.setData({
  373. work_orderList: res.data.data
  374. })
  375. }
  376. }
  377. })
  378. },
  379. loadmore: function() {
  380. //上拉加载更多的公共方法
  381. var that = this;
  382. var active = that.data.active;
  383. if (active == 0) {
  384. //当前是全部管理不需要加载
  385. return;
  386. }
  387. wx.showLoading({
  388. title: '加载中...',
  389. })
  390. var url = '';
  391. var page = that.data.page + 1;
  392. var data = '';
  393. var name = '';
  394. if (that.data.name != '') {
  395. name = '&' + that.data.name
  396. }
  397. if (active == 1) {
  398. //用户管理
  399. if (that.data.areaID != '') {
  400. data = '&put_area_id=' + that.data.areaID
  401. }
  402. url = 'user/list?page=' + that.data.userUrl;
  403. } else if (active == 2) {
  404. //车辆管理
  405. if (that.data.areaID != '') {
  406. data = '&put_area_id=' + that.data.areaID
  407. }
  408. url = 'bike/list?page=';
  409. } else if (active == 3) {
  410. //订单管理
  411. if (that.data.areaID != '') {
  412. data = '&put_area_id=' + that.data.areaID
  413. }
  414. url = 'order/list?page=';
  415. // if (that.data.curPage == 1) {
  416. // url = 'order/list?page=';
  417. // } else {
  418. // url = 'orderRent/list?page=';
  419. // }
  420. } else if (active == 4) {
  421. //工单管理
  422. if (that.data.areaID != '') {
  423. data = '&put_area_id=' + that.data.areaID
  424. }
  425. url = 'work_order/list?page=';
  426. }
  427. app.request(url + page + data + name, '', 'GET').then(res => {
  428. console.log(res)
  429. if (res.statusCode == 200) {
  430. if (res.data.data.length > 0) {
  431. wx.hideLoading()
  432. that.setData({
  433. page
  434. })
  435. if (active == 1) {
  436. that.setData({
  437. userList: that.data.userList.concat(res.data.data)
  438. })
  439. } else if (active == 2) {
  440. that.setData({
  441. bikeList: that.data.bikeList.concat(res.data.data)
  442. })
  443. } else if (active == 3) {
  444. that.setData({
  445. orderList: that.data.orderList.concat(res.data.data)
  446. })
  447. } else if (active == 4) {
  448. that.setData({
  449. work_orderList: that.data.work_orderList.concat(res.data.data)
  450. })
  451. }
  452. } else {
  453. wx.showToast({
  454. title: '暂无更多数据',
  455. icon: 'none'
  456. })
  457. }
  458. }
  459. })
  460. },
  461. users: function(e) {
  462. var that = this;
  463. var url = e.currentTarget.dataset.url;
  464. var data = ''
  465. if (url != '') {
  466. data = '&' + url
  467. }
  468. app.request('user/list/?page=1' + data, '', 'GET').then(res => {
  469. console.log(res, '用户')
  470. that.setData({
  471. userList: res.data.data,
  472. userUrl: data
  473. })
  474. })
  475. },
  476. detail: function(e) {
  477. //用户详情
  478. wx.navigateTo({
  479. url: '/pages/userDetail/userDetail?id=' + e.currentTarget.dataset.id,
  480. })
  481. },
  482. bike_detail: function(e) {
  483. //车辆详情
  484. var event = e.currentTarget.dataset
  485. wx.navigateTo({
  486. url: '/pages/carDetails/carDetails?id=' + event.id + '&bike_no=' + event.bike_no,
  487. })
  488. },
  489. orderDetail: function(e) {
  490. //订单详情
  491. wx.navigateTo({
  492. // url: '/pages/orderDetail/orderDetail?id=' + e.currentTarget.dataset.id + '&index=' + this.data.curPage,
  493. url: '/pages/orderDetail/orderDetail?id=' + e.currentTarget.dataset.id,
  494. })
  495. },
  496. wordDetail: function(e) {
  497. //工单详情
  498. wx.navigateTo({
  499. url: '/pages/workDetail/workDetail?id=' + e.currentTarget.dataset.id,
  500. })
  501. },
  502. onReady: function() {
  503. },
  504. onShow: function() {
  505. token = wx.getStorageSync('token')
  506. },
  507. onHide: function() {
  508. },
  509. onUnload: function() {
  510. },
  511. onPullDownRefresh: function() {
  512. wx.showNavigationBarLoading();
  513. this.screen(), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
  514. },
  515. onReachBottom: function() {
  516. this.loadmore()
  517. },
  518. onShareAppMessage: function() {
  519. }
  520. })