123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <template>
- <view class="main">
- <view class="head_bg">
- <u-avatar size="150" @click="chooseAvatar" :src="form.avatar" mode="circle">
- </u-avatar>
- </view>
- <view style="border-radius: 16rpx;box-shadow: 6rpx 6rpx 10rpx rgba(122, 122, 122, 0.2);"
- class="u-margin-left-20 u-margin-right-20 u-margin-top-20 bg-white padding">
- <u-form :model="form" ref="uForm">
- <u-form-item label="姓名" label-width="125" :border-bottom="true">
- <u-input border placeholder="请输入您的真实姓名" v-model="form.name" />
- </u-form-item>
- <u-form-item label="年龄" label-width="125" :border-bottom="true">
- <u-input border type="number" maxlength="18" placeholder="请输入您的年龄" v-model="form.age" />
- </u-form-item>
- <u-form-item label="手机号" label-width="125" :border-bottom="true">
- <u-input border type="number" maxlength="11" placeholder="请输入您的手机号码" v-model="form.phone" />
- </u-form-item>
- <u-form-item label="所属地区" label-width="125" :border-bottom="true">
- <u-input border placeholder="请选择所属地区" border type="select" @click="show = true"
- v-model="form.cityName" />
- </u-form-item>
- </u-form>
- <u-picker mode="region" @confirm="selectReg" v-model="show"
- :area-code='[form.province, form.city, form.area]'>
- </u-picker>
- </view>
- <u-button shape="circle" hover-class="none" :custom-style="customStyle" @click="editInfo" throttle-time="1000">
- 提交</u-button>
- </view>
- </template>
- <script>
- import store from '@/store'
- export default {
- data() {
- return {
- form: {
- avatar: '',
- name: '',
- city: '1303',
- sex: 1,
- age: '',
- phone: '',
- area: '130304',
- province: '13',
- cityName: ''
- },
- show: false,
- customStyle: {
- marginTop: '30rpx',
- marginLeft: '20rpx',
- marginRight: '20rpx',
- // width:'182rpx',
- height: '74rpx',
- color: '#fff',
- background: '#FBC600',
- border: 'none'
- },
- }
- },
- onLoad() {
- if (this.vuex_user.name != null) {
- this.form = {
- ...store.state.vuex_user
- }
- if (this.form.province.length != 2) {
- this.form.province = (this.form.province / 10000) + ''
- }
- if (this.form.city.length != 4) {
- this.form.city = (this.form.city / 100) + ''
- }
- console.log(this.form)
- }
- },
- created() {
- // 监听从裁剪页发布的事件,获得裁剪结果
- uni.$on('uAvatarCropper', path => {
- // 可以在此上传到服务端
- uni.uploadFile({
- url: this.$upload + '/common/uploadImg',
- filePath: path,
- name: 'file',
- complete: (res) => {
- this.form.avatar = JSON.parse(res.data).data.file_url
- }
- });
- })
- },
- methods: {
- chooseAvatar() {
- // 此为uView的跳转方法,详见"文档-JS"部分,也可以用uni的uni.navigateTo
- this.$u.route({
- // 关于此路径,请见下方"注意事项"
- url: '/uview-ui/components/u-avatar-cropper/u-avatar-cropper',
- // 内部已设置以下默认参数值,可不传这些参数
- params: {
- // 输出图片宽度,高等于宽,单位px
- destWidth: 300,
- // 裁剪框宽度,高等于宽,单位px
- rectWidth: 300,
- // 输出的图片类型,如果'png'类型发现裁剪的图片太大,改成"jpg"即可
- fileType: 'jpg',
- }
- })
- },
- selectReg(e) {
- this.form.province = e.province.value
- this.form.city = e.city.value
- this.form.area = e.area.value
- this.form.cityName = e.province.label + '-' + e.city.label + '-' + e.area.label
- },
- async editInfo() {
- let province = this.form.province + "0000"
- let city = this.form.city + "00"
- let res = await this.$u.post("manager/updateUser", {
- ...this.form,
- province,
- city
- })
- if (res.code == 200) {
- let obj = {
- ...this.form,
- }
- this.$u.vuex('vuex_user', obj)
- uni.showToast({
- title: "修改成功",
- icon: "none",
- duration: 1000
- })
- setTimeout(() => {
- uni.switchTab({
- url: "./mine"
- })
- }, 1000)
- }else{
- uni.showToast({
- title:res.message,
- icon:"none"
- })
- return false
- }
- }
- }
- }
- </script>
- <style>
- .head_bg {
- background-color: #FBC600;
- height: 350rpx;
- width: 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column;
- /* border-radius: 0 0 50rpx 50rpx; */
- }
- </style>
|