Pārlūkot izejas kodu

用户详情修改

junyuanz 4 gadi atpakaļ
vecāks
revīzija
d543816c3e

+ 2 - 1
app.json

@@ -69,7 +69,8 @@
         "pages/user/transfer/transferList/transferList",
 		"pages/user/proxyApply/proxyApply",
 		"pages/user/proxyList/proxyList",
-		"pages/user/proxyReview/proxyReview"
+		"pages/user/proxyReview/proxyReview",
+		"pages/user/userInfo/userInfo"
       ]
     },
     {

+ 312 - 0
packageUser/pages/user/userInfo/userInfo.js

@@ -0,0 +1,312 @@
+var _request = require('../../../../utils/request.js')
+var validator = require('../../../../utils/validator.js')
+var _handle = require('../../../../utils/handle.js')
+Page({
+  data: {
+    address: '请选择',
+    region: ['北京市', '北京市', '东城区'],
+    name: '',
+    tel: 0,
+    more: '',
+    countdown: 0,
+    yzm:'',
+    remark:'',
+    userinfo:{},
+	user:{},
+    showpage:0,
+	adimg:'',
+	applyTotal:0,
+	
+	imgUrl:null,
+	imgFile:null,
+	avatar:'',
+	nickname:'',
+	sex:0,
+	birthday:'',
+	phone:'',
+	columns: ["未知", "男", "女"],
+  },
+  onLoad: function (options) {
+  	this.getUserInfo();
+	this.getADimg();
+	this.getApplyTotal();
+  },
+  pickSex: function(e) {
+	  console.log('e.detail.value',e.detail.value);
+	 this.setData({
+		 sex: e.detail.value
+	 });
+	 // console.log("当前选择性别-sex", e.detail.value);
+ },
+  getUserInfo(){
+  	var that = this
+    var url = 'v1/user/info'
+    var params = {}
+    var success = function (res) {
+    	console.log(res);
+		
+    	that.setData({
+			userinfo: res.data.wx_user,
+			user:res.data.user,
+			
+			
+			avatar:res.data.user.head,
+			nickname:res.data.user.nickname,
+			sex:res.data.user.sex,
+			birthday:res.data.user.birthday.split('T').length > 1?res.data.user.birthday.split('T')[0]:res.data.user.birthday,
+			phone:res.data.user.tel
+		})
+    }
+    _request.$get(url, params, success)
+  },
+  savebtn(){
+	  var that = this;
+	  if(that.data.imgUrl){
+		var url = 'v1/user/update/info'
+		var params = {
+			  nickname:that.data.nickname,
+			  birthday:that.data.birthday,
+			  sex:that.data.sex,
+		}
+		var success = function (res) {
+			console.log(res);
+			wx.showToast({
+			  title: '更新成功',
+			  icon: 'none',
+			  duration: 2000
+			})
+		}
+		var fail = function (res) {
+			console.log(res);
+		}
+		
+		_request.$uploadFile(url,'head',that.data.imgFile, params, success,fail) 
+	  }else{
+		 var url = 'v1/user/update/info'
+		 var params = {
+			  nickname:that.data.nickname,
+			  birthday:that.data.birthday,
+			  sex:that.data.sex,
+		 }
+		 var success = function (res) {
+		 	console.log(res);
+			wx.showToast({
+			  title: '更新成功',
+			  icon: 'none',
+			  duration: 2000
+			})
+		 }
+		 _request.$post(url, params, success) 
+	  }
+	  
+	  
+  },
+  setAvatar(){
+	var that = this;
+	  wx.chooseImage({
+		  count:1,
+		  sizeType:['original','compressed'],
+		  sourceType:['album','camera'],
+		  success:function(res){
+			  var tempfile = res.tempFilePaths;
+			  that.setData({
+				  imgUrl:tempfile,
+				  imgFile:tempfile[0]
+				})
+		  }
+	  })
+  },
+  getADimg(){
+  	var that = this
+    var url = 'v1/ad/shop_apply/items'
+    var params = {}
+    var success = function (res) {
+    	console.log(res);
+		if(res.data.length > 0){
+			that.setData({
+				adimg: res.data[0].img
+			})
+		}
+    }
+    _request.$get(url, params, success)
+  },
+  getApplyTotal(){
+  	var that = this
+    var url = 'v1/sys_config/apply_total'
+    var params = {}
+    var success = function (res) {
+    	console.log(res);
+  		that.setData({
+  			applyTotal: res.data.total / 100
+  		})
+    }
+    _request.$get(url, params, success)
+  },
+  getTel (val) {
+    console.log(val)
+    if (val.detail.encryptedData) {
+      this.bindWxTel(val.detail)
+    }
+  },
+  bindWxTel (res) {
+    var str = JSON.stringify({
+      encryptedData: res.encryptedData,
+      iv: res.iv
+    })
+    var that = this
+    var url = 'v1/wxuser/one_click/binding/phonumer'
+    var params = {
+      userinfo: str
+    }
+    var success = function (res) {
+    	console.log(res);
+    }
+    _request.$post(url, params, success)
+  },
+  getYzm (e) {
+    _handle.setFormId(e)
+    if (validator.telphone(this.data.tel)) {
+      this.requireYzm()
+    } else {
+      wx.showToast({
+        title: '手机号码格式不正确',
+        icon: 'none',
+        duration: 2000
+      })
+    }
+  },
+  startCountdown: function () {
+    var smsRequestTime = wx.getStorageSync('sms_request_time')
+    if (smsRequestTime) {
+      var count = parseInt((60000 - (new Date() - smsRequestTime)) / 1000)
+      this.setData({
+        countdown: count
+      })
+      if (this.data.countdown > 0) {
+        var timer = setInterval(() => {
+          var countdown = this.data.countdown - 1
+          this.setData({
+            countdown: countdown
+          })
+          if (this.data.countdown <= 0) {
+            clearInterval(timer)
+          }
+        }, 1000)
+        // clearInterval(this.interval)
+      }
+    } else {
+    }
+  },
+  requireYzm () {
+    var that = this
+    var url = 'v1/code/send'
+    console.log(typeof(this.data.tel))
+    var params = {
+      tel: this.data.tel,
+      valid_type: 'shop_application'
+    }
+    var success = function (res) {
+      wx.setStorageSync('sms_request_time', Date.now())
+      that.startCountdown()
+    }
+    _request.$post(url, params, success)
+  },
+  bindNickname(e){
+	 this.setData({
+	   nickname: e.detail.value
+	 }) 
+  },
+  bindBirthday(e){
+  	 this.setData({
+  	   birthday: e.detail.value
+  	 }) 
+  },
+  bindPhone (e) {
+    this.setData({
+      tel: e.detail.value
+    })
+  },
+  bindYzm (e) {
+    this.setData({
+      yzm: e.detail.value
+    })
+  },
+  bindName: function (e) {
+    this.setData({
+      name: e.detail.value
+    })
+  },
+  bindMore: function (e) {
+    this.setData({
+      more: e.detail.value
+    })
+  },
+  bindRemark: function (e) {
+    this.setData({
+      remark: e.detail.value
+    })
+  },
+  validate () {
+    var msg
+    if (!validator.required(this.data.name)) {
+      msg = '姓名不能为空'
+    } else if (!validator.required(this.data.tel)) {
+      msg = '联系电话不能为空'
+    } else if (!validator.telphone(this.data.tel)) {
+      msg = '手机号码格式不正确'
+    } else if (this.data.address === '请选择') {
+      msg = '请选择所在地区'
+    } else if (!validator.required(this.data.more)) {
+      msg = '详细地址不能为空'
+    }
+    return { isOk: !msg, msg }
+  },
+  save: function (e) {
+    _handle.setFormId(e)
+    var { isOk, msg } = this.validate()
+    if (isOk) {
+      this.shopApplication()
+    } else {
+      wx.showToast({
+        title: msg,
+        icon: 'none',
+        duration: 2000
+      })
+    }
+  },
+  shopApplication () {
+    var that = this
+    var url = 'v1/user/shop_application'
+    var params = {
+      name: this.data.name,
+      mobile: this.data.tel,
+      code:this.data.yzm,
+      province: this.data.region[0],
+      city: this.data.region[1],
+      district: this.data.region[2],
+      address: this.data.more,
+      remark: this.data.remark
+    }
+    var success = function (res) {
+      wx.showToast({
+        title: '申请成功,我们将尽快处理,请您耐心等待',
+        icon: 'none',
+        duration: 2000
+      })
+      that.setData({showpage:1})
+    }
+    _request.$put(url, params, success)
+  },
+  bindRegionChange: function (e) {
+    console.log(e)
+    this.setData({
+      region: e.detail.value,
+      address: e.detail.value[0] + e.detail.value[1] + e.detail.value[2]
+    })
+  },
+//onShareAppMessage: function (val) {
+//  return _request.share({
+//    sc: 'xcx_user_newaddress'
+//  })
+//}
+})

+ 4 - 0
packageUser/pages/user/userInfo/userInfo.json

@@ -0,0 +1,4 @@
+{
+  "navigationBarTitleText": "用户信息",
+  "backgroundColor": "#f3f3f3"
+}

+ 48 - 0
packageUser/pages/user/userInfo/userInfo.wxml

@@ -0,0 +1,48 @@
+<view class="bg">
+  <view class="userinfo-line">
+    <view class="userinfo-title">头像</view>
+    
+	<view style="display: inline;" bindtap="setAvatar">
+		<image src="{{imgUrl}}" class="img-avatar" wx:if="{{imgUrl != null}}"></image>
+		<image src="{{avatar}}" class="img-avatar" wx:if="{{imgUrl == null}}"></image>
+	</view>
+	
+    <view class="clean"></view>
+  </view>
+  
+  <view class="userinfo-line">
+    <view class="userinfo-title">昵称</view>
+    <input class="nameText" placeholder="昵称" placeholder-class="text-placeholder" bindinput="bindNickname" value="{{nickname}}" />
+    <view class="clean"></view>
+  </view>
+  
+  <view class="userinfo-line">
+    <view class="userinfo-title">性别</view>
+    <picker bindchange="pickSex" value="{{ sex }}" class="sex" range="{{ columns }}" class="sexpicker">
+		<view>
+			{{ columns[sex] }}
+		</view>
+	</picker>
+    <view class="clean"></view>
+  </view>
+  
+  <view class="userinfo-line">
+    <view class="userinfo-title">生日</view>
+	<picker mode="date" value="{{birthday}}" bindchange="bindBirthday" class="sexpicker">
+	    <view class="picker">
+	      {{birthday}}
+	    </view>
+	</picker>
+    <view class="clean"></view>
+  </view>
+  
+  <view class="userinfo-line">
+    <view class="userinfo-title">手机号</view>
+    <input maxlength="11" class="nameText" placeholder="手机号" placeholder-class="text-placeholder" value="{{user.tel}}" disabled="disabled"/>
+    <view class="clean"></view>
+  </view>
+  
+	<button bindtap="savebtn" class="savebtn">
+	  保存修改
+	</button>
+</view>

+ 57 - 0
packageUser/pages/user/userInfo/userInfo.wxss

@@ -0,0 +1,57 @@
+.bg {
+  position: relative;
+  width: 100%;
+  min-height: 100%;
+  background-color: #f3f3f3;
+}
+
+.userinfo-line {
+  line-height: 90rpx;
+  background-color: #fff;
+  font-size: 28rpx;
+  border-bottom: 1px solid #eeeeee;
+  overflow:hidden;
+  padding: 20rpx;
+}
+
+.userinfo-title {
+  margin-left: 20rpx;
+  color: #4c4c4c;
+  width:80px;
+  vertical-align: middle;
+  display: inline-block;
+}
+
+.nameText {
+	width: 330rpx;
+    height: 90rpx;
+    line-height: 90rpx;
+    color: #4c4c4c;
+    float: right;
+    text-align: right;
+    padding-right: 20rpx;
+}
+.img-avatar{
+	width: 120rpx;
+	height: 120rpx;
+	border-radius: 50%;
+	vertical-align: middle;
+	float:right;
+}
+.savebtn{
+	width: 90%;
+	    padding: 5rpx;
+	    border-radius: 90rpx;
+	    background: #eab86a;
+	    color: #FFF;
+	    font-size: 30rpx;
+	    margin: 5%;
+	    margin-top: 100rpx;
+}
+.sexpicker{
+	display: inline;
+	width: 200rpx;
+	float: right;
+	text-align: right;
+	padding-right: 25rpx;
+}

+ 5 - 0
pages/user/all/all.js

@@ -425,6 +425,11 @@ Page({
     	})
   	}
   },
