// pages/neighbor/help/new.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { token: app.globalData.token, sourceUrl: app.baseUrls.sourceUrl, helpType: [], index: 0, helpTypeAll: [], helpSelected: '', content: '', contentSupplement: '', userIcon: wx.getStorageSync('userIcon'), userName: wx.getStorageSync('name'), imageList: [], serviceUrl: app.baseUrls.serviceUrl, baseImgUrl: app.baseUrls.baseImgUrl, videoId: '', communityId: '', areaCode: '', isLoading: false }, bindPickerChange: function(e) { var self = this this.setData({ index: e.detail.value, helpSelected: self.data.helpTypeAll[e.detail.value - 1].dataId }) }, // 发布互助 submitHelp: function () { var self = this if (!self.data.isLoading) { var photo = '' if (self.data.imageList.length > 0) { for (let i = 0; i < self.data.imageList.length; i++) { if (i != self.data.imageList.length - 1) { photo += self.data.imageList[i] + ',' } else { photo += self.data.imageList[i] } } } var info = { content: self.data.content, contentSupplement: self.data.contentSupplement, photo: photo, video: self.data.videoId, videoCover: '', headPortrait: self.data.userIcon, nickName : self.data.userName, communityId: self.data.communityId, areaCode: self.data.areaCode } self.setData({ isLoading: true }) app.restAjax.post(app.restAjax.path(app.apis.submitNeighborCircle, [app.baseUrls.requestUrl]), info, { headers: { token: self.data.token } }, function (code, data) { if (code == '200') { wx.showToast({ title: '发布成功!', icon: 'success' }) setTimeout(function () { self.setData({ isLoading: false }) wx.navigateBack({ delta: 1 }) }, 1500) } console.log(code) }, function (code, data) { console.log(data) self.setData({ isLoading: false }) }) } }, // 上传图片 uploadImage: function () { var self = this if (!self.data.isLoading) { wx.chooseImage({ count: 9 - self.data.imageList.length, sourceType: ['album', 'camera'], success: function (res) { wx.showToast({ title: '上传中', icon: 'loading' }) for (let i = 0; i < res.tempFiles.length; i++) { var path = res.tempFiles[i].path; app.restAjax.file(app.restAjax.path(app.apis.uploadImg, [app.baseUrls.serviceUrl]), path, 'image', { headers: { token: app.globalData.token } }, function (code, data) { if (code == '200') { var id = JSON.parse(data).data var arr = self.data.imageList arr.push(id) self.setData({ imageList: arr }) if (i == res.tempFiles.length - 1) { self.setData({ isLoading: false }) } wx.hideToast() } }, function (code, data) { console.log(data) self.setData({ isLoading: false }) }) } } }) } }, // 上传视频 uploadVideo: function () { var self = this if (!self.data.isLoading) { self.setData({ isLoading: true }) wx.chooseVideo({ sourceType: ['album','camera'], success: function (res) { app.restAjax.file(app.restAjax.path(app.apis.uploadVideo, [app.baseUrls.serviceUrl]), res.tempFilePath, 'video', { headers: { token: app.globalData.token } }, function (code, data) { if (code == '200') { self.setData({ isLoading: false }) var id = JSON.parse(data).data self.setData({ videoId: id }) } }, function (code, data) { console.log(data) self.setData({ isLoading: false }) }) } }) } }, // 删除图片 deleteImg: function (e) { var self = this var idx = e.currentTarget.dataset.cur var arr = this.data.imageList arr.splice(idx, 1) this.setData({ imageList: arr }) }, // 删除视频 deleteVideo: function () { this.setData({ videoId: '' }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ communityId: options.communityId, areaCode: options.areaCode, userIcon: wx.getStorageSync('userIcon'), userName: wx.getStorageSync('name') }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })