adresss.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <view class="box">
  3. <view class="address-list">
  4. <up-radio-group v-model="radioValue" @change="handleChane">
  5. <view
  6. v-for="(item, index) in dataList"
  7. :key="index"
  8. class="address-item"
  9. >
  10. <!-- 左侧单选框 -->
  11. <view class="radio-group">
  12. <up-radio
  13. shape="circle"
  14. activeColor="red"
  15. :name="item.addressId"
  16. ></up-radio>
  17. </view>
  18. <!-- 中间内容区(自动伸缩) -->
  19. <view class="content-wrapper">
  20. <view class="address-line">
  21. <text class="address-text">
  22. {{ item.provinceName }}{{ item.cityName
  23. }}{{ item.districtName }}
  24. </text>
  25. </view>
  26. <view class="contact-info">
  27. <text class="name">{{ item.name }}</text>
  28. <text class="phone">{{ item.telephone }}</text>
  29. </view>
  30. </view>
  31. <!-- 右侧编辑图标(固定宽度) -->
  32. <view class="edit-icon" @click="hadlClickTo(item)">
  33. <up-icon name="edit-pen" size="16"></up-icon>
  34. </view>
  35. <view @click="hadlClickEdit(item)">
  36. <up-icon name="trash" size="16"></up-icon>
  37. </view>
  38. </view>
  39. </up-radio-group>
  40. </view>
  41. <!-- 底部新增按钮 -->
  42. <view class="add-bottom-btn" @click="handlHeader">
  43. <view class="add-bottom-btn-inner">
  44. <text class="plus">+</text>
  45. <text>新增收货地址</text>
  46. </view>
  47. </view>
  48. </view>
  49. </template>
  50. <script setup>
  51. import { ref, onMounted } from 'vue'
  52. import {
  53. onShow,
  54. onBackPress
  55. } from "@dcloudio/uni-app";
  56. import { addressList, addressAddressIds } from '@/api/userSettings.js'
  57. const radioValue = ref(null)
  58. const dataList = ref([])
  59. const total = ref(0)
  60. // 处理系统返回按钮事件,直接返回到商品详情页
  61. onBackPress(() => {
  62. uni.navigateTo({
  63. url: '/pages_home/pages/Volunteerside/goodsDetails'
  64. })
  65. return true // 返回true表示自己处理返回逻辑
  66. })
  67. const handlHeader = () => {
  68. uni.navigateTo({
  69. url: `/pages_home/pages/setupUser/Address`,
  70. })
  71. }
  72. const props = defineProps({
  73. modelValue: {
  74. type: Boolean,
  75. default: false,
  76. },
  77. addressInfo: {
  78. type: Object,
  79. default: () => {},
  80. },
  81. })
  82. const hadlClickEdit = async (item) => {
  83. try {
  84. const res = await addressAddressIds(item.addressId) // 使用 addressId
  85. if (res.code == 200) {
  86. uni.showToast({
  87. title: '删除成功',
  88. icon: 'success',
  89. })
  90. }
  91. await getListData()
  92. } catch (error) {
  93. console.error('删除失败', error)
  94. uni.showToast({
  95. title: '删除失败',
  96. icon: 'error',
  97. })
  98. }
  99. }
  100. const emits = defineEmits(['update:modelValue', 'update:addressInfo'])
  101. function handleChane(addressId, item) {
  102. const selectedItem = dataList.value.find(
  103. (item) => item.addressId === addressId
  104. )
  105. emits('update:modelValue', false)
  106. emits('update:addressInfo', selectedItem)
  107. }
  108. const hadlClickTo = (item) => {
  109. console.log(item)
  110. const {
  111. address,
  112. addressId,
  113. age,
  114. cityName,
  115. districtName,
  116. label,
  117. name,
  118. provinceName,
  119. sex,
  120. telephone,
  121. cityCode,
  122. districtCode,
  123. provinceCode,
  124. detailAddress
  125. } = item
  126. const params = `address=${encodeURIComponent(
  127. address
  128. )}&addressId=${encodeURIComponent(addressId)}&age=${encodeURIComponent(
  129. age
  130. )}&cityName=${encodeURIComponent(cityName)}&districtName=${encodeURIComponent(
  131. districtName
  132. )}&label=${encodeURIComponent(label)}&name=${encodeURIComponent(
  133. name
  134. )}&provinceName=${encodeURIComponent(provinceName)}&sex=${encodeURIComponent(
  135. sex
  136. )}&telephone=${encodeURIComponent(telephone)}&cityCode=${encodeURIComponent(
  137. cityCode
  138. )}&districtCode=${encodeURIComponent(
  139. districtCode
  140. )}&provinceCode=${encodeURIComponent(provinceCode)}&detailAddress=${encodeURIComponent(detailAddress)}`
  141. // 使用拼接的查询参数进行页面跳转
  142. uni.navigateTo({
  143. url: `/pages_home/pages/selectAddress/edit?${params}`,
  144. })
  145. }
  146. const getListData = async () => {
  147. const res = await addressList()
  148. dataList.value = res.rows
  149. total.value = res.total
  150. }
  151. onShow(() => {
  152. getListData()
  153. })
  154. onMounted(() => {
  155. getListData()
  156. })
  157. </script>
  158. <style lang="scss">
  159. .box {
  160. height: 100vh;
  161. width: 100vw;
  162. position: fixed;
  163. top: 0;
  164. left: 0;
  165. z-index: 999999;
  166. background: #f0f0f0;
  167. display: flex;
  168. flex-direction: column;
  169. }
  170. .address-list {
  171. flex: 1;
  172. overflow-y: auto;
  173. padding: 0 0 120rpx 0;
  174. }
  175. .footer {
  176. position: fixed;
  177. left: 0;
  178. right: 0;
  179. bottom: 0;
  180. background: transparent;
  181. display: flex;
  182. justify-content: center;
  183. align-items: center;
  184. padding-bottom: env(safe-area-inset-bottom);
  185. z-index: 1000;
  186. }
  187. .add-item {
  188. display: flex;
  189. align-items: center;
  190. justify-content: center;
  191. gap: 10rpx;
  192. background: #fff;
  193. border-radius: 40rpx;
  194. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.06);
  195. padding: 0 40rpx;
  196. height: 80rpx;
  197. margin: 20rpx 0 30rpx 0;
  198. font-size: 30rpx;
  199. color: #222;
  200. font-weight: 500;
  201. }
  202. .add-item text {
  203. font-size: 30rpx;
  204. color: #222;
  205. }
  206. .address-item {
  207. display: flex;
  208. align-items: flex-start;
  209. padding: 24rpx 0;
  210. border-bottom: 1rpx solid #f0f0f0;
  211. background: transparent;
  212. }
  213. .radio-group {
  214. flex-shrink: 0;
  215. /* 禁止压缩 */
  216. margin-right: 20rpx;
  217. }
  218. .content-wrapper {
  219. flex: 1;
  220. min-width: 0;
  221. }
  222. .edit-icon {
  223. flex-shrink: 0;
  224. margin-left: 330rpx;
  225. padding: 8rpx;
  226. }
  227. .address-text {
  228. display: inline-block;
  229. max-width: 100%;
  230. font-size: 32rpx;
  231. font-weight: 500;
  232. white-space: nowrap;
  233. overflow: hidden;
  234. text-overflow: ellipsis;
  235. }
  236. .contact-info {
  237. display: flex;
  238. gap: 20rpx;
  239. margin-top: 8rpx;
  240. }
  241. .name,
  242. .phone {
  243. font-size: 28rpx;
  244. color: #666;
  245. }
  246. .add-bottom-btn {
  247. position: fixed;
  248. left: 0;
  249. bottom: 0;
  250. width: 100vw;
  251. background: #fff;
  252. display: flex;
  253. justify-content: center;
  254. align-items: center;
  255. padding: 24rpx 0 32rpx 0;
  256. z-index: 10;
  257. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.03);
  258. }
  259. .add-bottom-btn-inner {
  260. display: flex;
  261. align-items: center;
  262. font-size: 30rpx;
  263. color: #222;
  264. font-weight: 500;
  265. background: #fff;
  266. border-radius: 40rpx;
  267. padding: 8rpx 32rpx;
  268. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
  269. }
  270. .add-bottom-btn-inner .plus {
  271. font-size: 38rpx;
  272. color: #f5b400;
  273. margin-right: 12rpx;
  274. }
  275. </style>