增加删除功能
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
:search-columns="searchColumns"
|
||||
:query="queryList"
|
||||
row-key="productId"
|
||||
:selection="true"
|
||||
>
|
||||
<template #toolbar="{ selection }">
|
||||
<el-col :span="1.5">
|
||||
@@ -33,6 +34,16 @@
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
type="danger"
|
||||
plain
|
||||
icon="Delete"
|
||||
:disabled="!selection.length"
|
||||
@click="handleBatchDelete(selection)"
|
||||
v-hasPermi="['price:product:remove']"
|
||||
>批量删除</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button plain icon="Clock" @click="expiredRef.open()" v-hasPermi="['price:product:list']">失效价格</el-button>
|
||||
</el-col>
|
||||
@@ -152,9 +163,10 @@ import ProductExcelFileDrawer from './components/ProductExcelFileDrawer.vue'
|
||||
import ProductCountryDrawer from './components/ProductCountryDrawer.vue'
|
||||
import ProductSurchargeDrawer from './components/ProductSurchargeDrawer.vue'
|
||||
import ProductExpiredDrawer from './components/ProductExpiredDrawer.vue'
|
||||
import { listProduct, importProductExcelAsync, importProductCountryExcelAsync } from '@/api/price/product'
|
||||
import { listProduct, delProduct, importProductExcelAsync, importProductCountryExcelAsync } from '@/api/price/product'
|
||||
import { listRegionOptions } from '@/api/data/region'
|
||||
|
||||
const { proxy } = getCurrentInstance()
|
||||
const { bms_product_effect_status } = useDict('bms_product_effect_status')
|
||||
|
||||
const extraParams = { statusGroup: 'active' }
|
||||
@@ -225,11 +237,24 @@ const columns = [
|
||||
|
||||
const searchColumns = [
|
||||
{ prop: 'productCode', label: '产品代码', component: 'input', placeholder: '产品代码' },
|
||||
{ prop: 'productName', label: '产品名称', component: 'input', placeholder: '产品名称' }
|
||||
{ prop: 'productName', label: '产品名称', component: 'input', placeholder: '产品名称' },
|
||||
{
|
||||
prop: 'status',
|
||||
label: '状态',
|
||||
component: 'select',
|
||||
dict: 'bms_product_effect_status',
|
||||
placeholder: '请选择状态',
|
||||
width: '160px'
|
||||
}
|
||||
]
|
||||
|
||||
function queryList(params) {
|
||||
return listProduct(params)
|
||||
const p = { ...(params || {}) }
|
||||
// Exact status search must not be limited by default statusGroup=active.
|
||||
if (p.status != null && p.status !== '') {
|
||||
delete p.statusGroup
|
||||
}
|
||||
return listProduct(p)
|
||||
}
|
||||
|
||||
function handleAdd() {
|
||||
@@ -240,6 +265,48 @@ function handleUpdate(row) {
|
||||
formRef.value.open(row)
|
||||
}
|
||||
|
||||
function isPendingProduct(row) {
|
||||
if (!row) return false
|
||||
if (String(row.status) === '0') return true
|
||||
// fallback: effective in future and not expired
|
||||
if (!row.effectiveDate) return false
|
||||
const eff = new Date(String(row.effectiveDate).replace(/-/g, '/')).getTime()
|
||||
if (Number.isNaN(eff) || eff <= Date.now()) return false
|
||||
if (row.expireDate) {
|
||||
const exp = new Date(String(row.expireDate).replace(/-/g, '/')).getTime()
|
||||
if (!Number.isNaN(exp) && exp <= Date.now()) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function handleBatchDelete(selection) {
|
||||
const rows = (selection || []).filter(r => r && r.productId != null)
|
||||
if (!rows.length) {
|
||||
proxy.$modal.msgWarning('请先勾选产品')
|
||||
return
|
||||
}
|
||||
const pending = rows.filter(isPendingProduct)
|
||||
const blocked = rows.filter(r => !isPendingProduct(r))
|
||||
if (!pending.length) {
|
||||
proxy.$modal.msgWarning('仅待生效产品可删除,当前勾选无待生效记录')
|
||||
return
|
||||
}
|
||||
if (blocked.length) {
|
||||
const tip = blocked.map(r => r.productCode || r.productId).join('、')
|
||||
proxy.$modal.msgWarning('已跳过非待生效产品:' + tip)
|
||||
}
|
||||
const codes = pending.map(r => r.productCode || r.productId).join('、')
|
||||
const ids = pending.map(r => r.productId)
|
||||
proxy.$modal.confirm(
|
||||
'确认删除已选待生效产品(' + pending.length + '个):'
|
||||
+ codes
|
||||
+ '?删除后产品及国家/重量段明细将一并清除,且不可恢复。'
|
||||
).then(() => delProduct(ids)).then(() => {
|
||||
tableRef.value.refresh()
|
||||
proxy.$modal.msgSuccess('删除成功')
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
function handleImportCommand(command) {
|
||||
if (command === 'country') {
|
||||
handleCountryImport()
|
||||
|
||||
Reference in New Issue
Block a user