[baozhangchao] преди 3 години
родител
ревизия
289a90dfbf

BIN
src/assets/icons/comm/deletes.png Целия файл


BIN
src/assets/icons/comm/edit.png Целия файл


+ 8
- 10
src/pages/MyAddressList/AddressInfos/index.jsx Целия файл

@@ -2,6 +2,7 @@ import { View, Form, Input, Switch, Textarea } from "@tarojs/components"
2 2
 import Taro from "@tarojs/taro"
3 3
 import CustomNav from "@/components/CustomNav"
4 4
 import ButtontWX from '@/components/ButtontWX'
5
+import { addressSave, getAddress, addressDelete, addressUpdate } from "@/services/address"
5 6
 
6 7
 import './style.less'
7 8
 import { useEffect } from "react"
@@ -13,32 +14,29 @@ export default (props) => {
13 14
   const formSubmit = e => {
14 15
     const value = e.detail.value
15 16
     console.log(value)
17
+    addressSave({ address: value.address, isDefault: value.isDefault }).then((e) => {
18
+      console.log('e', e);
19
+    })
16 20
 
17 21
   }
18 22
 
19 23
   const formReset = e => {
20 24
     console.log(e)
21 25
   }
22
-  const handelSwitch = (e) => {
23
-    const { value } = e.detail
24
-    console.log('e', value);
25 26
 
26
-  }
27 27
   return (
28 28
 
29 29
     <View className='form-content'>
30 30
       <Form onSubmit={formSubmit} onReset={formReset} >
31 31
         <View className='example-body'>
32 32
           <View>详细地址:</View>
33
-          <Textarea name='locastInfo' className='aTextareaCentent' placeholder='请输入地址信息' />
33
+          <Textarea name='address' className='aTextareaCentent' placeholder='请输入地址信息' />
34 34
         </View>
35
-        <View className='example-body'>
35
+        {/* <View className='example-body'>
36 36
           <View>是否设为默认地址:</View>
37
-          {/* <Textarea name='locastInfo' className='aTextareaCentent' placeholder='请输入地址信息' /> */}
38 37
 
39
-
40
-          <Switch name='Switch' onChange={handelSwitch} />
41
-        </View>
38
+          <Switch name='isDefault' onChange={handelSwitch} type='checkbox' />
39
+        </View> */}
42 40
         <View className='buton-bottom'>
43 41
           <ButtontWX onClick={formSubmit} formType='submit' butText='保存' butWidth={315} butHeight={49} butFontSize={16} butBorderRadius={49} />
44 42
         </View>

+ 100
- 5
src/pages/MyAddressList/index.jsx Целия файл

@@ -1,30 +1,125 @@
1
-import { View, Form, Input, Button, Textarea } from "@tarojs/components"
1
+import { View, Image, Switch, Button, Textarea } from "@tarojs/components"
2 2
 import Taro from "@tarojs/taro"
3
+import { useState } from "react"
3 4
 import CustomNav from "@/components/CustomNav"
5
+import edit from "@/assets/icons/comm/edit.png"
6
+import userRight from '@/assets/mineImgaes/userRight.png'
7
+
8
+import deletes from "@/assets/icons/comm/deletes.png"
4 9
 import ButtontWX from '@/components/ButtontWX'
5 10
 import { useEffect } from "react"
6 11
 
7
-import './style.less'
12
+import { addressDefault, getAddress, addressDelete, addressUpdate } from "@/services/address"
8 13
 
14
+import './style.less'
9 15
 
10 16
 
11 17
 
12 18
 export default (props) => {
19
+  const [addresList, setAddresList] = useState([])
13 20
 
14 21
   const addAddress = () => {
15 22
     Taro.navigateTo({ url: `/pages/MyAddressList/AddressInfos/index?id=${1}` })
16 23
   }
17 24
 
25
+  const addressDeletess = (e) => {
26
+    Taro.showModal({
27
+      title: '提示',
28
+      content: '您确定要删除此地址吗',
29
+      success: function (res) {
30
+        if (res.confirm) {
31
+          addressDelete(e).then((e) => {
32
+
33
+          })
34
+        } else if (res.cancel) {
35
+          console.log('用户点击取消')
36
+        }
37
+      }
38
+    })
39
+
40
+  }
41
+
42
+  const handelSwitch = (e) => {
43
+    const { value } = e.detail
44
+    console.log('e', value);
45
+
46
+  }
47
+  const addressEdit = (e) => {
48
+    console.log('e', e);
49
+
50
+  }
51
+
52
+
53
+  const getList = () => {
54
+    // getAddress().then((e) => {
55
+    //   console.log('地址列表', e);
56
+    //   setAddresList(e.records)
57
+
58
+
59
+    // })
60
+  }
61
+
18 62
   useEffect(() => {
63
+    // getList()
64
+    getAddress().then((e) => {
65
+      console.log('地址列表', e);
66
+      setAddresList(e.records)
67
+
68
+
69
+    })
70
+  }, [])
71
+
72
+
19 73
 
20
-  })
21 74
   return (
22 75
     <View className='page-index'>
23 76
       <View className='index-navbar'>
24
-        <CustomNav title='我的地址' />
77
+        <CustomNav title='地址管理' />
25 78
       </View>
26 79
       <scroll-view scrollY style='height: 100%;' >
27
-        <ButtontWX onClick={addAddress} formType='submit' butText='+新增收货地址' butWidth={315} butHeight={49} butFontSize={16} butBorderRadius={49} />
80
+        <View>
81
+          {
82
+
83
+            addresList.map((item, index) => {
84
+              return (
85
+                <View className='addressList-box' key={index}>
86
+                  <View className='addressList-box-addressTop'>
87
+                    <View className='addressList-box-addressTop-redText'>默认地址</View>
88
+                    <View className='addressList-box-addressTop-title'>我的地址{index + 1}</View>
89
+                  </View>
90
+                  <View className='addressList-box-addressBotton'>
91
+                    <View className='addressList-box-addressBotton-editTextImage'>
92
+                      <View>
93
+                        {item.address}
94
+                      </View>
95
+                      <Image src={edit} onClick={() => addressEdit(item.addressId)} />
96
+                    </View>
97
+
98
+                    <View className='addressList-box-addressBotton-setAddress'>
99
+                      <View>
100
+                        设为默认地址: <Switch name='isDefault' onChange={handelSwitch} type='checkbox' />
101
+                      </View>
102
+
103
+                      <View className='addressList-box-addressBotton-addressDelete' onClick={() => addressDeletess(item.addressId)}>
104
+                        <View>
105
+                          删除
106
+                        </View>
107
+                        <Image src={deletes} />
108
+
109
+                      </View>
110
+                    </View>
111
+                  </View>
112
+                </View>
113
+              )
114
+            })
115
+          }
116
+
117
+          <View className='bottomButtom' >
118
+            <ButtontWX onClick={addAddress} formType='submit' butText='+新增收货地址' butWidth={315} butHeight={49} butFontSize={16} butBorderRadius={49} />
119
+
120
+          </View>
121
+
122
+        </View>
28 123
       </scroll-view>
29 124
     </View >
30 125
   )

