var getUserStatusTime = 0; var orderPayload = null; var orderEvent = { endOrderInterval: function () { getUserStatusTime = 0; localStorage.removeItem("RECEIPT_START_TIME") localStorage.removeItem("START_KEY"); // localStorage.removeItem("DEVICE_START_TIME"); }, noDeviceOrder: function () { // 非启动设备的订单,无需等待。显示回到主页 $('.order-status').remove() if (detailLink != null) { $('#toOrder').removeClass('hide') } }, success: function () { $('.order-icon').removeClass('loading').addClass('iconfont icon-success') $('.order-tips').text('设备启动成功') if (detailLink != null) { $('#toOrder').removeClass('hide') } if (orderPayload && orderPayload.record && orderPayload.record.isIns) { $('.order-ins').show() } }, orderLoading: function () { $('.order-icon').addClass('loading') $('.order-tips').text('正在获取订单') }, devInStartTips: function () { $('.order-icon').addClass('loading') $('.order-tips').text('正在启动设备') }, fail: function () { $('.order-icon').removeClass('loading').addClass('iconfont icon-close-dark') if (detailLink != null) { $('.order-tips').text('设备启动失败,请点击[详情]查看订单详细状态。') $('#toOrder').removeClass('hide') } else { $('.order-tips').text('设备启动失败') $('#serviceBtn').removeClass('hide') } }, timeover: function () { $('.order-icon').removeClass('loading').addClass('iconfont icon-close-dark') $('.order-tips').text('获取设备启动状态超时') $('#serviceBtn').removeClass('hide') }, retry: function () { $('#restart').removeClass('hide') }, getUserStatusInterval: function (callback, timeout) { console.log("call getUserStatusInterval") var that = this if (timeout == null) { timeout = 2000; } var deviceStartTime = localStorage.getItem("RECEIPT_START_TIME");// 用户上次成功启动的时间,目前设置5分钟过期,过期后不再轮询 let exp = new Date().getTime() - deviceStartTime // 判断是否超过3分钟 if (exp > 3 * 60 * 1000) { that.timeover() that.endOrderInterval() return; } else { setTimeout(function () { that.devInStartTips() sendRequest({ url: '/user/getCurrentOrder', type: "GET", data: {devNo: devNo, startKey: startKey, exp: exp}, contentType: "application/json", success: function (res) { var obj = res.payload; orderPayload = obj if (obj) { var orderProcessing = obj.orderProcessing;//是否有订单在处理 var desc = obj.desc; if (orderProcessing === false) { that.endOrderInterval() // 如果订单成功,则提示用户:对订单是否还有疑问,失败则直接提示desc即可 if (obj.succeeded === true) { detailLink = obj.record.detailLink that.success() } else if (obj.succeeded === false) { if(obj.record) { detailLink = obj.record.detailLink } that.fail() mui.alert(desc, '温馨提示', '确定'); } else { that.fail() mui.alert('订单的succeeded状态为:' + obj.succeeded, '温馨提示', '确定'); } } else if (orderProcessing === true) { getUserStatusTime++; that.getUserStatusInterval(callback, 10000);//下一次2000秒间隔轮询 } else if (orderProcessing === null || orderProcessing === undefined) { mui.alert('未获取到上次订单信息') that.endOrderInterval(); that.fail() } } } }) }, timeout); } } }