index.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. import {
  6. TestVerify
  7. } from "../../utils/verify";
  8. const _Verify = new TestVerify();
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. userMessage: {}, //用户数据列表
  15. /* 错误提示 */
  16. errTips: {
  17. fname: false, //用户名
  18. frole: false, //身份/职位
  19. fphonenumber: false, //手机号
  20. },
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. const userMessage = JSON.parse(options.data);
  27. const attinfos = {
  28. attinfos: userMessage.attinfos
  29. }
  30. this.setData({
  31. userMessage: attinfos,
  32. fname: userMessage.fname,
  33. fphonenumber: userMessage.fphonenumber,
  34. fsex: userMessage.fsex,
  35. fbirthdate: userMessage.fbirthdate,
  36. femail: userMessage.femail,
  37. fwechatno: userMessage.fwechatno,
  38. faddress: userMessage.faddress,
  39. frole: userMessage.frole
  40. })
  41. },
  42. /* 表单验证 */
  43. formVerify() {
  44. let errTips = this.data.errTips,
  45. verify = true;
  46. /* 验证用户名 */
  47. if (!_Verify.required(this.data.fname)) {
  48. errTips.fname = true;
  49. verify = false;
  50. }
  51. /* 验证身份 */
  52. if (!_Verify.required(this.data.frole)) {
  53. errTips.frole = true;
  54. verify = false;
  55. }
  56. if (!verify) {
  57. this.setData({
  58. errTips
  59. })
  60. }
  61. return verify;
  62. },
  63. /* 提交 */
  64. submit() {
  65. if (!this.formVerify()) return wx.showToast({
  66. title: '请检查表单内容',
  67. icon: "none"
  68. });
  69. _Http.basic({
  70. "accesstoken": wx.getStorageSync('userData').token,
  71. "classname": "customer.usercenter.usermsg.usermsg",
  72. "method": "update_usermsg",
  73. "content": {
  74. "fname": this.data.fname,
  75. "fsex": this.data.fsex,
  76. "fbirthdate": this.data.fbirthdate,
  77. "femail": this.data.femail,
  78. "fwechatno": this.data.fwechatno,
  79. "faddress": this.data.faddress,
  80. "frole": this.data.frole
  81. }
  82. }).then(res => {
  83. if (res.msg == "成功") {
  84. wx.showToast({
  85. title: '保存成功',
  86. })
  87. setTimeout(() => {
  88. wx.navigateBack({
  89. delta: 1
  90. })
  91. }, 500)
  92. }
  93. })
  94. },
  95. /* 获取焦点 */
  96. inputFocus(e) {
  97. const {
  98. name
  99. } = e.currentTarget.dataset;
  100. let errTips = this.data.errTips;
  101. errTips[name] = false;
  102. this.setData({
  103. errTips
  104. })
  105. },
  106. /* 失去焦点 */
  107. inputBlur(e) {
  108. const {
  109. name
  110. } = e.currentTarget.dataset;
  111. const {
  112. value
  113. } = e.detail;
  114. if (value.trim() == "") {
  115. let errTips = this.data.errTips;
  116. errTips[name] = true;
  117. this.setData({
  118. errTips
  119. })
  120. }
  121. },
  122. /* 修改用户头像 */
  123. userImageChange(data) {
  124. const attinfos = [{
  125. ownerid: data.detail.fileList[0].ownerid,
  126. tattachmentid: data.detail.fileList[0].tattachmentid,
  127. fobsurl: data.detail.fileList[0].url
  128. }]
  129. this.setData({
  130. 'userMessage.attinfos': attinfos
  131. })
  132. },
  133. /**
  134. * 生命周期函数--监听页面初次渲染完成
  135. */
  136. onReady: function () {
  137. },
  138. /**
  139. * 生命周期函数--监听页面显示
  140. */
  141. onShow: function () {
  142. },
  143. /**
  144. * 生命周期函数--监听页面隐藏
  145. */
  146. onHide: function () {
  147. },
  148. /**
  149. * 生命周期函数--监听页面卸载
  150. */
  151. onUnload: function () {
  152. },
  153. /**
  154. * 页面相关事件处理函数--监听用户下拉动作
  155. */
  156. onPullDownRefresh: function () {
  157. },
  158. /**
  159. * 页面上拉触底事件的处理函数
  160. */
  161. onReachBottom: function () {
  162. },
  163. /**
  164. * 用户点击右上角分享
  165. */
  166. onShareAppMessage: function () {
  167. }
  168. })