index.js 6.1 KB

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