// pages/moment/create/index.js const request = require('../../../utils/request') //导入模块 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 { request.get('/recycle-service/get/paper-mill-list').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 }) request.get('/information-center/article/get/Article-detail/' + options.id).then(result => { // imgUrlList var fileList = [] if (result.data.imgUrlList && result.data.imgUrlList.length) { result.data.imgUrlList.forEach(element => { fileList.push({ url: element, status: 8 }) }) } 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)){ // /article/save/Article 发文章 request.post('/information-center/article/save/Article', 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 { // /article/update/Article/{id} 编辑文章 request.post('/information-center/article/update/Article/' + 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 }) request.get('/recycle-service/get/paper-mill-list').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 }) } })