You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
249 lines
7.8 KiB
249 lines
7.8 KiB
import { zconfig, getBaseInfo, updateUserInfoZtb, postRelation } from '../../../api/ztb'
|
|
import { updateUserInfo } from '../../../api/user'
|
|
const util = require('../../../utils/util')
|
|
const tdsdk = require('../../../libs/tdweapp')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
backStatus: true,
|
|
nickName: '', //用户昵称
|
|
avatarUrl: '', //用户头像
|
|
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,
|
|
bizUserId:res.data.bizUserId,
|
|
bizUserName:res.data.bizUserName,
|
|
})
|
|
})
|
|
},
|
|
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 (e1) {
|
|
this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog')
|
|
var that = this
|
|
var placeholderName = ''
|
|
if (e1.currentTarget.dataset.tag == '打包厂名') {
|
|
placeholderName = that.data.userInfo.packageFactoryName
|
|
} else if (e1.currentTarget.dataset.tag == '打包厂占地面积') {
|
|
placeholderName = that.data.userInfo.packageFactoryArea
|
|
} else if (e1.currentTarget.dataset.tag == '工厂人数') {
|
|
placeholderName = that.data.userInfo.numberOfEmployee
|
|
} else if (e1.currentTarget.dataset.tag == '打包机数') {
|
|
placeholderName = that.data.userInfo.numberOfPackageMachine
|
|
} else if (e1.currentTarget.dataset.tag == '昵称') {
|
|
placeholderName = that.data.userInfo.nickname
|
|
}
|
|
else if (e1.currentTarget.dataset.tag == '业务人员邀请码') {
|
|
placeholderName = that.data.userInfo.bizUserId
|
|
}
|
|
this.wuxDialog.prompt({
|
|
resetOnClose: true,
|
|
title: e1.currentTarget.dataset.tag,
|
|
placeholder: placeholderName || '请输入' + e1.currentTarget.dataset.tag,
|
|
maxlength: 18,
|
|
onConfirm(e, response) {
|
|
//非头像,昵称需要调用ztb修改用户信息接口
|
|
if (util.isEmpty(response)) {
|
|
util.showToast('请输入' + e1.currentTarget.dataset.tag)
|
|
return
|
|
} else
|
|
if (e1.currentTarget.dataset.tag == '打包厂名') {
|
|
that.updateUserInfoFct({
|
|
packageFactoryName: response
|
|
})
|
|
} else
|
|
if (e1.currentTarget.dataset.tag == '业务人员邀请码') {
|
|
// that.updateUserInfoFct({
|
|
// bizUserId: response
|
|
// })
|
|
postRelation(response).then(result => {
|
|
//成功回调
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
} else
|
|
if (e1.currentTarget.dataset.tag == '打包厂占地面积') {
|
|
if (parseInt(response)>0 && parseInt(response)==Number(response)) {
|
|
that.updateUserInfoFct({
|
|
packageFactoryArea: response
|
|
})
|
|
} else {
|
|
util.showToast('请输入正整数')
|
|
return
|
|
}
|
|
} else
|
|
if (e1.currentTarget.dataset.tag == '工厂人数') {
|
|
if (parseInt(response)>0 && parseInt(response)==Number(response)) {
|
|
that.updateUserInfoFct({
|
|
numberOfEmployee: response
|
|
})
|
|
} else {
|
|
util.showToast('请输入正整数')
|
|
return
|
|
}
|
|
} else
|
|
if (e1.currentTarget.dataset.tag == '打包机数') {
|
|
if (parseInt(response)>0 && parseInt(response)==Number(response)) {
|
|
that.updateUserInfoFct({
|
|
numberOfPackageMachine: response
|
|
})
|
|
} else {
|
|
util.showToast('请输入正整数')
|
|
return
|
|
}
|
|
} else {
|
|
//修改头像,昵称去UEC(user中的updateMemberInfo)
|
|
that.updateMemberInfo({
|
|
nickname: response
|
|
})
|
|
}
|
|
},
|
|
})
|
|
},
|
|
updateUserInfoFct: function (model) {
|
|
if (model) {
|
|
wx.showLoading({ title: '处理中', mask: true })
|
|
}
|
|
updateUserInfoZtb(model).then(result => {
|
|
wx.hideLoading()
|
|
if (model.packageFactoryName) {
|
|
this.setData({
|
|
['userInfo.packageFactoryName']: model.packageFactoryName
|
|
})
|
|
} else if (model.packageFactoryArea) {
|
|
this.setData({
|
|
['userInfo.packageFactoryArea']: model.packageFactoryArea
|
|
})
|
|
} else if (model.numberOfEmployee) {
|
|
this.setData({
|
|
['userInfo.numberOfEmployee']: model.numberOfEmployee
|
|
})
|
|
} else if (model.numberOfPackageMachine) {
|
|
this.setData({
|
|
['userInfo.numberOfPackageMachine']: model.numberOfPackageMachine
|
|
})
|
|
}
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
})
|
|
},
|
|
updateMemberInfo: function (form) {
|
|
if (form.nickname) {
|
|
wx.showLoading({ title: '处理中', mask: true })
|
|
}
|
|
updateUserInfo(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
|
|
})
|
|
},
|
|
goPersonalInfo: function () {
|
|
wx.navigateTo({url: '/submodel/pages/html/personal/index' })
|
|
},
|
|
goEnterpriseInfo: function () {
|
|
if(app.globalData.userInfo.isEnterpriseAuth){
|
|
wx.navigateTo({ url: '/submodel/pages/home/enterprise/index' })
|
|
} else {
|
|
wx.navigateTo({ url: '/pages/home/certificate/index' })
|
|
}
|
|
},
|
|
onShow: function () {
|
|
tdsdk.Page.onShow()
|
|
},
|
|
onHide: function(){
|
|
tdsdk.Page.onHide()
|
|
},
|
|
onUnload: function () {
|
|
tdsdk.Page.onUnload()
|
|
}
|
|
})
|