adresss.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. } = item
  117. const params = `address=${encodeURIComponent(
  118. address
  119. )}&addressId=${encodeURIComponent(addressId)}&age=${encodeURIComponent(
  120. age
  121. )}&cityName=${encodeURIComponent(cityName)}&districtName=${encodeURIComponent(
  122. districtName
  123. )}&label=${encodeURIComponent(label)}&name=${encodeURIComponent(
  124. name
  125. )}&provinceName=${encodeURIComponent(provinceName)}&sex=${encodeURIComponent(
  126. sex
  127. )}&telephone=${encodeURIComponent(telephone)}&cityCode=${encodeURIComponent(
  128. cityCode
  129. )}&districtCode=${encodeURIComponent(
  130. districtCode
  131. )}&provinceCode=${encodeURIComponent(provinceCode)}`
  132. // 使用拼接的查询参数进行页面跳转
  133. uni.navigateTo({
  134. url: `/pages_home/pages/selectAddress/edit?${params}`,
  135. })
  136. }
  137. const getListData = async () => {
  138. const res = await addressList()
  139. dataList.value = res.rows
  140. total.value = res.total
  141. }
  142. onShow(() => {
  143. getListData()
  144. })
  145. onMounted(() => {
  146. getListData()
  147. })
  148. </script>
  149. <style lang="scss">
  150. .box {
  151. height: 100vh;
  152. width: 100vw;
  153. position: fixed;
  154. top: 0;
  155. left: 0;
  156. z-index: 999999;
  157. background: #f0f0f0;
  158. display: flex;
  159. flex-direction: column;
  160. }
  161. .address-list {
  162. flex: 1;
  163. overflow-y: auto;
  164. padding: 0 0 120rpx 0;
  165. }
  166. .footer {
  167. position: fixed;
  168. left: 0;
  169. right: 0;
  170. bottom: 0;
  171. background: transparent;
  172. display: flex;
  173. justify-content: center;
  174. align-items: center;
  175. padding-bottom: env(safe-area-inset-bottom);
  176. z-index: 1000;
  177. }
  178. .add-item {
  179. display: flex;
  180. align-items: center;
  181. justify-content: center;
  182. gap: 10rpx;
  183. background: #fff;
  184. border-radius: 40rpx;
  185. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.06);
  186. padding: 0 40rpx;
  187. height: 80rpx;
  188. margin: 20rpx 0 30rpx 0;
  189. font-size: 30rpx;
  190. color: #222;
  191. font-weight: 500;
  192. }
  193. .add-item text {
  194. font-size: 30rpx;
  195. color: #222;
  196. }
  197. .address-item {
  198. display: flex;
  199. align-items: flex-start;
  200. padding: 24rpx 0;
  201. border-bottom: 1rpx solid #f0f0f0;
  202. background: transparent;
  203. }
  204. .radio-group {
  205. flex-shrink: 0;
  206. /* 禁止压缩 */
  207. margin-right: 20rpx;
  208. }
  209. .content-wrapper {
  210. flex: 1;
  211. min-width: 0;
  212. }
  213. .edit-icon {
  214. flex-shrink: 0;
  215. margin-left: 330rpx;
  216. padding: 8rpx;
  217. }
  218. .address-text {
  219. display: inline-block;
  220. max-width: 100%;
  221. font-size: 32rpx;
  222. font-weight: 500;
  223. white-space: nowrap;
  224. overflow: hidden;
  225. text-overflow: ellipsis;
  226. }
  227. .contact-info {
  228. display: flex;
  229. gap: 20rpx;
  230. margin-top: 8rpx;
  231. }
  232. .name,
  233. .phone {
  234. font-size: 28rpx;
  235. color: #666;
  236. }
  237. .add-bottom-btn {
  238. position: fixed;
  239. left: 0;
  240. bottom: 0;
  241. width: 100vw;
  242. background: #fff;
  243. display: flex;
  244. justify-content: center;
  245. align-items: center;
  246. padding: 24rpx 0 32rpx 0;
  247. z-index: 10;
  248. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.03);
  249. }
  250. .add-bottom-btn-inner {
  251. display: flex;
  252. align-items: center;
  253. font-size: 30rpx;
  254. color: #222;
  255. font-weight: 500;
  256. background: #fff;
  257. border-radius: 40rpx;
  258. padding: 8rpx 32rpx;
  259. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
  260. }
  261. .add-bottom-btn-inner .plus {
  262. font-size: 38rpx;
  263. color: #f5b400;
  264. margin-right: 12rpx;
  265. }
  266. </style>