conference.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // pages/conference/conference.js
  2. const app = getApp()
  3. var host = app.globalData.host;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. info:{},
  10. text:'发送验证码',
  11. labels: {
  12. company: '单位', name: '姓名', tax_company: '发票单位', idcard: '身份证号',
  13. email: '邮箱', sex: '性别', age: '年龄', title: '职称',
  14. remark1: '备注1', remark2: '备注2', remark3: '备注3', phone:'手机号'
  15. },
  16. sex_array: ['男', '女'],
  17. sex: -1,
  18. phone:'',
  19. show:0
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. var that = this;
  26. wx.showNavigationBarLoading()
  27. var that = this;
  28. wx.getStorage({
  29. key: 'uid',
  30. success: res => {
  31. if (res.data) {
  32. this.setData({
  33. user_id: res.data
  34. })
  35. wx.request({
  36. url: host + '/api/detail',
  37. method: 'GET',
  38. data: {
  39. type: 'activity',
  40. id: options.id,
  41. uid: res.data
  42. },
  43. success: function (res) {
  44. wx.hideNavigationBarLoading();
  45. if(res.data.code != 0){
  46. wx.showToast({
  47. title: '服务器开小差啦!',
  48. icon: 'none'
  49. })
  50. return
  51. }
  52. const info = res.data.data
  53. if (info.sign_note) { info.sign_note = info.sign_note.replace(/\\n/, '\n') }
  54. that.setData({
  55. info: info
  56. })
  57. },
  58. fail: function () {
  59. wx.hideLoading();
  60. wx.showToast({
  61. title: '服务器开小差啦!',
  62. icon: 'none'
  63. })
  64. }
  65. })
  66. }
  67. },
  68. })
  69. },
  70. close: function () {
  71. this.setData({
  72. show: 0
  73. })
  74. },
  75. open: function () {
  76. this.setData({
  77. show: 1
  78. })
  79. },
  80. phoneChange: function (e) {
  81. this.setData({
  82. phone: e.detail.value
  83. })
  84. },
  85. sendcode: function () {
  86. if (this.data.phone.length < 11) {
  87. wx.showToast({
  88. title: '请输入正确的手机号',
  89. icon: 'none'
  90. })
  91. return;
  92. }
  93. wx.request({
  94. url: host + '/api/phcode',
  95. method: 'POST',
  96. data: { phone: this.data.phone },
  97. success: res => {
  98. if (res.data.code == 0) {
  99. wx.showToast({
  100. title: '验证码已发送',
  101. })
  102. this.countdown()
  103. } else {
  104. wx.showToast({
  105. title: '发送失败',
  106. icon: 'none'
  107. })
  108. }
  109. },
  110. })
  111. },
  112. countdown: function () {
  113. var time = 60, text;
  114. var timer = setInterval(() => {
  115. if (time > 0) {
  116. time--;
  117. text = time + 's'
  118. } else {
  119. text = '发送验证码'
  120. clearInterval(timer)
  121. }
  122. this.setData({
  123. text: text
  124. })
  125. }, 1000)
  126. },
  127. bindSexChange: function (e) {
  128. this.setData({
  129. sex: e.detail.value
  130. })
  131. },
  132. //提交报名信息
  133. submit: function (e) {
  134. var form = e.detail.value;
  135. var list = this.data.list, index = this.data.index;
  136. if (this.data.info.signup_fields.indexOf('sex') >= 0) {
  137. form.sex = this.data.sex > -1 ? this.data.sex:''
  138. }
  139. form.uid = this.data.user_id;
  140. form.conference_id = this.data.info.id;
  141. form.conference_name = this.data.info.name;
  142. form.type ='activity';
  143. console.log(form)
  144. var fields = this.data.info.signup_fields;
  145. for(let i=0;i<fields.length;i++){
  146. if (!form[fields[i]]){
  147. wx.showToast({
  148. title: '请输入' + this.data.labels[fields[i]]+'!',
  149. icon: 'none'
  150. })
  151. return;
  152. }
  153. }
  154. if (!form.code) {
  155. wx.showToast({
  156. title: '请输入验证码!',
  157. icon: 'none'
  158. })
  159. return;
  160. }
  161. wx.showLoading({
  162. title: '正在提交',
  163. })
  164. wx.request({
  165. url: host + '/api/user/signup',
  166. method: 'POST',
  167. data: form,
  168. success: (res => {
  169. if (res.data.code == 0) {
  170. wx.hideLoading()
  171. this.setData({
  172. show: 0
  173. })
  174. wx.redirectTo({
  175. url: '../order/order',
  176. })
  177. } else {
  178. wx.showToast({
  179. title: '提交失败',
  180. icon: 'none'
  181. })
  182. }
  183. })
  184. })
  185. },
  186. /**
  187. * 生命周期函数--监听页面初次渲染完成
  188. */
  189. onReady: function () {
  190. },
  191. /**
  192. * 生命周期函数--监听页面显示
  193. */
  194. onShow: function () {
  195. },
  196. /**
  197. * 生命周期函数--监听页面隐藏
  198. */
  199. onHide: function () {
  200. },
  201. /**
  202. * 生命周期函数--监听页面卸载
  203. */
  204. onUnload: function () {
  205. },
  206. /**
  207. * 页面相关事件处理函数--监听用户下拉动作
  208. */
  209. onPullDownRefresh: function () {
  210. },
  211. /**
  212. * 页面上拉触底事件的处理函数
  213. */
  214. onReachBottom: function () {
  215. },
  216. /**
  217. * 用户点击右上角分享
  218. */
  219. onShareAppMessage: function () {
  220. }
  221. })