鲍张超 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
-import { View, Image, Switch, Button, Textarea } from "@tarojs/components"
1
+import { View, Image, Switch, Radio, RadioGroup } from "@tarojs/components"
2
 import Taro from "@tarojs/taro"
2
 import Taro from "@tarojs/taro"
3
-import { useState } from "react"
3
+import { useState, useEffect } from "react"
4
 import CustomNav from "@/components/CustomNav"
4
 import CustomNav from "@/components/CustomNav"
5
 import edit from "@/assets/icons/comm/edit.png"
5
 import edit from "@/assets/icons/comm/edit.png"
6
 import userRight from '@/assets/mineImgaes/userRight.png'
6
 import userRight from '@/assets/mineImgaes/userRight.png'
7
 
7
 
8
 import deletes from "@/assets/icons/comm/deletes.png"
8
 import deletes from "@/assets/icons/comm/deletes.png"
9
 import ButtontWX from '@/components/ButtontWX'
9
 import ButtontWX from '@/components/ButtontWX'
10
-import { useEffect } from "react"
10
+
11
 
11
 
12
 import { addressDefault, getAddress, addressDelete, addressUpdate } from "@/services/address"
12
 import { addressDefault, getAddress, addressDelete, addressUpdate } from "@/services/address"
13
 
13
 
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
     const { value } = e.detail
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
   const addressEdit = (e) => {
60
   const addressEdit = (e) => {
51
 
64
 
52
 
65
 
53
   const getList = () => {
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
     getAddress().then((e) => {
67
     getAddress().then((e) => {
65
       console.log('地址列表', e);
68
       console.log('地址列表', e);
66
       setAddresList(e.records)
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
 
105
 
98
                     <View className='addressList-box-addressBotton-setAddress'>
106
                     <View className='addressList-box-addressBotton-setAddress'>
99
                       <View>
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
                       </View>
116
                       </View>
102
 
117
 
103
                       <View className='addressList-box-addressBotton-addressDelete' onClick={() => addressDeletess(item.addressId)}>
118
                       <View className='addressList-box-addressBotton-addressDelete' onClick={() => addressDeletess(item.addressId)}>

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

49
       display: flex;
49
       display: flex;
50
       justify-content: space-between;
50
       justify-content: space-between;
51
       align-items: center;
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
     &-addressDelete {
87
     &-addressDelete {
54
       display: flex;
88
       display: flex;
64
 .bottomButtom {
98
 .bottomButtom {
65
   width: 100%;
99
   width: 100%;
66
   margin: 0 auto;
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
  * @param {*} data 
40
  * @param {*} data 
41
  * @returns 
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