index.js 7.4 KB

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