examTeamApp/pages/my/userInfo.vue

306 lines
7.2 KiB
Vue
Raw Normal View History

2024-05-02 15:59:36 +08:00
<template>
<view class="box">
<view class="lanBox">
<view class="headbox">
<view class="touxiang">
<image v-if="headimg" :src="headimg" class="headimage" />
2026-03-23 14:22:23 +08:00
<icon v-else class="iconfont icon-user-filling headimage"></icon>
2024-05-02 15:59:36 +08:00
</view>
</view>
<view class="lan border-bottom">
<view class="left">姓名</view>
<view class="right">
2024-05-29 16:35:45 +08:00
<input name="name" type="text" v-model="memInfo.nickname" placeholder="请输入姓名" />
2024-06-13 18:03:50 +08:00
<uni-icons type="clear" color="#999" v-if="memInfo.nickname" @click="memInfo.nickname=''"
size="20"></uni-icons>
2024-05-02 15:59:36 +08:00
</view>
</view>
<view class="lan border-bottom">
<view class="left">性别</view>
<view class="right">
<picker mode="selector" :range="sexItem" @change="onsexArr">
2024-05-29 16:35:45 +08:00
<view class="uni-input">{{memInfo.gender==0?'请选择':memInfo.gender==1?'男':'女'}}</view>
2024-05-02 15:59:36 +08:00
<icon class="iconfont icon-arrow-down-bold"></icon>
</picker>
</view>
</view>
2024-06-13 18:03:50 +08:00
<view class="lan border-bottom">
<view class="left">身高</view>
<view class="right">
<input name="name" class="mr-5" type="digit" v-model="memInfo.height" placeholder="请输入身高" />CM
<uni-icons type="clear" color="#999" v-if="memInfo.height" @click="memInfo.height=''"
size="20"></uni-icons>
</view>
</view>
<view class="lan border-bottom">
<view class="left">体重</view>
<view class="right">
<input name="name" type="digit" class="mr-5" v-model="memInfo.weight" placeholder="请输入体重" />KG
<uni-icons type="clear" color="#999" v-if="memInfo.weight" @click="memInfo.weight=''"
size="20"></uni-icons>
</view>
</view>
2024-05-02 15:59:36 +08:00
<view class="lan border-bottom">
<view class="left">出生日期</view>
<view class="right">
2024-08-05 10:01:06 +08:00
<picker mode="date" :end="endDate" @change="maskClick"
:value="memInfo.birthday?memInfo.birthday:endDate" fields="time">
2024-07-22 14:13:19 +08:00
<view class="uni-input">{{memInfo.birthday?memInfo.birthday:'请选择'}}</view>
<icon class="iconfont icon-arrow-down-bold"></icon>
</picker>
<!-- <uni-datetime-picker type="date" :end="startDate" :clear-icon="false" v-model="memInfo.birthday"
@change="maskClick" :border="false" /> -->
2024-05-02 15:59:36 +08:00
</view>
</view>
<view class="lan border-bottom">
<view class="left">所在年级</view>
<view class="right">
2024-05-29 16:35:45 +08:00
<picker mode="selector" :range="gradeList" :value="index" range-key="name" @change="changegType">
<view class="uni-input">{{gradeList[index]?gradeList[index].name:"请选择"}}</view>
<icon class="iconfont icon-arrow-down-bold"></icon>
</picker>
2024-05-02 15:59:36 +08:00
</view>
</view>
</view>
<view class="btn" @click="confirmInfo">提交</view>
</view>
</template>
<script>
import {
mapState
} from "vuex";
export default {
data() {
return {
2024-05-29 16:35:45 +08:00
isEdit: false,
2024-05-02 15:59:36 +08:00
sexItem: [
"男",
"女"
],
2024-05-29 16:35:45 +08:00
memInfo: {
birthday: "",
gender: 0,
nickname: "",
2024-06-13 18:03:50 +08:00
grade: "",
height: "",
weight: ""
2024-05-29 16:35:45 +08:00
},
2024-05-02 15:59:36 +08:00
headimg: "",
2024-05-29 16:35:45 +08:00
index: 0,
gradeList: []
2024-05-02 15:59:36 +08:00
};
},
computed: {
2024-05-29 16:35:45 +08:00
...mapState(["user", "familayList"]),
2024-07-22 14:13:19 +08:00
2024-07-25 16:55:39 +08:00
endDate() {
return this.$tools.getDate("start")
},
2024-05-02 15:59:36 +08:00
startDate() {
2024-07-25 16:55:39 +08:00
return this.$tools.GetDateStr(-90);
2024-07-22 14:13:19 +08:00
},
2024-05-02 15:59:36 +08:00
},
onLoad(options) {
2024-06-13 18:03:50 +08:00
let that = this
this.handleGradeList()
2024-05-29 16:35:45 +08:00
if (options.info) {
2024-06-13 18:03:50 +08:00
that.memInfo = JSON.parse(options.info)
that.isEdit = true
2024-05-29 16:35:45 +08:00
}
2024-06-13 18:03:50 +08:00
console.log("1111", this.memInfo)
2024-05-02 15:59:36 +08:00
},
methods: {
2024-05-29 16:35:45 +08:00
handleGradeList() {
let that = this
that.$model.getGradeList({}).then(res => {
console.log("年级列表", res)
if (res.code != 0) {
that.$tools.msg(res.msg)
return
}
that.gradeList = res.data
2024-06-13 18:03:50 +08:00
if (that.isEdit == true) {
that.index = res.data.findIndex(ite => ite.id == that.memInfo.grade)
}
2024-08-05 10:01:06 +08:00
that.memInfo.grade = res.data[that.index].id
2024-05-29 16:35:45 +08:00
}).catch(err => {})
},
2024-05-02 15:59:36 +08:00
// 提交
confirmInfo() {
let that = this
2024-05-29 16:35:45 +08:00
if (!that.memInfo.nickname) {
that.$tools.msg("请输入姓名")
2024-05-02 15:59:36 +08:00
return;
}
2024-05-29 16:35:45 +08:00
if (!that.memInfo.gender) {
that.$tools.msg("请选择性别")
2024-05-02 15:59:36 +08:00
return;
}
2024-06-13 18:03:50 +08:00
if (!that.memInfo.height) {
that.$tools.msg("请选择身高")
return;
}
if (!that.memInfo.weight) {
that.$tools.msg("请选择体重")
return;
}
2024-05-29 16:35:45 +08:00
if (!that.memInfo.birthday) {
that.$tools.msg("请选择出生日期")
2024-05-02 15:59:36 +08:00
return;
}
2024-05-29 16:35:45 +08:00
if (!that.memInfo.grade) {
that.$tools.msg("请选择所在年级")
return;
}
let https = that.isEdit ? that.$model.getEditUser(that.memInfo) : that.$model.getAddUser(that.memInfo)
return https.then(res => {
console.log("成功", res)
2024-05-02 15:59:36 +08:00
if (res.code == 0) {
that.$tools.msg("提交成功");
2024-06-13 18:03:50 +08:00
that.handleUserList(res.data.aud_id)
} else {
that.$tools.msg(res.msg);
}
});
},
handleUserList(id) {
let that = this
that.$model.getUserList({
type: 2
}).then(res => {
console.log("成员列表", res)
that.$store.commit('changeFamilay', res.data)
// 修改用户
if (that.isEdit && that.memInfo.id == uni.getStorageSync('userid')) {
console.log("修改用户")
that.$store.dispatch('getUserInfo', {
aud_id: uni.getStorageSync('userid')
})
}
// 添加用户
if (!that.isEdit) {
console.log("添加用户")
uni.setStorageSync('userid', id)
uni.setStorageSync('gender', that.memInfo.gender)
that.$store.dispatch('getUserInfo', {
aud_id: id
})
that.$store.dispatch("getCardList", {
aud_id: id
})
uni.redirectTo({
url: "/pages/cardList/card"
2024-05-02 15:59:36 +08:00
})
2024-06-13 18:03:50 +08:00
} else {
2024-05-29 16:35:45 +08:00
uni.navigateBack({
delta: 1
});
2024-05-02 15:59:36 +08:00
}
2024-06-13 18:03:50 +08:00
}).catch(err => {})
2024-05-02 15:59:36 +08:00
},
//确定年龄
2024-06-13 18:03:50 +08:00
maskClick(e) {
2024-07-22 14:13:19 +08:00
this.memInfo.birthday = e.detail.value
2024-05-02 15:59:36 +08:00
},
//确定性别
onsexArr(e) {
2024-05-29 16:35:45 +08:00
this.memInfo.gender = this.sexItem[e.target.value] == "男" ? 1 : 2
},
// 年级
changegType(e) {
this.index = e.detail.value
this.memInfo.grade = this.gradeList[e.target.value].id
2024-05-02 15:59:36 +08:00
},
},
};
</script>
<style scoped="scoped" lang="scss">
.box {
height: 100vh;
background-color: #fff;
}
input {
border: none;
background: inherit;
}
.headbox {
2024-09-03 09:57:22 +08:00
height: 180rpx;
padding-top: 10px;
2024-05-29 16:35:45 +08:00
border-radius: 0 0 5px 5px;
2024-05-02 15:59:36 +08:00
background: $maincolor;
}
.headimage {
display: block;
padding-top: 10px;
width: 70px;
height: 70px;
border-radius: 50%;
2024-08-05 10:01:06 +08:00
font-size: 140rpx;
2024-05-02 15:59:36 +08:00
margin: auto;
2024-05-29 16:35:45 +08:00
color: #fff;
2024-05-02 15:59:36 +08:00
}
.lan {
display: flex;
align-items: center;
2024-08-05 10:01:06 +08:00
font-size: 32rpx;
2024-05-02 15:59:36 +08:00
padding: 5px 0;
margin: 5px 15px;
border-bottom: 1px solid #f7f7f7;
}
2024-06-13 18:03:50 +08:00
.left {
2024-05-02 15:59:36 +08:00
width: 24%;
text-align: left;
}
2024-06-13 18:03:50 +08:00
.right {
2024-05-02 15:59:36 +08:00
display: flex;
align-items: center;
justify-content: flex-end;
width: 72%;
2024-08-05 10:01:06 +08:00
height: 40px;
line-height: 40px;
2024-05-02 15:59:36 +08:00
box-sizing: border-box;
position: relative;
text-align: right;
picker {
width: 100%;
text-align: right;
border: none;
2024-08-05 10:01:06 +08:00
margin-right: 15px;
font-size: 32rpx;
color: #333333;
2024-05-02 15:59:36 +08:00
}
2024-06-13 18:03:50 +08:00
/deep/input {
height: 35px;
2024-08-05 10:01:06 +08:00
padding-top: 1px;
font-size: 32rpx;
color: #333333;
margin-right: 15px;
2024-06-13 18:03:50 +08:00
}
2024-05-02 15:59:36 +08:00
.iconfont {
color: #333333;
2024-08-05 10:01:06 +08:00
font-size: 32rpx;
2024-05-02 15:59:36 +08:00
position: absolute;
right: -10px;
top: 0;
}
}
.btn {
width: auto;
margin: 40px 15px 0;
background: $btncolor !important;
}
</style>