+ 70
- 0
src/pages/MyAddressList/style.less Целия файл

@@ -0,0 +1,70 @@
1
+.addressList-box {
2
+  // border-bottom: 1px solid rgba(0, 0, 0, 0.2);
3
+  box-shadow: 0px 10px 24px 0px rgba(0, 0, 0, 0.1);
4
+  padding: 1em 30px;
5
+  border-radius: 20px;
6
+  width: 87%;
7
+  margin: 40px auto;
8
+  &-addressTop {
9
+    display: flex;
10
+    align-items: center;
11
+    &-redText {
12
+      margin-right: 10px;
13
+      border-radius: 10px;
14
+      padding: 2px 10px;
15
+      background-color: red;
16
+      color: #fff;
17
+      font-size: 30px;
18
+    }
19
+    &-title {
20
+      font-size: 30px;
21
+      font-weight: 700;
22
+    }
23
+  }
24
+  &-addressBotton {
25
+    &-editTextImage {
26
+      padding: 10px 0;
27
+      display: flex;
28
+      justify-content: space-between;
29
+      align-items: center;
30
+
31
+      > View {
32
+        color: #666;
33
+        font-size: 30px;
34
+        overflow: hidden;
35
+        text-overflow: ellipsis;
36
+        display: -webkit-box;
37
+        -webkit-line-clamp: 2; // 控制多行的行数
38
+        -webkit-box-orient: vertical;
39
+        width: 77vw;
40
+      }
41
+      > Image {
42
+        width: 70px;
43
+        height: 65px;
44
+      }
45
+    }
46
+    &-setAddress {
47
+      border-top: 1px solid rgba(0, 0, 0, 0.2);
48
+      padding: 0.5em 0;
49
+      display: flex;
50
+      justify-content: space-between;
51
+      align-items: center;
52
+    }
53
+    &-addressDelete {
54
+      display: flex;
55
+      align-items: center;
56
+      > Image {
57
+        width: 50px;
58
+        height: 50px;
59
+      }
60
+    }
61
+  }
62
+}
63
+
64
+.bottomButtom {
65
+  width: 100%;
66
+  margin: 0 auto;
67
+  position: absolute;
68
+  bottom: -29vh;
69
+  margin: 15vh 0;
70
+}

