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