index.jsx 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 { type } = $instance.router.params
  17. console.log("🚀 ~ file: index.jsx ~ line 23 ~ withLayout ~ orderAddress", type)
  18. const { setUserOrderAddress, userOrderAddress } = useModel('userData')
  19. const addAddress = () => {
  20. Taro.navigateTo({ url: `/pages/MyAddressList/AddressInfos/index` })
  21. }
  22. const addressDeletess = (e) => {
  23. Taro.showModal({
  24. title: '提示',
  25. content: '您确定要删除此地址吗',
  26. success: function (res) {
  27. if (res.confirm) {
  28. addressDelete(e).then((e) => {
  29. Taro.showToast({
  30. title: '地址删除成功',
  31. icon: 'success',
  32. duration: 2000
  33. })
  34. getList()
  35. })
  36. } else if (res.cancel) {
  37. console.log('用户点击取消')
  38. }
  39. }
  40. })
  41. }
  42. const [switchBool, setSwitchBool] = useState()
  43. // const [switchValue, setSwitchValue] = useState('')
  44. const handelSwitch = (a, e) => {
  45. const { value } = e.detail
  46. addressDefault(a).then((se) => {
  47. console.log('e', se);
  48. getList()
  49. })
  50. // if (value == '') {
  51. // setSwitchBool(!!value)
  52. // } else {
  53. // setSwitchBool(!value)
  54. // }
  55. }
  56. const addressEdit = (e, res) => {
  57. console.log('e', e);
  58. Taro.navigateTo({ url: `/pages/MyAddressList/AddressInfos/index?addressId=${e}&address=${res}` })
  59. }
  60. const getList = () => {
  61. getAddress().then((e) => {
  62. console.log('地址列表', e);
  63. // let abccList = e.records.sort((a, b) => b.isDefault - a.isDefault)
  64. // console.log("🚀 ~ file: index.jsx ~ line 75 ~ getAddress ~ abccList", abccList)
  65. setAddresList(e.records)
  66. })
  67. }
  68. useDidShow(() => {
  69. getList()
  70. })
  71. useEffect(() => {
  72. getList()
  73. }, [])
  74. const srcor = (e) => {
  75. console.log('评分', e.detail);
  76. }
  77. const handleAddress = (e) => {
  78. if (e) {
  79. setUserOrderAddress(e)
  80. Taro.showToast({
  81. title: '选择成功',
  82. icon: 'success',
  83. duration: 2000
  84. }).then(() => {
  85. setTimeout(() => {
  86. Taro.navigateBack({
  87. delta: 1
  88. })
  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. !type ? <>
  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. })