index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. if(data.text_1_need == 1 && !value.text_1) {
  46. wx.showToast({
  47. icon: 'none',
  48. title: data.text_1 + '必填',
  49. })
  50. return false;
  51. }
  52. if (data.text_2_need == 1 && !value.text_2) {
  53. wx.showToast({
  54. icon: 'none',
  55. title: data.text_2 + '必填',
  56. })
  57. return false;
  58. }
  59. if (data.text_3_need == 1 && !value.text_3) {
  60. wx.showToast({
  61. icon: 'none',
  62. title: data.text_3 + '必填',
  63. })
  64. return false;
  65. }
  66. if (data.text_4_need == 1 && !value.text_4) {
  67. wx.showToast({
  68. icon: 'none',
  69. title: data.text_4 + '必填',
  70. })
  71. return false;
  72. }
  73. if (data.multi_text_need == 1 && !value.multi_text) {
  74. wx.showToast({
  75. icon: 'none',
  76. title: data.multi_text + '必填',
  77. })
  78. return false;
  79. }
  80. if (data.radio_need == 1 && !value.radio) {
  81. wx.showToast({
  82. icon: 'none',
  83. title: data.radio + '必填',
  84. })
  85. return false;
  86. }
  87. if (data.checkbox_need == 1 && !value.checkbox) {
  88. wx.showToast({
  89. icon: 'none',
  90. title: data.checkbox + '必填',
  91. })
  92. return false;
  93. }
  94. wx.request({
  95. url: api.submitFormUrl,
  96. method: 'POST',
  97. data: {
  98. data: value
  99. },
  100. success: res => {
  101. console.log(res)
  102. if (res.data.status == 'success') {
  103. if(value.type == 'pay') {
  104. console.log(res);
  105. } else {
  106. wx.showToast({
  107. icon: 'none',
  108. title: '提交成功',
  109. })
  110. }
  111. }
  112. }
  113. })
  114. },
  115. /**
  116. * 生命周期函数--监听页面初次渲染完成
  117. */
  118. onReady: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面显示
  122. */
  123. onShow: function () {
  124. },
  125. /**
  126. * 生命周期函数--监听页面隐藏
  127. */
  128. onHide: function () {
  129. },
  130. /**
  131. * 生命周期函数--监听页面卸载
  132. */
  133. onUnload: function () {
  134. },
  135. /**
  136. * 页面相关事件处理函数--监听用户下拉动作
  137. */
  138. onPullDownRefresh: function () {
  139. },
  140. /**
  141. * 页面上拉触底事件的处理函数
  142. */
  143. onReachBottom: function () {
  144. },
  145. /**
  146. * 用户点击右上角分享
  147. */
  148. onShareAppMessage: function () {
  149. }
  150. })