index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. /* console.log(options)
  41. let auth = options.auth ? JSON.parse(options.auth) : {};
  42. auth
  43. */
  44. this.setData({
  45. attinfos: JSON.parse(options.attinfos),
  46. "fromList1[0].value": options.name,
  47. "fromList1[1].value": options.phonenumber,
  48. "fromList1[1].callback": function ({
  49. value
  50. }) {
  51. that.setData({
  52. show: (value != that.data.copyPhonenumber) ? true : false,
  53. newPhone: value
  54. })
  55. },
  56. "copyPhonenumber": options.phonenumber
  57. });
  58. },
  59. /* from1监听 */
  60. form1CompletedOrNot({
  61. detail
  62. }) {
  63. this.setData({
  64. disabled: !detail
  65. })
  66. if (this.data.show) this.setData({
  67. disabled: this.data.password.length == 6
  68. })
  69. },
  70. /* 开始倒计时 */
  71. startCountDown() {
  72. let countDown = this.data.countDown;
  73. if (countDown != 0) return wx.showToast({
  74. title: '已发送验证码,请勿重新发送',
  75. icon: "none"
  76. });
  77. if (this.data.newPhone.trim().length != 11) return wx.showToast({
  78. title: '请输入正常手机号码',
  79. icon: "none"
  80. })
  81. _Http.basic({
  82. "classname": "common.usercenter.usercenter",
  83. "method": "updateUserMsg_getPassWord",
  84. "content": {
  85. "phonenumber": this.data.newPhone.trim()
  86. }
  87. }).then(res => {
  88. console.log(res)
  89. wx.showToast({
  90. title: res.msg,
  91. icon: "none"
  92. })
  93. if (res.code != 1) return;
  94. this.setData({
  95. countDown: 30
  96. })
  97. time = setInterval(() => {
  98. if (this.data.countDown == '0') return clearInterval(time);
  99. this.setData({
  100. countDown: this.data.countDown - 1
  101. })
  102. }, 1000);
  103. })
  104. },
  105. /* 提交 */
  106. submit() {
  107. if (this.data.disabled || this.data.loading) return;
  108. let data = this.selectComponent("#form1").getData().returnData;
  109. if (data.phonenumber.length != 11) return wx.showToast({
  110. title: '请输入正常手机号码',
  111. icon: "none"
  112. });
  113. if (this.data.show && this.data.password.length == 0) return wx.showToast({
  114. title: '请输入短信验证码',
  115. icon: "none"
  116. });
  117. this.setData({
  118. loading: true
  119. })
  120. _Http.basic({
  121. "classname": "common.usercenter.usercenter",
  122. "method": "updateUserMsg",
  123. "content": {
  124. "name": data.name,
  125. "phonenumber": data.phonenumber,
  126. "password": MD5.hexMD5(this.data.password.trim())
  127. }
  128. }).then(res => {
  129. this.setData({
  130. loading: false
  131. })
  132. if (res.code != 1) return wx.showToast({
  133. title: res.msg,
  134. icon: "none"
  135. });
  136. wx.showToast({
  137. title: '修改成功'
  138. });
  139. this.changeUserMsg();
  140. setTimeout(() => {
  141. wx.navigateBack({
  142. delta: 0,
  143. })
  144. }, 300);
  145. })
  146. },
  147. changeUserMsg() {
  148. let pages = getCurrentPages();
  149. let prevPage = pages[pages.length - 2];
  150. prevPage.queryUserMsg();
  151. },
  152. changeUserImage({
  153. detail
  154. }) {
  155. _Http.basic({
  156. "classname": "system.attachment.Attachment",
  157. "method": "createFileLink",
  158. "content": {
  159. "ownertable": "sys_users",
  160. "ownerid": wx.getStorageSync('userMsg').userid,
  161. "usetype": "headportrait",
  162. "attachmentids": detail
  163. }
  164. }).then(res => {
  165. console.log(res)
  166. if (res.msg != '成功') return wx.showToast({
  167. title: res.data,
  168. icon: "none"
  169. })
  170. let attinfos = this.data.attinfos;
  171. if (attinfos[0]) _Http.basic({
  172. "classname": "system.attachment.Attachment",
  173. "method": "deleteFileLink",
  174. "content": {
  175. "linksids": [attinfos[0].linksid]
  176. }
  177. });
  178. attinfos = res.data;
  179. this.setData({
  180. attinfos
  181. })
  182. this.changeUserMsg();
  183. })
  184. },
  185. })