index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // pages/form/index.js
  2. var api = require('../../utils/api.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. data: {
  9. formContainerClass: 'mode-1-container'
  10. }
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. var that = this;
  17. wx.request({
  18. url: api.getFormSetUrl,
  19. method: 'GET',
  20. success: res => {
  21. if(res.data.status == 'success') {
  22. var formContainerClass = res.data.data.mode == 1 ? 'mode-1-container' : 'mode-2-container'
  23. that.setData({
  24. data: res.data.data,
  25. formContainerClass: formContainerClass
  26. })
  27. if(res.data.data.top_title) {
  28. wx.setNavigationBarTitle({
  29. title: res.data.data.top_title
  30. })
  31. }
  32. }
  33. }
  34. })
  35. },
  36. formSubmit: function(e) {
  37. var that = this,
  38. data = that.data.data,
  39. value = e.detail.value;
  40. if(data.money && data.money != '0') {
  41. value.type = 'pay';
  42. } else {
  43. value.type = 'form';
  44. }
  45. var id = wx.getStorageSync('we_chat_user_id')
  46. if(data.text_1_need == 1 && !value.text_1) {
  47. wx.showToast({
  48. icon: 'none',
  49. title: data.text_1 + '必填',
  50. })
  51. return false;
  52. }
  53. if (data.text_2_need == 1 && !value.text_2) {
  54. wx.showToast({
  55. icon: 'none',
  56. title: data.text_2 + '必填',
  57. })
  58. return false;
  59. }
  60. if (data.text_3_need == 1 && !value.text_3) {
  61. wx.showToast({
  62. icon: 'none',
  63. title: data.text_3 + '必填',
  64. })
  65. return false;
  66. }
  67. if (data.text_4_need == 1 && !value.text_4) {
  68. wx.showToast({
  69. icon: 'none',
  70. title: data.text_4 + '必填',
  71. })
  72. return false;
  73. }
  74. if (data.multi_text_need == 1 && !value.multi_text) {
  75. wx.showToast({
  76. icon: 'none',
  77. title: data.multi_text + '必填',
  78. })
  79. return false;
  80. }
  81. if (data.radio_need == 1 && !value.radio) {
  82. wx.showToast({
  83. icon: 'none',
  84. title: data.radio + '必填',
  85. })
  86. return false;
  87. }
  88. if (data.checkbox_need == 1 && !value.checkbox) {
  89. wx.showToast({
  90. icon: 'none',
  91. title: data.checkbox + '必填',
  92. })
  93. return false;
  94. }
  95. wx.request({
  96. url: api.submitFormUrl,
  97. method: 'POST',
  98. data: {
  99. data: value,
  100. id: id
  101. },
  102. success: res => {
  103. console.log(res)
  104. if (res.data.status == 'success') {
  105. if(value.type == 'pay') {
  106. // wx.requestPayment({
  107. // timeStamp: '',
  108. // nonceStr: '',
  109. // package: '',
  110. // signType: '',
  111. // paySign: '',
  112. // })
  113. console.log(res);
  114. } else {
  115. wx.showToast({
  116. icon: 'none',
  117. title: '提交成功',
  118. })
  119. }
  120. }
  121. }
  122. })
  123. },
  124. /**
  125. * 生命周期函数--监听页面初次渲染完成
  126. */
  127. onReady: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面显示
  131. */
  132. onShow: function () {
  133. },
  134. /**
  135. * 生命周期函数--监听页面隐藏
  136. */
  137. onHide: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面卸载
  141. */
  142. onUnload: function () {
  143. },
  144. /**
  145. * 页面相关事件处理函数--监听用户下拉动作
  146. */
  147. onPullDownRefresh: function () {
  148. },
  149. /**
  150. * 页面上拉触底事件的处理函数
  151. */
  152. onReachBottom: function () {
  153. },
  154. /**
  155. * 用户点击右上角分享
  156. */
  157. onShareAppMessage: function (t) {
  158. var a = this;
  159. return {
  160. path: "/pages/index/index",
  161. success: function (t) {
  162. },
  163. title:"钢琴时间打卡"
  164. };
  165. },
  166. })