index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. value.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. },
  101. success: res => {
  102. console.log(res)
  103. if (res.data.status == 'success') {
  104. if(value.type == 'pay') {
  105. // wx.requestPayment({
  106. // timeStamp: '',
  107. // nonceStr: '',
  108. // package: '',
  109. // signType: '',
  110. // paySign: '',
  111. // })
  112. console.log(res);
  113. } else {
  114. wx.showToast({
  115. icon: 'none',
  116. title: '提交成功',
  117. })
  118. }
  119. }
  120. }
  121. })
  122. },
  123. /**
  124. * 生命周期函数--监听页面初次渲染完成
  125. */
  126. onReady: function () {
  127. },
  128. /**
  129. * 生命周期函数--监听页面显示
  130. */
  131. onShow: function () {
  132. },
  133. /**
  134. * 生命周期函数--监听页面隐藏
  135. */
  136. onHide: function () {
  137. },
  138. /**
  139. * 生命周期函数--监听页面卸载
  140. */
  141. onUnload: function () {
  142. },
  143. /**
  144. * 页面相关事件处理函数--监听用户下拉动作
  145. */
  146. onPullDownRefresh: function () {
  147. },
  148. /**
  149. * 页面上拉触底事件的处理函数
  150. */
  151. onReachBottom: function () {
  152. },
  153. /**
  154. * 用户点击右上角分享
  155. */
  156. onShareAppMessage: function (t) {
  157. var a = this;
  158. return {
  159. path: "/pages/index/index",
  160. success: function (t) {
  161. },
  162. title:"钢琴时间打卡"
  163. };
  164. },
  165. })