const util = require('../../utils/util.js'); const app = getApp() Page({ data: { userInfo: wx.getStorageSync("userInfo"), cloudCardOrder: {}, validTime: 0, imageList: [], fileList: [], sec: 1, countdown: "", name: "",//姓名 phone: "",//手机号 code: '',//验证码 iscode: null,//用于存放验证码接口里获取到的code codename: '获取验证码', disabled: false, //按钮是否禁用 click: true, canShow: false }, onLoad: function (option) { var that = this; wx.login({ success: res => { wx.request({ url: app.globalData.serverUrl + '/user/weiXinLogin', data: { code: res.code }, header: { 'content-type': 'application/json' }, success: function (res) { if(res.data.statusCode != null){ wx.showToast({ title: '获取用户信息失败', icon: 'none', duration: 2000 }) } else { app.globalData.userInfo = res.data.data; wx.setStorageSync('userInfo', res.data.data); wx.setStorageSync('openId', res.data.data.openid); that.getDetail(option.id); } }, fail: function (res) { wx.showToast({ title: '获取用户信息失败', icon: 'none', duration: 2000 }) } }) } }) wx.showShareMenu({ withShareTicket: true }) }, //获取详情 getDetail: function(id){ var that = this; wx.request({ url: app.globalData.serverUrl + '/cloudcard/detail', data: { openId : wx.getStorageSync("openId"), id : id, type: 1 }, success(res) { if (res.data.data != null) { var cloudCardOrder = res.data.data.cloudCardOrder, imageList = [], fileList = []; var strId = cloudCardOrder.initiatorId + "," + cloudCardOrder.receiverId + ","; var lawyeIds = ""; for (var i in cloudCardOrder.lawyes) { strId += cloudCardOrder.lawyes[i].id + ","; lawyeIds += cloudCardOrder.lawyes[i].id + ","; } for (var i in cloudCardOrder.uploadFileModels) { var str = app.globalData.fileUrl + cloudCardOrder.uploadFileModels[i].fileUrl; imageList.push(str); } if (cloudCardOrder.receiverId != null) { if(strId.indexOf(wx.getStorageSync("userInfo").id) == -1) { wx.showToast({ title: '您没有权限预览!', icon: 'none', duration: 2000 }) setTimeout(function () { wx.reLaunch({ url: '../index/index' }) }, 100) return false } } if(res.data.data.cloudCardOrder.isOpen == 1 && res.data.data.cloudCardOrder.initiatorId != that.data.userInfo.id){ wx.request({ url: app.globalData.serverUrl + '/cloudcard/orderChecking', data: { id : res.data.data.cloudCardOrder.id }, method:"GET", success(res) { setTimeout(function() { wx.reLaunch({ url: '../detail/detail?id=' + res.data.data.cloudCardOrder.id + '&fromReceiver=1' }) }, 200) }, fail: function (res) { setTimeout(function() { wx.reLaunch({ url: '../detail/detail?id=' + res.data.data.cloudCardOrder.id + '&fromReceiver=1' }) }, 200) } }) setTimeout(function() { wx.reLaunch({ url: '../detail/detail?id=' + res.data.data.cloudCardOrder.id + '&fromReceiver=1' }) }, 200) } if(res.data.data.cloudCardOrder.orderStatus != "NOT_SIGN"){ setTimeout(function() { wx.reLaunch({ url: '../detail/detail?id=' + res.data.data.cloudCardOrder.id + '&fromReceiver=1' }) }, 200) } for (var i in cloudCardOrder.textFile) { var str = app.globalData.fileUrl + cloudCardOrder.textFile[i].fileUrl; fileList.push({ url: str, name: cloudCardOrder.textFile[i].fileName }); } for (var i in cloudCardOrder.lawyes) { var str = app.globalData.fileUrl + cloudCardOrder.lawyes[i].headPortrait; cloudCardOrder.lawyes[i].headPortrait = str; } that.setData({ cloudCardOrder: cloudCardOrder, validTime: res.data.data.minute, sec: res.data.data.second, imageList: imageList, fileList: fileList }) that.countTime(); if (cloudCardOrder.initiatorId == that.data.userInfo.id) { that.setData({ // countdown: cloudCardOrder.validTime + "分 00 秒", canShow: false }) } else { that.setData({ canShow: true }) wx.request({ url: app.globalData.serverUrl + "/cloudcard/checkIsOpen", method: "GET", data: { id: that.data.cloudCardOrder.id, isOpen: 1 }, success(res) { }, fail: function (res) { } }) } } else { wx.showToast({ title: '获取失败!', icon: 'none', duration: 2000 }) } }, fail: function (res) { wx.showToast({ title: '获取失败!', icon: 'none', duration: 2000 }) } }) }, //倒计时 countTime: function(){ var m = this.data.validTime , s = this.data.sec; if (m >= 0) { m = m < 10 ? "0" + m : m; s = s < 10 ? "0" + s : s; this.setData({ countdown: m + "分 " + s + " 秒", }) this.data.sec--; if(this.data.sec < 0){ this.data.sec = 59; this.data.validTime--; } this.setData({ validTime: this.data.validTime, sec: this.data.sec }) //递归每秒调用countTime方法,显示动态时间效果 setTimeout(this.countTime, 1000); } else { this.setData({ countdown: '已过期' }) setTimeout(function() { wx.reLaunch({ url: '../detail/detail?id=' + that.data.cloudCardOrder.id + '&fromReceiver=1' }) }, 200) } }, //图片预览 handleImagePreview: function(e){ const i = e.target.dataset.index; const images = this.data.imageList; wx.previewImage({ current: images[i], urls: images, }) }, //文件预览 showFile: function(e){ const i = e.target.dataset.index; var that = this , url = this.data.fileList[i].url; // wx.getSystemInfo({ // success: function (res) { // if(res.system.indexOf("iOS") > -1){ // wx.navigateTo({ // url: '../book/pdf?url=' + url + '&type=1' // }) // } else { wx.showLoading({ title: '正在打开请稍候...', }) wx.downloadFile({ url: url, success: function (res) { wx.hideLoading() var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用 wx.openDocument({ filePath: Path, success: function (res) { console.log('打开成功'); } }) }, fail: function (res) { wx.hideLoading() wx.showToast({ title: '文件打开失败!', icon: 'none', duration: 1000 }) } }) // } // } // }) }, getNameValue: function (e) { this.setData({ name: e.detail.value }) }, getPhoneValue: function (e) { this.setData({ phone: e.detail.value }) }, getCodeValue: function (e) { this.setData({ code: e.detail.value }) }, //判断手机号 getCode: function () { var phoneNum = this.data.phone; var that = this; var myreg = /^1[0-9]{10,11}$/; if (this.data.phone == "") { wx.showToast({ title: '手机号不能为空', icon: 'none', duration: 1000 }) return false; } else if (!myreg.test(this.data.phone)) { wx.showToast({ title: '请输入正确的手机号', icon: 'none', duration: 1000 }) return false; } else { wx.showLoading({ title: '请稍候...', mask: true }) wx.request({ url: app.globalData.serverUrl + "/cloudcard/getVcode", data: { mobile: phoneNum }, success(res) { wx.hideLoading(); // that.setData({ // iscode: res.data.data // }) var num = 61; var timer = setInterval(function () { num--; if (num <= 0) { clearInterval(timer); that.setData({ codename: '重新发送', disabled: false }) } else { that.setData({ codename: num + "s" }) } }, 1000) }, fail: function (res) { wx.hideLoading(); } }) } }, //获取验证码 getVerificationCode() { this.getCode(); var that = this that.setData({ disabled: true }) }, //查看确认书 book: function(){ wx.navigateTo({ url: '../book/book' }) }, //同意 agree: function(e){ var myreg = /^1[0-9]{10,11}$/; if (this.data.name == "") { wx.showToast({ title: '姓名不能为空', icon: 'none', duration: 1000 }) return false; } else if (this.data.phone == "") { wx.showToast({ title: '手机号不能为空', icon: 'none', duration: 1000 }) return false; } else if (!myreg.test(this.data.phone)) { wx.showToast({ title: '请输入正确的手机号', icon: 'none', duration: 1000 }) return false; } else if (this.data.code == "") { wx.showToast({ title: '请输入验证码', icon: 'none', duration: 1000 }) return false; } else { if(this.data.click){ var that = this; that.setData({ click: false }) wx.request({ url: app.globalData.serverUrl + "/cloudcard/orderAgree", method: "GET", data: { orderId: that.data.cloudCardOrder.id, openid: wx.getStorageSync("openId"), userName: that.data.name, mobile: that.data.phone, VCode: that.data.code, formId: e.detail.formId }, success(res) { wx.request({ url: app.globalData.fileUrl + "/index/copy", method: "GET", data: { id: that.data.cloudCardOrder.id }, success(res) { }, fail: function (res) { } }) that.setData({ click: true }) if(res.data.code == "ok"){ wx.showToast({ title: "操作成功", icon: 'success', duration: 2000 }) } else { wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000 }) } setTimeout(function() { wx.reLaunch({ url: '../detail/detail?id=' + that.data.cloudCardOrder.id + '&fromReceiver=1' }) }, 200) }, fail: function (res) { that.setData({ click: true }) wx.showToast({ title: "操作失败", icon: 'none', duration: 2000 }) } }) } else { wx.showToast({ title: '保存中,请勿重复提交', icon: 'none', duration: 1000 }) } } }, //拒绝 refuse: function(e){ if(this.data.click){ var that = this; that.setData({ click: false }) wx.request({ url: app.globalData.serverUrl + "/cloudcard/orderReject", method: "GET", data: { orderId: that.data.cloudCardOrder.id, openid: wx.getStorageSync("openId"), formId: e.detail.formId }, success(res) { if(res.data.code == "ok"){ wx.showToast({ title: "操作成功", icon: 'success', duration: 2000 }) } else { wx.showToast({ title: "操作失败", icon: 'none', duration: 2000 }) } setTimeout(function() { wx.reLaunch({ url: '../detail/detail?id=' + that.data.cloudCardOrder.id + '&fromReceiver=1' }) }, 200) }, fail: function (res) { wx.showToast({ title: "操作失败", icon: 'none', duration: 2000 }) } }) } else { wx.showToast({ title: '保存中,请勿重复提交', icon: 'none', duration: 1000 }) } } })