index.js 12 KB

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