123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <template>
- <view class="main">
- <view class="one">
- <upload class='upload' :list="user.logo" name="logo" :count="1" @uplSuc="uplSuc" @uplDel="uplDel">
- </upload>
- </view>
- <view class="two">
- <view class="two_1">
- <view class="left">真实姓名</view>
- <view class="right">
- <input v-model="user.name" placeholder="请输入真实姓名" />
- <text class="iconfont icon-dayuhao"></text>
- </view>
- </view>
- <view class="two_1">
- <view class="left">昵称</view>
- <view class="right">
- <input v-model="user.nick_name" placeholder="请输入昵称" />
- <text class="iconfont icon-dayuhao"></text>
- </view>
- </view>
- <view class="two_1">
- <view class="left">性别</view>
- <view class="right">
- <picker class="picker" mode="selector" :range="genderList" @change="genderChange" range-key="label">
- <view>{{gender_name||'请选择性别'}}</view>
- </picker>
- <text class="iconfont icon-dayuhao"></text>
- </view>
- </view>
- <view class="two_1">
- <view class="left">手机号</view>
- <view class="right">
- <input v-model="user.phone" placeholder="请输入手机号" />
- <text class="iconfont icon-dayuhao"></text>
- </view>
- </view>
- <view class="two_1">
- <view class="left">生日</view>
- <view class="right">
- <picker mode="date" :value="user.birthday" :start="startDate" :end="endDate"
- @change="bindDateChange">
- <view>{{user.birthday||'请选择生日'}}</view>
- </picker>
- <text class="iconfont icon-dayuhao"></text>
- </view>
- </view>
- <view class="two_1">
- <view class="left">所在城市</view>
- <view class="right">
- <picker class="picker" :value="user.city" mode="selector" :range="cityList" @change="cityChange"
- range-key="name">
- <view>{{user.city||'请选择所在城市'}}</view>
- </picker>
- <text class="iconfont icon-dayuhao"></text>
- </view>
- </view>
- </view>
- <view class="thr">
- <button class="button" type="primary" size="mini" @click="onSubmit()">保存</button>
- </view>
- </view>
- </template>
- <script>
- import upload from '../../components/upload/index.vue';
- export default {
- components: {
- upload
- },
- data() {
- return {
- user: {},
- gender_name: '',
- // 字典表
- genderList: [],
- cityList: [],
- }
- },
- onLoad: async function() {
- const that = this;
- await that.searchOther();
- await that.search();
- },
- onShow: async function(e) {
- const that = this;
- that.searchToken();
- },
- methods: {
- searchToken() {
- const that = this;
- try {
- const res = uni.getStorageSync('token');
- if (res) that.$set(that, `user`, res);
- } catch (e) {
- uni.showToast({
- title: err.errmsg,
- icon: 'error',
- duration: 2000
- });
- }
- },
- // 查询
- async search() {
- const that = this;
- let data = that.genderList.find(i => i.value == that.user.gender);
- if (data) that.$set(that, `gender_name`, data.label)
- },
- // 图片上传
- uplSuc(e) {
- const that = this;
- that.$set(that.user, `logo`, [e.data]);
- },
- // 图片删除
- uplDel(e) {
- const that = this;
- that.$set(that.user, `logo`, [])
- },
- // 性别选择
- genderChange(e) {
- const that = this;
- let data = that.genderList.find(i => i.value == e.detail.value);
- if (data) {
- that.$set(that.user, `gender`, data.value)
- that.$set(that, `gender_name`, data.label)
- }
- },
- // 生日选择
- bindDateChange: function(e) {
- const that = this;
- that.$set(that.user, `birthday`, e.detail.value)
- },
- // 城市选择
- cityChange(e) {
- const that = this;
- let data = that.cityList[e.detail.value];
- that.$set(that.user, `city`, data.name)
- },
- // 保存
- async onSubmit() {
- const that = this;
- const form = that.user;
- delete form.gender_name
- const res = await that.$api(`/user/${form._id}`, 'POST', form);
- if (res.errcode == '0') {
- uni.showToast({
- title: '维护信息成功',
- icon: 'none'
- })
- let arr = await that.$api(`/user/${form._id}`, 'GET', {})
- uni.setStorage({
- key: 'token',
- data: arr.data,
- success: function(res) {
- uni.navigateBack({
- delta: 1
- })
- },
- fail: function(err) {
- console.log(err);
- }
- })
- } else {
- uni.showToast({
- title: res.errmsg,
- icon: 'none'
- })
- }
- },
- async searchOther() {
- const that = this;
- let res;
- // 查询类型
- res = await that.$api(`/dictData`, 'GET', {
- type: 'gender',
- is_use: '0',
- })
- if (res.errcode == '0') that.$set(that, `genderList`, res.data);
- let config = that.$config;
- that.$set(that, `cityList`, config.china);
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .main {
- .one {
- display: flex;
- justify-content: center;
- padding: 2vw;
- }
- .two {
- padding: 2vw;
- .two_1 {
- display: flex;
- justify-content: space-between;
- padding: 4vw;
- border-bottom: 1px solid var(--f9Color);
- font-size: var(--font14Size);
- color: var(--f69Color);
- .right {
- display: flex;
- align-items: center;
- input {
- text-align: right;
- padding: 0 1vw;
- }
- }
- }
- }
- .thr {
- text-align: center;
- .button {
- margin: 2vw 0 0 0;
- background-color: var(--f3CColor);
- color: var(--mainColor);
- font-size: var(--font14Size);
- }
- }
- }
- </style>
|