index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. detailAddress,
  81. } = item
  82. const params = `address=${encodeURIComponent(
  83. address
  84. )}&addressId=${encodeURIComponent(addressId)}&age=${encodeURIComponent(
  85. age
  86. )}&cityName=${encodeURIComponent(cityName)}&districtName=${encodeURIComponent(
  87. districtName
  88. )}&label=${encodeURIComponent(label)}&name=${encodeURIComponent(
  89. name
  90. )}&provinceName=${encodeURIComponent(provinceName)}&sex=${encodeURIComponent(
  91. sex
  92. )}&telephone=${encodeURIComponent(telephone)}&cityCode=${encodeURIComponent(
  93. cityCode
  94. )}&districtCode=${encodeURIComponent(
  95. districtCode
  96. )}&provinceCode=${encodeURIComponent(provinceCode)}&detailAddress=${encodeURIComponent(detailAddress)}`
  97. // 使用拼接的查询参数进行页面跳转
  98. uni.navigateTo({
  99. url: `/pages_mine/pages/selectAddress/edit?${params}`,
  100. })
  101. }
  102. const hadlClickEdit = async (item) => {
  103. try {
  104. const res = await addressAddressIds(item.addressId) // 使用 addressId
  105. if (res.code == 200) {
  106. uni.showToast({
  107. title: '删除成功',
  108. icon: 'success',
  109. })
  110. }
  111. await getListData()
  112. } catch (error) {
  113. console.error('删除失败', error)
  114. uni.showToast({
  115. title: '删除失败',
  116. icon: 'error',
  117. })
  118. }
  119. }
  120. const handlHeader = () => {
  121. uni.navigateTo({
  122. url: `/pages_mine/pages/setupUser/Address`,
  123. })
  124. }
  125. const handleRadioChange = (addressId, item) => {
  126. console.log('当前选中的 addressId:', addressId)
  127. const selectedItem = dataList.value.find(
  128. (item) => item.addressId === addressId
  129. )
  130. console.log('选中项完整数据:', selectedItem)
  131. }
  132. // onLoad((options) => {
  133. // onLoadOptions.value = JSON.parse(decodeURIComponent(options.onLoadOptions));
  134. // })
  135. onMounted(() => {
  136. getListData()
  137. })
  138. </script>
  139. <style scoped>
  140. .address-list {
  141. padding: 20rpx;
  142. }
  143. .header {
  144. display: flex;
  145. justify-content: flex-end;
  146. align-items: center;
  147. margin-bottom: 20rpx;
  148. }
  149. .add-item {
  150. display: flex;
  151. align-items: center;
  152. }
  153. .add-item image {
  154. width: 40rpx;
  155. height: 40rpx;
  156. margin-right: 8rpx;
  157. }
  158. .add-item text {
  159. font-size: 25rpx;
  160. color: crimson;
  161. }
  162. .address-item {
  163. display: flex;
  164. align-items: center; /* 确保垂直居中 */
  165. justify-content: space-between; /* 让内容均匀分布 */
  166. padding: 24rpx 0;
  167. border-bottom: 1rpx solid #f0f0f0;
  168. position: relative; /* 可选:用于绝对定位 */
  169. width: 100%;
  170. }
  171. .radio-group {
  172. flex-shrink: 0;
  173. /* 禁止压缩 */
  174. margin-right: 20rpx;
  175. }
  176. .content-wrapper {
  177. flex: 1;
  178. min-width: 0;
  179. }
  180. .edit-icon {
  181. flex-shrink: 0;
  182. padding: 8rpx;
  183. }
  184. .address-text {
  185. display: inline-block;
  186. max-width: 100%;
  187. font-size: 32rpx;
  188. font-weight: 500;
  189. white-space: nowrap;
  190. overflow: hidden;
  191. text-overflow: ellipsis;
  192. }
  193. .contact-info {
  194. display: flex;
  195. gap: 20rpx;
  196. margin-top: 8rpx;
  197. }
  198. .name,
  199. .phone {
  200. font-size: 28rpx;
  201. color: #666;
  202. }
  203. .add-bottom-btn {
  204. position: fixed;
  205. left: 0;
  206. bottom: 0;
  207. width: 100vw;
  208. background: #fff;
  209. display: flex;
  210. justify-content: center;
  211. align-items: center;
  212. padding: 24rpx 0 32rpx 0;
  213. z-index: 10;
  214. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.03);
  215. }
  216. .add-bottom-btn-inner {
  217. display: flex;
  218. align-items: center;
  219. font-size: 30rpx;
  220. color: #222;
  221. font-weight: 500;
  222. background: #fff;
  223. border-radius: 40rpx;
  224. padding: 8rpx 32rpx;
  225. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
  226. }
  227. .add-bottom-btn-inner .plus {
  228. font-size: 38rpx;
  229. color: #f5b400;
  230. margin-right: 12rpx;
  231. }
  232. </style>