index.vue 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <script setup lang="ts">
  2. import { createGlobalLoadingMiddleware } from '@/api/core/middleware'
  3. import { StaticUrl } from '@/config'
  4. import router from '@/router'
  5. definePage({
  6. name: 'common-addressList',
  7. islogin: true,
  8. style: {
  9. navigationBarTitleText: '收获地址',
  10. },
  11. })
  12. const defaultId = ref()
  13. const { addresses } = storeToRefs(useUserStore())
  14. const route = useRoute()
  15. const { send: updateData } = useRequest(data => Apis.sys.updateAddresses({
  16. data,
  17. }), { middleware: createGlobalLoadingMiddleware({ loadingText: '设置中。。。' }), immediate: false })
  18. onShow(async () => {
  19. await useUserStore().getuserAddresslist()
  20. useUserStore().getSelectedAddress()
  21. })
  22. watch(() => addresses.value, () => {
  23. defaultId.value = addresses.value.find(item => item.defaulted === 1)?.id
  24. })
  25. async function handleChange(e: { value: number }) {
  26. const item = addresses.value.find(i => i.id === e.value)
  27. if (item) {
  28. updateData({ ...item, defaulted: 1 })
  29. }
  30. }
  31. function handleSelectAddress(item: Api.addressList) {
  32. if (!route.query?.type)
  33. return
  34. useUserStore().updateSelectedAddress(item)
  35. router.back()
  36. }
  37. async function handleAddAddress() {
  38. await isWxMiniProgram()
  39. router.push({ name: 'common-editAddress', params: { type: '1' } })
  40. }
  41. async function handleEditAddress(item: Api.addressList) {
  42. await isWxMiniProgram()
  43. router.push({ name: 'common-editAddress', params: { type: '2', id: `${item.id}` } })
  44. }
  45. </script>
  46. <template>
  47. <view class="page">
  48. <view class="px24rpx py20rpx">
  49. <wd-radio-group v-model="defaultId" @change="handleChange">
  50. <view v-for="item in addresses" :key="item.id" class="mb20rpx rounded-16rpx bg-white p24rpx" @click="handleSelectAddress(item)">
  51. <view class="flex items-center justify-between">
  52. <view class="text-28rpx font-semibold">
  53. {{ item.consigneeName }} {{ item.consigneeMobile }}
  54. </view>
  55. <image
  56. :src="`${StaticUrl}/edit-address.png`"
  57. class="h40rpx w40rpx"
  58. @click.stop="handleEditAddress(item)"
  59. />
  60. </view>
  61. <view class="mt24rpx text-24rpx text-#AAAAAA">
  62. {{ item.province }}{{ item.city }}{{ item.detailAddress }}
  63. </view>
  64. <view class="my24rpx h2rpx w-full bg-#F0F0F0" />
  65. <wd-radio :value="item.id" shape="dot" inline>
  66. 设为默认地址
  67. </wd-radio>
  68. </view>
  69. <view class="ios h120rpx" />
  70. </wd-radio-group>
  71. <wd-status-tip v-if="!addresses.length" image="content" tip="暂无内容" />
  72. </view>
  73. <view class="ios fixed bottom-0 left-0 box-border w-full rounded-t-32rpx bg-white px24rpx">
  74. <view class="w-full py20rpx">
  75. <wd-button size="large" block @click="handleAddAddress">
  76. 新增收货地址
  77. </wd-button>
  78. </view>
  79. </view>
  80. </view>
  81. </template>
  82. <style scoped lang="scss">
  83. .page{
  84. :deep(){
  85. .wd-radio-group{
  86. background-color: unset !important;
  87. }
  88. }
  89. }
  90. </style>