index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // pages/agent/index.js
  2. import {
  3. saveAgent
  4. } from '../../services/index.js'
  5. import {
  6. imgServerUrl
  7. } from '../../config/config.js'
  8. import {
  9. showToast
  10. } from '../../utils/tips.js'
  11. const app = getApp();
  12. Page({
  13. /**
  14. * 页面的初始数据
  15. */
  16. data: {
  17. name: '',
  18. contact: '',
  19. year: '',
  20. sex: ["请选择", "男", "女"],
  21. sex_index: 0,
  22. imgServerUrl: imgServerUrl,
  23. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  24. isLogin: false
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function(options) {
  30. this.getNodePos();
  31. },
  32. /**
  33. * 生命周期函数--监听页面初次渲染完成
  34. */
  35. onReady: function() {
  36. },
  37. /**
  38. * 生命周期函数--监听页面显示
  39. */
  40. onShow: function() {
  41. //获取用户user_id和member_id,判断是否处于登录态
  42. var userId = wx.getStorageSync("user_id");
  43. var userToken = wx.getStorageSync("user_token");
  44. var memberId = wx.getStorageSync("member_id");
  45. var isLogin = false;
  46. if (userId && memberId) {
  47. isLogin = true;
  48. app.globalData.userId = userId;
  49. app.globalData.userToken = userToken;
  50. app.globalData.memberId = memberId;
  51. }
  52. this.setData({
  53. isLogin: isLogin
  54. })
  55. },
  56. imageLoad() {
  57. var that = this
  58. var query = wx.createSelectorQuery()
  59. query.select('.agent1').boundingClientRect()
  60. query.select('.agent2').boundingClientRect()
  61. query.select('.agent3').boundingClientRect()
  62. query.select('.agent4').boundingClientRect()
  63. query.exec(function(res) {
  64. that.setData({
  65. swiperH: res[0].height,
  66. swiperH2: res[1].height,
  67. swiperH3: res[2].height,
  68. swiperH4: res[3].height
  69. })
  70. })
  71. },
  72. //获取位置
  73. getNodePos() {
  74. var query = wx.createSelectorQuery()
  75. query.select('#agentJoin').boundingClientRect()
  76. var that = this;
  77. query.exec(function(res) {
  78. that.setData({
  79. basePos: res[0].top + 500,
  80. })
  81. })
  82. },
  83. baoming(e) {
  84. let top = e.currentTarget.dataset.top
  85. wx.pageScrollTo({
  86. scrollTop: top,
  87. duration: 0
  88. })
  89. },
  90. changeName: function(e) {
  91. this.setData({
  92. name: e.detail.value
  93. })
  94. },
  95. changeContact: function(e) {
  96. this.setData({
  97. contact: e.detail.value
  98. })
  99. },
  100. //改变性别
  101. bindSexChange(e) {
  102. let {
  103. value
  104. } = e.detail
  105. this.setData({
  106. sex_index: value
  107. })
  108. },
  109. changeYear: function(e) {
  110. this.setData({
  111. year: e.detail.value
  112. })
  113. },
  114. submit() {
  115. if (!this.data.isLogin) {
  116. wx.navigateTo({
  117. url: '/pages/login/login',
  118. })
  119. return;
  120. }
  121. var name = this.data.name;
  122. var contact = this.data.contact;
  123. var sex = this.data.sex_index;
  124. var year = this.data.year;
  125. if (!name) {
  126. showToast("请填写姓名")
  127. return;
  128. }
  129. if (contact == "" || contact.length != 11) {
  130. showToast("请输入11位手机号")
  131. return;
  132. }
  133. if (sex == 0) {
  134. showToast("请选择性别")
  135. return;
  136. }
  137. if (!year) {
  138. showToast("请填写年龄")
  139. return;
  140. }
  141. var regNum = new RegExp('[0-9]', 'g');
  142. var rsNum = regNum.exec(year);
  143. if (!rsNum){
  144. showToast("年龄请输入正确的数字")
  145. return;
  146. }
  147. wx.showModal({
  148. title: '提示',
  149. content: '确定提交吗?',
  150. success: function(res) {
  151. if (res.confirm) {
  152. let paramsObj = {
  153. user_id: app.globalData.userId,
  154. user_token: app.globalData.userToken,
  155. member_id: app.globalData.memberId,
  156. name: name,
  157. phone: contact,
  158. gender: sex,
  159. age: year
  160. }
  161. Object.assign(paramsObj);
  162. saveAgent(paramsObj).then(data => {
  163. showToast('提交成功', 'success')
  164. setTimeout(function() {
  165. wx.navigateBack();
  166. }, 1000)
  167. })
  168. } else if (res.cancel) {
  169. }
  170. }
  171. })
  172. }
  173. })