index.js 4.7 KB

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