160 lines
5.5 KiB
Vue
160 lines
5.5 KiB
Vue
<template>
|
||
<el-drawer v-model="visible" size="860px" append-to-body>
|
||
<template #header>
|
||
<div class="drawer-head">
|
||
<span class="drawer-title">国家分区</span>
|
||
<span v-if="country" class="drawer-sub">
|
||
{{ country.countryName || '未填写国家' }}
|
||
<template v-if="country.countryCode">({{ country.countryCode }})</template>
|
||
,共 {{ zoneList.length }} 个分区
|
||
</span>
|
||
</div>
|
||
</template>
|
||
|
||
<div v-loading="loading">
|
||
<div class="zone-toolbar">
|
||
<el-button type="primary" plain icon="Plus" size="small" :disabled="!country" @click="handleAdd" v-hasPermi="['data:payPostcode:edit']">新增分区</el-button>
|
||
</div>
|
||
<el-table :data="zoneList" border :row-key="rowKey" :empty-text="country ? '这个国家还没有分区' : '请选择国家'">
|
||
<el-table-column label="分区" min-width="180" align="center">
|
||
<template #default="{ row }">
|
||
<div class="zone-country-cell">
|
||
<div class="zone-title">{{ row.zoneName }}</div>
|
||
<el-button link type="primary" class="zone-click" @click="openLines(row)" v-hasPermi="['data:payPostcode:query']">分区点击</el-button>
|
||
</div>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="渠道" min-width="140" align="center" show-overflow-tooltip>
|
||
<template #default="{ row }">{{ row.channelName || '-' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="邮编属性" width="120" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag v-if="row.coverage" size="small" :type="coverageType(firstPart(row.coverage))">{{ coverageLabel(firstPart(row.coverage)) }}</el-tag>
|
||
<el-tag v-else size="small" type="info">普通</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="邮编数" prop="lineCount" width="100" align="center" />
|
||
<el-table-column label="操作" width="220" align="center" fixed="right">
|
||
<template #default="{ row }">
|
||
<el-button link type="primary" icon="View" @click="openLines(row)" v-hasPermi="['data:payPostcode:query']">明细</el-button>
|
||
<el-button link type="primary" icon="Edit" @click="handleEdit(row)" v-hasPermi="['data:payPostcode:edit']">编辑</el-button>
|
||
<el-button link type="primary" icon="Delete" @click="handleDelete(row)" v-hasPermi="['data:payPostcode:remove']">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</div>
|
||
|
||
<pay-zone-form-dialog ref="formRef" :country="country" @success="onChanged" />
|
||
<pay-postcode-drawer ref="lineRef" @changed="onChanged" />
|
||
</el-drawer>
|
||
</template>
|
||
|
||
<script setup name="PayZoneDrawer">
|
||
import { listPayPostcodeZone, delPayPostcodeZone } from '@/api/data/payPostcode'
|
||
import PayZoneFormDialog from './PayZoneFormDialog.vue'
|
||
import PayPostcodeDrawer from './PayPostcodeDrawer.vue'
|
||
|
||
const { proxy } = getCurrentInstance()
|
||
const emit = defineEmits(['changed'])
|
||
|
||
const visible = ref(false)
|
||
const loading = ref(false)
|
||
const country = ref(null)
|
||
const zoneList = ref([])
|
||
const formRef = ref()
|
||
const lineRef = ref()
|
||
|
||
const coverageOptions = [
|
||
{ label: '可达', value: 'REACH' },
|
||
{ label: '不可达', value: 'UNREACH' },
|
||
{ label: '偏远', value: 'REMOTE' }
|
||
]
|
||
|
||
function firstPart(value) {
|
||
return String(value || '').split('、').map(item => item.trim()).filter(Boolean)[0] || ''
|
||
}
|
||
|
||
function coverageLabel(value) {
|
||
return coverageOptions.find(item => item.value === value)?.label || value
|
||
}
|
||
|
||
function coverageType(value) {
|
||
if (value === 'UNREACH') return 'danger'
|
||
if (value === 'REMOTE') return 'warning'
|
||
return 'success'
|
||
}
|
||
|
||
function rowKey(row) {
|
||
return (row.zoneName || '') + '||' + (row.channelName || '')
|
||
}
|
||
|
||
function open(row) {
|
||
country.value = row
|
||
visible.value = true
|
||
loadList()
|
||
}
|
||
|
||
function loadList() {
|
||
if (!country.value) {
|
||
zoneList.value = []
|
||
return
|
||
}
|
||
loading.value = true
|
||
listPayPostcodeZone({
|
||
countryCode: country.value.countryCode,
|
||
countryName: country.value.countryName,
|
||
allChannels: true
|
||
}).then(res => {
|
||
zoneList.value = res.data || []
|
||
}).catch(() => {
|
||
zoneList.value = []
|
||
}).finally(() => {
|
||
loading.value = false
|
||
})
|
||
}
|
||
|
||
function onChanged() {
|
||
loadList()
|
||
emit('changed')
|
||
}
|
||
|
||
function handleAdd() {
|
||
formRef.value.open()
|
||
}
|
||
|
||
function handleEdit(row) {
|
||
formRef.value.open(row)
|
||
}
|
||
|
||
function handleDelete(row) {
|
||
const channel = row.channelName ? '(' + row.channelName + ')' : ''
|
||
proxy.$modal.confirm('删除分区「' + row.zoneName + '」' + channel + '及其邮编?').then(() => {
|
||
return delPayPostcodeZone({
|
||
countryCode: country.value.countryCode,
|
||
countryName: country.value.countryName,
|
||
channelName: row.channelName || '',
|
||
zoneName: row.zoneName
|
||
})
|
||
}).then(() => {
|
||
proxy.$modal.msgSuccess('删除成功')
|
||
onChanged()
|
||
}).catch(() => {})
|
||
}
|
||
|
||
function openLines(row) {
|
||
lineRef.value.open({ ...country.value, channelName: row.channelName || '' }, row)
|
||
}
|
||
|
||
defineExpose({ open })
|
||
</script>
|
||
|
||
<style scoped>
|
||
.drawer-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
|
||
.drawer-title { font-size: 16px; font-weight: 600; }
|
||
.drawer-sub { color: #909399; font-size: 13px; }
|
||
.zone-toolbar { display: flex; align-items: center; margin-bottom: 12px; }
|
||
.zone-country-cell { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; }
|
||
.zone-title { font-weight: 500; }
|
||
.zone-click { padding: 0; height: auto; font-size: 12px; }
|
||
</style>
|