Files
BMS/bms-front/src/views/data/payPostcode/index.vue
T

201 lines
7.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="app-container">
<el-alert
type="info"
:closable="false"
show-icon
class="mb16"
title="每个国家一行,多个渠道用顿号分隔。点「分区」后,各渠道的分区分开显示。订单计费只拿本渠道的邮编对分区。"
/>
<basic-table
ref="tableRef"
:columns="columns"
:search-columns="searchColumns"
:query="queryList"
row-key="groupId"
search-action-align="right"
>
<template #toolbar>
<el-col :span="1.5">
<el-button type="primary" plain icon="Upload" @click="open = true" v-hasPermi="['data:payPostcode:import']">导入邮编</el-button>
</el-col>
</template>
<template #col-coverage="{ row }">
<template v-if="coverageParts(row.coverage).length">
<el-tag v-for="item in coverageParts(row.coverage)" :key="item" size="small" class="cov-tag" :type="coverageType(item)">{{ coverageLabel(item) }}</el-tag>
</template>
<el-tag v-else size="small" type="info">普通</el-tag>
</template>
<template #col-action="{ row }">
<el-button link type="primary" icon="List" @click.stop="openZones(row)" v-hasPermi="['data:payPostcode:query']">分区</el-button>
<el-button link type="primary" icon="Edit" @click.stop="handleUpdate(row)" v-hasPermi="['data:payPostcode:edit']">修改</el-button>
<el-button link type="danger" icon="Delete" @click.stop="handleClear(row)" v-hasPermi="['data:payPostcode:remove']">清空</el-button>
</template>
</basic-table>
<el-dialog v-model="open" title="导入应付邮编" width="480px" append-to-body destroy-on-close>
<!-- <p class="import-tip">导入后按国家归成一行。表头里带邮编或附加费的工作表会被导入。可达、可派记为可达,不可达记为不可达,偏远和岛屿记为偏远。英国附加费里的空气减排地区和空气减排地区邮编记为附加费,渠道为 Evri 48H。</p>-->
<el-upload :auto-upload="false" :limit="1" accept=".xlsx" :on-change="onFile" :on-remove="() => file = null">
<el-button type="primary" plain>选择 xlsx</el-button>
</el-upload>
<template #footer>
<el-button type="primary" :loading="importing" @click="submitImport">开始导入</el-button>
<el-button @click="open = false">取消</el-button>
</template>
</el-dialog>
<el-dialog title="修改国家邮编" v-model="editOpen" width="520px" append-to-body destroy-on-close>
<el-form ref="formRef" :model="form" label-width="100px">
<el-form-item label="国家">
<span>{{ form.countryName || '-' }}<template v-if="form.countryCode">({{ form.countryCode }})</template></span>
</el-form-item>
<el-form-item label="服务类型">
<el-input v-model="form.serviceType" maxlength="100" />
</el-form-item>
<el-form-item label="销售产品">
<el-input v-model="form.productName" maxlength="200" />
</el-form-item>
<el-form-item label="渠道">
<span>{{ form.channelName || '-' }}</span>
</el-form-item>
</el-form>
<p class="import-tip">保存后,这个国家下各渠道的服务类型和销售产品一起更新。渠道仍留在各自的分区上,不在这里改。</p>
<template #footer>
<el-button type="primary" @click="submitEdit">确定</el-button>
<el-button @click="editOpen = false">取消</el-button>
</template>
</el-dialog>
<pay-zone-drawer ref="zoneDrawerRef" @changed="reload" />
</div>
</template>
<script setup name="PayPostcode">
import { listPayPostcode, importPayPostcode, updatePayPostcodeCountry, delPayPostcodeCountry } from '@/api/data/payPostcode'
import PayZoneDrawer from './components/PayZoneDrawer.vue'
const { proxy } = getCurrentInstance()
const tableRef = ref()
const zoneDrawerRef = ref()
const open = ref(false)
const editOpen = ref(false)
const importing = ref(false)
const file = ref(null)
const form = ref({})
const coverageOptions = [
{ label: '可达', value: 'REACH' },
{ label: '不可达', value: 'UNREACH' },
{ label: '偏远', value: 'REMOTE' },
{ label: '附加费', value: 'SURCHARGE' }
]
function coverageParts(value) {
return String(value || '').split('、').map(item => item.trim()).filter(Boolean)
}
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'
if (value === 'SURCHARGE') return 'primary'
return 'success'
}
function firstPart(value) {
return coverageParts(value)[0] || ''
}
const searchColumns = [
{ label: '国家', prop: 'countryName', component: 'input', placeholder: '国家或二字码', width: '160px' },
{ label: '服务类型', prop: 'serviceType', component: 'input', placeholder: '服务类型', width: '140px' },
{ label: '销售产品', prop: 'productName', component: 'input', placeholder: '销售产品', width: '160px' },
{ label: '渠道', prop: 'channelName', component: 'input', placeholder: '渠道名称', width: '140px' },
{ label: '邮编属性', prop: 'coverage', component: 'select', options: coverageOptions, placeholder: '全部', width: '130px', props: { clearable: true } },
{ label: '邮编', prop: 'postcode', component: 'input', placeholder: '邮编', width: '140px' }
]
const columns = [
{ label: '国家', prop: 'countryName', minWidth: 120, showOverflowTooltip: true },
{ label: '邮编属性', prop: 'coverage', minWidth: 140, align: 'center', slot: 'coverage' },
{ label: '服务类型', prop: 'serviceType', minWidth: 120, showOverflowTooltip: true },
{ label: '销售产品', prop: 'productName', minWidth: 140, showOverflowTooltip: true },
{ label: '渠道名称', prop: 'channelName', minWidth: 140, showOverflowTooltip: true },
{ label: '分区数', prop: 'zoneCount', width: 90, align: 'center' },
{ label: '邮编总数', prop: 'lineCount', width: 100, align: 'center' },
{ label: '导入时间', prop: 'createTime', width: 170, align: 'center' },
{ label: '操作', prop: 'action', width: 200, align: 'center', fixed: 'right', slot: 'action', showInToolbar: false }
]
function queryList(params) {
return listPayPostcode(params)
}
function reload() {
tableRef.value?.refresh?.() || tableRef.value?.reload?.()
}
function onFile(uploadFile) {
file.value = uploadFile.raw
}
function submitImport() {
if (!file.value) {
proxy.$modal.msgWarning('请选择 xlsx 文件')
return
}
importing.value = true
importPayPostcode(file.value).then(res => {
proxy.$modal.msgSuccess(res.data?.message || res.msg || '导入完成')
open.value = false
file.value = null
reload()
}).finally(() => {
importing.value = false
})
}
function openZones(row) {
zoneDrawerRef.value.open(row)
}
function handleUpdate(row) {
form.value = {
countryCode: row.countryCode,
countryName: row.countryName,
serviceType: firstPart(row.serviceType),
productName: firstPart(row.productName),
channelName: row.channelName || ''
}
editOpen.value = true
}
function submitEdit() {
updatePayPostcodeCountry(form.value).then(() => {
proxy.$modal.msgSuccess('保存成功')
editOpen.value = false
reload()
})
}
function handleClear(row) {
const name = row.countryName || row.countryCode
proxy.$modal.confirm('清空「' + name + '」下的全部分区和邮编?计费将不再使用这些邮编。').then(() => {
return delPayPostcodeCountry({ countryCode: row.countryCode, countryName: row.countryName, allChannels: true })
}).then(() => {
proxy.$modal.msgSuccess('已清空')
reload()
}).catch(() => {})
}
</script>
<style scoped>
.mb16 { margin-bottom: 16px; }
.import-tip { margin: 0 0 12px; color: var(--el-text-color-secondary); line-height: 1.5; }
.cov-tag { margin: 0 4px 4px 0; }
</style>