safepasspord.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. const app = getApp()
  2. var api = require('../../utils/request');
  3. var util = require('../../utils/util');
  4. var common = require('../../utils/common');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. disabled: false,
  11. countdown: 60,
  12. isPassword:false,
  13. sms: '',
  14. showType: 'number',//如果是密码换成'password'
  15. isFocus: true,
  16. dataSource: [{initValue:''},{initValue:''}, {initValue:''},{initValue:''},{initValue:''},{initValue:''}]
  17. },
  18. /**
  19. * 生命周期函数--监听页面显示
  20. */
  21. onShow: function () {
  22. let that = this;
  23. app.isLogin(function (rel) {
  24. that.isPassword();
  25. });
  26. },
  27. /**
  28. * 用户tap假的Input,focus到隐藏的input
  29. */
  30. onTapFocus: function () {
  31. this.setData({
  32. isFocus:true
  33. });
  34. },
  35. /**
  36. * 移动端键入
  37. * 注意:在pc端无法显示键盘,移动端下编译、预览正常
  38. */
  39. mobileInput: function (e) {
  40. let dataSource = this.data.dataSource;
  41. let curInpArr = e.detail.value.split('');
  42. let curInpArrLength = curInpArr.length;
  43. if (curInpArr.length != this.data.dataSource.length)
  44. for (let i = 0; i < dataSource.length - curInpArrLength; i++)
  45. curInpArr.push('');
  46. for (let i = 0; i < this.data.dataSource.length; i++) {
  47. let initValue = 'dataSource[' + i + '].initValue';
  48. this.setData({
  49. [initValue]: curInpArr[i]
  50. });
  51. }
  52. if (6 == curInpArrLength){
  53. var checkPassword = curInpArr.join("");
  54. this.checkPassword(checkPassword);
  55. }
  56. },
  57. /**
  58. * 第一次近期检测是否设置了密码
  59. */
  60. isPassword: function () {
  61. let that = this;
  62. api.Get('openapi/v1/user/isSafePassword',{types:1},function (res) {
  63. if (res.code == 204) {
  64. that.setData({
  65. isPassword: true
  66. })
  67. }
  68. })
  69. },
  70. /**
  71. * 读取手机验证码
  72. */
  73. getSms: function (e) {
  74. let that = this;
  75. var detail = e.detail;
  76. if (detail.errMsg == 'getPhoneNumber:ok') {
  77. var parms = {
  78. encryptedData: detail.encryptedData,
  79. errMsg: detail.errMsg,
  80. iv: detail.iv
  81. }
  82. app.api().Post('openapi/v1/getBindWechatPhoneSms',parms,function (rel) {
  83. if (rel.code == 200) {
  84. wx.setStorageSync('session_id', rel.data.session_id);
  85. common.settime(that);
  86. that.setData({
  87. disabled: true,
  88. sms: rel.data.sms
  89. })
  90. }
  91. })
  92. }
  93. },
  94. /**
  95. * 验证密码是否正确
  96. */
  97. checkPassword: function (safepassword) {
  98. let that = this;
  99. if (safepassword.length == 6){
  100. wx.showLoading({
  101. title: '密码验证中',
  102. })
  103. var parms = {
  104. safepassword:safepassword,
  105. }
  106. api.Post('openapi/v1/user/checksafepassword',parms,function (res) {
  107. wx.hideLoading();
  108. if (res.code == 200) {
  109. that.setData({
  110. isPassword:true
  111. })
  112. }
  113. wx.hideLoading();
  114. })
  115. }
  116. },
  117. /**
  118. * 修改密码
  119. */
  120. formSubmit: function (e) {
  121. let that = this;
  122. var data = e.detail.value;
  123. var isPost = true;
  124. if (util.isNull(data.code)) {
  125. wx.showModal({
  126. content: '验证码必须输入'
  127. })
  128. isPost = false;
  129. } else {
  130. if (!(/^\d{6}$/.test(data.code))) {
  131. wx.showModal({
  132. content: '验证码输入错误'
  133. })
  134. isPost = false;
  135. }
  136. }
  137. if (data.safepassword != data.resafepassword) {
  138. wx.showModal({
  139. content: '两次密码必须一致'
  140. })
  141. isPost = false;
  142. }
  143. if (util.isNull(data.resafepassword)) {
  144. wx.showModal({
  145. content: '确认密码必须输入'
  146. })
  147. isPost = false;
  148. }
  149. if (util.isNull(data.safepassword)) {
  150. wx.showModal({
  151. content: '密码必须输入'
  152. })
  153. isPost = false;
  154. } else {
  155. if (!(/^\d{6}$/.test(data.safepassword))) {
  156. wx.showModal({
  157. content: '密码只能是6位数字'
  158. })
  159. isPost = false;
  160. }
  161. }
  162. //提交数据
  163. if (isPost == true) {
  164. wx.showLoading({
  165. title: '提交申请中',
  166. mask: true
  167. })
  168. var parms = {
  169. safepassword: data.safepassword,
  170. resafepassword: data.resafepassword,
  171. code: data.code,
  172. }
  173. api.Post('openapi/v1/user/setSafePassword', parms, function (res) {
  174. wx.showModal({
  175. showCancel: false,
  176. title: '友情提示',
  177. content: res.msg,
  178. complete: function () {
  179. wx.navigateBack({
  180. delta: 1
  181. })
  182. }
  183. })
  184. })
  185. wx.hideLoading();
  186. }
  187. }
  188. })