index.js 5.3 KB

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