重构渠道选择对话框,优化添加渠道逻辑
This commit is contained in:
@@ -0,0 +1,189 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
v-model="visible"
|
||||||
|
title="选择渠道"
|
||||||
|
width="920px"
|
||||||
|
append-to-body
|
||||||
|
destroy-on-close
|
||||||
|
@opened="onOpened"
|
||||||
|
>
|
||||||
|
<div class="picker-bar">
|
||||||
|
<el-input
|
||||||
|
v-model="keyword"
|
||||||
|
clearable
|
||||||
|
placeholder="搜索渠道编码、渠道名称"
|
||||||
|
class="picker-search"
|
||||||
|
/>
|
||||||
|
<span class="picker-meta">共 {{ filteredRows.length }} 项,已选 {{ picked.length }} 项</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<el-table
|
||||||
|
ref="tableRef"
|
||||||
|
v-loading="loading"
|
||||||
|
:data="filteredRows"
|
||||||
|
row-key="id"
|
||||||
|
border
|
||||||
|
size="small"
|
||||||
|
max-height="420"
|
||||||
|
empty-text="暂无可选渠道"
|
||||||
|
@selection-change="onSelectionChange"
|
||||||
|
>
|
||||||
|
<el-table-column type="selection" width="46" :selectable="canSelect" />
|
||||||
|
<el-table-column prop="channelCode" label="渠道编码" min-width="140" show-overflow-tooltip />
|
||||||
|
<el-table-column prop="channelName" label="渠道名称" min-width="200" show-overflow-tooltip />
|
||||||
|
<el-table-column label="状态" width="90" align="center">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<el-tag v-if="String(row.blOpen) === '1'" size="small" type="success">启用</el-tag>
|
||||||
|
<el-tag v-else size="small" type="info">停用</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<div class="picker-hint">
|
||||||
|
绑定为收款(AR),落库 srv_channel_product_map;一个渠道同一收付类型仅保留一条产品映射。已绑定渠道不可重复勾选。
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #footer>
|
||||||
|
<el-button @click="visible = false">取 消</el-button>
|
||||||
|
<el-button type="primary" :disabled="!picked.length" @click="submit">确 定</el-button>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="LabelChannelPickerDialog">
|
||||||
|
import { listChannelOptions } from '@/api/masterdata/serviceChannel'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
modelValue: { type: Boolean, default: false },
|
||||||
|
/** 已绑定的渠道 id,用于禁用重复勾选 */
|
||||||
|
excludeChannelIds: { type: Array, default: () => [] }
|
||||||
|
})
|
||||||
|
const emit = defineEmits(['update:modelValue', 'confirm'])
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance()
|
||||||
|
const tableRef = ref()
|
||||||
|
const loading = ref(false)
|
||||||
|
const keyword = ref('')
|
||||||
|
const rows = ref([])
|
||||||
|
const pickedIds = ref(new Set())
|
||||||
|
const syncing = ref(false)
|
||||||
|
|
||||||
|
const visible = computed({
|
||||||
|
get: () => props.modelValue,
|
||||||
|
set: v => emit('update:modelValue', v)
|
||||||
|
})
|
||||||
|
|
||||||
|
const excludeSet = computed(() => new Set((props.excludeChannelIds || []).map(id => String(id))))
|
||||||
|
|
||||||
|
function canSelect(row) {
|
||||||
|
if (row?.id == null) return false
|
||||||
|
return !excludeSet.value.has(String(row.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
const filteredRows = computed(() => {
|
||||||
|
const text = String(keyword.value || '').trim().toLowerCase()
|
||||||
|
const list = rows.value || []
|
||||||
|
if (!text) return list
|
||||||
|
return list.filter(row => {
|
||||||
|
const bag = [row.channelCode, row.channelName, row.id]
|
||||||
|
.map(v => String(v ?? '').toLowerCase())
|
||||||
|
return bag.some(item => item.includes(text))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const picked = computed(() => {
|
||||||
|
const ids = pickedIds.value
|
||||||
|
return (rows.value || []).filter(row => row?.id != null && ids.has(String(row.id)) && canSelect(row))
|
||||||
|
})
|
||||||
|
|
||||||
|
function onSelectionChange(selection) {
|
||||||
|
if (syncing.value) return
|
||||||
|
const visibleIds = new Set((filteredRows.value || []).map(row => String(row.id)))
|
||||||
|
const next = new Set(pickedIds.value)
|
||||||
|
for (const id of visibleIds) {
|
||||||
|
next.delete(id)
|
||||||
|
}
|
||||||
|
for (const row of selection || []) {
|
||||||
|
if (row?.id != null && canSelect(row)) next.add(String(row.id))
|
||||||
|
}
|
||||||
|
pickedIds.value = next
|
||||||
|
}
|
||||||
|
|
||||||
|
function restoreSelection() {
|
||||||
|
const table = tableRef.value
|
||||||
|
if (!table) return
|
||||||
|
syncing.value = true
|
||||||
|
table.clearSelection()
|
||||||
|
for (const row of filteredRows.value || []) {
|
||||||
|
if (row?.id != null && pickedIds.value.has(String(row.id))) {
|
||||||
|
table.toggleRowSelection(row, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nextTick(() => {
|
||||||
|
syncing.value = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadRows() {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const res = await listChannelOptions({ blOpen: '1' })
|
||||||
|
rows.value = res.data || []
|
||||||
|
} catch (e) {
|
||||||
|
rows.value = []
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
nextTick(() => restoreSelection())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onOpened() {
|
||||||
|
keyword.value = ''
|
||||||
|
pickedIds.value = new Set()
|
||||||
|
nextTick(() => {
|
||||||
|
tableRef.value?.clearSelection?.()
|
||||||
|
})
|
||||||
|
loadRows()
|
||||||
|
}
|
||||||
|
|
||||||
|
function submit() {
|
||||||
|
const list = picked.value
|
||||||
|
if (!list.length) {
|
||||||
|
proxy.$modal.msgWarning('请先勾选要添加的渠道')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
emit('confirm', list)
|
||||||
|
visible.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(keyword, () => {
|
||||||
|
nextTick(() => restoreSelection())
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(() => props.modelValue, v => {
|
||||||
|
if (v && !rows.value.length) loadRows()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.picker-bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 12px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
.picker-search {
|
||||||
|
width: 320px;
|
||||||
|
}
|
||||||
|
.picker-meta {
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
.picker-hint {
|
||||||
|
margin-top: 10px;
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -73,46 +73,11 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
|
|
||||||
<el-dialog
|
<label-channel-picker-dialog
|
||||||
v-model="addVisible"
|
v-model="addVisible"
|
||||||
:title="addTitle"
|
:exclude-channel-ids="currentBoundIds()"
|
||||||
width="560px"
|
@confirm="onPickerConfirm"
|
||||||
append-to-body
|
/>
|
||||||
destroy-on-close
|
|
||||||
@closed="onAddClosed"
|
|
||||||
>
|
|
||||||
<div v-loading="addLoading">
|
|
||||||
<el-form label-width="88px">
|
|
||||||
<el-form-item :label="lblProduct">
|
|
||||||
<span>{{ bindProductName }}</span>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item :label="lblChannels">
|
|
||||||
<el-select
|
|
||||||
v-model="addChannelIds"
|
|
||||||
multiple
|
|
||||||
filterable
|
|
||||||
clearable
|
|
||||||
collapse-tags
|
|
||||||
collapse-tags-tooltip
|
|
||||||
:placeholder="phChannels"
|
|
||||||
style="width: 100%"
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="item in addableChannelOptions"
|
|
||||||
:key="item.id"
|
|
||||||
:label="channelOptionLabel(item)"
|
|
||||||
:value="String(item.id)"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<div class="bind-hint">{{ bindHint }}</div>
|
|
||||||
</el-form>
|
|
||||||
</div>
|
|
||||||
<template #footer>
|
|
||||||
<el-button @click="addVisible = false">取消</el-button>
|
|
||||||
<el-button type="primary" :loading="addSaving" @click="submitAddChannels">保存</el-button>
|
|
||||||
</template>
|
|
||||||
</el-dialog>
|
|
||||||
|
|
||||||
<el-drawer
|
<el-drawer
|
||||||
v-model="detailVisible"
|
v-model="detailVisible"
|
||||||
@@ -140,8 +105,8 @@ import {
|
|||||||
replaceLabelProductChannels,
|
replaceLabelProductChannels,
|
||||||
getLabelProduct
|
getLabelProduct
|
||||||
} from '@/api/price/label'
|
} from '@/api/price/label'
|
||||||
import { listChannelOptions } from '@/api/masterdata/serviceChannel'
|
|
||||||
import LabelConfigDetail from './LabelConfigDetail.vue'
|
import LabelConfigDetail from './LabelConfigDetail.vue'
|
||||||
|
import LabelChannelPickerDialog from './LabelChannelPickerDialog.vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
visible: { type: Boolean, default: false },
|
visible: { type: Boolean, default: false },
|
||||||
@@ -159,12 +124,9 @@ const bindListLoading = ref(false)
|
|||||||
const bindProductId = ref(null)
|
const bindProductId = ref(null)
|
||||||
const bindProductName = ref('')
|
const bindProductName = ref('')
|
||||||
const boundChannels = ref([])
|
const boundChannels = ref([])
|
||||||
const channelOptions = ref([])
|
|
||||||
|
|
||||||
const addVisible = ref(false)
|
const addVisible = ref(false)
|
||||||
const addLoading = ref(false)
|
|
||||||
const addSaving = ref(false)
|
const addSaving = ref(false)
|
||||||
const addChannelIds = ref([])
|
|
||||||
const detailVisible = ref(false)
|
const detailVisible = ref(false)
|
||||||
const detailLoading = ref(false)
|
const detailLoading = ref(false)
|
||||||
const detailProduct = ref(null)
|
const detailProduct = ref(null)
|
||||||
@@ -186,12 +148,7 @@ const colBoundChannels = '绑定渠道'
|
|||||||
const colAction = '操作'
|
const colAction = '操作'
|
||||||
const colChannelCode = '渠道编码'
|
const colChannelCode = '渠道编码'
|
||||||
const colChannelName = '渠道名称'
|
const colChannelName = '渠道名称'
|
||||||
const lblProduct = '产品'
|
|
||||||
const lblChannels = '添加渠道'
|
|
||||||
const phChannels = '请选择要添加的渠道(可多选)'
|
|
||||||
const bindHint = '绑定为收款(AR),落库 srv_channel_product_map;一个渠道同一收付类型仅保留一条产品映射。'
|
|
||||||
const emptyBound = '暂无绑定渠道'
|
const emptyBound = '暂无绑定渠道'
|
||||||
const addTitle = '添加渠道'
|
|
||||||
|
|
||||||
const title = computed(() => {
|
const title = computed(() => {
|
||||||
const v = props.version || {}
|
const v = props.version || {}
|
||||||
@@ -212,11 +169,6 @@ const filteredRows = computed(() => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const addableChannelOptions = computed(() => {
|
|
||||||
const bound = new Set((boundChannels.value || []).map(item => String(item.channelId)))
|
|
||||||
return (channelOptions.value || []).filter(item => item && item.id != null && !bound.has(String(item.id)))
|
|
||||||
})
|
|
||||||
|
|
||||||
function formatHour(val) {
|
function formatHour(val) {
|
||||||
if (!val) return ''
|
if (!val) return ''
|
||||||
const text = String(val).replace('T', ' ')
|
const text = String(val).replace('T', ' ')
|
||||||
@@ -269,12 +221,6 @@ async function load() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function ensureChannelOptions() {
|
|
||||||
if (channelOptions.value.length) return
|
|
||||||
const res = await listChannelOptions({ blOpen: '1' })
|
|
||||||
channelOptions.value = res.data || []
|
|
||||||
}
|
|
||||||
|
|
||||||
async function loadBoundChannels() {
|
async function loadBoundChannels() {
|
||||||
if (!bindProductId.value) {
|
if (!bindProductId.value) {
|
||||||
boundChannels.value = []
|
boundChannels.value = []
|
||||||
@@ -323,33 +269,21 @@ function onBindListClosed() {
|
|||||||
bindProductName.value = ''
|
bindProductName.value = ''
|
||||||
boundChannels.value = []
|
boundChannels.value = []
|
||||||
addVisible.value = false
|
addVisible.value = false
|
||||||
addChannelIds.value = []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function openAddChannels() {
|
async function openAddChannels() {
|
||||||
addChannelIds.value = []
|
|
||||||
addVisible.value = true
|
addVisible.value = true
|
||||||
addLoading.value = true
|
|
||||||
try {
|
|
||||||
await ensureChannelOptions()
|
|
||||||
} finally {
|
|
||||||
addLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onAddClosed() {
|
|
||||||
addChannelIds.value = []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function currentBoundIds() {
|
function currentBoundIds() {
|
||||||
return (boundChannels.value || []).map(item => String(item.channelId)).filter(Boolean)
|
return (boundChannels.value || []).map(item => String(item.channelId)).filter(Boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitAddChannels() {
|
function onPickerConfirm(list) {
|
||||||
if (!bindProductId.value) return
|
if (!bindProductId.value) return
|
||||||
const selected = (addChannelIds.value || []).map(String).filter(Boolean)
|
const selected = (list || []).map(item => String(item.id)).filter(Boolean)
|
||||||
if (!selected.length) {
|
if (!selected.length) {
|
||||||
proxy.$modal.msgWarning('请先选择要添加的渠道')
|
proxy.$modal.msgWarning('请先勾选要添加的渠道')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const merged = Array.from(new Set(currentBoundIds().concat(selected)))
|
const merged = Array.from(new Set(currentBoundIds().concat(selected)))
|
||||||
@@ -398,10 +332,4 @@ watch(() => [props.visible, props.priceSetId, props.version?.versionNo], ([vis])
|
|||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
}
|
}
|
||||||
.bind-hint {
|
|
||||||
margin: -4px 0 0 88px;
|
|
||||||
color: #909399;
|
|
||||||
font-size: 12px;
|
|
||||||
line-height: 1.5;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user