鲍张超 3 年之前
父節點
當前提交
073cef6a7a
共有 3 個檔案被更改,包括 69 行新增22 行删除
  1. 33
    18
      src/pages/MyAddressList/index.jsx
  2. 35
    3
      src/pages/MyAddressList/style.less
  3. 1
    1
      src/services/address.js

+ 33
- 18
src/pages/MyAddressList/index.jsx 查看文件

@@ -1,13 +1,13 @@
1
-import { View, Image, Switch, Button, Textarea } from "@tarojs/components"
1
+import { View, Image, Switch, Radio, RadioGroup } from "@tarojs/components"
2 2
 import Taro from "@tarojs/taro"
3
-import { useState } from "react"
3
+import { useState, useEffect } from "react"
4 4
 import CustomNav from "@/components/CustomNav"
5 5
 import edit from "@/assets/icons/comm/edit.png"
6 6
 import userRight from '@/assets/mineImgaes/userRight.png'
7 7
 
8 8
 import deletes from "@/assets/icons/comm/deletes.png"
9 9
 import ButtontWX from '@/components/ButtontWX'
10
-import { useEffect } from "react"
10
+
11 11
 
12 12
 import { addressDefault, getAddress, addressDelete, addressUpdate } from "@/services/address"
13 13
 
@@ -38,10 +38,23 @@ export default (props) => {
38 38
     })
39 39
 
40 40
   }
41
+  const [switchBool, setSwitchBool] = useState()
42
+  // const [switchValue, setSwitchValue] = useState('')
41 43
 
42
-  const handelSwitch = (e) => {
44
+  const handelSwitch = (a, e) => {
43 45
     const { value } = e.detail
44
-    console.log('e', value);
46
+    // console.log('e', !!value);
47
+    console.log('a,e', a, value);
48
+    addressDefault(a).then((se) => {
49
+      console.log('e', se);
50
+      getList()
51
+    })
52
+    // if (value == '') {
53
+    //   setSwitchBool(!!value)
54
+
55
+    // } else {
56
+    //   setSwitchBool(!value)
57
+    // }
45 58
 
46 59
   }
47 60
   const addressEdit = (e) => {
@@ -51,23 +64,18 @@ export default (props) => {
51 64
 
52 65
 
53 66
   const getList = () => {
54
-    // getAddress().then((e) => {
55
-    //   console.log('地址列表', e);
56
-    //   setAddresList(e.records)
57
-
58
-
59
-    // })
60
-  }
61
-
62
-  useEffect(() => {
63
-    // getList()
64 67
     getAddress().then((e) => {
65 68
       console.log('地址列表', e);
66 69
       setAddresList(e.records)
70
+    })
71
+  }
72
+
73
+  useEffect(() => {
74
+    getList()
67 75
 
68 76
 
69
-    })
70
-  }, [])
77
+    console.log('执行了', switchBool,);
78
+  }, [switchBool,])
71 79
 
72 80
 
73 81
 
@@ -97,7 +105,14 @@ export default (props) => {
97 105
 
98 106
                     <View className='addressList-box-addressBotton-setAddress'>
99 107
                       <View>
100
-                        设为默认地址: <Switch name='isDefault' onChange={handelSwitch} type='checkbox' />
108
+
109
+                        设为默认地址:
110
+
111
+                        <RadioGroup className='radio-group' onChange={(res) => handelSwitch(item.addressId, res)} >
112
+                          <Radio color='#FC5531' checked={item.isDefault}></Radio>
113
+                        </RadioGroup>
114
+
115
+
101 116
                       </View>
102 117
 
103 118
                       <View className='addressList-box-addressBotton-addressDelete' onClick={() => addressDeletess(item.addressId)}>

+ 35
- 3
src/pages/MyAddressList/style.less 查看文件

@@ -49,6 +49,40 @@
49 49
       display: flex;
50 50
       justify-content: space-between;
51 51
       align-items: center;
52
+      > View {
53
+        font-size: 30px;
54
+
55
+        .radio-group {
56
+          display: inline-block;
57
+
58
+          .wx-radio-input {
59
+            position: relative;
60
+            display: flex;
61
+            left: 2vw;
62
+            height: 40rpx;
63
+            width: 40rpx;
64
+            margin-top: -4rpx;
65
+            border-radius: 50%;
66
+            border: 2rpx solid #999;
67
+            background: transparent;
68
+          }
69
+        }
70
+
71
+        // .wx-radio-input.wx-radio-input-checked::before {
72
+        //   /* 去除对号 */
73
+        //   content: "";
74
+        //   /* background: #fff; */
75
+        //   width: 40rpx;
76
+        //   height: 40rpx;
77
+        //   border-radius: 50%;
78
+        //   /* background: red; */
79
+        //   background-color: rgb(216, 216, 216);
80
+        //   /* 居中 */
81
+        //   margin-top: 0rpx;
82
+        //   display: flex;
83
+        //   position: relative;
84
+        // }
85
+      }
52 86
     }
53 87
     &-addressDelete {
54 88
       display: flex;
@@ -64,7 +98,5 @@
64 98
 .bottomButtom {
65 99
   width: 100%;
66 100
   margin: 0 auto;
67
-  position: absolute;
68
-  bottom: -29vh;
69
-  margin: 15vh 0;
101
+  margin-bottom: 15vh;
70 102
 }

+ 1
- 1
src/services/address.js 查看文件

@@ -40,6 +40,6 @@ export const addressUpdate = (id, data) => request(`/address/${id}`, { data, met
40 40
  * @param {*} data 
41 41
  * @returns 
42 42
  */
43
-export const addressDefault = (id, data) => request(`/address${id}/default`, { data, method: 'PUT' })
43
+export const addressDefault = (id, data) => request(`/address/${id}/default`, { data, method: 'PUT' })
44 44
 
45 45