// 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: { type:String, tpId:String }, /** * 组件的初始数据 */ data: { messageTitle:"", messageDetail:"", messageTemp:"", files: [], // 所在街道 streets: [], streetsIndex: 0, typeList:[], typeListIndex:0, //接口街道的数据 results:[], list:[], //选择后获取的街道的I, streetID:'', typeCode:'', textareaValue:'', error:'', company:'' }, /** * 组件的方法列表 */ 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(typeList) this.setData({ typeList: typeList }) //把接口数据放在results里 this.setData({ list: result }) }) }, methods: { bindPickerStreetsChange: function(e) { this.setData({ streetsIndex: e.detail.value }) if(e.detail.value == '0'){ this.setData({ streetID: '' }) }else{ this.setData({ streetID: this.data.results[this.data.streetsIndex-1].id }) } }, bindPickerTypeChange:function(e){ this.setData({ typeListIndex: e.detail.value }) if(e.detail.value == '0'){ this.setData({ typeCode: '' }) }else{ 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, }) console.log(e.detail.value.length) if(e.detail.value.length >= 200){ // wx.showToast({ // title: '超过字数', // duration: 2000, // icon: 'none' // }) this.setData({ error: '已达最大字数' }) } }, 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() { var 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.properties.type != 'resource'){ //判断是否选择街道 if (this.data.streetID === ''){ wx.showModal({ title: '提示', content: '请输入街道', showCancel:false }) return } } if(this.properties.type === ''){ if (this.data.typeCode === ''){ wx.showModal({ title: '提示', content: '请选择需求类型', showCancel:false }) return } } if(this.properties.type === 'rent'){ if (this.data.company === ''){ wx.showModal({ title: '提示', content: '请输入工作单位', showCancel:false }) return } if(this.data.files.length <= 0){ wx.showModal({ title: '提示', content: '请上传身份证、学历等相关证书', showCancel:false }) return } } if(this.properties.type == 'resource'){ var questionType = 0; }else if(this.properties.type == 'rent'){ var questionType = 1; }else{ var questionType = 2; } var data = { content:this.data.messageDetail, picList:this.data.files, departId:this.data.streetID, typeCode:this.data.typeCode, questionType:questionType, id:this.properties.tpId, company:this.data.company } topicModel.addTalents(data,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) { // 点击知道了 if(th.properties.type == ''){ setTimeout(function(){ th.setData({ textareaValue:'' }) }, 500); }else{ console.log(1212); wx.navigateBack({ delta: 1 }) } } } }) }) } }) this.setData({ streetsIndex: 0, typeListIndex:0, }) }, company:function(e){ var company = e.detail.value; this.setData({ company:company }) } }, })