index.js 5.9 KB

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