var app = getApp(); var token = wx.getStorageSync('token'); let touchDotX = 0; //X按下时坐标 let touchDotY = 0; //y按下时坐标 let interval; //计时器 let time = 0; Page({ data: { current: 2, option1: [{ //所有区域选项 areaID: '', text: '全部区域', value: -1, }], // option1: [], value1: -1, //第一个显示什么 active: 0, //当前tab切换的下标 bike: [], //车辆 work_order: [], //工单 user: [], //用户 orderProfit: [], //收益 order: [], //订单 bikeList: [], //车辆 work_orderList: [], //工单 userList: [], //用户 orderProfitList: [], //收益 orderList: [], //订单 areaID: '', //首页的区域变量 page: 1, //当前页数 name: '', //车辆管理的局部筛选 curPage: 1, //默认显示普通订单 userUrl: '', screenHeight: '', //屏幕可视高度 role:wx.getStorageSync('role'), }, // 触摸开始事件 touchStart: function (e) { let that = this; touchDotX = e.touches[0].pageX; // 获取触摸时的原点 touchDotY = e.touches[0].pageY; // 使用js计时器记录时间 interval = setInterval(function () { that.setData({ curPage: 1, //默认显示普通订单 userUrl: '' }) }, 1000) }, // 触摸结束事件 touchEnd: function (e) { var that = this; let touchMoveX = e.changedTouches[0].pageX; let touchMoveY = e.changedTouches[0].pageY; let tmX = touchMoveX - touchDotX; let tmY = touchMoveY - touchDotY; if (time < 20) { let absX = Math.abs(tmX); let absY = Math.abs(tmY); // if (absX > 2 * absY) { if (absX > 40 && (2 * absY) < 20) { if (tmX < 0) { if (that.data.active >= 4) return that.setData({ active: that.data.active + 1 }) that.goTop(); that.tabList(); that.allData(); } else { if (that.data.active <= 0) return that.setData({ active: that.data.active - 1 }) that.goTop(); that.tabList(); that.allData(); } } } clearInterval(interval); // 清除setInterval time = 0; }, goTop: function (e) { // 一键回到顶部 if (wx.pageScrollTo) { wx.pageScrollTo({ scrollTop: 0 }) } }, onLoad: function (options) { var that = this; wx.showLoading({ title: '加载中....', }) that.setData({ screenHeight: app.globalData.screenHeight, option1: that.data.option1.concat(wx.getStorageSync('allArea')), // option1: wx.getStorageSync('allArea'), }) let curVal = wx.getStorageSync('curVal') console.log(curVal, 'curVal') if (curVal != -1) { console.log(1111) that.setData({ value1: curVal }) } let areaID = wx.getStorageSync('curId') console.log(areaID, 'index_areaId') if (areaID) { that.setData({ areaID: areaID }) } else { let id = that.data.option1[0].areaID that.setData({ areaID: id }) } that.menu = that.selectComponent("#menu"); if (that.data.areaID) { that.menu.changeTitle(that.data.option1[that.data.value1 + 1].text); } else { that.menu.changeTitle(that.data.option1[0].text); } that.allData(); }, scanCode() { wx.reLaunch({ url: '/pages/logs/logs?scan=' + 1, }) }, //列表数据 tabList() { var that = this; let active = that.data.active; let curPage = that.data.curPage; let url = '' let name = '' wx.showLoading({ title: '加载中...', }) //当前是全部管理不需要加载 if (active == 0) { wx.hideLoading(); return; } if (that.data.name != '') { name = '&&' + that.data.name } let data = '&&put_area_id=' + that.data.areaID; if (active == 1) { //用户 url = 'user/list/?page=1' } else if (active == 2) { //车辆 url = 'bike/list/?page=1' } else if (active == 3) { //订单 if (curPage == 1) { url = 'order/list/?page=1' } else { url = 'orderRent/list/?page=1' } } else if (active == 4) { //工单 url = 'work_order/list?page=1' } app.request(url + data + name, '', 'GET').then(res => { console.log(res.data) wx.hideLoading(); that.setData({ userList: res.data.data, bikeList: res.data.data, orderList: res.data.data, work_orderList: res.data.data, }) }) }, // up() { // console.log(this.data.bikeList) // let bikeData = this.data.bikeList; // function compare(property) { // return function (a, b) { // var value1 = a[property]; // var value2 = b[property]; // return value1 - value2; // } // } // console.log(bikeData.sort(compare('average_profit'))) // this.setData({ // bikeList:bikeData // }) // }, // down() { // console.log(this.data.bikeList) // let bikeData = this.data.bikeList; // function compare(property) { // return function (a, b) { // var value1 = a[property]; // var value2 = b[property]; // return value2 -value1; // } // } // console.log(bikeData.sort(compare('average_profit'))) // this.setData({ // bikeList:bikeData // }) // }, // 汇总数据 allData() { wx.showLoading({ title: '加载中...', }) let that = this; let active = that.data.active; let areaId = that.data.areaID; let url = ''; if (active == 0) { //所有数据 if (areaId == '') { url = 'statistics/statistics' } else { url = 'statistics/statistics?put_area_id=' + areaId } app.request(url, '', 'GET').then(res => { wx.hideLoading(); console.log(res.data, '数据') wx.hideLoading() that.setData({ user: res.data.userData, bike: res.data.bikeData, order: res.data.orderData, work_order: res.data.workOrderData, orderProfit: res.data.profitData }) }) } else { if (active == 1) { //用户数据 if (areaId == '') { url = 'user/userStatistics' } else { url = 'user/userStatistics?put_area_id=' + areaId } } else if (active == 2) { //车辆数据 if (areaId == '') { url = 'bike/statistics' } else { url = 'bike/statistics?put_area_id=' + areaId } } else if (active == 3) { //订单数据 if (areaId == '') { url = 'order/orderStatistics' } else { url = 'order/orderStatistics?put_area_id=' + areaId } } else if (active == 4) { //工单数据 if (areaId == '') { url = 'work_order/workOrderStatistics' } else { url = 'work_order/workOrderStatistics?put_area_id=' + areaId } } app.request(url, '', 'GET').then(res => { console.log(res.data, '总数据') wx.hideLoading() that.setData({ user: res.data, bike: res.data, order: res.data, work_order: res.data }) }) } }, //点击手机号拨打用户电话 phoneCall(e) { wx.makePhoneCall({ phoneNumber: e.currentTarget.dataset.phone }) }, // 选择日租订单或者普通订单 choose(e) { var that = this; this.setData({ curPage: e.currentTarget.dataset.idx, name: '' }) that.tabList(); }, localscreen: function (e) { //车辆管理的局部筛选 console.log(e.currentTarget.dataset.name) this.setData({ name: e.currentTarget.dataset.name }); this.tabList(); }, //切换tab按钮 onChange(event) { var that = this; that.setData({ active: event.detail.name, page: 1 }) that.goTop(); //回到顶部 that.allData(); that.tabList(); }, screen1: function (e) { var index = Number(e.currentTarget.dataset.index) this.setData({ active: index, page: 1 }) this.tabList(); }, skipNext() { let that = this; wx.navigateTo({ url: '/pages/statistics/statistics?areaId=' + that.data.areaID, }) }, //选择区域事件 change(event) { var that = this; this.setData({ page: 1 }) var options = this.data.option1; var areaId = options[event.detail + 1].areaID; console.log(areaId) that.setData({ areaID: areaId, name: '' }) if (that.data.areaID) { wx.setStorageSync('curVal', options[event.detail + 1].value) wx.setStorageSync('curId', areaId); } else { wx.removeStorageSync('curId') wx.removeStorageSync('curVal') } that.goTop(); that.tabList(); that.allData(); }, loadmore: function () { //上拉加载更多的公共方法 console.log('loadMore') var that = this; var active = that.data.active; if (active == 0) { //当前是全部管理不需要加载 return; } wx.showLoading({ title: '加载中...', }) var url = ''; var page = that.data.page + 1; var data = ''; var name = ''; if (that.data.name != '') { name = '&' + that.data.name } data = '&put_area_id=' + that.data.areaID if (active == 1) { //用户管理 url = 'user/list?page=' + that.data.userUrl; } else if (active == 2) { //车辆管理 url = 'bike/list?page='; } else if (active == 3) { //订单管理 if (that.data.curPage == 1) { url = 'order/list?page='; } else { url = 'orderRent/list?page='; } } else if (active == 4) { //工单管理 url = 'work_order/list?page='; } app.request(url + page + data + name, '', 'GET').then(res => { if (res.data.data.length > 0) { wx.hideLoading() that.setData({ page }) if (active == 1) { that.setData({ userList: that.data.userList.concat(res.data.data) }) } else if (active == 2) { that.setData({ bikeList: that.data.bikeList.concat(res.data.data) }) } else if (active == 3) { that.setData({ orderList: that.data.orderList.concat(res.data.data) }) } else if (active == 4) { that.setData({ work_orderList: that.data.work_orderList.concat(res.data.data) }) } } else { wx.showToast({ title: '暂无更多数据', icon: 'none' }) } }) }, detail: function (e) { //用户详情 wx.navigateTo({ url: '/pages/userDetail/userDetail?id=' + e.currentTarget.dataset.id, }) }, bike_detail: function (e) { //车辆详情 var event = e.currentTarget.dataset wx.navigateTo({ url: '/pages/carDetails/carDetails?id=' + event.id + '&bike_no=' + event.bike_no, }) }, orderDetail: function (e) { //订单详情 wx.navigateTo({ url: '/pages/orderDetail/orderDetail?id=' + e.currentTarget.dataset.id + '&index=' + this.data.curPage, //普通订单和日租订单 }) }, wordDetail: function (e) { //工单详情 wx.navigateTo({ url: '/pages/workDetail/workDetail?id=' + e.currentTarget.dataset.id, }) }, onPullDownRefresh: function () { wx.showNavigationBarLoading(); this.tabList(), this.allData(), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh(); }, onReachBottom: function () { this.loadmore() }, onShareAppMessage: function () { return { title: '轻松出行,方便你我', path: '/pages/login/login', success: function (res) {} } } })