123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <template>
- <mobile-frame>
- <view class="info">
- <view class="one">
- <uni-forms ref="form" :modelValue="form" :rules="rules" label-width="auto">
- <uni-forms-item label="头像" name="icon">
- <view class="icon">
- <view class="icon_1" v-if="form.icon&&form.icon.length>0">
- <image class="image" v-for="i in form.icon" :key="i" :src="i.url" mode=""></image>
- <uni-icons class="del" type="close" size="30" color="#ff0000" @click="iconDel()">
- </uni-icons>
- </view>
- <view class="icon_2" v-else>
- <button open-type="chooseAvatar" @chooseavatar="chooseavatar">上传头像</button>
- </view>
- </view>
- </uni-forms-item>
- <uni-forms-item label="用户名" name="name">
- <input class="input" type="nickname" :value="form.name" placeholder="请输入用户名" @input="nameInput">
- <!-- <uni-easyinput type="nick" v-model="form.name" placeholder="请输入用户名" /> -->
- </uni-forms-item>
- <uni-forms-item label="性别" name="gender">
- <picker @change="genderChange" name="gender" :value="form.gender" :range="genderList"
- range-key="label">
- <view class="uni-input">{{form.zhGender||'请选择性别'}}</view>
- </picker>
- </uni-forms-item>
- <uni-forms-item label="生日" name="birth">
- <picker mode="date" :value="form.birth" name="birth" @change="bindDateChange">
- <view class="uni-input">{{form.birth||'请选择日期'}}</view>
- </picker>
- </uni-forms-item>
- </uni-forms>
- <view class="btn">
- <button type="primary" @click="onSubmit('form')" size="small">提交</button>
- </view>
- </view>
- </view>
- </mobile-frame>
- </template>
- <script>
- export default {
- components: {},
- data() {
- return {
- frameStyle: {
- useBar: false
- },
- form: {
- icon: []
- },
- rules: {
- name: {
- rules: [{
- required: true,
- errorMessage: '请输入用户名',
- }]
- },
- phone: {
- rules: [{
- required: true,
- errorMessage: '请输入手机号',
- }]
- },
- },
- genderList: [],
- };
- },
- onLoad: async function(e) {
- const that = this;
- await that.searchOther();
- that.watchLogin();
- },
- methods: {
- async searchOther() {
- const that = this;
- let res;
- res = await that.$api(`/dictData`, 'GET', {
- code: "gender"
- });
- if (res.errcode == '0') {
- that.$set(that, `genderList`, res.data)
- }
- },
- watchLogin() {
- const that = this;
- uni.getStorage({
- key: 'token',
- success: async (res) => {
- let user = that.$jwt(res.data);
- if (user) {
- const arr = await that.$api(`/user/${user.id}`, 'GET');
- if (arr.errcode == '0') {
- let gender = that.genderList.find(i => i.value == arr.data
- .gender)
- if (gender) arr.data.zhGender = gender.label;
- that.$set(that, `form`, arr.data)
- } else {
- uni.showToast({
- title: arr.errmsg,
- icon: 'error',
- duration: 2000
- });
- }
- }
- },
- fail: (err) => {}
- })
- },
- toPath(e) {
- if (e && e.route) uni.redirectTo({
- url: `/${e.route}`
- })
- },
- // 删除头像
- iconDel() {
- const that = this;
- that.$set(that.form, `icon`, [])
- },
- // 头像上传
- async chooseavatar(e) {
- const that = this;
- let avatarUrl = e.detail.avatarUrl;
- let serverUrl = that.$config.serverUrl;
- const res = await that.$apifile(`/point/shopOne/upload`, 'file', avatarUrl, 'file');
- if (res.errcode == '0') {
- let obj = {
- name: res.name,
- uri: res.uri,
- url: serverUrl + res.uri
- }
- that.$set(that.form, `icon`, [obj])
- } else {
- uni.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- },
- // 选择,输入昵称
- nameInput(e) {
- const that = this;
- that.$set(that.form, `name`, e.detail.value);
- },
- // 选择性别
- genderChange(e) {
- const that = this;
- let data = that.genderList[e.detail.value];
- if (data) {
- that.$set(that.form, `gender`, data.value);
- that.$set(that.form, `zhGender`, data.label);
- }
- },
- // 选择日期
- bindDateChange(e) {
- const that = this;
- that.$set(that.form, `birth`, e.detail.value);
- },
- // 返回
- back() {
- uni.navigateBack({
- delta: 1
- })
- },
- // 提交保存
- onSubmit(ref) {
- const that = this;
- that.$refs[ref].validate().then(async params => {
- uni.getStorage({
- key: 'shop',
- success: async function(res) {
- parmas.shop = res.data
- }
- })
- const arr = await that.$api(`/user/${that.form.id}`, 'POST', params);
- if (arr.errcode == '0') {
- uni.showToast({
- title: `维护信息成功`,
- icon: 'success',
- });
- that.back();
- } else {
- uni.showToast({
- title: arr.errmsg,
- })
- }
- })
- },
- }
- }
- </script>
- <style lang="scss">
- .info {
- display: flex;
- flex-direction: column;
- width: 100vw;
- height: 100vh;
- .one {
- padding: 2vw;
- .uni-input {
- border: #f1f1ff 1px solid;
- padding: 2vw 2vw;
- border-radius: 1vw;
- }
- .input {
- border: #f1f1ff 1px solid;
- padding: 1.5vw 1vw;
- border-radius: 5px;
- }
- .btn {
- text-align: center;
- button {
- margin: 0 2vw 2vw 2vw;
- background-color: var(--fFB1Color);
- color: var(--fffColor);
- }
- .name {
- color: var(--f85Color);
- font-size: var(--font14Size);
- }
- }
- .icon {
- display: flex;
- .icon_1 {
- position: relative;
- .image {
- width: 30vw;
- height: 30vw;
- }
- .del {
- position: absolute;
- top: 0;
- left: 22vw;
- }
- }
- .icon_2 {
- text-align: left;
- button {
- width: 30vw;
- padding: 0vw 1vw;
- font-size: 14px;
- }
- }
- }
- }
- }
- .uni-forms-item {
- margin-bottom: 6vw !important;
- display: flex;
- flex-direction: row;
- }
- </style>
|