index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view class="address-list">
  3. <!-- 上方区域:图片和"新增"文字在右边 -->
  4. <!-- <view class="header">
  5. <view class="add-item" @click="handlHeader">
  6. <image src="../../../static/img/新增.png" mode=""></image>
  7. <text>新增</text>
  8. </view>
  9. </view> -->
  10. <up-radio-group v-model="radioValue" @change="handleRadioChange">
  11. <view v-for="(item, index) in dataList" :key="index" class="address-item">
  12. <!-- 左侧单选框 -->
  13. <view class="radio-group">
  14. <up-radio
  15. shape="circle"
  16. activeColor="red"
  17. :name="item.addressId"
  18. ></up-radio>
  19. </view>
  20. <!-- 中间内容区(自动伸缩) -->
  21. <view class="content-wrapper">
  22. <view class="address-line">
  23. <text class="address-text">
  24. {{ item.provinceName }}{{ item.cityName }}{{ item.districtName }}
  25. </text>
  26. </view>
  27. <view class="contact-info">
  28. <text class="name">{{ item.name }}</text>
  29. <text class="phone">{{ item.telephone }}</text>
  30. </view>
  31. </view>
  32. <!-- 右侧编辑图标(固定宽度) -->
  33. <view class="edit-icon" @click="hadlClickTo(item)">
  34. <up-icon name="edit-pen" size="16"></up-icon>
  35. </view>
  36. <view class="edit-icon" @click="hadlClickEdit(item)">
  37. <up-icon name="trash" size="16"></up-icon>
  38. </view>
  39. </view>
  40. </up-radio-group>
  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 { onMounted, ref } from 'vue'
  52. import { addressList, addressAddressIds } from '@/api/userSettings.js'
  53. const radioValue = ref(null)
  54. const dataList = ref([])
  55. const total = ref(0)
  56. const addressId = ref('')
  57. const getListData = async () => {
  58. const res = await addressList()
  59. dataList.value = res.rows
  60. total.value = res.total
  61. console.log(dataList.value, '>>>>>dataList.value')
  62. }
  63. const onLoadOptions = ref({})
  64. const hadlClickTo = (item) => {
  65. console.log(item)
  66. const {
  67. address,
  68. addressId,
  69. age,
  70. cityName,
  71. districtName,
  72. label,
  73. name,
  74. provinceName,
  75. sex,
  76. telephone,
  77. cityCode,
  78. districtCode,
  79. provinceCode,
  80. } = item
  81. const params = `address=${encodeURIComponent(
  82. address
  83. )}&addressId=${encodeURIComponent(addressId)}&age=${encodeURIComponent(
  84. age
  85. )}&cityName=${encodeURIComponent(cityName)}&districtName=${encodeURIComponent(
  86. districtName
  87. )}&label=${encodeURIComponent(label)}&name=${encodeURIComponent(
  88. name
  89. )}&provinceName=${encodeURIComponent(provinceName)}&sex=${encodeURIComponent(
  90. sex
  91. )}&telephone=${encodeURIComponent(telephone)}&cityCode=${encodeURIComponent(
  92. cityCode
  93. )}&districtCode=${encodeURIComponent(
  94. districtCode
  95. )}&provinceCode=${encodeURIComponent(provinceCode)}`
  96. // 使用拼接的查询参数进行页面跳转
  97. uni.navigateTo({
  98. url: `/pages_mine/pages/selectAddress/edit?${params}`,
  99. })
  100. }
  101. const hadlClickEdit = async (item) => {
  102. try {
  103. const res = await addressAddressIds(item.addressId) // 使用 addressId
  104. if (res.code == 200) {
  105. uni.showToast({
  106. title: '删除成功',
  107. icon: 'success',
  108. })
  109. }
  110. await getListData()
  111. } catch (error) {
  112. console.error('删除失败', error)
  113. uni.showToast({
  114. title: '删除失败',
  115. icon: 'error',
  116. })
  117. }
  118. }
  119. const handlHeader = () => {
  120. uni.navigateTo({
  121. url: `/pages_mine/pages/setupUser/Address`,
  122. })
  123. }
  124. const handleRadioChange = (addressId, item) => {
  125. console.log('当前选中的 addressId:', addressId)
  126. const selectedItem = dataList.value.find(
  127. (item) => item.addressId === addressId
  128. )
  129. console.log('选中项完整数据:', selectedItem)
  130. }
  131. // onLoad((options) => {
  132. // onLoadOptions.value = JSON.parse(decodeURIComponent(options.onLoadOptions));
  133. // })
  134. onMounted(() => {
  135. getListData()
  136. })
  137. </script>
  138. <style scoped>
  139. .address-list {
  140. padding: 20rpx;
  141. }
  142. .header {
  143. display: flex;
  144. justify-content: flex-end;
  145. align-items: center;
  146. margin-bottom: 20rpx;
  147. }
  148. .add-item {
  149. display: flex;
  150. align-items: center;
  151. }
  152. .add-item image {
  153. width: 40rpx;
  154. height: 40rpx;
  155. margin-right: 8rpx;
  156. }
  157. .add-item text {
  158. font-size: 25rpx;
  159. color: crimson;
  160. }
  161. .address-item {
  162. display: flex;
  163. align-items: center; /* 确保垂直居中 */
  164. justify-content: space-between; /* 让内容均匀分布 */
  165. padding: 24rpx 0;
  166. border-bottom: 1rpx solid #f0f0f0;
  167. position: relative; /* 可选:用于绝对定位 */
  168. width: 100%;
  169. }
  170. .radio-group {
  171. flex-shrink: 0;
  172. /* 禁止压缩 */
  173. margin-right: 20rpx;
  174. }
  175. .content-wrapper {
  176. flex: 1;
  177. min-width: 0;
  178. }
  179. .edit-icon {
  180. flex-shrink: 0;
  181. padding: 8rpx;
  182. }
  183. .address-text {
  184. display: inline-block;
  185. max-width: 100%;
  186. font-size: 32rpx;
  187. font-weight: 500;
  188. white-space: nowrap;
  189. overflow: hidden;
  190. text-overflow: ellipsis;
  191. }
  192. .contact-info {
  193. display: flex;
  194. gap: 20rpx;
  195. margin-top: 8rpx;
  196. }
  197. .name,
  198. .phone {
  199. font-size: 28rpx;
  200. color: #666;
  201. }
  202. .add-bottom-btn {
  203. position: fixed;
  204. left: 0;
  205. bottom: 0;
  206. width: 100vw;
  207. background: #fff;
  208. display: flex;
  209. justify-content: center;
  210. align-items: center;
  211. padding: 24rpx 0 32rpx 0;
  212. z-index: 10;
  213. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.03);
  214. }
  215. .add-bottom-btn-inner {
  216. display: flex;
  217. align-items: center;
  218. font-size: 30rpx;
  219. color: #222;
  220. font-weight: 500;
  221. background: #fff;
  222. border-radius: 40rpx;
  223. padding: 8rpx 32rpx;
  224. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
  225. }
  226. .add-bottom-btn-inner .plus {
  227. font-size: 38rpx;
  228. color: #f5b400;
  229. margin-right: 12rpx;
  230. }
  231. </style>