index.js 5.8 KB

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