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.
220 lines
4.5 KiB
220 lines
4.5 KiB
3 years ago
|
// pages/user/editNeeds/index.js
|
||
|
const util = require('../../../utils/util.js')
|
||
|
const app = getApp()
|
||
|
import WxValidate from '../../../utils/WxValidate.js'
|
||
|
Page({
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
form: {
|
||
|
resourceType: 0,
|
||
|
title: '',
|
||
|
detailedDescription: '',
|
||
|
resourceImgs: [],
|
||
|
capital:'',
|
||
|
resourceStartTime:'',
|
||
|
resourceEndTime: '',
|
||
|
},
|
||
|
typeArr:['供应' , '需求'],
|
||
|
active: 1
|
||
|
},
|
||
|
tabClick(e){
|
||
|
let i = e.currentTarget.dataset.i;
|
||
|
if(i == 2){
|
||
|
this.setData({
|
||
|
['form.capital']: '价格可议'
|
||
|
})
|
||
|
}
|
||
|
this.setData({
|
||
|
active: e.currentTarget.dataset.i
|
||
|
})
|
||
|
},
|
||
|
startTimeChange(e){
|
||
|
this.setData({
|
||
|
['form.resourceStartTime']: e.detail.value
|
||
|
})
|
||
|
},
|
||
|
endTimeChange(e){
|
||
|
this.setData({
|
||
|
['form.resourceEndTime']: e.detail.value
|
||
|
})
|
||
|
},
|
||
|
bindPickerChange(e){
|
||
|
this.setData({
|
||
|
['form.resourceType']: this.data.typeArr[e.detail.value]
|
||
|
})
|
||
|
},
|
||
|
upImgs(){
|
||
|
util.chooseImages2(img => {
|
||
|
let imgs = this.data.form.imgPaths
|
||
|
imgs.push(img)
|
||
|
this.setData({
|
||
|
['form.resourceImgs']: imgs
|
||
|
})
|
||
|
});
|
||
|
},
|
||
|
/**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad: function (options) {
|
||
|
console.log(options)
|
||
|
if(options.id){
|
||
|
this.getDetail()
|
||
|
}
|
||
|
if(options.type){
|
||
|
this.setData({
|
||
|
['form.resourceType']: Number(options.type) - 1
|
||
|
})
|
||
|
}
|
||
|
this.initValidate()//验证规则函数
|
||
|
},
|
||
|
// 重新发布,获取提交数据
|
||
|
getDetail(){
|
||
|
|
||
|
},
|
||
|
initValidate(){
|
||
|
const rules = {
|
||
|
title: {
|
||
|
required: true,
|
||
|
},
|
||
|
resourceCagetoryId: {
|
||
|
required: true,
|
||
|
},
|
||
|
detailedDescription: {
|
||
|
required: true,
|
||
|
},
|
||
|
resourceStartTime:{
|
||
|
required:true,
|
||
|
},
|
||
|
resourceEndTime:{
|
||
|
required:true,
|
||
|
}
|
||
|
}
|
||
|
const messages = {
|
||
|
title: {
|
||
|
required: '请填写标题',
|
||
|
},
|
||
|
resourceCagetoryId: {
|
||
|
required: '请填写需求类型',
|
||
|
},
|
||
|
detailedDescription: {
|
||
|
required: '请填写内容',
|
||
|
},
|
||
|
resourceEndTime:{
|
||
|
required: '请设置展示开始时间',
|
||
|
},
|
||
|
resourceEndTime:{
|
||
|
required: '请设置展示结束时间',
|
||
|
}
|
||
|
}
|
||
|
this.WxValidate = new WxValidate(rules, messages)
|
||
|
},
|
||
|
upImgs(){
|
||
|
util.chooseImages2(img => {
|
||
|
let imgs = this.data.form.resourceImgs
|
||
|
imgs.push(img)
|
||
|
this.setData({
|
||
|
['form.resourceImgs']: imgs
|
||
|
})
|
||
|
});
|
||
|
},
|
||
|
submit(e){
|
||
|
let that = this
|
||
|
let type = e.currentTarget.dataset.type
|
||
|
wx.showModal({
|
||
|
title: '提示!',
|
||
|
content: '是否确认提交?',
|
||
|
success(res){
|
||
|
if(res.confirm){
|
||
|
const params = e.detail.value
|
||
|
params.resourceType = that.data.form.resourceType + 1
|
||
|
params.resourceImgs = that.data.form.resourceImgs
|
||
|
params.capital = that.data.form.capital
|
||
|
params.resourceAuditState = type
|
||
|
if (!that.WxValidate.checkForm(params)) {
|
||
|
const error = that.WxValidate.errorList[0]
|
||
|
that.showModal(error)
|
||
|
return false
|
||
|
}
|
||
|
app.http('post','Resources/create',params).then((res)=>{
|
||
|
if(res.data.success){
|
||
|
wx.showToast({
|
||
|
title: '提交成功',
|
||
|
duration: 2000
|
||
|
})
|
||
|
setTimeout(()=>{
|
||
|
wx.navigateBack({
|
||
|
delta: 1,
|
||
|
})
|
||
|
},2000)
|
||
|
} else{
|
||
|
wx.showToast({
|
||
|
title: '请求失败',
|
||
|
duration: 2000,
|
||
|
icon: 'none'
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
} else{
|
||
|
console.log('已取消')
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
showModal(error) {
|
||
|
wx.showModal({
|
||
|
content: error.msg,
|
||
|
showCancel: false,
|
||
|
})
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面初次渲染完成
|
||
|
*/
|
||
|
onReady: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面显示
|
||
|
*/
|
||
|
onShow: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面隐藏
|
||
|
*/
|
||
|
onHide: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 生命周期函数--监听页面卸载
|
||
|
*/
|
||
|
onUnload: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||
|
*/
|
||
|
onPullDownRefresh: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 页面上拉触底事件的处理函数
|
||
|
*/
|
||
|
onReachBottom: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
/**
|
||
|
* 用户点击右上角分享
|
||
|
*/
|
||
|
onShareAppMessage: function () {
|
||
|
|
||
|
}
|
||
|
})
|