| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <template>
- <view>
- <view class="flex padding justify-between align-center">
- <view class="title">头像</view>
- <u-avatar :src="userData.avatar" size="120"></u-avatar>
- </view>
- <u-line color="#f1f1f1"></u-line>
- <view class="flex padding justify-between align-center">
- <view class="title">昵称</view>
- <u-input v-model="userData.nickName" :clearable="false" inputAlign="right" placeholder="请输入昵称"></u-input>
- </view>
- <u-line color="#f1f1f1"></u-line>
- <view class="flex padding justify-between align-center">
- <view class="title">性别</view>
- <view style="width: 200upx;">
- <u-input v-model="sex" type="select" :border="border" @click="sexShow = true"></u-input>
- <u-action-sheet :list="actionSheetList" v-model="sexShow" @click="actionSheetCallback"></u-action-sheet>
- </view>
- </view>
- <u-line color="#f1f1f1"></u-line>
- <view class="flex padding justify-between align-center" @click="calendarShow = true">
- <view class="title">生日</view>
- <view>{{birthday}}</view>
- <u-calendar v-model="calendarShow" mode="date" @change="change"></u-calendar>
- </view>
- <u-line color="#f1f1f1"></u-line>
- <view class="padding">
- <view class="title">个人介绍</view>
- </view>
- <view style="padding: 0 40upx">
- <u-input v-model="introduction" type="textarea" :clearable="false" height="140" :autoHeight="false" maxlength="60" placeholder="请输入个人简介" />
- </view>
- <view class="flex justify-end padding-right-sm padding-bottom-sm text-gray">{{introduction.length}} / 60</view>
- <view class="footer-fixed margin-bottom">
- <u-button class="custom-style" shape="circle" @click="save">保存</u-button>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- userData: {},
- name: 'Daniel Hua',
- sex: '',
- sexShow: false,
- border: true,
- show: false,
- actionSheetList: [
- {
- text: '男'
- },
- {
- text: '女'
- },
- {
- text: '保密'
- }
- ],
- calendarShow: false,
- birthday: '',
- introduction: '',
- }
- },
- onLoad(options) {
- this.getUserInfo(options.userId);
- },
- methods: {
- getUserInfo(userId) {
- this.$u.api.user.detail({id: userId}).then(res => {
- this.userData = res;
- if (res.gender == 1) {
- this.sex = '男';
- } else if (res.gender == 2) {
- this.sex = "女";
- } else {
- this.sex = "未知";
- }
- })
- },
- // 点击actionSheet回调
- actionSheetCallback(index) {
- this.sex = this.actionSheetList[index].text;
- },
- change(e) {
- this.birthday = e.result;
- },
- save() {
- if (this.$u.test.isEmpty(this.introduction) || this.$u.test.isEmpty(this.userData.nickName)) {
- uni.showToast({
- icon: "none",
- title: "请填写个人昵称和个人介绍",
- })
- return;
- } else {
- let data = {
- id: this.userData.id,
- name: this.userData.nickName,
- gender: this.sex == '男' ? 1 : this.sex == '女' ? 2 : 0,
- birthday: this.birthday,
- introduce: this.introduction,
- }
- this.$u.api.user.submit(data).then(res => {
- uni.showToast({
- icon: "none",
- title: "修改成功",
- duration: 2000,
- success() {
- uni.navigateBack({
- delta: 1
- })
- }
- })
- })
- }
- }
- }
- }
- </script>
- <style>
- page {
- background-color: #ffffff;
- }
- </style>
- <style lang="scss" scoped>
- .title {
- font-size: 30upx;
- font-weight: bold;
- color: #060606;
- padding-left: 10upx;
- }
- .custom-style {
- background-color: #5a3ee7;
- color: #ffffff;
- width: 600rpx;
- }
- </style>
|