|
@@ -1,66 +1,159 @@
|
|
|
-
|
|
|
+const app = getApp()
|
|
|
+import WxValidate from '../../utils/wxValidate'
|
|
|
+const moment = require("../../utils/moment.min")
|
|
|
+import { is_show_project } from '../../utils/dict';
|
|
|
+import { news_type } from '../../utils/dict';
|
|
|
Page({
|
|
|
|
|
|
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
-
|
|
|
+ frameStyle: { useTop: true, name: '信息管理', leftArrow: true, useBar: false },
|
|
|
+ id: '',
|
|
|
+ form: { home_url: [], },
|
|
|
+
|
|
|
+ is_showList: is_show_project,
|
|
|
+ typeList: news_type,
|
|
|
+ },
|
|
|
+ initValidate() {
|
|
|
+ const rules = { title: { required: true }, type: { required: true }, origin: { required: true }, brief: { required: true }, is_show: { required: true } }
|
|
|
+
|
|
|
+ const messages = { title: { required: '请输入资讯名称', }, type: { required: '请输入资讯类型', }, origin: { required: '请输入来源', }, brief: { required: '请输入内容' }, is_show: { required: '请选择是否公开' } };
|
|
|
+ this.WxValidate = new WxValidate(rules, messages)
|
|
|
+ },
|
|
|
+
|
|
|
+ back: function () {
|
|
|
+ wx.navigateBack({ delta: 1 })
|
|
|
+ },
|
|
|
+
|
|
|
+ inputChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let html = e.detail.html;
|
|
|
+ that.setData({ "form.content": html });
|
|
|
+ },
|
|
|
+
|
|
|
+ typeChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.typeList[e.detail.value];
|
|
|
+ if (data) that.setData({ 'form.type': data.value })
|
|
|
+ },
|
|
|
+
|
|
|
+ is_showChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.is_showList[e.detail.value];
|
|
|
+ that.setData({ 'form.is_show': data.value });
|
|
|
+ },
|
|
|
+
|
|
|
+ imgUpload: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let data = that.data.form.home_url;
|
|
|
+ data.push(e.detail)
|
|
|
+ that.setData({ "form.home_url": data })
|
|
|
+ },
|
|
|
+
|
|
|
+ imgDel: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let list = that.data.form.home_url;
|
|
|
+ let arr = list.filter((i, index) => index != e.detail.index)
|
|
|
+ that.setData({ "form.home_url": arr })
|
|
|
+ },
|
|
|
+
|
|
|
+ onSubmit: async function (e) {
|
|
|
+ const that = this;
|
|
|
+ const params = e.detail.value;
|
|
|
+ params.create_time = moment().format('YYYY-MM-DD');
|
|
|
+ const form = that.data.form;
|
|
|
+ params.content = form.content;
|
|
|
+ params.home_url = form.home_url;
|
|
|
+ if (!this.WxValidate.checkForm(params)) {
|
|
|
+ const error = this.WxValidate.errorList[0];
|
|
|
+ wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ let arr;
|
|
|
+ if (form._id) { arr = await app.$post(`/newCourt/api/news/${form._id}`, params); }
|
|
|
+ else { arr = await app.$post(`/newCourt/api/news`, params); }
|
|
|
+ if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
|
|
|
+ else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
|
|
|
+
|
|
|
+ }
|
|
|
},
|
|
|
-
|
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad(options) {
|
|
|
-
|
|
|
+ onLoad: function (options) {
|
|
|
+ const that = this;
|
|
|
+ that.setData({ id: options.id || '' })
|
|
|
+
|
|
|
+ that.initValidate();
|
|
|
+
|
|
|
+ that.watchLogin();
|
|
|
+ },
|
|
|
+
|
|
|
+ watchLogin: async function () {
|
|
|
+ const that = this;
|
|
|
+ wx.getStorage({
|
|
|
+ key: 'user',
|
|
|
+ success: async res => {
|
|
|
+ if (that.data.id) {
|
|
|
+ const arr = await app.$get(`/newCourt/api/news/${that.data.id}`);
|
|
|
+ if (arr.errcode == '0') {
|
|
|
+ that.setData({ form: arr.data });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: res => {
|
|
|
+ wx.redirectTo({ url: '/pages/index/index', })
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
-
|
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
- onReady() {
|
|
|
+ onReady: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
- onShow() {
|
|
|
+ onShow: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
- onHide() {
|
|
|
+ onHide: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
- onUnload() {
|
|
|
+ onUnload: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
- onPullDownRefresh() {
|
|
|
+ onPullDownRefresh: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
- onReachBottom() {
|
|
|
+ onReachBottom: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
* 用户点击右上角分享
|
|
|
*/
|
|
|
- onShareAppMessage() {
|
|
|
+ onShareAppMessage: function () {
|
|
|
|
|
|
}
|
|
|
})
|