index.jsx 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 withLayout from '@/layouts'
  8. import deletes from "@/assets/icons/comm/deletes.png"
  9. import ButtontWX from '@/components/ButtontWX'
  10. import { useModel } from "@/store"
  11. import { addressDefault, getAddress, addressDelete, addressUpdate } from "@/services/address"
  12. import './style.less'
  13. export default withLayout((props) => {
  14. const [addresList, setAddresList] = useState([])
  15. const $instance = Taro.getCurrentInstance()
  16. const { orderAddress } = $instance.router.params
  17. const { setUserOrderAddress, userOrderAddress } = useModel('userData')
  18. const addAddress = () => {
  19. Taro.navigateTo({ url: `/pages/MyAddressList/AddressInfos/index?id=${1}` })
  20. }
  21. const addressDeletess = (e) => {
  22. Taro.showModal({
  23. title: '提示',
  24. content: '您确定要删除此地址吗',
  25. success: function (res) {
  26. if (res.confirm) {
  27. addressDelete(e).then((e) => {
  28. Taro.showToast({
  29. title: '地址删除成功',
  30. icon: 'success',
  31. duration: 2000
  32. })
  33. getList()
  34. })
  35. } else if (res.cancel) {
  36. console.log('用户点击取消')
  37. }
  38. }
  39. })
  40. }
  41. const [switchBool, setSwitchBool] = useState()
  42. // const [switchValue, setSwitchValue] = useState('')
  43. const handelSwitch = (a, e) => {
  44. const { value } = e.detail
  45. addressDefault(a).then((se) => {
  46. console.log('e', se);
  47. getList()
  48. })
  49. // if (value == '') {
  50. // setSwitchBool(!!value)
  51. // } else {
  52. // setSwitchBool(!value)
  53. // }
  54. }
  55. const addressEdit = (e, res) => {
  56. console.log('e', e);
  57. Taro.navigateTo({ url: `/pages/MyAddressList/AddressInfos/index?addressId=${e}&address=${res}` })
  58. }
  59. const getList = () => {
  60. getAddress().then((e) => {
  61. console.log('地址列表', e);
  62. // let abccList = e.records.sort((a, b) => b.isDefault - a.isDefault)
  63. // console.log("🚀 ~ file: index.jsx ~ line 75 ~ getAddress ~ abccList", abccList)
  64. setAddresList(e.records)
  65. })
  66. }
  67. useDidShow(() => {
  68. getList()
  69. })
  70. useEffect(() => {
  71. getList()
  72. }, [])
  73. const srcor = (e) => {
  74. console.log('评分', e.detail);
  75. }
  76. const handleAddress = (e) => {
  77. if (e) {
  78. setUserOrderAddress(e)
  79. Taro.showToast({
  80. title: '选择成功',
  81. icon: 'success',
  82. duration: 2000
  83. }).then(() => {
  84. setTimeout(() => {
  85. Taro.navigateBack({
  86. delta: 1
  87. })
  88. setInterval()
  89. }, 300)
  90. })
  91. console.log('选择的地址存放在store', userOrderAddress);
  92. }
  93. }
  94. return (
  95. <View className='page-index'>
  96. <View className='index-navbar'>
  97. <CustomNav title='地址管理' />
  98. </View>
  99. <scroll-view scrollY style='height: 100%;' >
  100. <View>
  101. {/* <mp-orderRater raterChange={srcor} initW='50%' /> */}
  102. {
  103. addresList.map((item, index) => {
  104. return (
  105. <View className='addressList-box' key={index}>
  106. <View className='addressList-box-addressTop'>
  107. {
  108. item.isDefault ?
  109. <View className='addressList-box-addressTop-redText'>默认地址</View> : ''
  110. }
  111. <View className='addressList-box-addressTop-title'>我的地址{index + 1}</View>
  112. </View>
  113. <View className='addressList-box-addressBotton'>
  114. <View className='addressList-box-addressBotton-editTextImage'>
  115. <View>
  116. {item.address}
  117. </View>
  118. <Image src={edit} onClick={() => addressEdit(item.addressId, item.address)} />
  119. </View>
  120. <View className='addressList-box-addressBotton-setAddress'>
  121. {
  122. orderAddress ? <>
  123. <View>
  124. 设为默认地址:
  125. <RadioGroup className='radio-group' onChange={(res) => handelSwitch(item.addressId, res)} >
  126. <Radio color='#FC5531' checked={item.isDefault}></Radio>
  127. </RadioGroup>
  128. </View>
  129. <View className='addressList-box-addressBotton-addressDelete' onClick={() => addressDeletess(item.addressId)}>
  130. <View>
  131. 删除
  132. </View>
  133. <Image src={deletes} />
  134. </View>
  135. </>
  136. : <View className='orderAddressa' onClick={() => handleAddress(item.address)}>
  137. 选择此地址
  138. </View>
  139. }
  140. </View>
  141. </View>
  142. </View>
  143. )
  144. })
  145. }
  146. <View className='bottomButtom' >
  147. <ButtontWX onClick={addAddress} formType='submit' butText='+新增收货地址' butWidth={315} butHeight={49} butFontSize={16} butBorderRadius={49} />
  148. </View>
  149. </View>
  150. </scroll-view>
  151. </View >
  152. )
  153. })