+ 10
- 0
src/pages/userInfo/index.config.js Целия файл

@@ -0,0 +1,10 @@
1
+
2
+export default {
3
+  navigationBarTitleText: '个人信息',
4
+  navigationStyle: 'custom',
5
+  disableScroll: true,
6
+  usingComponents: {
7
+  }
8
+
9
+
10
+}

+ 108
- 0
src/pages/userInfo/index.jsx Целия файл

@@ -0,0 +1,108 @@
1
+import { useState } from "react"
2
+import { useModel } from '@/store'
3
+import Taro from "@tarojs/taro"
4
+import { Input, View, Image } from "@tarojs/components"
5
+import CustomNav from '@/components/CustomNav'
6
+import ButtontWX from '@/components/ButtontWX'
7
+import { updateInfo } from "@/services/login"
8
+// import banner1 from '@/assets/banner/1.jpg'
9
+// import resetImg from '@/assets/user/cancel.png'
10
+import './style.less'
11
+
12
+export default (props) => {
13
+
14
+  const { person, setPerson } = useModel('userData')
15
+
16
+  const [name, setName] = useState(person.nickName)
17
+  const [phone, setPhone] = useState(person.phone)
18
+  const [avatar, setAvatar] = useState(person.avatar)
19
+  const changeName = (e) => {
20
+    setName(e.detail.value)
21
+  }
22
+  const changePhone = (e) => {
23
+    setPhone(e.detail.value)
24
+  }
25
+  const rulePhone = (val) => {
26
+    if (!/^1[0-9]{10}$/.test(val)) {
27
+      Taro.showToast({
28
+        title: '请输入正确的11位手机号',
29
+        icon: 'none',
30
+        duration: 2000
31
+      })
32
+      return false
33
+    } else return true
34
+  }
35
+  const handleSave = () => {
36
+    if (rulePhone(phone)) {
37
+      updateInfo(person.personId, { ...person, avatar: avatar, phone: phone, nickName: name }).then((res) => {
38
+        setPerson(res)
39
+        Taro.showToast({
40
+          title: '保存成功',
41
+          icon: 'none',
42
+        })
43
+        Taro.navigateBack({ delta: 1 })
44
+      }).catch((e) => {
45
+        console.log(e)
46
+        Taro.showToast({
47
+          title: '网络异常, 请刷新小程序重试',
48
+          icon: 'none',
49
+        })
50
+      })
51
+    }
52
+  }
53
+  const resetName = () => {
54
+    setName()
55
+  }
56
+  const resetPhone = () => {
57
+    setPhone()
58
+  }
59
+  const changeAvatar = () => {
60
+    Taro.getUserProfile({
61
+      lang: 'zh_CN',
62
+      desc: "获取你的昵称、头像、地区及性别",
63
+      success: function (res) {
64
+        setAvatar(res.userInfo.avatarUrl)
65
+      },
66
+      fail: () => {
67
+        //拒绝授权
68
+        console.error("拒绝了请求");
69
+        return;
70
+      }
71
+    })
72
+  }
73
+  return (
74
+    <View className='page-index'>
75
+      <View className='index-navbar'>
76
+        <CustomNav title='个人信息' />
77
+      </View>
78
+      <View className='index-container userCard'>
79
+        <View className='avatar' onClick={changeAvatar}>
80
+          <Image src={avatar} className='avatarImg' />
81
+          <View className='change'>更换头像</View>
82
+        </View>
83
+        <View className='userCell'>
84
+          <View>姓名:</View>
85
+          <View style={{ display: 'flex', alignItems: 'center', height: '54px' }}>
86
+            <Input type='text' placeholder='请输入您的姓名' value={name} onBlur={changeName} className='userName' />
87
+            <View className='reset' onClick={resetName}>
88
+              {/* <Image src={resetImg} className='close' /> */}
89
+            </View>
90
+          </View>
91
+        </View>
92
+        <View className='userCell'>
93
+          <View>手机号:</View>
94
+          <View style={{ display: 'flex', alignItems: 'center', height: '54px' }}>
95
+            <Input type='text' placeholder='请输入您的手机号' value={phone} onBlur={changePhone} className='userName' />
96
+            <View className='reset' onClick={resetPhone}>
97
+              {/* <Image src={resetImg} className='close' /> */}
98
+            </View>
99
+          </View>
100
+        </View>
101
+        <View className='bottomBtn'>
102
+          <ButtontWX onClick={handleSave} butText='保存' butWidth={300} butHeight={49} butFontSize={16} butBorderRadius={49} />
103
+
104
+        </View>
105
+      </View>
106
+    </View>
107
+  )
108
+}

