123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- 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) {}
- }
- }
- })
|