123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- //引入请求
- import {
- ApiModel
- } from "../../utils/api"
- //引入校验文件
- import {
- TestVerify
- } from "../../utils/verify"
- const _Http = new ApiModel();
- const _Verify = new TestVerify();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- fobsurl: {}, //头像
- fname: "", //用户名
- frole: "", //角色
- fphonenumber: "", //手机号
- fsex: "", //性别
- fbirthdate: "", //生日
- femail: "", //邮箱
- fwechatno: "", //微信
- faddress: "", //地址
- /* 必填项未填红色显示 */
- inputErrRed: {
- isFname: false, //用户名
- isFrole: false, //角色
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- /* 初始化数据 */
- const data = JSON.parse(options.data)
- this.setData({
- fobsurl: data.attinfos[0],
- fname: data.fname,
- frole: data.frole,
- fsex: data.fsex,
- fbirthdate: data.fbirthdate,
- femail: data.femail,
- fwechatno: data.fwechatno,
- faddress: data.faddress,
- frole: data.frole,
- faddress: data.faddress,
- fphonenumber: data.fphonenumber,
- })
- },
- /* 修改用户头像 */
- changeUserImg() {
- var that = this;
- wx.chooseMedia({
- count: 1,
- mediaType: ['image'],
- sourceType: ['album', 'camera'],
- camera: 'back',
- success(res) {
- const file = res.tempFiles[0];
- var index = file.tempFilePath.lastIndexOf(".");
- var ext = file.tempFilePath.substr(index + 1);
- var timestamp = Date.parse(new Date());
- wx.getFileSystemManager().readFile({
- filePath: file.tempFilePath,
- // encoding:'utf-8',
- success: result => {
- //返回临时文件路径
- const fileData = result.data
- _Http.basic({
- "accesstoken": wx.getStorageSync('token'),
- "classname": "system.system.docManage",
- "method": "getFileName",
- "content": {
- "filename": 'wx' + timestamp,
- "filetype": ext,
- "ownertable": "tenterprise_users",
- "ownerid": getApp().globalData.accountList[wx.getStorageSync('userIndex')].userid,
- "ftype": "headportrait",
- }
- }).then(res => {
- /* 删除之前头像 */
- _Http.basic({
- "accesstoken": wx.getStorageSync('token'),
- "classname": "system.system.docManage",
- "method": "deleteDoc",
- "content": {
- "ownertable": "tnotice",
- "ownerid": that.data.fobsurl.ownerid,
- "tattachmentid": that.data.fobsurl.tattachmentid
- }
- })
- /* 上次并查询头像 */
- that.uploadFile(res, fileData)
- }).catch(err => {
- console.log(err)
- })
- },
- fail: console.error
- })
- }
- })
- },
- uploadFile(res, data) {
- var that = this
- wx.request({
- url: res.data.obsuploadurl,
- method: "PUT",
- data: data,
- header: {
- 'content-type': 'application/octet-stream' // 默认值
- },
- success() {
- _Http.basic({
- "accesstoken": wx.getStorageSync('token'),
- "classname": "system.system.docManage",
- "method": "uploadSuccsess",
- "content": {
- "obsfilename": res.data.obsfilename
- }
- }).then(res => {
- that.setData({
- fobsurl: res.data[0]
- })
- }).catch(err => {
- console.log(err)
- })
- }
- })
- },
- /* input必填项获取焦点 */
- inputEssentialFocus(e) {
- const {
- name
- } = e.currentTarget.dataset;
- let inputErrRed = this.data.inputErrRed;
- inputErrRed[name] = false;
- this.setData({
- inputErrRed
- })
- },
- /* input必填项失去焦点 */
- inputEssentialBlur(e) {
- if (e.detail.value != "" && e.detail.value != " ") return;
- const {
- name
- } = e.currentTarget.dataset;
- let inputErrRed = this.data.inputErrRed;
- inputErrRed[name] = true;
- this.setData({
- inputErrRed
- })
- },
- /* 校验必填项 */
- inputCertain() {
- let state = true,
- inputErrRed = this.data.inputErrRed;
- if (!_Verify.required(this.data.fname)) {
- inputErrRed["isFname"] = true;
- state = false;
- };
- if (!_Verify.required(this.data.frole)) {
- inputErrRed["isFrole"] = true;
- state = false;
- };
- this.setData({
- inputErrRed
- });
- return state;
- },
- /* 表单提交 */
- formSubmit() {
- /* 检测是否还有为空必填项 */
- if (!this.inputCertain()) return wx.showToast({
- title: '必填项不可为空!',
- icon: "none"
- });
- /* 发送请求 */
- _Http.basic({
- "accesstoken": wx.getStorageSync('token'),
- "classname": "customer.usercenter.usermsg.usermsg",
- "method": "update_usermsg",
- "content": {
- fname: this.data.fname,
- frole: this.data.frole,
- fsex: this.data.fsex,
- fbirthdate: this.data.fbirthdate,
- femail: this.data.femail,
- fwechatno: this.data.fwechatno,
- faddress: this.data.faddress,
- }
- }).then(s => {
- if (s.msg != "成功") return;
- wx.showToast({
- title: '保存成功',
- })
- setTimeout(() => {
- wx.navigateBack({
- delta: 1
- })
- }, 500)
- this.setData({
- userMsg: s.data[0]
- })
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|