index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. let time = null;
  2. const _Http = getApp().globalData.http;
  3. const MD5 = require('../../../../utils/md5');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. attinfos: [],
  10. fromList1: [{
  11. label: "姓名",
  12. error: false,
  13. errMsg: "",
  14. type: "text",
  15. value: "",
  16. placeholder: "请填写",
  17. valueName: "name", //绑定的字段名称
  18. required: true, //必填
  19. }, {
  20. label: "手机号",
  21. error: false,
  22. errMsg: "",
  23. type: "text",
  24. value: "",
  25. placeholder: "请填写",
  26. valueName: "phonenumber", //绑定的字段名称
  27. required: true, //必填
  28. callback: null,
  29. }],
  30. disabled: false, //禁用按钮
  31. show: false, //显示验证码输入框
  32. password: "", //验证码
  33. countDown: 0, //倒计时
  34. loading: false
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad(options) {
  40. const that = this;
  41. this.setData({
  42. attinfos: JSON.parse(options.attinfos),
  43. "fromList1[0].value": options.name,
  44. "fromList1[1].value": options.phonenumber,
  45. "fromList1[1].callback": function ({
  46. value
  47. }) {
  48. that.setData({
  49. show: (value != that.data.copyPhonenumber) ? true : false,
  50. newPhone: value
  51. })
  52. },
  53. "copyPhonenumber": options.phonenumber
  54. })
  55. },
  56. /* from1监听 */
  57. form1CompletedOrNot({
  58. detail
  59. }) {
  60. this.setData({
  61. disabled: !detail
  62. })
  63. if (this.data.show) this.setData({
  64. disabled: this.data.password.length == 6
  65. })
  66. },
  67. /* 开始倒计时 */
  68. startCountDown() {
  69. let countDown = this.data.countDown;
  70. if (countDown != 0) return wx.showToast({
  71. title: '已发送验证码,请勿重新发送',
  72. icon: "none"
  73. });
  74. if (this.data.newPhone.trim().length != 11) return wx.showToast({
  75. title: '请输入正常手机号码',
  76. icon: "none"
  77. })
  78. _Http.basic({
  79. "classname": "common.usercenter.usercenter",
  80. "method": "updateUserMsg_getPassWord",
  81. "content": {
  82. "phonenumber": this.data.newPhone.trim()
  83. }
  84. }).then(res => {
  85. console.log(res)
  86. wx.showToast({
  87. title: res.msg,
  88. icon: "none"
  89. })
  90. if (res.code != 1) return;
  91. this.setData({
  92. countDown: 30
  93. })
  94. time = setInterval(() => {
  95. if (this.data.countDown == '0') return clearInterval(time);
  96. this.setData({
  97. countDown: this.data.countDown - 1
  98. })
  99. }, 1000);
  100. })
  101. },
  102. /* 提交 */
  103. submit() {
  104. if (this.data.disabled || this.data.loading) return;
  105. let data = this.selectComponent("#form1").getData().returnData;
  106. if (data.phonenumber.length != 11) return wx.showToast({
  107. title: '请输入正常手机号码',
  108. icon: "none"
  109. });
  110. if (this.data.show && this.data.password.length == 0) return wx.showToast({
  111. title: '请输入短信验证码',
  112. icon: "none"
  113. });
  114. this.setData({
  115. loading: true
  116. })
  117. _Http.basic({
  118. "classname": "common.usercenter.usercenter",
  119. "method": "updateUserMsg",
  120. "content": {
  121. "name": data.name,
  122. "phonenumber": data.phonenumber,
  123. "password": MD5.hexMD5(this.data.password.trim())
  124. }
  125. }).then(res => {
  126. this.setData({
  127. loading: false
  128. })
  129. if (res.code != 1) return wx.showToast({
  130. title: res.msg,
  131. icon: "none"
  132. });
  133. wx.showToast({
  134. title: '修改成功'
  135. });
  136. this.changeUserMsg();
  137. setTimeout(() => {
  138. wx.navigateBack({
  139. delta: 0,
  140. })
  141. }, 300);
  142. })
  143. },
  144. changeUserMsg() {
  145. let pages = getCurrentPages();
  146. let prevPage = pages[pages.length - 2];
  147. prevPage.queryUserMsg();
  148. },
  149. changeUserImage({
  150. detail
  151. }) {
  152. _Http.basic({
  153. "classname": "system.attachment.Attachment",
  154. "method": "createFileLink",
  155. "content": {
  156. "ownertable": "sys_users",
  157. "ownerid": wx.getStorageSync('userMsg').userid,
  158. "usetype": "headportrait",
  159. "attachmentids": detail
  160. }
  161. }).then(res => {
  162. console.log(res)
  163. if (res.msg != '成功') return wx.showToast({
  164. title: res.data,
  165. icon: "none"
  166. })
  167. let attinfos = this.data.attinfos;
  168. if (attinfos[0]) _Http.basic({
  169. "classname": "system.attachment.Attachment",
  170. "method": "deleteFileLink",
  171. "content": {
  172. "linksids": [attinfos[0].linksid]
  173. }
  174. });
  175. attinfos = res.data;
  176. this.setData({
  177. attinfos
  178. })
  179. this.changeUserMsg();
  180. })
  181. },
  182. })