|
@@ -3,7 +3,7 @@
|
|
|
<view class="item-box">
|
|
|
<view class="item-left"> 头像 : </view>
|
|
|
<view class="item-right flex-end">
|
|
|
- <image @click="handlerUploadImg" class="img" :src="queryParams.avatar"></image>
|
|
|
+ <image @click="handlerUploadImg" class="img" :src="uoloadImg"></image>
|
|
|
</view>
|
|
|
</view>
|
|
|
<view class="item-box">
|
|
@@ -34,7 +34,7 @@
|
|
|
</view>
|
|
|
|
|
|
<u-datetime-picker :show="timeShow" v-model="time_value" mode="date" @cancel='timeShow = false'
|
|
|
- @confirm='confirmTime'></u-datetime-picker>
|
|
|
+ @confirm='confirmTime' :minDate="0" :maxDate='maxDataTime'></u-datetime-picker>
|
|
|
|
|
|
<view class="btn-box">
|
|
|
<button class="btn" @click="handlerSubmitBtn">提交</button>
|
|
@@ -44,6 +44,7 @@
|
|
|
|
|
|
<script>
|
|
|
import { getUserInfo } from '@/api/user';
|
|
|
+ import { uploadFile } from "@/utils/upload"
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
@@ -57,26 +58,36 @@
|
|
|
timeShow: false,
|
|
|
sexList: [{
|
|
|
id: 0,
|
|
|
- name: '男'
|
|
|
+ name: '男',
|
|
|
+ type:'MALE'
|
|
|
},
|
|
|
{
|
|
|
id: 1,
|
|
|
- name: '女'
|
|
|
- },
|
|
|
- {
|
|
|
- id: 2,
|
|
|
- name: '沃尔玛塑料袋'
|
|
|
+ name: '女',
|
|
|
+ type:'FEMALE'
|
|
|
}
|
|
|
],
|
|
|
- current: 0
|
|
|
+ current: 0,
|
|
|
+ uoloadImg:'',
|
|
|
+ maxDataTime:0
|
|
|
}
|
|
|
},
|
|
|
mounted(){
|
|
|
+ this.maxDataTime = new Date().getTime()
|
|
|
getUserInfo().then(res=>{
|
|
|
- console.log("@@@res",res)
|
|
|
- this.queryParams.avatar = res.data.avatar
|
|
|
- this.queryParams.nickname = res.data.nickname
|
|
|
- // this.queryParams.gender = res.data.gender
|
|
|
+ let { avatar , nickname , gender } = res.data
|
|
|
+ this.uoloadImg = avatar
|
|
|
+ this.queryParams.avatar = avatar
|
|
|
+ this.queryParams.nickname = nickname
|
|
|
+ if(gender){
|
|
|
+ for(let key in gender){
|
|
|
+ this.sexList.map(rs=>{
|
|
|
+ if(key == rs.type){
|
|
|
+ this.current = rs.id
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
})
|
|
|
},
|
|
|
methods: {
|
|
@@ -86,19 +97,8 @@
|
|
|
},
|
|
|
// 选择时间
|
|
|
confirmTime(e) {
|
|
|
- this.timeShow = false
|
|
|
- let time = new Date(e.value)
|
|
|
- let year = time.getFullYear()
|
|
|
- let month = time.getMonth() + 1
|
|
|
- let date = time.getDate()
|
|
|
- if (month < 10) {
|
|
|
- month = '0' + month
|
|
|
- }
|
|
|
- if (date < 10) {
|
|
|
- date = '0' + date
|
|
|
- }
|
|
|
- this.queryParams.birthday = year + '-' + month + '-' + date
|
|
|
-
|
|
|
+ this.queryParams.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');
|
|
|
+ this.timeShow = false
|
|
|
},
|
|
|
// 上传头像
|
|
|
async handlerUploadImg() {
|
|
@@ -106,42 +106,23 @@
|
|
|
const res = await uni.showActionSheet({
|
|
|
itemList: ['拍照', '从相册选择'],
|
|
|
});
|
|
|
-
|
|
|
if (res.tapIndex === 0) {
|
|
|
// 用户选择拍照
|
|
|
- this.takePhoto();
|
|
|
+ this.takeOrChoosePhoto(0);
|
|
|
} else if (res.tapIndex === 1) {
|
|
|
// 用户选择从相册选择
|
|
|
- this.chooseImage();
|
|
|
+ this.takeOrChoosePhoto(1);
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- console.error(error);
|
|
|
}
|
|
|
},
|
|
|
// 拍照
|
|
|
- takePhoto() {
|
|
|
- uni.chooseImage({
|
|
|
- sourceType: ['camera'],
|
|
|
- count: 9,
|
|
|
- success: res => {
|
|
|
- const tempFilePaths = res.tempFilePaths;
|
|
|
- console.log('@@@@tempFilePaths',tempFilePaths);
|
|
|
- // 调用上传图片的方法
|
|
|
- this.uploadAvatar(tempFilePaths[0]);
|
|
|
- },
|
|
|
- fail: error => {
|
|
|
- console.error(error);
|
|
|
- },
|
|
|
- });
|
|
|
- },
|
|
|
- //从相册中选择
|
|
|
- chooseImage() {
|
|
|
+ takeOrChoosePhoto(idx) {
|
|
|
uni.chooseImage({
|
|
|
- sourceType: ['album'],
|
|
|
- count: 9,
|
|
|
+ sourceType: idx == 0 ? ['camera'] : ['album'],
|
|
|
+ count: 1,
|
|
|
success: res => {
|
|
|
const tempFilePaths = res.tempFilePaths;
|
|
|
- console.log('@@@@tempFilePaths',tempFilePaths);
|
|
|
// 调用上传图片的方法
|
|
|
this.uploadAvatar(tempFilePaths[0]);
|
|
|
},
|
|
@@ -152,15 +133,21 @@
|
|
|
},
|
|
|
// 上传头像
|
|
|
uploadAvatar(filePath) {
|
|
|
- // 在这里实现上传头像的逻辑,将filePath作为参数传入
|
|
|
- this.queryParams.avatar = filePath;
|
|
|
+ this.uoloadImg = filePath
|
|
|
+ uploadFile(filePath).then(res=>{
|
|
|
+ this.queryParams.avatar = JSON.parse(res.data).data.url;
|
|
|
+ })
|
|
|
this.$forceUpdate(); // 手动触发组件的重新渲染
|
|
|
},
|
|
|
-
|
|
|
+
|
|
|
// 点击提交按钮
|
|
|
handlerSubmitBtn() {
|
|
|
- this.queryParams.gender = this.sexList[this.current].name
|
|
|
- console.log('@@@@queryParams', this.queryParams);
|
|
|
+ this.queryParams.gender = this.sexList[this.current].type
|
|
|
+ this.$store.dispatch('UpdateUserInfo',this.queryParams).then(res=>{
|
|
|
+ setTimeout(()=>{
|
|
|
+ uni.navigateBack(-1)
|
|
|
+ },1500)
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -241,4 +228,4 @@
|
|
|
.gray-color {
|
|
|
color: #D2D5DB;
|
|
|
}
|
|
|
-</style>
|
|
|
+</style>
|