|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- // pages/userMsg/userMsg.js
- const app = getApp()
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
-
- },
-
- /**
- * 组件的初始数据
- */
- data: {
- imgUrl: app.globalData.urlStatic,//图片路径
- submitData: {
- realName: "",
- mobile: "",//电话
- province: "",//省份
- city: "",//城市
- district: "",//地区
- addressDetail: ""//详细
- },
- userData:{
- avatarUrl:"",
- nickName:""
- },
- isAddress: false,//是否有地址
- marginT: 0,
- },
- attached:function(){
- if (app.globalData.userPhoneType == "ios") {
- this.setData({
- marginT: -20
- })
- }
- if (app.globalData.openid) {
- this.loadFun();
- } else {
- app.globalData.openidSuccessFuc = this.loadFun;
- }
- },
- /**
- * 组件的方法列表
- */
- methods: {
- loadFun: function () {
- if (app.globalData.userInfoData) {
- this.data.userData.avatarUrl = app.globalData.userInfoData.avatarUrl;
- this.data.userData.nickName = app.globalData.userInfoData.nickName;
- this.setData({
- userData: this.data.userData
- })
- }
- this.getAddress();
- },
- getAddress: function () {//获取地址
- app.wxRequest(app.globalData.urlRoot + "address/getAddress", {}, res => {
- if (res.code == 200) {
- if (res.data) {
- this.data.isAddress = true;
- this.data.submitData.realName = res.data.realName;
- this.data.submitData.mobile = res.data.mobile;
- this.data.submitData.province = res.data.province;
- this.data.submitData.city = res.data.city;
- this.data.submitData.district = res.data.district;
- this.data.submitData.addressDetail = res.data.addressDetail;
- this.setData({
- submitData: this.data.submitData
- })
- }
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this);
- },
- addAddress: function () {//添加地址
- app.wxRequest(app.globalData.urlRoot + "address/addAddress", this.data.submitData, res => {
- wx.showToast({
- title: res.msg,
- })
- if (res.code == 200) {
- this.closeXieyi();
- }
- }, this, "POST")
- },
- updateAddress: function () {//更新地址
- app.wxRequest(app.globalData.urlRoot + "address/updateAddress", this.data.submitData, res => {
- wx.showToast({
- title: res.msg,
- })
- if (res.code == 200) {
- this.closeXieyi();
- }
- }, this, "POST");
- },
- addressChange: function (e) {//所在地区发生改变
- this.data.submitData.province = e.detail.value[0];
- this.data.submitData.city = e.detail.value[1];
- this.data.submitData.district = e.detail.value[2];
- this.setData({
- submitData: this.data.submitData
- })
- },
- getNickName: function(e) {//获取昵称
- this.data.userData.nickName = e.detail.value;
- this.setData({
- userData: this.data.userData
- })
- },
- getRealName: function (e) {//获取收货人
- this.data.submitData.realName = e.detail.value;
- this.setData({
- submitData: this.data.submitData
- })
- },
- getMobile: function (e) {//获取手机号码
- this.data.submitData.mobile = e.detail.value;
- this.setData({
- submitData: this.data.submitData
- })
- },
- getAddressDetail: function (e) {//获取详细地址
- this.data.submitData.addressDetail = e.detail.value;
- this.setData({
- submitData: this.data.submitData
- })
- },
- saveUserMsg:function(){
- if (!this.data.submitData.realName) {
- wx.showToast({
- title: '请输入收货人',
- icon: "none"
- })
- return;
- }
- if (!app.mobileVerify(this.data.submitData.mobile)) {
- if (this.data.submitData.mobile) {
- wx.showToast({
- title: '请输入正确的电话',
- icon: 'none'
- })
- } else {
- wx.showToast({
- title: '请输入电话',
- icon: 'none'
- })
- }
- return;
- }
- if (!this.data.submitData.province) {
- wx.showToast({
- title: '请选择所在地区',
- icon: 'none'
- })
- return;
- }
- if (!this.data.submitData.addressDetail) {
- wx.showToast({
- title: '请输入详细地址',
- icon: "none"
- })
- return;
- }
- wx.showLoading({
- title: '保存中',
- mask: true
- })
- app.wxRequest(app.globalData.urlRoot + "userInfo/updateUserInfo", this.data.userData, res => {
- if (res.code == 200) {
- app.globalData.userInfoData.avatarUrl = this.data.userData.avatarUrl;
- app.globalData.userInfoData.nickName = this.data.userData.nickName;
- var userInfoData = wx.getStorageSync("userInfoData");
- userInfoData.avatarUrl = this.data.userData.avatarUrl;
- userInfoData.nickName = this.data.userData.nickName;
- wx.setStorageSync('userInfoData', userInfoData)
- this.submitAddress();
- }
- }, this, "POST")
- },
- submitAddress: function () {//保存地址
- if (this.data.isAddress) {
- this.updateAddress();
- } else {
- this.addAddress();
- }
- },
- closeXieyi: function () {
- this.triggerEvent('address')
- },
- changeHeadImg:function(){
- wx.chooseImage({
- count:1,
- success:(res)=>{
- wx.showLoading({
- title: '上传中',
- mask: true
- })
- wx.uploadFile({
- url: app.globalData.urlRoot + "upload/uploadImage",
- header: {
- "OPENID": app.globalData.openid,
- "VERSION": 100
- },
- filePath: res.tempFilePaths[0],
- name: "file",
- formData:{
- filePath:"avatar"
- },
- success: option => {
- wx.hideLoading();
- var json = JSON.parse(option.data);
- if (json.code==200){
- this.data.userData.avatarUrl = json.data[0].url;
- this.setData({
- userData: this.data.userData
- })
- }else{
- wx.showToast({
- title: option.msg,
- icon: 'none'
- })
- }
- }
- })
- }
- })
- }
- }
- })
|