123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- var app = getApp();
- let touchDotX = 0; //X按下时坐标
- let touchDotY = 0; //y按下时坐标
- let interval; //计时器
- let time = 0;
- Page({
- data: {
- active: 0,
- workList: [], //工单列表
- page: 1,
- current: 4,
- option1: [], //区域选择
- value1: 0, //第一个显示什么
- areaID: '',
- url: '',
- screenHeight: '', //屏幕可视高度
- },
- // 触摸开始事件
- touchStart: function (e) {
- touchDotX = e.touches[0].pageX; // 获取触摸时的原点
- touchDotY = e.touches[0].pageY;
- // 使用js计时器记录时间
- interval = setInterval(function () {
- time++;
- }, 100);
- },
- // 触摸结束事件
- 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) {
- that.setData({
- workList: ''
- })
- if (tmX < 0) {
- if (that.data.active >= 3) return
- that.setData({
- active: that.data.active + 1
- })
- that.goTop();
- that.getWork();
- } else {
- if (that.data.active <= 0) return
- that.setData({
- active: that.data.active - 1
- })
- that.goTop();
- that.getWork();
- }
- }
- }
- clearInterval(interval); // 清除setInterval
- time = 0;
- },
- onLoad: function (options) {
- let that = this;
- that.setData({
- screenHeight: app.globalData.screenHeight,
- option1: wx.getStorageSync('allArea'),
- })
- let curVal = wx.getStorageSync('curVal')
- if (curVal) {
- that.setData({
- value1: curVal
- })
- }
- let areaID = wx.getStorageSync('curId')
- if (areaID) {
- that.setData({
- areaID
- })
- } else {
- let id = that.data.option1[0].areaID
- that.setData({
- areaID: id
- })
- }
- that.menu = that.selectComponent("#menu");
- that.menu.changeTitle(that.data.option1[that.data.value1].text);
- that.getWork();
- wx.hideHomeButton();
- },
- change(e) {
- var that = this;
- var options = this.data.option1;
- var areaId = options[e.detail].areaID;
- this.setData({
- areaID: areaId
- })
- that.getWork();
- that.goTop();
- wx.setStorageSync('curVal', options[e.detail].value)
- wx.setStorageSync('curId', options[e.detail].areaID)
- },
- scanCode() {
- wx.reLaunch({
- url: '/pages/logs/logs?scan=' + 1,
- })
- },
- getWork() {
- wx.showLoading({
- title: '加载中',
- })
- let that = this;
- let planned = '';
- let url = "";
- let data = '&&put_area_id=' + that.data.areaID
- if (this.data.active == 0) {
- planned = 1
- url = "work_order/list?planned=" + planned + data
- } else if (this.data.active == 1) {
- planned = 2
- url = "work_order/myWorkOrderList?planned=" + planned + data
- } else if (this.data.active == 2) {
- planned = 3
- url = "work_order/myWorkOrderList?planned=" + planned + data
- } else if (this.data.active == 3) {
- planned = 4
- url = "work_order/myWorkOrderList?planned=" + planned + data
- }
- app.request(url, '', 'GET').then(res => {
- console.log(res,'工单')
- wx.hideLoading();
- this.setData({
- workList: res.data.data
- })
- })
- },
- //回到顶部
- goTop: function (e) { // 一键回到顶部
- if (wx.pageScrollTo) {
- wx.pageScrollTo({
- scrollTop: 0
- })
- }
- },
- wordDetail: function (e) {
- //工单详情
- wx.navigateTo({
- url: '/pages/workDetail/workDetail?id=' + e.currentTarget.dataset.id,
- })
- },
- onChange(event) {
- let that = this;
- that.setData({
- workList: '',
- active: event.detail.name,
- page: 1
- })
- that.getWork();
- that.goTop();
- },
- onPullDownRefresh: function () {
- wx.showNavigationBarLoading();
- this.getWork(), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
- },
- onReachBottom: function () {
- var that = this;
- wx.showLoading({
- title: '加载中',
- })
- let planned = '';
- var page = that.data.page + 1
- if (that.data.active == 0) {
- planned = 1
- } else if (that.data.active == 1) {
- planned = 2
- } else if (that.data.active == 2) {
- planned = 3
- } else if (that.data.active == 3) {
- planned = 4
- }
- let url = 'work_order/list?planned=' + planned + '&&put_area_id=' + that.data.areaID + '&&page=' + page
- app.request(url, '', 'GET').then(res => {
- console.log(res)
- wx.hideLoading()
- if (res.data.data.length > 0) {
- that.setData({
- workList: that.data.workList.concat(res.data.data),
- page
- })
- } else {
- wx.showToast({
- title: '没有更多了~',
- icon: 'none'
- })
- }
- })
- },
- onShareAppMessage: function () {
- return {
- title: '轻松出行,方便你我',
- path: '/pages/login/login',
- success: function (res) {}
- }
- }
- })
|