You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
4.3 KiB

1 year ago
  1. // pages/updateWord/updateWord.js
  2. const app = getApp();
  3. const WXAPI = require('../../utils/request')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. rightIcon:['closed-eye','closed-eye','closed-eye'],
  10. type:['password','password','password'],
  11. password:["","",""],
  12. role:''
  13. },
  14. onClickIcon(event){
  15. var rightIcon=this.data.rightIcon
  16. var type=this.data.type
  17. var index=event.currentTarget.dataset.index
  18. if(rightIcon[index]=="closed-eye"){
  19. rightIcon[index]="eye-o"
  20. type[index]="text"
  21. }else{
  22. rightIcon[index]="closed-eye"
  23. type[index]="password"
  24. }
  25. this.setData({
  26. rightIcon,
  27. type
  28. })
  29. },
  30. onChange(event) {
  31. var password=this.data.password
  32. password[event.currentTarget.dataset.index]=event.detail
  33. this.setData({
  34. password:password
  35. })
  36. },
  37. /**
  38. * 生命周期函数--监听页面加载
  39. */
  40. onLoad: function (options) {
  41. console.log(options);
  42. if(options.role){
  43. this.setData({
  44. role:options.role
  45. })
  46. }
  47. },
  48. // 修改密码
  49. modifyPassword(){
  50. console.log(this.data.role)
  51. if(this.data.role == 1){
  52. var userInfo=wx.getStorageSync('userInfo')
  53. if (this.data.password[2] != this.data.password[1]) {
  54. wx.showToast({
  55. title: '确认密码输入错误!',
  56. duration:2000,
  57. icon:'none'
  58. })
  59. } else if (this.data.password[0] == '' || this.data.password[1] == ''|| this.data.password[2] == '') {
  60. wx.showToast({
  61. title: '请输入修改的密码',
  62. duration:2000,
  63. icon:'none'
  64. })
  65. } else {
  66. var data = {
  67. userId: userInfo.id,
  68. new: this.data.password[2],
  69. old: this.data.password[0],
  70. };
  71. WXAPI.editPassword(data).then(res1 => {
  72. if (res1.success) {
  73. wx.showToast({
  74. title: "修改成功",
  75. duration: 2000,
  76. icon: 'none'
  77. })
  78. this.setData({
  79. rightIcon:['closed-eye','closed-eye','closed-eye'],
  80. type:['password','password','password'],
  81. password:["","",""]
  82. })
  83. } else {
  84. wx.showToast({
  85. title: "修改失败",
  86. duration: 2000,
  87. icon: 'none'
  88. })
  89. }
  90. })
  91. }
  92. }else if(this.data.role == 2){
  93. if (this.data.password[2] != this.data.password[1]) {
  94. wx.showToast({
  95. title: '确认密码输入错误!',
  96. duration:2000,
  97. icon:'none'
  98. })
  99. } else if (this.data.password[1] == ''|| this.data.password[2] == '') {
  100. wx.showToast({
  101. title: '请输入新的密码',
  102. duration:2000,
  103. icon:'none'
  104. })
  105. } else {
  106. let deviceinfo = wx.getStorageSync('deviceinfoList')
  107. var rowInfo = JSON.parse(deviceinfo[0].info)
  108. let loginKey = WXAPI.setCode("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXKHkNKieiGOTjXZJ0lFBjhRCa\nZTaAebTIfB9nnnVmNVIp//yCfyFXSlxbAj58CQwCVhwy109ROYf3BcsQNMZz7Djo\n8a5V0JThNye4ihxLiYLawLRjb2y2/IhzV0/JZiFtaM83xUt0tbqTKxD00Up7dy8c\n9OXc0h//0uQSraf6JwIDAQAB",this.data.password[2])
  109. var data = {
  110. loginKey: loginKey,
  111. number:rowInfo.userTelephone,
  112. signature:wx.getStorageSync('signature'),
  113. };
  114. WXAPI.updateCard(data).then(res=>{
  115. if(res.success){
  116. wx.showToast({
  117. title: '修改成功',
  118. duration:2000,
  119. icon:'none'
  120. })
  121. }else{
  122. wx.showToast({
  123. title: '修改失败',
  124. duration:2000,
  125. icon:'none'
  126. })
  127. }
  128. })
  129. }
  130. }
  131. },
  132. /**
  133. * 生命周期函数--监听页面初次渲染完成
  134. */
  135. onReady: function () {
  136. },
  137. /**
  138. * 生命周期函数--监听页面显示
  139. */
  140. onShow: function () {
  141. },
  142. /**
  143. * 生命周期函数--监听页面隐藏
  144. */
  145. onHide: function () {
  146. },
  147. /**
  148. * 生命周期函数--监听页面卸载
  149. */
  150. onUnload: function () {
  151. },
  152. /**
  153. * 页面相关事件处理函数--监听用户下拉动作
  154. */
  155. onPullDownRefresh: function () {
  156. },
  157. /**
  158. * 页面上拉触底事件的处理函数
  159. */
  160. onReachBottom: function () {
  161. },
  162. /**
  163. * 用户点击右上角分享
  164. */
  165. onShareAppMessage: function () {
  166. }
  167. })