wish.js 4.5 KB

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