From a75b18a4157ab486e0b51c438ac165ab3a08e3e0 Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期四, 25 七月 2024 18:10:00 +0800
Subject: [PATCH] 代码提交

---
 wechat_jiaxuan/pages/userinfo/index.js |  197 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 179 insertions(+), 18 deletions(-)

diff --git a/wechat_jiaxuan/pages/userinfo/index.js b/wechat_jiaxuan/pages/userinfo/index.js
index 2401160..a6c42a2 100644
--- a/wechat_jiaxuan/pages/userinfo/index.js
+++ b/wechat_jiaxuan/pages/userinfo/index.js
@@ -1,47 +1,208 @@
-// pages/userinfo/index.js
+import {
+  uploadUrl,
+  editMember,
+  getMemberInfo,
+  getArea
+} from '../../api/index'
 Page({
 
   /**
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
+    imgurl: "",
+    imgurlFull: "",
     name: "",
-    // 鍩庡競銆傚湴鍧�
-    region: [],
-    address: ''
+    nickname: "",
+    phone: "",
+    address: '',
+    latitude: '',
+    longitude: '',
+    district: '',
+    housearea: '',
+    
+    addr: {},
+    areaData: [],
+
+    showHouseType: false,
+    houseType: {
+      val1: '',
+      val2: '',
+      val3: '',
+      val4: '',
+      val5: '',
+    }
   },
   onLoad(options) {
-
+    this.initData()
   },
   onSubmit() {
-
-  },
-  changeAddr() {
-    console.log('鐐瑰嚮浜�');
-    wx.chooseLocation({
-      type: 'wgs84',
-      success: (res) => {
-        console.log('res', res);
-      }
+    const {
+      imgurl,
+      name,
+      nickname,
+      phone,
+      address,
+      latitude,
+      longitude,
+      district,
+      housearea,
+      houseType,
+      addr
+    } = this.data
+    if (!nickname) return wx.showToast({
+      title: '璇疯緭鍏ユ樀绉�',
+      icon: 'none'
     })
+    editMember({
+      ...addr,
+      imgurl: imgurl || '',
+      name: name || '',
+      nickname: nickname || '',
+      phone: phone || '',
+      address: address || '',
+      latitude: latitude || '',
+      longitude: longitude || '',
+      district: district || '',
+      housearea: housearea || '',
+      housetype: houseType.val1 + '-' + houseType.val2 + '-' + houseType.val3 + '-' + houseType.val4 + '-' + houseType.val5
+    }).then(res => {
+      wx.showToast({
+        title: '淇濆瓨鎴愬姛',
+        icon: 'none'
+      })
+    })
+  },
+  initData() {
+    getMemberInfo().then(res => {
+      if(res.data.housetype){
+        const temp = res.data.housetype.split('-')
+        let houseType = {
+          val1: temp[0],
+          val2: temp[1],
+          val3: temp[2],
+          val4: temp[3],
+          val5: temp[4],
+        }
+        this.setData({houseType})
+      }
+      this.setData({
+        imgurlFull: res.data.imgurl ? res.data.prefix + res.data.imgurl : '',
+        imgurl: res.data.imgurl,
+        name: res.data.name || '',
+        nickname: res.data.nickname || '',
+        phone: res.data.phone || '',
+        address: res.data.address || '',
+        latitude: res.data.latitude || '',
+        longitude: res.data.longitude || '',
+        district: res.data.district || '',
+        housearea: res.data.housearea || '',
+        addr: {
+          provinceCode: res.data.provinceCode,
+          provinceName: res.data.provinceName,
+          cityCode: res.data.cityCode,
+          cityName: res.data.cityName,
+          areaCode: res.data.areaCode,
+          areaName: res.data.areaName,
+        }
+
+      })
+    })
+    getArea().then(res => {
+      this.setData({ areaData: res.data })
+    })
+  },
+  positionChange (e) {
+    console.log(e.detail.value)
+    const names = e.detail.value
+    const codes = e.detail.code
+    let addr = {
+      provinceCode: codes[0] + '00',
+      provinceName: names[0],
+      cityCode: codes[1] + '00',
+      cityName: names[1],
+      areaCode: codes[2] + '00',
+      areaName: names[2],
+    }
+    this.setData({ addr })
   },
   bindRegionChange(e) {
     console.log('picker鍙戦�侀�夋嫨鏀瑰彉锛屾惡甯﹀�间负', e.detail.value)
+    const temp = e.detail.value
     this.setData({
       region: e.detail.value
     })
   },
+  changeAddr() {
+    // console.log('鐐瑰嚮浜�');
+    wx.chooseLocation({
+      type: 'wgs84',
+      success: (res) => {
+        this.setData({
+          longitude: res.longitude,
+          latitude: res.latitude,
+          address: res.address,
+        })
+      }
+    })
+  },
+  openHouse() {
+    this.setData({
+      showHouseType: true
+    })
+  },
+  onClose() {
+    this.setData({
+      showHouseType: false
+    })
+  },
+  houseBlur(e) {
+    const {
+      str
+    } = e.currentTarget.dataset
+    const {
+      value
+    } = e.detail
+    const houseType = {
+      ...this.data.houseType
+    }
+    houseType[str] = value
+    this.setData({
+      houseType
+    })
+  },
   selMedia() {
-    console.log('dianjile');
     wx.chooseMedia({
       count: 1,
       mediaType: ['image'],
       sourceType: ['album', 'camera'],
       maxDuration: 16,
       camera: 'back',
-      success(res) {
-        console.log(res.tempFiles[0].tempFilePath)
-        console.log(res.tempFiles[0].size)
+      success: (res) => {
+        // console.log(res.tempFiles[0].tempFilePath)
+        // console.log(res.tempFiles[0].size)
+        wx.uploadFile({
+          url: uploadUrl, //浠呬负绀轰緥锛岄潪鐪熷疄鐨勬帴鍙e湴鍧�
+          filePath: res.tempFiles[0].tempFilePath,
+          name: 'file',
+          formData: {
+            folder: 'member'
+          },
+          header: {
+            token: wx.getStorageSync('token')
+          },
+          success: (ress) => {
+            // console.log('ress', JSON.parse(ress.data));
+            let data = JSON.parse(ress.data)
+            this.setData({
+              imgurl: data.data.imgaddr,
+              imgurlFull: data.data.url,
+            })
+            setTimeout(() => {
+              console.log('imgurlFull', this.data.imgurlFull);
+            }, 1000)
+          }
+        })
       }
     })
   },

--
Gitblit v1.9.3