东风启辰小程序端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

335 linhas
8.7KB

  1. // pages/mobileVerification/mobileVerification.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. isAgreement: true,//是否同意协议
  10. verificationCode: '获取验证码',//验证码文案
  11. sendCode: true,
  12. realName:"",//姓名
  13. mobileText: "",//手机号
  14. verificationText: null,
  15. getMobileBtnShow: true,
  16. agreement: false,//是否显示协议
  17. httpState: false,
  18. provinceDataAll: null,//地区所有数据
  19. provinceDataArr: [[""], [""]],//省市数据
  20. provinceDataValue: [0, 0],//选中的省市下标
  21. nowProvince: "",//选中的省市文字
  22. storeArr: [],//专营店数据
  23. storeValue: 0,//选中的专营店下标
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. app.globalData.nowPage = 2;
  30. if (app.globalData.openid) {
  31. this.loadFun();
  32. } else {
  33. app.globalData.openidSuccessFuc = this.loadFun;
  34. }
  35. },
  36. loadFun: function () {
  37. if (app.globalData.userMobile) {
  38. this.setData({
  39. getMobileBtnShow: false,
  40. mobileText: app.globalData.userMobile
  41. })
  42. }
  43. this.getUserLocation();//获取用户当前位置
  44. },
  45. getUserLocation: function (e) {
  46. wx.getLocation({
  47. type: 'wgs84', //wgs84 gcj02
  48. success: (res) => {
  49. this.getDistributorList(res.longitude, res.latitude);
  50. },
  51. fail: (res) => {
  52. this.getDistributorList("", "");
  53. }
  54. })
  55. },
  56. getDistributorList: function (longitude, latitude) {//获取经销商列表
  57. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
  58. if (res.code == 200) {
  59. //整理数据
  60. var datas = res.data;
  61. var province = [];
  62. var city = [];
  63. for (let i = 0; i < res.data.list.length; i++) {
  64. province.push(res.data.list[i].province);
  65. }
  66. for (let j = 0; j < res.data.list[res.data.nearData.provinceIndex].children.length; j++) {
  67. city.push(res.data.list[res.data.nearData.provinceIndex].children[j].city)
  68. }
  69. //将数据赋值给变量
  70. this.setData({
  71. provinceDataAll: res.data.list,
  72. provinceDataArr: [province, city],
  73. provinceDataValue: [res.data.nearData.provinceIndex, res.data.nearData.cityIndex],
  74. nowProvince: province[res.data.nearData.provinceIndex] + " " + city[res.data.nearData.cityIndex],
  75. storeArr: res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children,
  76. storeValue: res.data.nearData.agentIndex
  77. })
  78. } else {
  79. wx.showToast({
  80. title: res.msg,
  81. icon: "none"
  82. })
  83. }
  84. }, this);
  85. },
  86. provinceDataChange: function (e) {
  87. if (e.detail.column == 0) {
  88. var city = [];
  89. for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length; i++) {
  90. city.push(this.data.provinceDataAll[e.detail.value].children[i].city);
  91. }
  92. this.data.provinceDataArr[1] = city;
  93. this.setData({
  94. provinceDataArr: this.data.provinceDataArr
  95. })
  96. }
  97. },
  98. provinceDataChane: function (e) {
  99. this.setData({
  100. provinceDataValue: e.detail.value,
  101. nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]],
  102. storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children,
  103. storeValue: 0
  104. })
  105. },
  106. storeChane: function (e) {
  107. this.setData({
  108. storeValue: e.detail.value
  109. })
  110. },
  111. /**
  112. * 生命周期函数--监听页面初次渲染完成
  113. */
  114. onReady: function () {
  115. },
  116. /**
  117. * 生命周期函数--监听页面显示
  118. */
  119. onShow: function () {
  120. },
  121. /**
  122. * 生命周期函数--监听页面隐藏
  123. */
  124. onHide: function () {
  125. },
  126. /**
  127. * 生命周期函数--监听页面卸载
  128. */
  129. onUnload: function () {
  130. },
  131. /**
  132. * 页面相关事件处理函数--监听用户下拉动作
  133. */
  134. onPullDownRefresh: function () {
  135. },
  136. /**
  137. * 页面上拉触底事件的处理函数
  138. */
  139. onReachBottom: function () {
  140. },
  141. /**
  142. * 用户点击右上角分享
  143. */
  144. onShareAppMessage: function () {
  145. return app.sharePack();
  146. },
  147. agreementState: function () {//协议
  148. this.setData({
  149. isAgreement: !this.data.isAgreement
  150. })
  151. },
  152. getCode: function (e) {//获取验证码
  153. if (!app.mobileVerify(this.data.mobileText)) {
  154. if (this.data.mobileText) {
  155. wx.showToast({
  156. title: '请输入正确的电话',
  157. icon: 'none'
  158. })
  159. } else {
  160. wx.showToast({
  161. title: '请输入电话',
  162. icon: 'none'
  163. })
  164. }
  165. return;
  166. }
  167. if (!this.data.sendCode) {
  168. return;
  169. }
  170. this.data.sendCode = false;
  171. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.mobileText }, res => {
  172. if (res.code == 200) {
  173. this.countDown();
  174. wx.showToast({
  175. title: '验证码获取成功',
  176. icon: "none"
  177. })
  178. this.setData({
  179. verificationCode: 60
  180. })
  181. } else {
  182. this.data.sendCode = true;
  183. wx.showToast({
  184. title: res.msg,
  185. icon: "none"
  186. })
  187. }
  188. }, this)
  189. },
  190. countDown: function () {//倒计时
  191. setTimeout(() => {
  192. this.setData({
  193. verificationCode: this.data.verificationCode - 1
  194. })
  195. if (this.data.verificationCode > 0) {
  196. this.countDown();
  197. } else {
  198. this.setData({
  199. verificationCode: "获取验证码"
  200. })
  201. this.data.sendCode = true;
  202. }
  203. }, 1000);
  204. },
  205. getRealName: function (e) {//获取用户输入的姓名
  206. this.data.realName = e.detail.value
  207. },
  208. getMoblie: function (e) {//获取用户输入的手机号
  209. this.data.mobileText = e.detail.value
  210. },
  211. getCodeText: function (e) {//获取用户输入的手机号
  212. this.data.verificationText = e.detail.value
  213. },
  214. submitMobile: function () {
  215. if (!this.data.realName) {
  216. wx.showToast({
  217. title: '请输入姓名',
  218. icon: 'none'
  219. })
  220. return;
  221. }
  222. if (!app.mobileVerify(this.data.mobileText)) {
  223. if (this.data.mobileText) {
  224. wx.showToast({
  225. title: '请输入正确的电话',
  226. icon: 'none'
  227. })
  228. } else {
  229. wx.showToast({
  230. title: '请输入电话',
  231. icon: 'none'
  232. })
  233. }
  234. return;
  235. }
  236. if (!this.data.verificationText) {
  237. wx.showToast({
  238. title: '请输入验证码',
  239. icon: 'none'
  240. })
  241. return;
  242. }
  243. if (!this.data.isAgreement) {
  244. wx.showToast({
  245. title: '请同意协议',
  246. icon: 'none'
  247. })
  248. return;
  249. }
  250. var parames = {
  251. realName:this.data.realName,
  252. mobile:this.data.mobileText,
  253. captcha:this.data.verificationText,
  254. province:this.data.provinceDataArr[0][this.data.provinceDataValue[0]],
  255. city:this.data.provinceDataArr[1][this.data.provinceDataValue[1]],
  256. agentDetail:this.data.storeArr[this.data.storeValue].agent_detail,
  257. agentCode:this.data.storeArr[this.data.storeValue].agent_code
  258. }
  259. // console.log(parames);
  260. // return;
  261. if (this.data.httpState) {
  262. return;
  263. }
  264. this.data.httpState = true;
  265. app.wxRequest(app.globalData.urlRoot + "userInfo/getCertificationInfoV2", parames, res => {
  266. this.data.httpState = false;
  267. if (res.code == 200) {
  268. wx.setStorageSync('userMobile', this.data.mobileText);
  269. app.globalData.userMobile = this.data.mobileText;
  270. if (res.data != null) {
  271. app.globalData.authenticationStatus = res.data;
  272. app.globalData.certificationState = res.data.certificationState;
  273. wx.redirectTo({
  274. url: '../scout/scout'
  275. })
  276. } else {
  277. wx.redirectTo({
  278. url: '../scout/register/register'
  279. })
  280. }
  281. } else {
  282. wx.showToast({
  283. title: res.msg,
  284. icon: 'none'
  285. })
  286. }
  287. }, this);
  288. },
  289. getPhone(e) {
  290. this.setData({
  291. getMobileBtnShow: false
  292. })
  293. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  294. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  295. if (res.code == 200) {
  296. if (res.data && res.data.decodeData) {
  297. this.setData({
  298. mobileText: res.data.decodeData.phoneNumber
  299. })
  300. }
  301. }
  302. }, this)
  303. }
  304. },
  305. agreementControl: function () {
  306. this.setData({
  307. agreement: !this.data.agreement
  308. })
  309. },
  310. showRule: function () {
  311. if (app.globalData.entered) {
  312. wx.navigateTo({ url: '/pages/everyday/everyday' })
  313. } else {
  314. wx.navigateTo({
  315. url: '/pages/fragmentRule/fragmentRule'
  316. })
  317. }
  318. }
  319. })