// miniprogram/pages/addDevice/addDevice.js var app = getApp() Page({ /** * 页面的初始数据 */ data: { longitude:'', latitude:'', photopath1:'', photopath2:'', photopath3:'', option1: [ { text: '雨水井', value: "1" }, { text: '污水井', value: "2" }, { text: '燃气井', value: "3" }, { text: '热力井', value: "4" }, { text: '电力井', value: "5" }, ], personoption1: [ { text: '宋达', value: "宋达" }, { text: '李恒', value: "李恒" }, { text: '吴甘牛', value: "吴甘牛" }, { text: '高峰', value: "高峰" }, { text: '王珏', value: "王珏" }, ], projectoption: [ { text: '赣州项目', value: "赣州项目" }, { text: '亦庄项目', value: "亦庄项目" }, { text: '北燃项目', value: "北燃项目" }, { text: '抚州项目', value: "抚州项目" }, { text: '昌平项目', value: "昌平项目" }, ], devcode: "", deviceMode: "", installtimeFmt: '', show: false, form: { devcode: "", wellcode: "", welltype: "", welldepth: "", installheigt: "", installperson: "", installtimeFmt: "", photopath: "", factory: "", workmsg: "", position: "", description: "", longitude: "", latitude: "", devicetype: "", project: "" }, fileList: [ // { // url: 'https://img.yzcdn.cn/vant/leaf.jpg', // statue: 'uploading', // message: '上传中', // }, // { // url: 'https://img.yzcdn.cn/vant/tree.jpg', // status: 'success', // message: '上传失败', // }, ], }, onDisplay() { this.setData({ show: true }); }, onClose() { this.setData({ show: false }); }, formatDate(date) { date = new Date(date); // return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`; var seperator1 = "-"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate; return currentdate; }, onConfirm(event) { var installtime = 'form.installtimeFmt'; this.setData({ show: false, installtimeFmt: this.formatDate(event.detail), [installtime]: this.formatDate(event.detail), }); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, formSubmit: function (event) { var that = this; wx.cloud.callFunction({ name: 'addDevice', data: { device: that.data.form, photopath1: that.data.photopath1, photopath2: that.data.photopath2, photopath3: that.data.photopath3, url:app.globalData.url+"appDeviceAdd/add" }, }).then(res => { if(res.result.code == 500){ wx.showToast({ title: '设备编号已安装!', }) }else if (res.result.code == 200) { wx.showModal({ content: '提交成功,是否返回?', success: function (res) { if (res.confirm) { wx.switchTab({ url: '../earth/earth' }) } else {//这里是点击了取消以后 console.log('用户点击取消') } } }) } }).catch(err => { console.error(err); wx.showToast({ title: "提交失败", }) }) }, confirm(event) { var that = this; var formValue = event.detail.value; var formName = event.target.dataset.id; var fromN = 'form.' + [formName]; that.setData({ [fromN]: formValue }) }, scan() { wx.scanCode({ success(res) { console.log(res) } }) }, paste() { var _this= this; wx.getClipboardData({ success: function (res) { var longitude ='form.longitude'; var latitude ='form.latitude'; _this.setData({ [longitude]:res.data.split(",")[1], [latitude]:res.data.split(",")[0], longitude:res.data.split(",")[1], latitude:res.data.split(",")[0], }); } }) }, selectValue(value) { var that = this; var wellType = 'form.welltype'; that.setData({ [wellType]: value.detail }) }, selectpersonValue(event) { var that = this; var installPerson = 'form.installperson'; that.setData({ [installPerson]: event.detail }) }, selectprojectValue(event) { var that = this; var project = 'form.project'; that.setData({ [project]: event.detail }) }, afterRead(event) { var _this=this; const { file } = event.detail; const { fileList = [] } = this.data; fileList.push({ ...file, url: file.path }); _this.setData({ fileList }); var base64= "data:image/png;base64,"+wx.getFileSystemManager().readFileSync(file.path,'base64'); wx.cloud.callFunction({ name: 'uploadFile', data: { url: app.globalData.url+"appDeviceAdd/fileUpload", fileBase64:base64 }, success: function (res) { if(res.result){ var photopath='photopath'+[event.detail.index+1] _this.setData({ [photopath]:res.result.data }) } }, complete: res => { }, }) }, deletePhoto(event){ var image_index = event.detail.index var fileList_new = this.data.fileList; fileList_new.splice(image_index,1); this.setData({ fileList: fileList_new }) }, })