import common from '../../utils/util'; import main from '../../utils/main'; import constant from '../../utils/constant'; const app = getApp(); var isViolate1 = false; var isViolate2 = false; Page({ data: { InputValue: "", ToWhomIndex: 0, IsOpen: true, IsShow:0, }, onLoad: function (options) { var that = this; that.setData({ Containnerheight: main.getWindowHeight(), IsShow:app.globalData.userInfo.IsShow, SchoolID: options.SchoolID, ID: 0, ArrToWhom: [{ Name: "给孩子",CSS: "btn11" }, { Name: "给自己",CSS: "" }, { Name: "给同学",CSS: "" }], }); if (options.type == "edit") { var mywish = app.globalData.MyWish; for (var i = 0; i < that.data.ArrToWhom.length; i++) { if (mywish.ToWhom == that.data.ArrToWhom[i].Name){ that.data.ArrToWhom[i].CSS = "btn11"; that.data.ToWhomIndex=i; } else that.data.ArrToWhom[i].CSS = ""; } that.setData({ inputName: mywish.ToName, inputContent: mywish.WishContent, SchoolID: mywish.SchoolID, IsOpen: mywish.IsOpen ? true : false, ArrToWhom: that.data.ArrToWhom, ToWhomIndex:that.data.ToWhomIndex, ID: mywish.ID, }); } if (app.globalData.userInfo.IsShow){ wx.setNavigationBarTitle({ title: "中考祝福", }); } }, onShow:function(){ if (app.globalData.TempParam=="return"){ app.globalData.TempParam=""; wx.navigateBack({ delta: 1 }); } else if (app.globalData.userInfo.NickName == "陌生用户") { wx.navigateTo({ url: 'userinfo?ReturnCount=2', }); } }, selectToWhom: function (event) { var index = event.currentTarget.dataset.index; this.data.ArrToWhom[0].CSS = ""; this.data.ArrToWhom[1].CSS = ""; this.data.ArrToWhom[2].CSS = ""; this.data.ArrToWhom[index].CSS = "btn11"; this.setData({ ArrToWhom: this.data.ArrToWhom, ToWhomIndex: index, }); }, randomWish: function () { var list = constant.arrWishInfo[this.data.ToWhomIndex].List; var index = common.random(0, list.length - 1); this.setData({ inputContent: list[index], }); }, bindKeyInputName: function (e) { var that = this; that.setData({ inputName: e.detail.value, }); that.onCheck(e.detail.value, 1); }, bindKeyInputContent: function (e) { var that = this; that.setData({ inputContent: e.detail.value, }); that.onCheck(e.detail.value, 2); }, clickCheckbox: function () { var that = this; that.setData({ IsOpen: !that.data.IsOpen, }); }, onCheck: function (content, num) { if (content) { if (num == 1) isViolate1 = false; else if (num == 2) isViolate2 = false; main.postData("MsgSecCheck2", { Content: content, UserID: app.globalData.userInfo.UserID, }, function (data) { if (data && data.errcode == 0) { } else { if (data.errmsg) { wx.showToast({ title: data.errmsg, duration: 2000, image: "../images/universalpic_exclamation_white_120x120.png", }); if (num == 1) isViolate1 = true; else if (num == 2) isViolate2 = true; } } }); } }, onSubmit: function () { var that = this; if (isViolate1 || isViolate2) { var str="名字或祝福语"; wx.showModal({ title: '生成失败', content: '抱歉,您填写的'+str+'未能通过微信敏感词检查故无法生成福帖。敏感词由微信官方功能判定,建议您调整内容多尝试几次。', showCancel: false, confirmText: '返回', }); } else { var param = {}; param.ID = that.data.ID; param.UserID = app.globalData.userInfo.UserID; param.SchoolID = that.data.SchoolID; param.ToWhom = that.data.ArrToWhom[that.data.ToWhomIndex].Name; param.ToName = that.data.inputName; if (param.ToName) param.ToName=common.Trim(param.ToName); param.WishContent = that.data.inputContent; if (param.WishContent) param.WishContent=common.Trim(param.WishContent); param.IsOpen = that.data.IsOpen ? 1 : 0; console.log(param); main.postData('MPSWish', param, function (data) { app.globalData.MyWish = data; //debugger; wx.redirectTo({ url: './wishinfo', }) }); } }, onShareAppMessage: function () { return { title: app.globalData.ShareTitle, path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID, imageUrl: app.globalData.ShareImage, } }, })