| | |
| | | // pages/userinfo/index.js |
| | | import { |
| | | getMemberInfo, |
| | | editMember, |
| | | uploadUrl |
| | | } from '../../api/index' |
| | | Page({ |
| | | |
| | | /** |
| | | * 页面的初始数据 |
| | | */ |
| | | data: { |
| | | editFalg: false, |
| | | slogans: '', |
| | | costomerNum: '', |
| | | qrcodeImg: '', |
| | | qrcodeImgFull: '', |
| | | companyQrcodeImg: '', |
| | | companyQrcodeImgFull: '', |
| | | userInfo: { |
| | | name: '', |
| | | phone: '', |
| | | jobDate: '', |
| | | }, |
| | | endDate: '', // 获取当前年 |
| | | |
| | | // 下面为实例 |
| | |
| | | }, |
| | | onLoad(options) { |
| | | const endDate = new Date().getFullYear() + '-09-01' |
| | | this.setData({endDate}) |
| | | console.log('endYear', endDate); |
| | | this.setData({ |
| | | endDate |
| | | }) |
| | | this.getUserInfo() |
| | | }, |
| | | startEdit() { |
| | | this.setData({ |
| | | editFalg: true |
| | | }) |
| | | }, |
| | | onSubmit() { |
| | | |
| | | console.log('点了'); |
| | | const { |
| | | slogans, |
| | | costomerNum, |
| | | userInfo |
| | | } = this.data |
| | | editMember({ |
| | | ...userInfo, |
| | | slogans, |
| | | costomerNum |
| | | }).then(res => { |
| | | this.setData({ |
| | | editFalg: false |
| | | }) |
| | | wx.showToast({ |
| | | title: '信息保存成功', |
| | | }) |
| | | }) |
| | | }, |
| | | getUserInfo() { |
| | | getMemberInfo().then(res => { |
| | | this.setData({ |
| | | userInfo: res.data, |
| | | slogans: res.data.slogans, |
| | | costomerNum: res.data.costomerNum, |
| | | qrcodeImgFull: res.data.qrcodeImgFull, |
| | | qrcodeImg: res.data.qrcodeImg, |
| | | companyQrcodeImgFull: res.data.companyQrcodeImgFull, |
| | | companyQrcodeImg: res.data.companyQrcodeImg, |
| | | }) |
| | | }) |
| | | }, |
| | | bindDateChange(e) { |
| | | console.log('点击了', e.detail.value); |
| | | const { |
| | | userInfo |
| | | } = this.data |
| | | const endDate = new Date().getFullYear() |
| | | userInfo.jobDate = endDate - e.detail.value |
| | | this.setData({ |
| | | userInfo |
| | | }) |
| | | }, |
| | | bindRegionChange(e) { |
| | | console.log('picker发送选择改变,携带值为', e.detail.value) |
| | |
| | | region: e.detail.value |
| | | }) |
| | | }, |
| | | getBindchooseavatar(e) { |
| | | var that = this |
| | | const { userInfo } = this.data |
| | | if (e.detail.avatarUrl) { |
| | | wx.uploadFile({ |
| | | url: uploadUrl, |
| | | filePath: e.detail.avatarUrl, |
| | | name: 'file', |
| | | success (res) { |
| | | console.log(JSON.parse(res.data)) |
| | | let data = JSON.parse(ress.data) |
| | | userInfo.imgurl = data.data.imgaddr |
| | | userInfo.imgurlFull = data.data.url |
| | | this.setData({userInfo}) |
| | | } |
| | | }) |
| | | } |
| | | }, |
| | | selMedia() { |
| | | console.log('dianjile'); |
| | | const { |
| | | editFalg, |
| | | qrcodeImgFull |
| | | } = this.data |
| | | if (editFalg) { |
| | | wx.chooseMedia({ |
| | | count: 1, |
| | | mediaType: ['image'], |
| | | sourceType: ['album', 'camera'], |
| | | maxDuration: 16, |
| | | camera: 'back', |
| | | success(res) { |
| | | console.log(res.tempFiles[0].tempFilePath) |
| | | console.log(res.tempFiles[0].size) |
| | | success: (res) => { |
| | | // console.log(res.tempFiles[0].tempFilePath) |
| | | // console.log(res.tempFiles[0].size) |
| | | wx.uploadFile({ |
| | | url: uploadUrl, |
| | | filePath: res.tempFiles[0].tempFilePath, |
| | | name: 'file', |
| | | formData: { |
| | | folder: 'member' |
| | | }, |
| | | header: { |
| | | token: wx.getStorageSync('token') |
| | | }, |
| | | success: (ress) => { |
| | | console.log('ress', JSON.parse(ress.data)); |
| | | let data = JSON.parse(ress.data) |
| | | this.setData({ |
| | | qrcodeImg: data.data.imgaddr, |
| | | qrcodeImgFull: data.data.url, |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | } else { |
| | | wx.previewImage({ |
| | | urls: [qrcodeImgFull], |
| | | }) |
| | | } |
| | | }, |
| | | selMedia2() { |
| | | const { |
| | | editFalg, |
| | | companyQrcodeImgFull |
| | | } = this.data |
| | | if (editFalg) { |
| | | wx.chooseMedia({ |
| | | count: 1, |
| | | mediaType: ['image'], |
| | | sourceType: ['album', 'camera'], |
| | | maxDuration: 16, |
| | | camera: 'back', |
| | | success: (res) => { |
| | | // console.log(res.tempFiles[0].tempFilePath) |
| | | // console.log(res.tempFiles[0].size) |
| | | wx.uploadFile({ |
| | | url: uploadUrl, |
| | | filePath: res.tempFiles[0].tempFilePath, |
| | | name: 'file', |
| | | formData: { |
| | | folder: 'member' |
| | | }, |
| | | header: { |
| | | token: wx.getStorageSync('token') |
| | | }, |
| | | success: (ress) => { |
| | | console.log('ress', JSON.parse(ress.data)); |
| | | let data = JSON.parse(ress.data) |
| | | this.setData({ |
| | | companyQrcodeImg: data.data.imgaddr, |
| | | companyQrcodeImgFull: data.data.url, |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | }else{ |
| | | wx.previewImage({ |
| | | urls: [companyQrcodeImgFull], |
| | | }) |
| | | } |
| | | }, |
| | | onReady() { |
| | | |