+ 54
- 0
src/pages/userInfo/style.less Целия файл

@@ -0,0 +1,54 @@
1
+.userCard {
2
+  margin: 30px;
3
+  .avatar {
4
+    height: 184px;
5
+    background: #fff;
6
+    box-shadow: 0px 2px 0px 0px rgba(0, 0, 0, 0.12);
7
+    display: flex;
8
+    align-items: center;
9
+    .avatarImg {
10
+      width: 124px;
11
+      height: 124px;
12
+      background: #f2f2f2;
13
+      border: 4px solid #ffffff;
14
+      border-radius: 50%;
15
+    }
16
+    .change {
17
+      font-size: 34px;
18
+      font-weight: 500;
19
+      color: #333333;
20
+      position: absolute;
21
+      right: 0;
22
+    }
23
+  }
24
+  .userCell {
25
+    background: #fff;
26
+    box-shadow: 0px 2px 0px 0px rgba(0, 0, 0, 0.12);
27
+    font-size: 34px;
28
+    font-weight: bold;
29
+    color: #333333;
30
+    margin-top: 80px;
31
+    .userName {
32
+      height: 108px;
33
+      flex: 1;
34
+    }
35
+    .reset {
36
+      flex: none;
37
+      width: 100px;
38
+      height: 100%;
39
+      display: flex;
40
+      align-items: center;
41
+      .close {
42
+        width: 36px;
43
+        height: 36px;
44
+        margin: auto;
45
+      }
46
+    }
47
+  }
48
+  .bottomBtn {
49
+    margin-bottom: 12px;
50
+    position: absolute;
51
+    bottom: 0;
52
+    width: 100%;
53
+  }
54
+}

+ 4
- 0
src/routes.js Целия файл

@@ -18,6 +18,10 @@ const Pages = [
18 18
     title: '我的地址列表',
19 19
     page: 'pages/MyAddressList/index',
20 20
   },
21
+  {
22
+    title: '个人信息',
23
+    page: 'pages/userInfo/index',
24
+  },
21 25
   {
22 26
     title: '我的详细地址',
23 27
     page: 'pages/MyAddressList/AddressInfos/index',

+ 36
- 2
src/services/address.js Целия файл

@@ -4,8 +4,42 @@ import request from '@/utils/request'
4 4
 
5 5
 
6 6
 /**
7
- * banner轮播图
7
+ * 地址保存
8 8
  * @param {*} data 
9 9
  * @returns 
10 10
  */
11
-export const getHomeBanner = (data) => request(`/banner`, { data, method: 'get' })
11
+export const addressSave = (data) => request(`/address`, { data, method: 'POST' })
12
+
13
+
14
+/**
15
+ * 地址列表
16
+ * @param {*} data 
17
+ * @returns 
18
+ */
19
+export const getAddress = (data) => request(`/address`, { data, method: 'GET' })
20
+
21
+
22
+/**
23
+* 地址删除
24
+* @param {*} data 
25
+* @returns 
26
+*/
27
+export const addressDelete = (id, data) => request(`/address/${id}`, { data, method: 'DELETE' })
28
+
29
+
30
+/**
31
+ * 地址修改更新
32
+ * @param {*} data 
33
+ * @returns 
34
+ */
35
+export const addressUpdate = (id, data) => request(`/address/${id}`, { data, method: 'PUT' })
36
+
37
+
38
+/**
39
+ * 地址是否默认
40
+ * @param {*} data 
41
+ * @returns 
42
+ */
43
+export const addressDefault = (id, data) => request(`/address${id}/default`, { data, method: 'PUT' })
44
+
45
+

+ 10
- 1
src/services/login.js Целия файл

@@ -14,9 +14,18 @@ export const login = (data) => request('/login', { data, method: 'post' })
14 14
 export const getUserQcode = (params) => request('/sms-captcha', { method: 'post', params })
15 15
 
16 16
 /**
17
-* 验证码登陆
17
+* 验证码登陆修改
18 18
 * @param {*} 
19 19
 * @returns 
20 20
 */
21 21
 
22 22
 export const setUserPhone = (id, data) => request(`/person/${id}/phone`, { method: 'put', data })
23
+
24
+
25
+/**
26
+ * 修改个人信息
27
+ * @param {*} 
28
+ * @returns 
29
+ */
30
+
31
+export const updateInfo = (id, data) => request(`/person/${id}`, { method: 'put', data })