index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. /**
  57. * 用户点击右上角分享
  58. */
  59. onShareAppMessage: function() {
  60. },
  61. imageLoad() {
  62. var that = this
  63. var query = wx.createSelectorQuery()
  64. query.select('.agent1').boundingClientRect()
  65. query.select('.agent2').boundingClientRect()
  66. query.select('.agent3').boundingClientRect()
  67. query.select('.agent4').boundingClientRect()
  68. query.exec(function(res) {
  69. console.log(res)
  70. that.setData({
  71. swiperH: res[0].height,
  72. swiperH2: res[1].height,
  73. swiperH3: res[2].height,
  74. swiperH4: res[3].height
  75. })
  76. })
  77. },
  78. //获取位置
  79. getNodePos() {
  80. var query = wx.createSelectorQuery()
  81. query.select('#agentJoin').boundingClientRect()
  82. var that = this;
  83. query.exec(function(res) {
  84. console.log(res)
  85. that.setData({
  86. basePos: res[0].top + 500,
  87. })
  88. })
  89. },
  90. baoming(e) {
  91. let top = e.currentTarget.dataset.top
  92. wx.pageScrollTo({
  93. scrollTop: top,
  94. duration: 0
  95. })
  96. },
  97. changeName: function(e) {
  98. console.log("s", e.detail.value);
  99. this.setData({
  100. name: e.detail.value
  101. })
  102. },
  103. changeContact: function(e) {
  104. console.log("s", e.detail.value);
  105. this.setData({
  106. contact: e.detail.value
  107. })
  108. },
  109. //改变性别
  110. bindSexChange(e) {
  111. console.log(e)
  112. let {
  113. value
  114. } = e.detail
  115. this.setData({
  116. sex_index: value
  117. })
  118. },
  119. changeYear: function(e) {
  120. console.log("s", e.detail.value);
  121. this.setData({
  122. year: e.detail.value
  123. })
  124. },
  125. submit() {
  126. if (!this.data.isLogin) {
  127. wx.navigateTo({
  128. url: '/pages/login/login',
  129. })
  130. return;
  131. }
  132. var name = this.data.name;
  133. var contact = this.data.contact;
  134. var sex = this.data.sex_index;
  135. var year = this.data.year;
  136. if (!name) {
  137. showToast("请填写姓名")
  138. return;
  139. }
  140. if (contact == "" || contact.length != 11) {
  141. showToast("请输入11位手机号")
  142. return;
  143. }
  144. if (sex == 0) {
  145. showToast("请选择性别")
  146. return;
  147. }
  148. if (!year) {
  149. showToast("请填写年龄")
  150. return;
  151. }
  152. var regNum = new RegExp('[0-9]', 'g');
  153. var rsNum = regNum.exec(year);
  154. console.log("rs",rsNum)
  155. if (!rsNum){
  156. showToast("年龄请输入正确的数字")
  157. return;
  158. }
  159. wx.showModal({
  160. title: '提示',
  161. content: '确定提交吗?',
  162. success: function(res) {
  163. if (res.confirm) {
  164. let paramsObj = {
  165. user_id: app.globalData.userId,
  166. user_token: app.globalData.userToken,
  167. member_id: app.globalData.memberId,
  168. name: name,
  169. phone: contact,
  170. gender: sex,
  171. age: year
  172. }
  173. Object.assign(paramsObj);
  174. saveAgent(paramsObj).then(data => {
  175. showToast('提交成功', 'success')
  176. setTimeout(function() {
  177. wx.navigateBack();
  178. }, 1000)
  179. })
  180. } else if (res.cancel) {
  181. }
  182. }
  183. })
  184. }
  185. })