adresss.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. } from "@dcloudio/uni-app";
  55. import { addressList,addressAddressIds } from '@/api/userSettings.js'
  56. const radioValue = ref(null)
  57. const dataList = ref([])
  58. const total = ref(0)
  59. const handlHeader = () => {
  60. uni.navigateTo({
  61. url: `/pages_home/pages/setupUser/Address`,
  62. })
  63. }
  64. const props = defineProps({
  65. modelValue: {
  66. type: Boolean,
  67. default: false,
  68. },
  69. addressInfo: {
  70. type: Object,
  71. default: () => {},
  72. },
  73. })
  74. const hadlClickEdit = async (item) => {
  75. try {
  76. const res = await addressAddressIds(item.addressId) // 使用 addressId
  77. if (res.code == 200) {
  78. uni.showToast({
  79. title: '删除成功',
  80. icon: 'success',
  81. })
  82. }
  83. await getListData()
  84. } catch (error) {
  85. console.error('删除失败', error)
  86. uni.showToast({
  87. title: '删除失败',
  88. icon: 'error',
  89. })
  90. }
  91. }
  92. const emits = defineEmits(['update:modelValue', 'update:addressInfo'])
  93. function handleChane(addressId, item) {
  94. const selectedItem = dataList.value.find(
  95. (item) => item.addressId === addressId
  96. )
  97. emits('update:modelValue', false)
  98. emits('update:addressInfo', selectedItem)
  99. }
  100. const hadlClickTo = (item) => {
  101. console.log(item)
  102. const {
  103. address,
  104. addressId,
  105. age,
  106. cityName,
  107. districtName,
  108. label,
  109. name,
  110. provinceName,
  111. sex,
  112. telephone,
  113. cityCode,
  114. districtCode,
  115. provinceCode,
  116. detailAddress
  117. } = item
  118. const params = `address=${encodeURIComponent(
  119. address
  120. )}&addressId=${encodeURIComponent(addressId)}&age=${encodeURIComponent(
  121. age
  122. )}&cityName=${encodeURIComponent(cityName)}&districtName=${encodeURIComponent(
  123. districtName
  124. )}&label=${encodeURIComponent(label)}&name=${encodeURIComponent(
  125. name
  126. )}&provinceName=${encodeURIComponent(provinceName)}&sex=${encodeURIComponent(
  127. sex
  128. )}&telephone=${encodeURIComponent(telephone)}&cityCode=${encodeURIComponent(
  129. cityCode
  130. )}&districtCode=${encodeURIComponent(
  131. districtCode
  132. )}&provinceCode=${encodeURIComponent(provinceCode)}&detailAddress=${encodeURIComponent(detailAddress)}`
  133. // 使用拼接的查询参数进行页面跳转
  134. uni.navigateTo({
  135. url: `/pages_home/pages/selectAddress/edit?${params}`,
  136. })
  137. }
  138. const getListData = async () => {
  139. const res = await addressList()
  140. dataList.value = res.rows
  141. total.value = res.total
  142. }
  143. onShow(() => {
  144. getListData()
  145. })
  146. onMounted(() => {
  147. getListData()
  148. })
  149. </script>
  150. <style lang="scss">
  151. .box {
  152. height: 100vh;
  153. width: 100vw;
  154. position: fixed;
  155. top: 0;
  156. left: 0;
  157. z-index: 999999;
  158. background: #f0f0f0;
  159. display: flex;
  160. flex-direction: column;
  161. }
  162. .address-list {
  163. flex: 1;
  164. overflow-y: auto;
  165. padding: 0 0 120rpx 0;
  166. }
  167. .footer {
  168. position: fixed;
  169. left: 0;
  170. right: 0;
  171. bottom: 0;
  172. background: transparent;
  173. display: flex;
  174. justify-content: center;
  175. align-items: center;
  176. padding-bottom: env(safe-area-inset-bottom);
  177. z-index: 1000;
  178. }
  179. .add-item {
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. gap: 10rpx;
  184. background: #fff;
  185. border-radius: 40rpx;
  186. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.06);
  187. padding: 0 40rpx;
  188. height: 80rpx;
  189. margin: 20rpx 0 30rpx 0;
  190. font-size: 30rpx;
  191. color: #222;
  192. font-weight: 500;
  193. }
  194. .add-item text {
  195. font-size: 30rpx;
  196. color: #222;
  197. }
  198. .address-item {
  199. display: flex;
  200. align-items: flex-start;
  201. padding: 24rpx 0;
  202. border-bottom: 1rpx solid #f0f0f0;
  203. background: transparent;
  204. }
  205. .radio-group {
  206. flex-shrink: 0;
  207. /* 禁止压缩 */
  208. margin-right: 20rpx;
  209. }
  210. .content-wrapper {
  211. flex: 1;
  212. min-width: 0;
  213. }
  214. .edit-icon {
  215. flex-shrink: 0;
  216. margin-left: 330rpx;
  217. padding: 8rpx;
  218. }
  219. .address-text {
  220. display: inline-block;
  221. max-width: 100%;
  222. font-size: 32rpx;
  223. font-weight: 500;
  224. white-space: nowrap;
  225. overflow: hidden;
  226. text-overflow: ellipsis;
  227. }
  228. .contact-info {
  229. display: flex;
  230. gap: 20rpx;
  231. margin-top: 8rpx;
  232. }
  233. .name,
  234. .phone {
  235. font-size: 28rpx;
  236. color: #666;
  237. }
  238. .add-bottom-btn {
  239. position: fixed;
  240. left: 0;
  241. bottom: 0;
  242. width: 100vw;
  243. background: #fff;
  244. display: flex;
  245. justify-content: center;
  246. align-items: center;
  247. padding: 24rpx 0 32rpx 0;
  248. z-index: 10;
  249. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.03);
  250. }
  251. .add-bottom-btn-inner {
  252. display: flex;
  253. align-items: center;
  254. font-size: 30rpx;
  255. color: #222;
  256. font-weight: 500;
  257. background: #fff;
  258. border-radius: 40rpx;
  259. padding: 8rpx 32rpx;
  260. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
  261. }
  262. .add-bottom-btn-inner .plus {
  263. font-size: 38rpx;
  264. color: #f5b400;
  265. margin-right: 12rpx;
  266. }
  267. </style>