市北人才赋能平台 --小程序端
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.
 

382 lines
8.4 KiB

// pages/topics/reportDemand/index.js
import {
config
} from '../../../config.js'
import {
store
} from '../../../utils/store.js'
import {
TopicModel
} from '../../../models/topic.js'
let topicModel = new TopicModel()
Page({
/**
* 页面的初始数据
*/
data: {
//类型
type: '',
messageTitle: "",
messageDetail: "",
messageTemp: "",
files: [],
// 所在街道
streets: [],
streetsIndex: 0,
typeList: [],
typeListIndex: 0,
//接口街道的数据
results: [],
list: [],
//选择后获取的街道的I,
streetID: '',
typeCode: '',
textareaValue: '',
error: '',
company: '',
username: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
uplaodFile: this.uplaodFile.bind(this)
})
this.initFormData()
this.getStreetList()
this.getWhistleTypeList()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
getStreetList() {
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)
})
},
getWhistleTypeList() {
topicModel.getWhistleTypeList(res => {
var result = res.result
var typeList = []
result.forEach((value, index) => {
typeList[index] = value.typeName
})
//把streett添加第一项设为空
typeList.unshift('')
this.setData({
typeList: typeList
})
//把接口数据放在results里
this.setData({
list: result
})
})
},
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 => {
console.log('item', 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 === '' || this.data.messageDetail.trim() === '') {
wx.showModal({
title: '提示',
content: '请输入正文内容',
showCancel: false
})
return
}
if (this.data.username === '' || this.data.username.trim() === '') {
wx.showModal({
title: '提示',
content: '请输入姓名',
showCancel: false
})
return
}
if (this.data.username.length > 15) {
wx.showModal({
title: '提示',
content: '姓名长度不能超过15',
showCancel: false,
})
return
}
if (this.data.company === '' || this.data.company.trim() === '') {
wx.showModal({
title: '提示',
content: '请输入工作单位',
showCancel: false
})
return
}
if (this.data.company.length > 15) {
wx.showModal({
title: '提示',
content: '工作单位长度不能超过15',
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
}
if (this.data.type == 'resource') {
var questionType = 0;
} 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,
workplace: this.data.company,
name: this.data.username
}
console.log('报需求-->',data)
// 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
})
},
username: function (e) {
var username = e.detail.value;
this.setData({
username: username
})
},
initFormData() {
let {
nickName,
phone
} = store.readUserInfo()
this.setData({
username: nickName,
phone: phone
})
},
})