index.js 5.8 KB

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