wishAdd.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. import constant from '../../utils/constant';
  4. const app = getApp();
  5. var isViolate1 = false;
  6. var isViolate2 = false;
  7. Page({
  8. data: {
  9. InputValue: "",
  10. ToWhomIndex: 0,
  11. IsOpen: true,
  12. IsShow:0,
  13. },
  14. onLoad: function (options) {
  15. var that = this;
  16. that.setData({
  17. Containnerheight: main.getWindowHeight(),
  18. IsShow:app.globalData.userInfo.IsShow,
  19. SchoolID: options.SchoolID,
  20. ID: 0,
  21. ArrToWhom: [{
  22. Name: "给孩子",CSS: "btn11"
  23. }, {
  24. Name: "给自己",CSS: ""
  25. }, {
  26. Name: "给同学",CSS: ""
  27. }],
  28. });
  29. if (options.type == "edit") {
  30. var mywish = app.globalData.MyWish;
  31. for (var i = 0; i < that.data.ArrToWhom.length; i++) {
  32. if (mywish.ToWhom == that.data.ArrToWhom[i].Name){
  33. that.data.ArrToWhom[i].CSS = "btn11";
  34. that.data.ToWhomIndex=i;
  35. }
  36. else
  37. that.data.ArrToWhom[i].CSS = "";
  38. }
  39. that.setData({
  40. inputName: mywish.ToName,
  41. inputContent: mywish.WishContent,
  42. SchoolID: mywish.SchoolID,
  43. IsOpen: mywish.IsOpen ? true : false,
  44. ArrToWhom: that.data.ArrToWhom,
  45. ToWhomIndex:that.data.ToWhomIndex,
  46. ID: mywish.ID,
  47. });
  48. }
  49. if (app.globalData.userInfo.IsShow){
  50. wx.setNavigationBarTitle({
  51. title: "中考祝福",
  52. });
  53. }
  54. },
  55. onShow:function(){
  56. if (app.globalData.TempParam=="return"){
  57. app.globalData.TempParam="";
  58. wx.navigateBack({
  59. delta: 1
  60. });
  61. }
  62. else if (app.globalData.userInfo.NickName == "陌生用户") {
  63. wx.navigateTo({
  64. url: 'userinfo?ReturnCount=2',
  65. });
  66. }
  67. },
  68. selectToWhom: function (event) {
  69. var index = event.currentTarget.dataset.index;
  70. this.data.ArrToWhom[0].CSS = "";
  71. this.data.ArrToWhom[1].CSS = "";
  72. this.data.ArrToWhom[2].CSS = "";
  73. this.data.ArrToWhom[index].CSS = "btn11";
  74. this.setData({
  75. ArrToWhom: this.data.ArrToWhom,
  76. ToWhomIndex: index,
  77. });
  78. },
  79. randomWish: function () {
  80. var list = constant.arrWishInfo[this.data.ToWhomIndex].List;
  81. var index = common.random(0, list.length - 1);
  82. this.setData({
  83. inputContent: list[index],
  84. });
  85. },
  86. bindKeyInputName: function (e) {
  87. var that = this;
  88. that.setData({
  89. inputName: e.detail.value,
  90. });
  91. that.onCheck(e.detail.value, 1);
  92. },
  93. bindKeyInputContent: function (e) {
  94. var that = this;
  95. that.setData({
  96. inputContent: e.detail.value,
  97. });
  98. that.onCheck(e.detail.value, 2);
  99. },
  100. clickCheckbox: function () {
  101. var that = this;
  102. that.setData({
  103. IsOpen: !that.data.IsOpen,
  104. });
  105. },
  106. onCheck: function (content, num) {
  107. if (content) {
  108. if (num == 1)
  109. isViolate1 = false;
  110. else if (num == 2)
  111. isViolate2 = false;
  112. main.postData("MsgSecCheck2", {
  113. Content: content,
  114. UserID: app.globalData.userInfo.UserID,
  115. },
  116. function (data) {
  117. if (data && data.errcode == 0) {
  118. } else {
  119. if (data.errmsg) {
  120. wx.showToast({
  121. title: data.errmsg,
  122. duration: 2000,
  123. image: "../images/universalpic_exclamation_white_120x120.png",
  124. });
  125. if (num == 1)
  126. isViolate1 = true;
  127. else if (num == 2)
  128. isViolate2 = true;
  129. }
  130. }
  131. });
  132. }
  133. },
  134. onSubmit: function () {
  135. var that = this;
  136. if (isViolate1 || isViolate2) {
  137. var str="名字或祝福语";
  138. wx.showModal({
  139. title: '生成失败',
  140. content: '抱歉,您填写的'+str+'未能通过微信敏感词检查故无法生成福帖。敏感词由微信官方功能判定,建议您调整内容多尝试几次。',
  141. showCancel: false,
  142. confirmText: '返回',
  143. });
  144. } else {
  145. var param = {};
  146. param.ID = that.data.ID;
  147. param.UserID = app.globalData.userInfo.UserID;
  148. param.SchoolID = that.data.SchoolID;
  149. param.ToWhom = that.data.ArrToWhom[that.data.ToWhomIndex].Name;
  150. param.ToName = that.data.inputName;
  151. if (param.ToName)
  152. param.ToName=common.Trim(param.ToName);
  153. param.WishContent = that.data.inputContent;
  154. if (param.WishContent)
  155. param.WishContent=common.Trim(param.WishContent);
  156. param.IsOpen = that.data.IsOpen ? 1 : 0;
  157. console.log(param);
  158. main.postData('MPSWish', param, function (data) {
  159. app.globalData.MyWish = data;
  160. //debugger;
  161. wx.redirectTo({
  162. url: './wishinfo',
  163. })
  164. });
  165. }
  166. },
  167. onShareAppMessage: function () {
  168. return {
  169. title: app.globalData.ShareTitle,
  170. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  171. imageUrl: app.globalData.ShareImage,
  172. }
  173. },
  174. })