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.
137 lines
4.1 KiB
137 lines
4.1 KiB
// pages/moment/create/index.js
|
|
import { getMomentDetail, postMoment, updateMoment } from "../../../api/moment"
|
|
import { getFactoryList } from "../../../api/ztb"
|
|
const util = require('../../../utils/util')
|
|
const event = require('../../../utils/event.js')
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
form: {},
|
|
requesting: false,
|
|
factoryFlag: true,
|
|
factoryList: []
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
if(!util.isEmpty(options.lableId)){
|
|
this.data.form.categoryId = Number(options.lableId)
|
|
}
|
|
if(options.factoryId){
|
|
this.data.form.millPaperId = options.factoryId
|
|
this.data.factoryFlag = false
|
|
this.setData({ ['form.millPaperName']: options.name })
|
|
} else {
|
|
getFactoryList().then(result => {
|
|
this.data.factoryList = []
|
|
for (let index = 0; index < result.data.records.length; index++) {
|
|
const element = result.data.records[index]
|
|
this.data.factoryList.push({value: element.paperMillId, text: element.name })
|
|
}
|
|
})
|
|
}
|
|
if(options.id){
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
getMomentDetail(options.id).then(result => {
|
|
var fileList = []
|
|
if (result.data.imageUrlList && result.data.imageUrlList.length) {
|
|
result.data.imageUrlList.forEach(element => {
|
|
fileList.push({ url: element, status: 8 })
|
|
})
|
|
}
|
|
result.data.imageUrls = result.data.imageUrlList
|
|
this.setData({ form: result.data, fileList: fileList })
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
})
|
|
}
|
|
},
|
|
bindInput: function (e) {
|
|
this.data.form[e.target.id] = e.detail.value
|
|
},
|
|
onImageChange: function (e) {
|
|
if (e.detail) {
|
|
var list = []
|
|
e.detail.forEach(element => {
|
|
if (!util.isEmpty(element.url)) {
|
|
list.push(element.url)
|
|
}
|
|
})
|
|
this.data.form['imageUrls'] = list
|
|
}
|
|
},
|
|
submitForm: function(){
|
|
if(this.data.requesting){
|
|
return
|
|
}
|
|
if(util.isEmpty(this.data.form.title)){
|
|
util.showToast('请输入标题')
|
|
return
|
|
}
|
|
if(util.isEmpty(this.data.form.content)){
|
|
util.showToast('请输入内容')
|
|
return
|
|
}
|
|
wx.showLoading({ title: '处理中', mask: true })
|
|
this.data.requesting = true
|
|
if(util.isEmpty(this.data.form.id)){
|
|
postMoment(this.data.form).then(result => {
|
|
wx.hideLoading()
|
|
var what = 570
|
|
if(Number(this.data.form.categoryId) > 0){
|
|
what += this.data.form.categoryId
|
|
}
|
|
event.emit('EventMessage', { what, desc: 'PostChange' })
|
|
util.showBackToast('发布成功')
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
this.data.requesting = false
|
|
util.showToast(err)
|
|
})
|
|
} else {
|
|
updateMoment(this.data.form.id, this.data.form).then(result => {
|
|
wx.hideLoading()
|
|
event.emit('EventMessage', { what: 501, desc: 'PostChange' })
|
|
util.showBackToast('编辑成功')
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
this.data.requesting = false
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
},
|
|
selectFactory: function (e) {
|
|
if(!this.data.factoryFlag){
|
|
return
|
|
}
|
|
this.pickerView = this.pickerView || this.selectComponent('#picker-view')
|
|
if(this.data.factoryList.length > 0){
|
|
this.pickerView.showPicker(this.data.factoryList)
|
|
} else {
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
getFactoryList().then(result => {
|
|
this.data.factoryList = []
|
|
for (let index = 0; index < result.data.records.length; index++) {
|
|
const element = result.data.records[index]
|
|
this.data.factoryList.push({value: element.paperMillId, text: element.name })
|
|
}
|
|
this.pickerView.showPicker(this.data.factoryList)
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
})
|
|
}
|
|
},
|
|
onPickerChange: function (e) {
|
|
if(!e.detail){
|
|
return
|
|
}
|
|
this.setData({ ['form.millPaperId']: e.detail.value, ['form.millPaperName']: e.detail.text })
|
|
}
|
|
|
|
})
|