+  toUserInfo() {
+    wx.navigateTo({
+      url: '/packageUser/pages/user/userInfo/userInfo'
+    })
+  },
   toBindOldSys () {
   	let that = this;
     wx.navigateTo({

+ 1 - 1
pages/user/all/all.wxml

@@ -26,7 +26,7 @@
 		    <view class="bind" style="top: 0;left: 192rpx;">立即绑定</view>
 		</navigator>
 	</span>
-    <image class="user-head" src="{{userInfo.full_head}}"></image>
+    <image class="user-head" src="{{userInfo.full_head}}" bindtap="toUserInfo"></image>
     <view class="clean"></view>
   </view>
   <view style="padding-bottom: 50rpx;">

+ 28 - 1
utils/request.js

@@ -314,6 +314,32 @@ function share (val) {
   }
 }
 
+function $uploadFile(url, name, file, params, success, fail){
+	wx.showNavigationBarLoading()
+	var session = wx.getStorageSync('lbt_session_key')
+	wx.uploadFile({
+		url: apiHost + url, //仅为示例,非真实的接口地址
+		filePath: file,
+		name: name,
+		formData: params,
+		header: {
+		  "content-type": "application/x-www-form-urlencoded",
+		  "terminal": 'mini-program',
+		  "Cookie": 'fohow_sid=' + session
+		},
+		success(res) {
+			callBack(res, success, fail)
+		},
+		fail(res) {
+			console.log('err',res)
+		},
+		complete(res) {
+		  wx.hideNavigationBarLoading()
+		}
+	})
+}
+
+
 function shareInfo (val) {
   var url = 'v1/share/info'
   var params = {
@@ -336,5 +362,6 @@ module.exports = {
   getAuthorize: getAuthorize,
   updateWxUserInfo: updateWxUserInfo,
   sendInfo: sendInfo,
-  share: share
+  share: share,
+  $uploadFile:$uploadFile
 }