edit.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //logs.js
  2. const util = require('../../utils/util.js');
  3. const app = getApp()
  4. Page({
  5. data: {
  6. name: '',//姓名
  7. phone: '',//手机号
  8. code: '',//验证码
  9. iscode: null,//用于存放验证码接口里获取到的code
  10. codename: '获取验证码',
  11. disabled: false, //按钮是否禁用
  12. click: true
  13. },
  14. onLoad: function () {
  15. },
  16. getNameValue: function (e) {
  17. this.setData({
  18. name: e.detail.value
  19. })
  20. },
  21. getPhoneValue: function (e) {
  22. this.setData({
  23. phone: e.detail.value
  24. })
  25. },
  26. getCodeValue: function (e) {
  27. this.setData({
  28. code: e.detail.value
  29. })
  30. },
  31. //判断手机号
  32. getCode: function () {
  33. var phoneNum = this.data.phone;
  34. var that = this;
  35. var myreg = /^1[0-9]{10,11}$/;
  36. if (this.data.phone == "") {
  37. wx.showToast({
  38. title: '手机号不能为空',
  39. icon: 'none',
  40. duration: 1000
  41. })
  42. return false;
  43. } else if (!myreg.test(this.data.phone)) {
  44. wx.showToast({
  45. title: '请输入正确的手机号',
  46. icon: 'none',
  47. duration: 1000
  48. })
  49. return false;
  50. } else {
  51. wx.showLoading({
  52. title: '请稍候...',
  53. mask: true
  54. })
  55. wx.request({
  56. url: app.globalData.serverUrl + "/cloudcard/getVcode",
  57. data: {
  58. mobile: phoneNum
  59. },
  60. success(res) {
  61. wx.hideLoading();
  62. // that.setData({
  63. // iscode: res.data.data
  64. // })
  65. var num = 61;
  66. var timer = setInterval(function () {
  67. num--;
  68. if (num <= 0) {
  69. clearInterval(timer);
  70. that.setData({
  71. codename: '重新发送',
  72. disabled: false
  73. })
  74. } else {
  75. that.setData({
  76. codename: num + "s"
  77. })
  78. }
  79. }, 1000)
  80. },
  81. fail: function (res) {
  82. wx.hideLoading();
  83. }
  84. })
  85. }
  86. },
  87. //获取验证码
  88. getVerificationCode() {
  89. this.getCode();
  90. var that = this
  91. that.setData({
  92. disabled: true
  93. })
  94. },
  95. //提交表单信息
  96. formSubmitHandle: function (e) {
  97. var userInfo = wx.getStorageSync("userInfo");
  98. if (this.data.name == "") {
  99. wx.showToast({
  100. title: '姓名不能为空',
  101. icon: 'none',
  102. duration: 1000
  103. })
  104. return false;
  105. } else if (this.data.phone == "") {
  106. wx.showToast({
  107. title: '手机号不能为空',
  108. icon: 'none',
  109. duration: 1000
  110. })
  111. return false;
  112. } else if (this.data.code == "") {
  113. wx.showToast({
  114. title: '验证码不能为空',
  115. icon: 'none',
  116. duration: 1000
  117. })
  118. return false;
  119. // } else if (this.data.code != this.data.iscode) {
  120. // wx.showToast({
  121. // title: '验证码错误',
  122. // icon: 'none',
  123. // duration: 1000
  124. // })
  125. // return false;
  126. } else {
  127. if(this.data.click){
  128. var that = this;
  129. that.setData({
  130. click: false
  131. })
  132. wx.request({
  133. url: app.globalData.serverUrl + "/user/linkPhone",
  134. method: "POST",
  135. data: {
  136. userName: that.data.name,
  137. mobile: that.data.phone,
  138. id: userInfo.id,
  139. VCode: that.data.code
  140. },
  141. header: {
  142. "Content-Type": "application/x-www-form-urlencoded"
  143. },
  144. success: function (res) {
  145. if(res.data.code == "ok"){
  146. wx.setStorageSync('userInfo', res.data.data);
  147. wx.showToast({
  148. title: '提交成功!',
  149. icon: 'success',
  150. duration: 2000
  151. })
  152. setTimeout(function() {
  153. wx.reLaunch({
  154. url: '../cloud/cloud'
  155. })
  156. }, 200)
  157. } else {
  158. that.setData({
  159. click: true
  160. })
  161. wx.showToast({
  162. title: res.data.msg,
  163. icon: 'none',
  164. duration: 2000
  165. })
  166. }
  167. },
  168. fail: function (res) {
  169. that.setData({
  170. click: true
  171. })
  172. wx.showToast({
  173. title: '提交失败!',
  174. icon: 'none',
  175. duration: 2000
  176. })
  177. }
  178. })
  179. } else {
  180. wx.showToast({
  181. title: '保存中,请勿重复提交',
  182. icon: 'none',
  183. duration: 1000
  184. })
  185. }
  186. }
  187. }
  188. })