// pages/pushArticle/pushArticle.js var app = getApp(); const request = require("../../utils/request.js"); const uploadImage = require('../../utils/uploadFile.js'); const login = require("../../utils/login.js"); Page({ /** * 页面的初始数据 */ data: { productId: null, uploadURL: request._debug ? 'test/toktok/cont/content/' : 'toktok/cont/content/', content: '', imgList: [], selectedTagList: [], }, pushContent() { let that = this; let tagIds_list = that.data.selectedTagList.map((item,index)=>{ return item.contTagId }) let parmas = { productId: that.data.productId, imgUrls: that.data.imgList.join(';'), tagIds: tagIds_list.join(';'), content: that.data.content } request.postData( 'app/cont/content/pub', parmas, res => { app.globalData.content = '' app.globalData.imgList = [] app.globalData.selectedTagList = [] wx.redirectTo({ url: '../circlesDetail/circlesDetail?contentId=' + res.data.data }) } ) }, delFun(event) { let index = event.currentTarget.dataset.idx; this.data.imgList.splice(index,1) this.setData({ imgList: this.data.imgList }) }, getbindinput(event) { app.globalData.content = event.detail.value; this.setData({ content: event.detail.value }) }, uploadImg() { let that = this; let count = Number(9 - that.data.imgList.length); wx.chooseMedia({ count: count, mediaType: ['image'], sourceType: ['album', 'camera'], success(res) { console.log(res) const tempFiles = res.tempFiles; tempFiles.forEach(function(value, index) { uploadImage(value.tempFilePath, that.data.uploadURL, function(res) { that.data.imgList.push(res) that.setData({ imgList: that.data.imgList }) }, function(res) { console.log(res) }) }) } }) }, addTags() { app.globalData.content = this.data.content; app.globalData.imgList = this.data.imgList; let tagObject = JSON.stringify(this.data.selectedTagList); wx.navigateTo({ url: '../addTags/addTags?tagObject='+tagObject }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { login.getAssumeRole() if(options.productId) { this.setData({ productId: options.productId }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { this.setData({ content: app.globalData.content, imgList: app.globalData.imgList, selectedTagList: app.globalData.selectedTagList }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })