| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <template>
- <view class="user-info">
- <view class="info-item">
- <text class="tit">头像</text>
- <view class="avater" @click="gainimg">
- <image :src="userinfos.image" mode="aspectFill" class="user"></image>
- <view class="sim_info_loding" v-if="loding">
- <image src="../../../static/images/cb/6286299.gif" mode="" class="img"></image>
- </view>
- </view>
- </view>
- <view class="info-item">
- <text class="tit">用户名</text>
- <text class="val">{{userinfos.username}}</text>
- <!-- <input type="text" v-model="userinfos.username" :class="compileTF?'valinput valinput2':'valinput'" :disabled="!compileTF"
- maxlength='8' /> -->
- </view>
- <view class="info-item">
- <text class="tit">用户身份</text>
- <text class="val">{{usertype[userinfos.user_type-1]}}</text>
- </view>
- <view class="info-item">
- <text class="tit">用户电话</text>
- <input type="text" v-model="userinfos.mobile" :class="compileTF?'valinput valinput2':'valinput'" :disabled="!compileTF"
- @blur="verifyphone" />
- <p class="hint" v-if="phonehint">手机号格式不正确</p>
- </view>
- <view class="info-item">
- <text class="tit">E-mail</text>
- <input type="text" v-model="userinfos.email" :class="compileTF?'valinput valinput2':'valinput'" :disabled="!compileTF"
- @blur="verifyemail" />
- <p class="hint" v-if="emailhint">邮箱格式不正确</p>
- </view>
- <view class="info-item">
- <text class="tit">我的地址</text>
- <!-- <text class="val" >{{location}}<u-icon v-if="compileTF" name="arrow-right"></u-icon></text> -->
- <input type="text" v-model="location" :class="compileTF?'valinput valinput2':'valinput'"
- :disabled="!compileTF" @click="cutticy"/>
- </view>
- <view class="compile">
- <p @click="compile" v-if="!compileTF">编辑</p>
- <p @click="submit" v-else>提交</p>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- userinfos: {},
- location:'',
- imageList: '',
- compileTF: false,
- phonehint: false,
- emailhint: false,
- loding:false,
- usertype:["超级管理员","经销商","农林政府单位","普通用户"],
- }
- },
- methods: {
- gainimg() { //添加图片
- return
- if (this.compileTF) {
- uni.chooseImage({
- count: 1, //默认9
- sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album', 'camera'], //从相册选择
- success: (res) => {
- this.loding=true
- uni.uploadFile({
- url: 'http://114.115.147.140:8002/api/api_gateway?method=base.bases.base_photo', //仅为示例,非真实的接口地址
- filePath: res.tempFilePaths[0],
- name: 'img_file',
- formData: {
- 'user': 'test'
- },
- success: (uploadFileRes) => {
- this.userinfos.image = JSON.parse(uploadFileRes.data).data.src
- this.$forceUpdate() //强制刷新视图
- this.loding=false
- }
- });
- }
- })
- }
- }, //
- async postusers() {
- const res = await this.$myRequest({
- url: '/api/api_gateway?method=home.homes.personal_center',
- data: {
- ret: 'change',
- username: this.userinfos.username,
- mobile: this.userinfos.mobile,
- province: this.userinfos.province,
- city: this.userinfos.city,
- district: this.userinfos.district,
- image: this.userinfos.image,
- email: this.userinfos.email
- }
- })
- console.log(res)
- if(res){
- this.compileTF = false
- uni.removeStorage({
- key: "location",
- })
- uni.navigateBack({
- delta:1
- })
- }
- },
- compile() { //编辑按钮
- this.compileTF = true
- },
- submit() {//提交按钮
- if(this.phonehint == false &&this.emailhint == false){
- this.userinfos.province = this.location.slice(0,this.location.indexOf("省")+1)
- this.userinfos.city = this.location.slice(this.location.indexOf("省")+1,this.location.indexOf("市")+1)
- this.userinfos.district = this.location.slice(this.location.indexOf("市")+1)
- this.postusers()
- }
- },
- verifyphone() { //手机号验证
- var reg = /^1[356789]\d{9}$/;
- if (!reg.test(this.userinfos.mobile)) {
- this.phonehint = true
- } else {
- this.phonehint = false
- }
- },
- verifyemail() { //邮箱验证
- var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
- if (!reg.test(this.userinfos.email)) {
- this.emailhint = true
- } else {
- this.emailhint = false
- }
- },
- cutticy(){
- if(this.compileTF){
- uni.navigateTo({
- url: "../../fourBase/city"
- })
- }
- },
- selectaddress(lng, lat) { //获取分布位置
- uni.request({
- type: "GET",
- url: "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=" + lng + "," + lat +
- "&key=78ce288400f4fc6d9458989875c833c2&radius=1000&extensions=all",
- dataType: "json",
- complete: ress => {
- // console.log(ress)
- if (ress.data.regeocode.formatted_address.length == 0) {
- this.location = "--"
- } else {
- this.location = ress.data.regeocode.formatted_address
- }
- }
- });
- },
- },
- onShow(){
- uni.getStorage({
- key: "location",
- success: (res) => {
- var lat = res.data[1]
- var lng = res.data[0]
- this.selectaddress(lng, lat)
- }
- })
- },
- onLoad(option) {
- this.userinfos = JSON.parse(option.data)
- this.location = this.userinfos.province+this.userinfos.city+this.userinfos.district
- console.log(this.userinfos)
- }
- }
- </script>
- <style lang="scss">
- page {
- background: $uni-bg-color-grey;
- .user-info {
- background: #fff;
- padding: 0 40rpx;
- .info-item {
- display: flex;
- justify-content: space-between;
- line-height: 100rpx;
- position: relative;
- .avater {
- width: 100rpx;
- height: 100rpx;
- border-radius: 50%;
- overflow: hidden;
- position: relative;
- .user {
- width: 100%;
- height: 100%;
- position: absolute;
- top: 0;
- left: 0;
- }
- .sim_info_loding{
- width: 100%;
- height: 100%;
- background-color: rgba(0,0,0,0.5);
- position: absolute;
- top: 0;
- left: 0;
- image{
- width: 100%;
- height: 100%;
- position: absolute;
- left: 6rpx;
- top: 6rpx;
- }
- }
- }
- .tit {
- font-size: 14px
- }
- .val {
- font-size: 12px;
- color: #666;
- }
- .valinput {
- margin-top: 24rpx;
- text-align: right;
- font-size: 12px;
- color: #666;
- padding: 10rpx 0;
- width: 360rpx;
- }
- .valinput2 {
- background-color: #e1e5ee;
- }
- .hint {
- position: absolute;
- top: 40rpx;
- right: 220rpx;
- font-size: 24rpx;
- color: #ff0000;
- }
- }
- .compile {
- width: 100%;
- margin-top: 40rpx;
- height: 60rpx;
- line-height: 60rpx;
- text-align: center;
- background-color: #58C77A;
- border-radius: 30rpx;
- color: #FFFFFF;
- }
- }
- }
- </style>
|