市北人才赋能平台 --小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

121 lines
2.7 KiB

// pages/topics/interactive/submitTopic/index.js
import { config } from '../../../../config.js'
import { store } from '../../../../utils/store.js'
import { TopicModel } from '../../../../models/topic.js'
let topicModel = new TopicModel()
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
topicTitle:"",
topicDetail:"",
files:[],
flag:0
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
flag:app.globalData.flag,
uplaodFile: this.uplaodFile.bind(this)
})
},
bindTextInput(e){
this.setData({
topicTitle:e.detail.value
})
},
bindTextAreaInput(e){
this.setData({
topicDetail: e.detail.value
})
},
uplaodFile(files) {
console.log('upload files', files)
// 文件上传的函数,返回一个promise
const token = store.readToken()
console.log(token)
return new Promise((resolve, reject) => {
files.tempFilePaths.forEach(item=>{
wx.uploadFile({
url: config.api_url + "/api/common/upload",
filePath: item,
header: {
'token': token,
'content-type': 'application/json',
},
name: 'files',
success: (res)=> {
console.log(res);
const data = JSON.parse(res.data)
const image = {
url: config.api_url + '/' + data.result.imgUrl,
}
this.setData({
files: [...this.data.files, image]
})
resolve(this.data.files)
}
})
})
})
},
deleteFile(e){
console.log(e)
let tempImages = this.data.files
const index = e.detail.index
tempImages.splice(index, 1);
this.setData({
files:tempImages
})
},
submit(){
if (this.data.topicTitle === ""){
wx.showToast({
title: '请输入议题标题',
icon: 'none'
})
return
}
if (this.data.topicDetail === "") {
wx.showToast({
title: '请输入议题内容',
icon: 'none'
})
return
}
const tempImages = []
this.data.files.forEach(item=>{
tempImages.push(item.url)
})
let title = this.data.topicTitle
let content = this.data.topicDetail
let images = ''
if (this.data.files.length > 0) {
images = tempImages.join('')
}
topicModel.topicAddGroup(title,content,images,res=>{
console.log(res)
wx.showToast({
title: res.message,
icon: 'none',
duration:2000,
success(res){
setTimeout(function () {
wx.navigateBack({
delta: 1
})
}, 2000)
}
})
})
}
})