// pages/topics/common/message/index.js import { config } from '../../../config.js' import { store } from '../../../utils/store.js' import { TopicModel } from '../../../models/topic.js' let topicModel = new TopicModel() Component({ /** * 组件的属性列表 */ properties: { }, /** * 组件的初始数据 */ data: { messageTitle:"", messageDetail:"", messageTemp:"", files: [], // 所在街道 streets: [], streetsIndex: 0, typeList:[], typeListIndex:0, //接口街道的数据 results:[], list:[], //选择后获取的街道的I, streetID:'', typeCode:'', textareaValue:'' }, // lifetimes: { // attached: function () { // // 在组件实例进入页面节点树时执行 // }, // detached: function () { // // 在组件实例被从页面节点树移除时执行 // } // }, // attached: function () { // console.log('啦啦啦') // }, /** * 组件的方法列表 */ attached: function () { console.log('talents页面') // var th = this; this.setData({ uplaodFile: this.uplaodFile.bind(this) }) topicModel.getStreetList(res=>{ var resultss = res.result var streett = [] resultss.forEach((value,index)=>{ streett[index] = value.departName }) //把streett添加第一项设为空 streett.unshift('') console.log(streett) this.setData({ streets: streett }) //把接口数据放在results里 this.setData({ results: resultss }) console.log(this.data.results) }) topicModel.getWhistleTypeList(res=>{ var result = res.result var typeList = [] result.forEach((value,index)=>{ typeList[index] = value.typeName }) //把streett添加第一项设为空 typeList.unshift('') console.log(111111111) console.log(typeList) this.setData({ typeList: typeList }) //把接口数据放在results里 this.setData({ list: result }) }) }, methods: { bindPickerStreetsChange: function(e) { // console.log("1"+e.detail.value) this.setData({ streetsIndex: e.detail.value }) // console.log("2"+this.data.streetsIndex) this.setData({ streetID: this.data.results[this.data.streetsIndex-1].id }) // console.log(this.data.streetID) }, bindPickerTypeChange:function(e){ this.setData({ typeListIndex: e.detail.value }) this.setData({ typeCode: this.data.list[this.data.typeListIndex-1].typeCode }) }, bindTextInput(e) { this.setData({ messageTitle: e.detail.value }) }, bindTextAreaInput(e) { console.log("bindTextAreaInput"); this.setData({ messageDetail: e.detail.value, }) if(e.detail.value.length>200){ wx.showToast({ title: '超过字数', duration: 2000, icon: 'none' }) } }, 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() { let th =this; if (this.data.messageDetail.length >200){ wx.showModal({ title: '提示', content: '问题超过字数,请重新输入', showCancel:false, }) return } if (this.data.messageDetail === ''){ wx.showModal({ title: '提示', content: '请输入正文内容', showCancel:false }) return } //判断是否选择街道 if (this.data.streetID === ''){ wx.showModal({ title: '提示', content: '请输入街道', showCancel:false }) return } if (this.data.typeCode === ''){ wx.showModal({ title: '提示', content: '请选择赋能类型', showCancel:false }) return } topicModel.addTalents(this.data.messageDetail, this.data.files,this.data.streetID,this.data.typeCode,res=>{ const id = res.result; if(res.code === 200){ this.setData({ messageDetail: '', streetID:'', typeCode:'', files:[], },()=>{ wx.showModal({ title: '提交成功', content: '问题已收到!', cancelText:'知道了', confirmText:'查看进度', success (res) { if (res.confirm) { wx.redirectTo({ url: '/pages/user/myWhistle/whistleDetail/index?id='+id, }) } else if (res.cancel) { setTimeout(function(){ th.setData({ textareaValue:'' }) }, 500); console.log('用户点击知道了') } } }) }) } }) this.setData({ streetsIndex: 0, typeListIndex:0, }) } }, })