wish.js 4.4 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 (num==1)
  86. isViolate1 = false;
  87. else if (num==2)
  88. isViolate2 = false;
  89. main.postData("MsgSecCheck2", {
  90. Content: content,
  91. UserID: app.globalData.userInfo.UserID,
  92. },
  93. function (data) {
  94. if (data && data.errcode == 0) {
  95. } else {
  96. if (data.errmsg) {
  97. wx.showToast({
  98. title: data.errmsg,
  99. duration: 2000,
  100. image: "../images/universalpic_wrong_white_120x120.png",
  101. });
  102. if (num==1)
  103. isViolate1 = true;
  104. else if (num==2)
  105. isViolate2 = true;
  106. }
  107. }
  108. });
  109. },
  110. onSubmit: function () {
  111. var that = this;
  112. if (isViolate1) {
  113. wx.showModal({
  114. title: '生成失败',
  115. content: '抱歉,您填写的名字未能通过微信敏感词检查故无法生成福帖。敏感词由微信官方功能判定,建议您调整内容多尝试几次。',
  116. showCancel: false,
  117. confirmText: '返回',
  118. });
  119. }
  120. else if (isViolate2) {
  121. wx.showModal({
  122. title: '生成失败',
  123. content: '抱歉,您填写的祝福语未能通过微信敏感词检查故无法生成福帖。敏感词由微信官方功能判定,建议您调整内容多尝试几次。',
  124. showCancel: false,
  125. confirmText: '返回',
  126. });
  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. })