index.js 3.5 KB

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