adresss.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="box">
  3. <!-- <view class="" @click="handleChane">
  4. 改变
  5. </view> -->
  6. <up-radio-group v-model="radioValue" @change="handleChane">
  7. <view v-for="(item, index) in dataList" :key="index" class="address-item">
  8. <!-- 左侧单选框 -->
  9. <view class="radio-group">
  10. <up-radio shape="circle" activeColor="red" :name="item.addressId"></up-radio>
  11. </view>
  12. <!-- 中间内容区(自动伸缩) -->
  13. <view class="content-wrapper">
  14. <view class="address-line">
  15. <text class="address-text">
  16. {{ item.provinceName }}{{ item.cityName }}{{ item.districtName }}
  17. </text>
  18. </view>
  19. <view class="contact-info">
  20. <text class="name">{{ item.name }}</text>
  21. <text class="phone">{{ item.telephone }}</text>
  22. </view>
  23. </view>
  24. <!-- 右侧编辑图标(固定宽度) -->
  25. <view class="edit-icon" @click="hadlClickTo(item)">
  26. <up-icon name="edit-pen" size="16"></up-icon>
  27. </view>
  28. </view>
  29. </up-radio-group>
  30. </view>
  31. </template>
  32. <script setup>
  33. import {
  34. onMounted,
  35. ref
  36. } from 'vue'
  37. import {
  38. addressList
  39. } from "@/api/userSettings.js"
  40. const radioValue = ref(null)
  41. const dataList = ref([])
  42. const total = ref(0)
  43. const addressId = ref('')
  44. const onLoadOptions = ref({})
  45. const getListData = async () => {
  46. const res = await addressList()
  47. dataList.value = res.rows
  48. total.value = res.total
  49. }
  50. const props = defineProps({
  51. modelValue: {
  52. type: Boolean,
  53. default: false
  54. },
  55. addressInfo: {
  56. type: Object,
  57. default: () => {}
  58. },
  59. })
  60. const emits = defineEmits([
  61. 'update:modelValue',
  62. 'update:addressInfo'
  63. ])
  64. function handleChane(addressId, item) {
  65. console.log('当前选中的 addressId:', addressId);
  66. const selectedItem = dataList.value.find(item => item.addressId === addressId);
  67. console.log('准备发送的数据:', JSON.stringify(selectedItem));
  68. emits('update:modelValue', false)
  69. emits('update:addressInfo',selectedItem)
  70. }
  71. onMounted(() => {
  72. getListData()
  73. })
  74. </script>
  75. <style lang="scss">
  76. .box {
  77. height: 100vh;
  78. width: 100vw;
  79. position: fixed;
  80. top: 0;
  81. left: 0;
  82. z-index: 999999;
  83. background: #f0f0f0;
  84. }
  85. .address-list {
  86. padding: 20rpx;
  87. }
  88. .header {
  89. display: flex;
  90. justify-content: flex-end;
  91. align-items: center;
  92. margin-bottom: 20rpx;
  93. }
  94. .add-item {
  95. display: flex;
  96. align-items: center;
  97. }
  98. .add-item image {
  99. width: 40rpx;
  100. height: 40rpx;
  101. margin-right: 8rpx;
  102. }
  103. .add-item text {
  104. font-size: 25rpx;
  105. color: crimson;
  106. }
  107. .address-item {
  108. display: flex;
  109. align-items: flex-start;
  110. padding: 24rpx 0;
  111. border-bottom: 1rpx solid #f0f0f0;
  112. }
  113. .radio-group {
  114. flex-shrink: 0;
  115. /* 禁止压缩 */
  116. margin-right: 20rpx;
  117. }
  118. .content-wrapper {
  119. flex: 1;
  120. min-width: 0;
  121. }
  122. .edit-icon {
  123. flex-shrink: 0;
  124. margin-left: 330rpx;
  125. padding: 8rpx;
  126. }
  127. .address-text {
  128. display: inline-block;
  129. max-width: 100%;
  130. font-size: 32rpx;
  131. font-weight: 500;
  132. white-space: nowrap;
  133. overflow: hidden;
  134. text-overflow: ellipsis;
  135. }
  136. .contact-info {
  137. display: flex;
  138. gap: 20rpx;
  139. margin-top: 8rpx;
  140. }
  141. .name,
  142. .phone {
  143. font-size: 28rpx;
  144. color: #666;
  145. }
  146. </style>