var app = getApp() Page({ /** * 页面的初始数据 */ data: { defaultSize: 'mini', src: null, photos: [], inputValue: '', orgId: null, orgName: null, // value: "", // 文本的内容 placeholder: "", maxlength: -1, // 最大输入长度,设置为 -1 的时候不限制最大长度 focus: true, id: '', url:'', showPopup:false, modalHidden:true }, onLoad: function (options) { const id = options.id; // var img = "/images/add.png"; // var tmpphoto = this.data.photos; // var tp = {}; // tp['path'] = img; // tp['type'] = 0; //tp['fileName'] = ''; //tmpphoto.push(tp); //console.debug("fffffffffffffffffff"); this.setData({ // photos: tmpphoto, // orgId: options.orgId, // orgName: options.orgName id: id }); this.detailInfo(id); }, buttonTap: function() { this.setData({ modalHidden: false }) }, /** * 点击取消 */ modalCandel: function() { // do something this.setData({ modalHidden: true }) }, /** * 点击确认 */ modalConfirm: function() { // do something this.setData({ modalHidden: true }) } , detailInfo: function (id) { var that = this; var url = app.globalData.cloudBase + "/Wx/Work/Report/" + id; wx.request({ url: url, method: 'GET', header: { "Content-Type": "json" }, // data: { // openid: openid // } // , success: function (res) { console.debug(res.data); if (res.data.code === "0") { var photos = res.data.data.photos; var tmpphoto = that.data.photos; if (null != photos) { for (var i = 0; i < photos.length; i++) { var p = photos[i] var tp = {}; tp['path'] = app.globalData.cloudBase + "/ts/source/img/" + p.photo; tp['type'] = 1; tp['fileName'] = p.photo; tmpphoto.unshift(tp); } } that.setData({ inputValue: res.data.data.info, photos: tmpphoto }); } }, fail: function (error) { console.log(error) } }) }, imageViewEvent:function(e){ var photo = e.currentTarget.dataset.photo; var image_path =app.globalData.cloudBase + "/ts/source/img/" +photo; this.setData({ url: image_path, modalHidden: false }); }, takePhoto: function (event) { console.debug("takePhoto"); var that = this; wx.showActionSheet({ itemList: ['拍摄', '相册'], success: function (res) { if (!res.cancel) { console.log(res.tapIndex); if (res.tapIndex == 0) { wx.chooseImage({ count: 1, // 默认9 sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res) { // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 var tempFilePaths = res.tempFilePaths console.debug(tempFilePaths); wx.uploadFile({ url: app.globalData.cloudBase + "/Wx/Upload/Image", //仅为示例,非真实的接口地址 filePath: tempFilePaths[0], name: 'image', success: function (res) { var data = res.data; var jsonStr = data.replace(" ", ""); var json; if (typeof jsonStr != 'object') { jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点 json = JSON.parse(jsonStr); } if (json.code == "0") { var tmpphoto = that.data.photos; var img = tempFilePaths[0]; console.log("path " + img); var tp = {}; tp['path'] = img; tp['type'] = 1; tp['fileName'] = json.filename; tmpphoto.unshift(tp); that.setData({ photos: tmpphoto }) } //console.log("upload back " + res.data); // var jsonStr = data.replace(" ", ""); // var json; // if (typeof jsonStr != 'object') { // jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点 // json = JSON.parse(jsonStr); // } // if (json.status === 'ok') { // var tmpphoto = that.data.photos; // var img = tempFilePaths[0]; // console.log("path " + img); // var tp = {}; // tp['path'] = img; // tp['type'] = 1; // tp['fileName'] = json.filename; // tmpphoto.unshift(tp); // that.setData({ // photos: tmpphoto // }) // } } }) } }) } else if (res.tapIndex == 1) { wx.chooseImage({ count: 1, // 默认9 sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res) { // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 var tempFilePaths = res.tempFilePaths console.debug(tempFilePaths); // var tmpphoto = that.data.photos; // var img = tempFilePaths[0]; // var tp = {}; // tp['path'] = img; // tp['type'] = 1; // tp['fileName'] = ''; // tmpphoto.unshift(tp); // that.setData({ // photos: tmpphoto // }) wx.uploadFile({ url: app.globalData.cloudBase + "/Wx/Upload/Image", //仅为示例,非真实的接口地址 filePath: tempFilePaths[0], name: 'image', success: function (res) { var data = res.data; var jsonStr = data.replace(" ", ""); var json; if (typeof jsonStr != 'object') { jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点 json = JSON.parse(jsonStr); } if (json.code == "0") { var tmpphoto = that.data.photos; var img = tempFilePaths[0]; console.log("path " + img); var tp = {}; tp['path'] = img; tp['type'] = 1; tp['fileName'] = json.filename; tmpphoto.unshift(tp); that.setData({ photos: tmpphoto }) } // console.log("upload back " + res.data); // var jsonStr = data.replace(" ", ""); // var json; // if (typeof jsonStr != 'object') { // jsonStr = jsonStr.replace(/\ufeff/g, ""); //重点 // json = JSON.parse(jsonStr); // } // if (json.status === 'ok') { // var tmpphoto = that.data.photos; // var img = tempFilePaths[0]; // console.log("path " + img); // var tp = {}; // tp['path'] = img; // tp['type'] = 1; // tp['fileName'] = json.filename; // tmpphoto.unshift(tp); // that.setData({ // photos: tmpphoto // }) // } } }) } }) } } } }) }, editPhoto: function (event) { console.debug("editPhoto"); wx.navigateBack({ delta: 1 }) }, sendPhoto: function (event) { if (this.data.inputValue.length > 0 || (this.data.photos.length - 1) > 0) { var that = this; try { wx.showModal({ title: '提示', content: '确定上报项目情况?', success: function (res) { if (res.confirm) { wx.showNavigationBarLoading() var data = {}; data['orgId'] = that.data.orgId; var openid = wx.getStorageSync('openid') if (openid) { data['openid'] = openid; } if (that.data.inputValue.length > 0) { data['desc'] = that.data.inputValue; } else { data['desc'] = ''; } var photos = that.data.photos; var tmpphotos = []; for (var i = 0; i < photos.length; i++) { var photo = photos[i]; if (photo.type !== 0) { var photoobj = { id: i, showBoxId: 0, photo: photo.fileName } tmpphotos.push(photoobj); } } data['photos'] = tmpphotos; console.log(data); wx.request({ url: app.globalData.cloudBase + "/Wx/Porject/Report/" + openid, data: data, method: "POST", header: { 'content-type': 'application/json' // 默认值 }, success: function (res) { console.log(res.data) if (res.data.code === '0') { wx.showModal({ title: '提示', content: '上报成功!', showCancel: false, success: function (res) { if (res.confirm) { wx.navigateBack({ delta: 1 }) } } }) } else { wx.showModal({ title: '提示', content: '上报失败!', showCancel: false, success: function (res) {} }) } }, fail: function (res) { console.log(res.errMsg) } }) } else { console.log('用户点击取消') } } }); } catch (e) { console.log(e); } } else { console.debug("sendPhoto fail"); wx.showToast({ title: '请检查是否正确录入项目情况!', icon: 'none', duration: 3000 }) } }, bindKeyInput: function (e) { this.setData({ inputValue: e.detail.value }) }, error(e) { console.log(e.detail) } })