index.vue 5.9 KB

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