const app = getApp() Page({ data: { indicatorDots: true, arr: [], loaddisplay: true, autoplay: true, interval: 5000, duration: 2000, userInfo: {}, hasUserInfo: false, canIUse: wx.canIUse('button.open-type.getUserInfo') }, //事件处理函数 bindViewTap: function () { wx.navigateTo({ url: '../logs/logs' }) }, onLoad: function () { var that = this wx.request({ url: app.globalData.url + '/getCustomerEq', method: 'get', data: { eh_cmidcard: app.globalData.openid }, success: function (res) { var arrlist = []; for (var i = 0; i < res.data.length; i++) { var tmpdetail = {}; var now = new Date(); var startjf = new Date(res.data[i].ed_startdate.replace(/\./g, '/')); var days = parseInt((now.getTime() - startjf.getTime()) / (1000 * 60 * 60 * 24)); if(days < 0) { days = 0 } tmpdetail.et_type = res.data[i].et_type; tmpdetail.ei_rent = Number(res.data[i].ei_rent).toFixed(2); tmpdetail.ed_startdate =res.data[i].ed_startdate; tmpdetail.ed_enddate = res.data[i].ed_enddate; tmpdetail.eh_mortagage = res.data[i].eh_mortagage; tmpdetail.equipmenturl = res.data[i].equipmenturl; tmpdetail.ehcode = res.data[i].eh_code; tmpdetail.days = days; tmpdetail.eh_status = res.data[i].eh_status if (res.data[i].eh_status == 9) { tmpdetail.buttonname = "返还确认"; tmpdetail.buttoncolor = "#92CEFE"; } else if (res.data[i].eh_status == 3 || res.data[i].eh_status == 2) { if (res.data[i].ed_emcode == null) { tmpdetail.ed_emcode = '设备确认中...' tmpdetail.buttonname = "设备确认"; tmpdetail.buttoncolor = "#92CEFE"; tmpdetail.buttonhref = ""; } else { tmpdetail.buttonname = "立即返还"; tmpdetail.buttoncolor = "#FC7E8E"; tmpdetail.buttonhref = "returneq"; tmpdetail.ed_emcode = res.data[i].ed_emcode; } } else if (res.data[i].eh_status == 4) { tmpdetail.buttonname = "订单完成"; tmpdetail.buttoncolor = "#FCC66E"; tmpdetail.buttonhref = ""; } tmpdetail.totalrent = (days * Number(res.data[i].ei_rent)).toFixed(2); arrlist.push(tmpdetail); } that.setData({ arr: arrlist, loaddisplay: 'none' }) }, fail() { app.timeOut() } }) let _this = this; _this.setData({ navH: app.globalData.navHeight }) }, // hrefCl: function (e) { // wx.navigateTo({ // url: '/pages/consultant/consultant' // }) // }, // hrefPm: function (e) { // wx.navigateTo({ // url: '/pages/promotion/promotion' // }) // }, // hrefEq: function (e) { // wx.navigateTo({ // url: '/pages/equipment/equipment' // }) // }, returneq: function (e) { var duedate = new Date(); var year = duedate.getFullYear(); var month = duedate.getMonth() + 1; var strDate = duedate.getDate(); var seperator1 = "-"; var date = new Date(); var year = date.getFullYear(); var month = ("0" + (date.getMonth() + 1)).slice(-2);; var strDate = ("0" + (date.getDate())).slice(-2); var hours = ("0" + (date.getHours())).slice(-2); var minutes = ("0" + (date.getMinutes())).slice(-2); var seconds = ("0" + (date.getSeconds())).slice(-2); var eh_time = year + '-' + month + '-' + strDate + ' ' + hours + ':' + minutes + ':' + seconds; var that = this; wx.showModal({ title: '确认返还?', content: '租赁天数:\t' + e.currentTarget.dataset.days + '天\r\n租赁费用:\t¥' + e.currentTarget.dataset.totalrent + '\r\n设备押金:\t¥' +e.currentTarget.dataset.mortagage, success: function (res) { if (res.confirm) { wx.request({ url: app.globalData.url + '/insertEqCustomerBooking', method: 'post', header: { "Content-Type": "application/x-www-form-urlencoded" }, data: { bk_phone: app.globalData.userphone, bk_date: year + seperator1 + month + seperator1 + strDate, bk_type: 5, bk_desc: e.currentTarget.dataset.ehcode, eh_code: e.currentTarget.dataset.ehcode }, success: function (res) { wx.hideLoading() wx.showToast({ title: '提交成功!', icon: 'success', duration: 1500 }) // 发送消息 wx.request({ url: app.globalData.url + '/WXSendBookingMessage', method: 'post', header: { "Content-Type": "application/x-www-form-urlencoded" }, data: { bk_phone: app.globalData.userphone, bk_type: 5, bk_date: eh_time, bk_desc: e.currentTarget.dataset.ehcode } }) wx.request({ url: app.globalData.url + '/getCustomerEq', method: 'get', data: { eh_cmidcard: app.globalData.openid }, success: function (res) { var arrlist = []; for (var i = 0; i < res.data.length; i++) { var tmpdetail = {}; var now = new Date(); var startjf = new Date(res.data[i].ed_startdate); var days = parseInt((now.getTime() - startjf.getTime()) / (1000 * 60 * 60 * 24)); tmpdetail.ed_emcode = res.data[i].ed_emcode; tmpdetail.et_type = res.data[i].et_type; tmpdetail.ei_rent = Number(res.data[i].ei_rent).toFixed(2); tmpdetail.ed_startdate = res.data[i].ed_startdate; tmpdetail.ed_enddate = res.data[i].ed_enddate; tmpdetail.eh_mortagage = res.data[i].eh_mortagage; tmpdetail.equipmenturl = res.data[i].equipmenturl; tmpdetail.ehcode = res.data[i].eh_code; tmpdetail.days = days; if (res.data[i].eh_status == 9) { tmpdetail.buttonname = "返还确认"; tmpdetail.buttoncolor = "#92CEFE"; } else if (res.data[i].eh_status == 3 || res.data[i].eh_status == 2) { if (res.data[i].ed_emcode == null) { tmpdetail.ed_emcode = '设备确认中...' tmpdetail.buttonname = "设备确认"; tmpdetail.buttoncolor = "#92CEFE"; tmpdetail.buttonhref = ""; } else { tmpdetail.buttonname = "立即返还"; tmpdetail.buttoncolor = "#FC7E8E"; tmpdetail.buttonhref = "returneq"; tmpdetail.ed_emcode = res.data[i].ed_emcode; } } else if (res.data[i].eh_status == 4) { tmpdetail.buttonname = "订单完成"; tmpdetail.buttoncolor = "#FCC66E"; tmpdetail.buttonhref = ""; } tmpdetail.totalrent = (days * Number(res.data[i].ei_rent)).toFixed(2) arrlist.push(tmpdetail); } that.setData({ arr: arrlist }) }, fail() { app.timeOut() } }) }, fail() { app.timeOut() } }) } else if (res.cancel) { } }, fail() { app.timeOut() } }) } })