import { zconfig, getBaseInfo, modifyMemberInfo } from '../../api/ztb' const util = require('../../../utils/util') const app = getApp() Page({ /** * 页面的初始数据 */ data: { backStatus: true, nickName: '', //用户昵称 avatarUrl: '', //用户头像 banckCardList: [ { id: 1, name: '个体回收户' }, { id: 2, name: '打包站' }, { id: 3, name: '废品站' }, { id: 4, name: '印刷' }, { id: 6, name: '包装厂' }, { id: 7, name: '纸箱纸板厂' }, { id: 8, name: '后加工' }, { id: 5, name: '其他' } ], cardList: [ { value: '1', text: '个体回收户' }, { value: '2', text: '打包站' }, { value: '3', text: '废品站' }, { value: '4', text: '印刷' }, { value: '6', text: '包装厂' }, { value: '7', text: '纸箱纸板厂' }, { value: '8', text: '后加工' }, { value: '5', text: '其他' } ], userInfo: null, userType: 1, srcList: null, visible: false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { getBaseInfo().then(res => { this.setData({ userInfo: res.data, nickName: res.data.realName, avatarUrl: res.data.avatarUrl || '/assets/image/ygImg.png', linkman: res.data.realName, linkPhone: res.data.mobile, companyAddress: res.data.fullAddress, userType: res.data.userType, realName:res.data.realName || res.data.userName }) }) }, uploadFile: function (path) { var that = this wx.showLoading({ title: '上传中', mask: true }) var header = { ...zconfig.header, 'X-APP-ID': app.xAppId, appversion: app.version } this.task = wx.uploadFile({ url: zconfig.baseUrl + '/recycle-user-center/file-uploading/upload/image', filePath: path, name: 'image', header, success: function (result) { var resp = null if (!util.isEmpty(result.data)) { resp = JSON.parse(result.data) } if (resp && resp.code === 0) { that.updateMemberInfo({avatar: resp.data}) } else { wx.hideLoading() util.showToast('头像上传失败,请重新上传') } }, fail: function (res) { wx.hideLoading() util.showToast('头像上传失败,请重新上传') } }) }, showDialog: function(){ this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog') var that = this this.wuxDialog.prompt({ resetOnClose: true, title: '修改昵称', placeholder: that.data.userInfo.nickname || '请输入昵称', maxlength: 18, onConfirm(e, response) { if(util.isEmpty(response)){ util.showToast('请输入昵称') return } that.updateMemberInfo({nickname: response}) }, }) }, updateMemberInfo: function(form){ if(form.nickname){ wx.showLoading({ title: '处理中', mask: true }) } modifyMemberInfo(form).then(result => { wx.hideLoading() if(form.nickname){ this.setData({['userInfo.nickname']: form.nickname}) } else if(form.avatar){ this.setData({avatarUrl: form.avatar}) } }).catch(err => { wx.hideLoading() util.showToast(err) }) }, toAuth: function(){ if(this.data.userInfo && !this.data.userInfo.isAuth){ wx.navigateTo({ url: '/pages/home/idcard/index' }) } }, //通过事件执行更换头像方法比如点击头像执行该方法 chooseImage: function() { var that = this wx.chooseImage({ count: 1, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res) { // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 // that.uploadFile(res.tempFilePaths[0]) that.setData({ visible: true, srcList: res.tempFilePaths }) } }) }, //裁剪图片回调 onCropback: function (event) { this.setData({ visible: false }) this.uploadFile(event.detail[0]) }, //关闭回调 closeCallback: function () { this.setData({ visible: false }) } })