index.js 5.7 KB

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