|
@@ -1,7 +1,8 @@
|
|
|
const app = getApp()
|
|
|
import WxValidate from '../../utils/wxValidate'
|
|
|
-import { is_use_project } from '../../utils/dict';
|
|
|
-
|
|
|
+const moment = require("../../utils/moment.min")
|
|
|
+import { is_show_project } from '../../utils/dict';
|
|
|
+import { news_type } from '../../utils/dict';
|
|
|
Page({
|
|
|
|
|
|
|
|
@@ -10,51 +11,76 @@ Page({
|
|
|
data: {
|
|
|
frameStyle: { useTop: true, name: '信息管理', leftArrow: true, useBar: false },
|
|
|
id: '',
|
|
|
-
|
|
|
- referee_idList: [],
|
|
|
+
|
|
|
+ icon: [],
|
|
|
+ form: {},
|
|
|
|
|
|
- is_useList: is_use_project,
|
|
|
- form: {}
|
|
|
-
|
|
|
+ is_showList: is_show_project,
|
|
|
+ typeList: news_type,
|
|
|
},
|
|
|
initValidate() {
|
|
|
- const rules = { name: { required: true }, referee_id: { required: false }, remark: { required: false }, is_use: { required: false } }
|
|
|
+ const rules = { title: { required: true }, type: { required: true }, origin: { required: true }, brief: { required: true }, is_show: { required: true } }
|
|
|
|
|
|
- const messages = { name: { required: '请输入场地名称', }, referee_id: { required: '请选择裁判', }, remark: { required: '请输入备注', }, is_use: { required: '请选择是否使用' } };
|
|
|
+ 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 })
|
|
|
},
|
|
|
-
|
|
|
- referee_idChange: function (e) {
|
|
|
+
|
|
|
+ inputChange: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let html = e.detail.html;
|
|
|
+ that.setData({ "form.content": html });
|
|
|
+ },
|
|
|
+
|
|
|
+ typeChange: function (e) {
|
|
|
const that = this;
|
|
|
- let index = e.detail.value;
|
|
|
- let value = that.data.referee_idList[index];
|
|
|
- that.setData({ 'form.referee_id': value.openid });
|
|
|
- that.setData({ 'form.referee_name': value.name });
|
|
|
+ let data = that.data.typeList[e.detail.value];
|
|
|
+ if (data) that.setData({ 'form.type': data.value })
|
|
|
},
|
|
|
|
|
|
- is_useChange: function (e) {
|
|
|
+ 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 index = e.detail.value;
|
|
|
- let value = that.data.is_useList[index];
|
|
|
- that.setData({ 'form.is_use': value.value });
|
|
|
+ let data = that.data.icon;
|
|
|
+ data.push(e.detail)
|
|
|
+ that.setData({ icon: data })
|
|
|
+ },
|
|
|
+
|
|
|
+ imgDel: function (e) {
|
|
|
+ const that = this;
|
|
|
+ let list = that.data.icon;
|
|
|
+ let arr = list.filter((i, index) => index != e.detail.index)
|
|
|
+ that.setData({ icon: arr })
|
|
|
},
|
|
|
|
|
|
onSubmit: async function (e) {
|
|
|
const that = this;
|
|
|
const params = e.detail.value;
|
|
|
+ params.create_time = moment().format('YYYY-MM-DD');
|
|
|
const data = that.data.form;
|
|
|
+ params.content = data.content;
|
|
|
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 (data._id) arr = await app.$post(`/newCourt/api/ground/${data._id}`, params);
|
|
|
- else arr = await app.$post(`/newCourt/api/ground`, params);
|
|
|
+ if (data._id) {
|
|
|
+ if (!params.icon) params.home_url = that.data.icon;
|
|
|
+ arr = await app.$post(`/newCourt/api/news/${data._id}`, params);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ params.home_url = that.data.icon;
|
|
|
+ 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 })
|
|
|
|
|
@@ -77,18 +103,13 @@ Page({
|
|
|
wx.getStorage({
|
|
|
key: 'user',
|
|
|
success: async res => {
|
|
|
- const arr = await app.$get(`/newCourt/api/user`, { type: 1, skip: 0, limit: 1000 });
|
|
|
- if (arr.errcode == '0') { that.setData({ referee_idList: arr.data }); }
|
|
|
if (that.data.id) {
|
|
|
- const arr = await app.$get(`/newCourt/api/ground/${that.data.id}`);
|
|
|
+ const arr = await app.$get(`/newCourt/api/news/${that.data.id}`);
|
|
|
if (arr.errcode == '0') {
|
|
|
- let user = that.data.referee_idList.find((i) => i.openid == arr.data.referee_id);
|
|
|
- if (user) arr.data.referee_name = user.name;
|
|
|
+ if (arr.data.home_url) that.setData({ icon: arr.data.home_url });
|
|
|
that.setData({ form: arr.data });
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
},
|
|
|
fail: res => {
|
|
|
wx.redirectTo({ url: '/pages/index/index', })
|