index.js 3.9 KB

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