index.vue 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <ele-page flex-table>
  3. <PageSearch @search="handleSearch" />
  4. <common-table ref="tableRef" :pageConfig="pageConfig" :columns="columns">
  5. <template #toolbar>
  6. <div class="flex items-center space-x-2">
  7. <el-button type="primary" @click="handleAdd" :icon="Plus">添加新地址</el-button>
  8. </div>
  9. </template>
  10. <!-- Custom Slots for Radio Buttons -->
  11. <template #isSend="{ row }">
  12. <el-radio :model-value="row.isSend" :label="1" @change="handleSetDefault(row, 'send')">默认</el-radio>
  13. </template>
  14. <template #isReturn="{ row }">
  15. <el-radio :model-value="row.isReturn" :label="1" @change="handleSetDefault(row, 'return')">默认</el-radio>
  16. </template>
  17. <template #action="{ row }">
  18. <el-button link type="primary" @click="handleEdit(row)">编辑</el-button>
  19. <el-button link type="danger" @click="handleDelete(row)">删除</el-button>
  20. </template>
  21. </common-table>
  22. <EditDialog ref="editDialogRef" @success="refreshPage" />
  23. </ele-page>
  24. </template>
  25. <script setup>
  26. import { ref, reactive, getCurrentInstance } from 'vue';
  27. import { Plus } from '@element-plus/icons-vue';
  28. import CommonTable from '@/components/CommonPage/CommonTable.vue';
  29. import PageSearch from './components/page-search.vue';
  30. import EditDialog from './components/edit-dialog.vue';
  31. import { ElMessage, ElMessageBox } from 'element-plus';
  32. const { proxy } = getCurrentInstance();
  33. const tableRef = ref(null);
  34. const editDialogRef = ref(null);
  35. const pageConfig = reactive({
  36. pageUrl: '/mallLogistics/address/page',
  37. rowKey: 'id',
  38. fileName: '地址管理',
  39. params: {}
  40. });
  41. const columns = ref([
  42. { prop: 'isSend', label: '发货地址', slot: 'isSend', width: 100, align: 'center' },
  43. { prop: 'isReturn', label: '退货地址', slot: 'isReturn', width: 100, align: 'center' },
  44. { prop: 'contactName', label: '联系人', minWidth: 100 },
  45. { prop: 'area', label: '所在地区', minWidth: 150 },
  46. { prop: 'detailAddress', label: '详细地址', minWidth: 200 },
  47. { prop: 'phone', label: '手机号码', width: 120 },
  48. { columnKey: 'action', label: '操作', width: 150, fixed: 'right', align: 'center', slot: 'action' }
  49. ]);
  50. const handleSearch = (params) => {
  51. tableRef.value?.reload({ where: params });
  52. };
  53. const handleAdd = () => {
  54. editDialogRef.value?.handleOpen();
  55. };
  56. const handleEdit = (row) => {
  57. editDialogRef.value?.handleOpen(row);
  58. };
  59. const handleDelete = (row) => {
  60. tableRef.value.messageConfrim({
  61. message: "确认删除该地址?",
  62. fetch: () => proxy.$http.post('/mallLogistics/address/delete', { id: row.id })
  63. })
  64. };
  65. const handleSetDefault = (row, type) => {
  66. const url = type === 'send' ? '/mallLogistics/address/setDefaultSend' : '/mallLogistics/address/setDefaultReturn';
  67. proxy.$http.post(url, { id: row.id }).then(() => {
  68. ElMessage.success('设置成功');
  69. refreshPage();
  70. });
  71. };
  72. const refreshPage = () => {
  73. tableRef.value?.reload();
  74. };
  75. </script>