index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //引入请求
  2. import {
  3. ApiModel
  4. } from "../../utils/api"
  5. //引入校验文件
  6. import {
  7. TestVerify
  8. } from "../../utils/verify"
  9. const _Http = new ApiModel();
  10. const _Verify = new TestVerify();
  11. Page({
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. fname: "", //用户名
  17. frole: "", //角色
  18. fphonenumber: "", //手机号
  19. fsex: "", //性别
  20. fbirthdate: "", //生日
  21. femail: "", //邮箱
  22. fwechatno: "", //微信
  23. faddress: "", //地址
  24. /* 必填项未填红色显示 */
  25. inputErrRed: {
  26. isFname: false, //用户名
  27. isFrole: false, //角色
  28. }
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {
  34. /* 初始化数据 */
  35. const data = JSON.parse(options.data)
  36. this.setData({
  37. fname: data.fname,
  38. frole: data.frole,
  39. fsex: data.fsex,
  40. fbirthdate: data.fbirthdate,
  41. femail: data.femail,
  42. fwechatno: data.fwechatno,
  43. faddress: data.faddress,
  44. frole: data.frole,
  45. faddress: data.faddress,
  46. fphonenumber: data.fphonenumber,
  47. })
  48. },
  49. /* 修改用户头像 */
  50. changeUserImg() {
  51. var that = this;
  52. wx.chooseMedia({
  53. count: 1,
  54. mediaType: ['image'],
  55. sourceType: ['album', 'camera'],
  56. camera: 'back',
  57. success(res) {
  58. const file = res.tempFiles[0];
  59. var index = file.tempFilePath.lastIndexOf(".");
  60. var ext = file.tempFilePath.substr(index + 1);
  61. var timestamp = Date.parse(new Date());
  62. wx.getFileSystemManager().readFile({
  63. filePath: file.tempFilePath,
  64. // encoding:'utf-8',
  65. success: result => {
  66. //返回临时文件路径
  67. const fileData = result.data
  68. _Http.basic({
  69. "accesstoken": wx.getStorageSync('token'),
  70. "classname": "system.system.docManage",
  71. "method": "getFileName",
  72. "content": {
  73. "filename": 'wx' + timestamp,
  74. "filetype": ext,
  75. "ownertable": "tenterprise_users",
  76. "ownerid": getApp().globalData.accountList[0].userid,
  77. "ftype": "headportrait",
  78. }
  79. }).then(res => {
  80. const a1 = _Http.uploadFile(res, fileData);
  81. console.log(a1)
  82. /* .then(res => {
  83. if (res.msg != "成功") return;
  84. console.log(res)
  85. }).catch(err => {
  86. console.log(err)
  87. }) */
  88. }).catch(err => {
  89. console.log(err)
  90. })
  91. },
  92. fail: console.error
  93. })
  94. }
  95. })
  96. },
  97. /* input必填项获取焦点 */
  98. inputEssentialFocus(e) {
  99. const {
  100. name
  101. } = e.currentTarget.dataset;
  102. let inputErrRed = this.data.inputErrRed;
  103. inputErrRed[name] = false;
  104. this.setData({
  105. inputErrRed
  106. })
  107. },
  108. /* input必填项失去焦点 */
  109. inputEssentialBlur(e) {
  110. if (e.detail.value != "" && e.detail.value != " ") return;
  111. const {
  112. name
  113. } = e.currentTarget.dataset;
  114. let inputErrRed = this.data.inputErrRed;
  115. inputErrRed[name] = true;
  116. this.setData({
  117. inputErrRed
  118. })
  119. },
  120. /* 校验必填项 */
  121. inputCertain() {
  122. let state = true,
  123. inputErrRed = this.data.inputErrRed;
  124. if (!_Verify.required(this.data.fname)) {
  125. inputErrRed["isFname"] = true;
  126. state = false;
  127. };
  128. if (!_Verify.required(this.data.frole)) {
  129. inputErrRed["isFrole"] = true;
  130. state = false;
  131. };
  132. this.setData({
  133. inputErrRed
  134. });
  135. return state;
  136. },
  137. /* 表单提交 */
  138. formSubmit() {
  139. /* 检测是否还有为空必填项 */
  140. if (!this.inputCertain()) return wx.showToast({
  141. title: '必填项不可为空!',
  142. icon: "none"
  143. });
  144. /* 发送请求 */
  145. _Http.basic({
  146. "accesstoken": wx.getStorageSync('token'),
  147. "classname": "customer.usercenter.usermsg.usermsg",
  148. "method": "update_usermsg",
  149. "content": {
  150. fname: this.data.fname,
  151. frole: this.data.frole,
  152. fsex: this.data.fsex,
  153. fbirthdate: this.data.fbirthdate,
  154. femail: this.data.femail,
  155. fwechatno: this.data.fwechatno,
  156. faddress: this.data.faddress,
  157. }
  158. }).then(s => {
  159. if (s.msg != "成功") return;
  160. wx.showToast({
  161. title: '保存成功',
  162. })
  163. setTimeout(() => {
  164. wx.navigateBack({
  165. delta: 1
  166. })
  167. }, 500)
  168. this.setData({
  169. userMsg: s.data[0]
  170. })
  171. })
  172. },
  173. /**
  174. * 生命周期函数--监听页面初次渲染完成
  175. */
  176. onReady: function () {
  177. },
  178. /**
  179. * 生命周期函数--监听页面显示
  180. */
  181. onShow: function () {
  182. },
  183. /**
  184. * 生命周期函数--监听页面隐藏
  185. */
  186. onHide: function () {
  187. },
  188. /**
  189. * 生命周期函数--监听页面卸载
  190. */
  191. onUnload: function () {
  192. },
  193. /**
  194. * 页面相关事件处理函数--监听用户下拉动作
  195. */
  196. onPullDownRefresh: function () {
  197. },
  198. /**
  199. * 页面上拉触底事件的处理函数
  200. */
  201. onReachBottom: function () {
  202. },
  203. /**
  204. * 用户点击右上角分享
  205. */
  206. onShareAppMessage: function () {
  207. }
  208. })