wish.js 4.7 KB

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