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.
270 lines
5.6 KiB
270 lines
5.6 KiB
// 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: '', |
|
}, |
|
active: 1, |
|
resourcesList: [], |
|
resourcesIdx: null |
|
}, |
|
tabClick(e){ |
|
let i = e.currentTarget.dataset.i; |
|
if(i == 2){ |
|
this.setData({ |
|
['form.capital']: '价格可议' |
|
}) |
|
} |
|
this.setData({ |
|
active: e.currentTarget.dataset.i |
|
}) |
|
}, |
|
capitalChange(e){ |
|
this.setData({ |
|
['form.capital']: e.detail.value |
|
}) |
|
}, |
|
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) { |
|
if(options.id){ |
|
this.getDetail() |
|
} |
|
if(options.type){ |
|
this.setData({ |
|
['form.resourceType']: Number(options.type) |
|
}) |
|
} |
|
this.initValidate()//验证规则函数 |
|
this.getResourcesCagetory() |
|
}, |
|
//获取供应、需求类型 |
|
getResourcesCagetory(){ |
|
app.http('GET','ResourcesCagetory/listResourcesCagetory').then((res)=>{ |
|
// console.log(res) |
|
if(res.data.success){ |
|
this.setData({ |
|
resourcesList: res.data.data |
|
}) |
|
} |
|
}) |
|
}, |
|
resourcesChange(e){ |
|
// console.log(e) |
|
let idx = Number(e.detail.value) |
|
this.setData({ |
|
resourcesIdx: idx, |
|
['form.resourceCagetoryId']: this.data.resourcesList[idx].id |
|
}) |
|
}, |
|
// 重新发布,获取提交数据 |
|
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.detail.target.dataset.type |
|
let params = e.detail.value |
|
params.resourceType = that.data.form.resourceType |
|
params.resourceCagetoryId = that.data.form.resourceCagetoryId |
|
params.resourceImgs = that.data.form.resourceImgs |
|
params.capital = that.data.form.capital |
|
if(type == 0){ |
|
params.isDraft = true |
|
wx.showModal({ |
|
title: '提示!', |
|
content: '是否保存到草稿箱?', |
|
success(res){ |
|
if(res.confirm){ |
|
if (!that.WxValidate.checkForm(params)) { |
|
const error = that.WxValidate.errorList[0] |
|
that.showModal(error) |
|
return false |
|
} |
|
that.submitHttp(params) |
|
} else{ |
|
console.log('已取消') |
|
} |
|
} |
|
}) |
|
} else{ |
|
wx.showModal({ |
|
title: '提示!', |
|
content: '是否确认提交?', |
|
success(res){ |
|
if(res.confirm){ |
|
params.isDraft = false |
|
if (!that.WxValidate.checkForm(params)) { |
|
const error = that.WxValidate.errorList[0] |
|
that.showModal(error) |
|
return false |
|
} |
|
that.submitHttp(params) |
|
} else{ |
|
console.log('已取消') |
|
} |
|
} |
|
}) |
|
} |
|
|
|
}, |
|
submitHttp(params){ |
|
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' |
|
}) |
|
} |
|
}) |
|
}, |
|
showModal(error) { |
|
wx.showModal({ |
|
content: error.msg, |
|
showCancel: false, |
|
}) |
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面初次渲染完成 |
|
*/ |
|
onReady: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面显示 |
|
*/ |
|
onShow: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面隐藏 |
|
*/ |
|
onHide: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 生命周期函数--监听页面卸载 |
|
*/ |
|
onUnload: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 页面相关事件处理函数--监听用户下拉动作 |
|
*/ |
|
onPullDownRefresh: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 页面上拉触底事件的处理函数 |
|
*/ |
|
onReachBottom: function () { |
|
|
|
}, |
|
|
|
/** |
|
* 用户点击右上角分享 |
|
*/ |
|
onShareAppMessage: function () { |
|
|
|
} |
|
}) |