index.js 4.7 KB

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