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

4 years ago
// pages/topics/reportDemand/index.js
4 years ago
import {
config
} from '../../../config.js'
import {
store
} from '../../../utils/store.js'
import {
TopicModel
} from '../../../models/topic.js'
4 years ago
let topicModel = new TopicModel()
4 years ago
Page({
/**
* 页面的初始数据
*/
data: {
4 years ago
//类型
4 years ago
type: '',
messageTitle: "",
messageDetail: "",
messageTemp: "",
4 years ago
files: [],
// 所在街道
streets: [],
streetsIndex: 0,
4 years ago
typeList: [],
typeListIndex: 0,
4 years ago
//接口街道的数据
4 years ago
results: [],
list: [],
4 years ago
//选择后获取的街道的I,
4 years ago
streetID: '',
typeCode: '',
textareaValue: '',
error: '',
company: '',
username: ''
4 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
4 years ago
this.setData({
uplaodFile: this.uplaodFile.bind(this)
4 years ago
})
this.initFormData()
this.getStreetList()
this.getWhistleTypeList()
4 years ago
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
4 years ago
},
4 years ago
getStreetList() {
topicModel.getStreetList(res => {
4 years ago
var resultss = res.result
var streett = []
4 years ago
resultss.forEach((value, index) => {
4 years ago
streett[index] = value.departName
})
//把streett添加第一项设为空
4 years ago
streett.unshift('')
console.log('街道-->', streett)
4 years ago
this.setData({
streets: streett
})
//把接口数据放在results里
this.setData({
results: resultss
})
console.log(this.data.results)
})
},
4 years ago
getWhistleTypeList() {
topicModel.getWhistleTypeList(res => {
4 years ago
var result = res.result
var typeList = []
4 years ago
result.forEach((value, index) => {
4 years ago
typeList[index] = value.typeName
})
//把streett添加第一项设为空
4 years ago
typeList.unshift('')
4 years ago
this.setData({
typeList: typeList
})
//把接口数据放在results里
this.setData({
list: result
})
})
},
4 years ago
bindPickerStreetsChange: function (e) {
4 years ago
this.setData({
streetsIndex: e.detail.value,
})
4 years ago
if (e.detail.value == '0') {
4 years ago
this.setData({
streetID: ''
})
4 years ago
} else {
4 years ago
this.setData({
4 years ago
streetID: this.data.results[this.data.streetsIndex - 1].id
4 years ago
})
}
},
4 years ago
bindPickerTypeChange: function (e) {
4 years ago
this.setData({
typeListIndex: e.detail.value,
})
4 years ago
if (e.detail.value == '0') {
4 years ago
this.setData({
typeCode: ''
})
4 years ago
} else {
4 years ago
this.setData({
4 years ago
typeCode: this.data.list[this.data.typeListIndex - 1].typeCode
4 years ago
})
}
},
bindTextInput(e) {
this.setData({
messageTitle: e.detail.value
})
},
bindTextAreaInput(e) {
console.log("bindTextAreaInput");
this.setData({
4 years ago
messageDetail: e.detail.value,
4 years ago
})
console.log(e.detail.value.length)
4 years ago
if (e.detail.value.length >= 200) {
4 years ago
// 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 => {
4 years ago
console.log('item', item)
4 years ago
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() {
4 years ago
var th = this;
if (this.data.messageDetail.length > 200) {
4 years ago
wx.showModal({
title: '提示',
content: '问题超过字数,请重新输入',
4 years ago
showCancel: false,
4 years ago
})
return
4 years ago
}
if (this.data.messageDetail === '') {
4 years ago
wx.showModal({
title: '提示',
content: '请输入正文内容',
4 years ago
showCancel: false
4 years ago
})
return
}
4 years ago
if (this.data.username === '') {
4 years ago
wx.showModal({
title: '提示',
content: '请输入姓名',
4 years ago
showCancel: false
4 years ago
})
return
}
4 years ago
if (this.data.username.length > 15) {
4 years ago
wx.showModal({
title: '提示',
content: '姓名长度不能超过15',
4 years ago
showCancel: false,
4 years ago
})
return
4 years ago
}
if (this.data.company === '') {
4 years ago
wx.showModal({
title: '提示',
content: '请输入工作单位',
4 years ago
showCancel: false
4 years ago
})
return
}
4 years ago
if (this.data.company.length > 15) {
4 years ago
wx.showModal({
title: '提示',
content: '工作单位长度不能超过15',
4 years ago
showCancel: false,
4 years ago
})
return
4 years ago
}
4 years ago
//判断是否选择街道
4 years ago
if (this.data.streetID === '') {
4 years ago
wx.showModal({
title: '提示',
content: '请输入街道',
4 years ago
showCancel: false
4 years ago
})
return
}
4 years ago
if (this.data.typeCode === '') {
4 years ago
wx.showModal({
title: '提示',
content: '请选择需求类型',
4 years ago
showCancel: false
4 years ago
})
return
}
4 years ago
if (this.data.type == 'resource') {
4 years ago
var questionType = 0;
4 years ago
} else {
4 years ago
var questionType = 2;
}
var data = {
4 years ago
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
4 years ago
}
4 years ago
console.log('报需求-->',data)
4 years ago
topicModel.addTalents(data, res => {
const id = res.result;
if (res.code === 200) {
4 years ago
this.setData({
messageDetail: '',
4 years ago
streetID: '',
typeCode: '',
files: [],
}, () => {
4 years ago
wx.showModal({
title: '提交成功',
content: '问题已收到!',
4 years ago
cancelText: '知道了',
confirmText: '查看进度',
success(res) {
4 years ago
if (res.confirm) {
wx.redirectTo({
4 years ago
url: '/pages/user/myWhistle/whistleDetail/index?id=' + id,
4 years ago
})
4 years ago
} else if (res.cancel) { // 点击知道了
if (th.properties.type == '') {
setTimeout(function () {
4 years ago
th.setData({
4 years ago
textareaValue: ''
})
4 years ago
}, 500);
4 years ago
} else {
4 years ago
console.log(1212);
wx.navigateBack({
delta: 1
})
}
}
}
})
})
}
})
this.setData({
streetsIndex: 0,
4 years ago
typeListIndex: 0,
4 years ago
})
},
4 years ago
company: function (e) {
4 years ago
var company = e.detail.value;
this.setData({
4 years ago
company: company
4 years ago
})
},
4 years ago
username: function (e) {
4 years ago
var username = e.detail.value;
this.setData({
4 years ago
username: username
4 years ago
})
4 years ago
},
initFormData() {
let {
nickName,
phone
} = store.readUserInfo()
this.setData({
username: nickName,
phone: phone
})
},
4 years ago
})