chooseAddress.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <el-dialog v-model="visible" title="选择地址" width="800px" @close="handleClose">
  3. <el-table
  4. :data="addressList"
  5. border
  6. style="width: 100%"
  7. highlight-current-row
  8. @current-change="handleCurrentChange"
  9. @row-dblclick="handleRowDblClick"
  10. >
  11. <el-table-column label="选择" width="80" align="center">
  12. <template #default="scope">
  13. <el-radio v-model="selectedAddressId" :value="scope.row.id">
  14. <span></span>
  15. </el-radio>
  16. </template>
  17. </el-table-column>
  18. <el-table-column prop="consignee" label="收货人" width="120" />
  19. <el-table-column prop="phone" label="手机号" width="150" />
  20. <el-table-column prop="address" label="地址" show-overflow-tooltip>
  21. <template #default="scope"> {{ scope.row.provincialCityCountry }} {{ scope.row.address }} </template>
  22. </el-table-column>
  23. </el-table>
  24. <div v-if="addressList.length === 0" class="empty-data">暂无数据</div>
  25. <template #footer>
  26. <div class="dialog-footer">
  27. <el-button @click="handleClose">取消</el-button>
  28. <el-button type="primary" @click="handleConfirm">确定</el-button>
  29. </div>
  30. </template>
  31. </el-dialog>
  32. </template>
  33. <script setup lang="ts">
  34. import { ref, watch } from 'vue';
  35. import { listShippingAddress } from '@/api/customer/customerFile/shippingAddress';
  36. import { ShippingAddressVO, ShippingAddressQuery } from '@/api/customer/customerFile/shippingAddress/types';
  37. interface Props {
  38. modelValue: boolean;
  39. customerId?: string | number;
  40. addressList?: ShippingAddressVO[];
  41. }
  42. interface Emits {
  43. (e: 'update:modelValue', value: boolean): void;
  44. (e: 'confirm', address: ShippingAddressVO): void;
  45. }
  46. const props = defineProps<Props>();
  47. const emit = defineEmits<Emits>();
  48. const visible = ref(false);
  49. const selectedAddressId = ref<string | number>('');
  50. const selectedAddress = ref<ShippingAddressVO | null>(null);
  51. // 监听 modelValue 变化,同步到 visible
  52. watch(
  53. () => props.modelValue,
  54. (newVal) => {
  55. visible.value = newVal;
  56. },
  57. { immediate: true }
  58. );
  59. // 监听 visible 变化,同步到 modelValue
  60. watch(visible, (newVal) => {
  61. emit('update:modelValue', newVal);
  62. });
  63. // 选中行变化
  64. const handleCurrentChange = (row: ShippingAddressVO | null) => {
  65. if (row) {
  66. selectedAddressId.value = row.id;
  67. selectedAddress.value = row;
  68. }
  69. };
  70. // 双击行直接确认
  71. const handleRowDblClick = (row: ShippingAddressVO) => {
  72. selectedAddress.value = row;
  73. selectedAddressId.value = row.id;
  74. handleConfirm();
  75. };
  76. // 关闭对话框
  77. const handleClose = () => {
  78. emit('update:modelValue', false);
  79. selectedAddressId.value = '';
  80. selectedAddress.value = null;
  81. };
  82. // 确认选择
  83. const handleConfirm = () => {
  84. if (!selectedAddress.value) {
  85. return;
  86. }
  87. emit('confirm', selectedAddress.value);
  88. handleClose();
  89. };
  90. </script>
  91. <style scoped lang="scss">
  92. .empty-data {
  93. text-align: center;
  94. padding: 40px 0;
  95. color: #909399;
  96. font-size: 14px;
  97. }
  98. :deep(.el-radio__label) {
  99. display: none;
  100. }
  101. </style>