功能:新增业务基础资料页面
This commit is contained in:
@@ -126,6 +126,51 @@ const expectedReportExports = {
|
|||||||
'src/api/report/palletTrace.js': ['listPalletTrace']
|
'src/api/report/palletTrace.js': ['listPalletTrace']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const masterPageContracts = {
|
||||||
|
strain: {
|
||||||
|
relativePath: 'src/views/master/strain/index.vue',
|
||||||
|
apiNames: ['addStrain', 'delStrain', 'getStrain', 'listStrain', 'updateStrain'],
|
||||||
|
permissions: ['add', 'edit', 'list', 'query', 'remove'],
|
||||||
|
addPayloadKeys: ['remark', 'status', 'strainCode', 'strainName'],
|
||||||
|
editPayloadKeys: ['remark', 'status', 'strainCode', 'strainId', 'strainName']
|
||||||
|
},
|
||||||
|
customer: {
|
||||||
|
relativePath: 'src/views/master/customer/index.vue',
|
||||||
|
apiNames: ['addCustomer', 'delCustomer', 'getCustomer', 'listCustomer', 'updateCustomer'],
|
||||||
|
permissions: ['add', 'edit', 'list', 'query', 'remove'],
|
||||||
|
addPayloadKeys: ['customerCode', 'customerName', 'remark', 'status'],
|
||||||
|
editPayloadKeys: ['customerCode', 'customerId', 'customerName', 'remark', 'status']
|
||||||
|
},
|
||||||
|
site: {
|
||||||
|
relativePath: 'src/views/master/site/index.vue',
|
||||||
|
apiNames: ['addSite', 'delSite', 'getSite', 'listSite', 'updateSite'],
|
||||||
|
permissions: ['add', 'assign', 'edit', 'list', 'query', 'remove'],
|
||||||
|
addPayloadKeys: ['address', 'customerId', 'remark', 'siteCode', 'siteName', 'status'],
|
||||||
|
editPayloadKeys: ['address', 'customerId', 'remark', 'siteCode', 'siteId', 'siteName', 'status']
|
||||||
|
},
|
||||||
|
line: {
|
||||||
|
relativePath: 'src/views/master/line/index.vue',
|
||||||
|
apiNames: ['addLine', 'delLine', 'getLine', 'listLine', 'updateLine'],
|
||||||
|
permissions: ['add', 'edit', 'list', 'query', 'remove'],
|
||||||
|
addPayloadKeys: ['lineCode', 'lineName', 'remark', 'siteId', 'status'],
|
||||||
|
editPayloadKeys: ['lineCode', 'lineId', 'lineName', 'remark', 'siteId', 'status']
|
||||||
|
},
|
||||||
|
warehouse: {
|
||||||
|
relativePath: 'src/views/master/warehouse/index.vue',
|
||||||
|
apiNames: ['addWarehouse', 'delWarehouse', 'getWarehouse', 'listWarehouse', 'updateWarehouse'],
|
||||||
|
permissions: ['add', 'assign', 'edit', 'list', 'query', 'remove'],
|
||||||
|
addPayloadKeys: ['address', 'remark', 'status', 'warehouseCode', 'warehouseName'],
|
||||||
|
editPayloadKeys: ['address', 'remark', 'status', 'warehouseCode', 'warehouseId', 'warehouseName']
|
||||||
|
},
|
||||||
|
pallet: {
|
||||||
|
relativePath: 'src/views/master/pallet/index.vue',
|
||||||
|
apiNames: ['addPallet', 'delPallet', 'getPallet', 'getPalletQrcode', 'listPallet', 'updatePallet'],
|
||||||
|
permissions: ['add', 'edit', 'list', 'print', 'query', 'remove'],
|
||||||
|
addPayloadKeys: ['capacityPackages', 'palletCode', 'remark'],
|
||||||
|
editPayloadKeys: ['assetStatus', 'capacityPackages', 'palletId', 'remark']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const delimiterPairs = { '(': ')', '[': ']', '{': '}' }
|
const delimiterPairs = { '(': ')', '[': ']', '{': '}' }
|
||||||
|
|
||||||
function sanitizeSource(source) {
|
function sanitizeSource(source) {
|
||||||
@@ -301,6 +346,44 @@ function extractRequests(source) {
|
|||||||
return requests
|
return requests
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractImportedNames(source, modulePath) {
|
||||||
|
const escapedPath = modulePath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||||
|
const importMatch = new RegExp(`import\\s*{([^}]*)}\\s*from\\s*['"]${escapedPath}['"]`).exec(source)
|
||||||
|
assert.ok(importMatch, `缺少 ${modulePath} 的具名导入`)
|
||||||
|
return importMatch[1]
|
||||||
|
.split(',')
|
||||||
|
.map((name) => name.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
.sort()
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractCallObjectKeys(source, callName) {
|
||||||
|
const escapedCallName = callName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||||
|
const callMatch = new RegExp(`(?<![\\w$])${escapedCallName}\\s*\\(\\s*\\{([\\s\\S]*?)\\}\\s*\\)`).exec(source)
|
||||||
|
assert.ok(callMatch, `缺少 ${callName}({ ... }) 显式对象调用`)
|
||||||
|
|
||||||
|
const properties = callMatch[1].split(',').map((property) => property.trim()).filter(Boolean)
|
||||||
|
return properties.map((property) => {
|
||||||
|
const keyMatch = /^([A-Za-z_$][\w$]*)\s*:/.exec(property)
|
||||||
|
assert.ok(keyMatch, `${callName} payload 禁止展开、简写或动态属性`)
|
||||||
|
return keyMatch[1]
|
||||||
|
}).sort()
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractButtonBlocks(source, clickHandler) {
|
||||||
|
return [...source.matchAll(/<el-button\b[\s\S]*?<\/el-button>/g)]
|
||||||
|
.map((match) => match[0])
|
||||||
|
.filter((button) => button.includes(`@click="${clickHandler}`))
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertButtonsUsePermission(source, clickHandler, permission) {
|
||||||
|
const buttons = extractButtonBlocks(source, clickHandler)
|
||||||
|
assert.ok(buttons.length > 0, `缺少 ${clickHandler} 按钮`)
|
||||||
|
for (const button of buttons) {
|
||||||
|
assert.match(button, new RegExp(`v-hasPermi="\\['${permission}'\\]"`), `${clickHandler} 权限不精确`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function hasExpectedRequest(expectedRequest) {
|
function hasExpectedRequest(expectedRequest) {
|
||||||
return Object.values(expectedRequests).some((requests) =>
|
return Object.values(expectedRequests).some((requests) =>
|
||||||
requests.some((request) =>
|
requests.some((request) =>
|
||||||
@@ -475,3 +558,150 @@ test('扫码组件声明交互契约并保持触控尺寸', async () => {
|
|||||||
assert.match(source, /focus-within/)
|
assert.match(source, /focus-within/)
|
||||||
assert.doesNotMatch(source, /BarcodeDetector|camera|getUserMedia/i)
|
assert.doesNotMatch(source, /BarcodeDetector|camera|getUserMedia/i)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('六个基础资料页面逐页满足 API、权限、分页和安全删除契约', async (t) => {
|
||||||
|
for (const [resource, contract] of Object.entries(masterPageContracts)) {
|
||||||
|
await t.test(contract.relativePath, async () => {
|
||||||
|
const source = await readFile(path.join(frontendRoot, contract.relativePath), 'utf8')
|
||||||
|
const permissionPrefix = `master:${resource}`
|
||||||
|
const importedModules = [...source.matchAll(/from\s*['"]@\/api\/master\/([a-z]+)['"]/g)]
|
||||||
|
.map((match) => match[1])
|
||||||
|
|
||||||
|
assert.deepEqual(importedModules, [resource], `${resource} 页面不得跨调其他主数据 API`)
|
||||||
|
assert.deepEqual(extractImportedNames(source, `@/api/master/${resource}`), contract.apiNames)
|
||||||
|
|
||||||
|
const actualPermissions = [...new Set(
|
||||||
|
[...source.matchAll(new RegExp(`['"](${permissionPrefix}:[a-z]+)['"]`, 'g'))]
|
||||||
|
.map((match) => match[1].slice(permissionPrefix.length + 1))
|
||||||
|
)].sort()
|
||||||
|
assert.deepEqual(actualPermissions, contract.permissions, `${resource} 页面权限集合不精确`)
|
||||||
|
|
||||||
|
assertButtonsUsePermission(source, 'handleQuery', `${permissionPrefix}:list`)
|
||||||
|
assertButtonsUsePermission(source, 'resetQuery', `${permissionPrefix}:list`)
|
||||||
|
assertButtonsUsePermission(source, 'handleAdd', `${permissionPrefix}:add`)
|
||||||
|
assertButtonsUsePermission(source, 'submitCreate', `${permissionPrefix}:add`)
|
||||||
|
assertButtonsUsePermission(source, 'handleUpdate', `${permissionPrefix}:edit`)
|
||||||
|
assertButtonsUsePermission(source, 'submitUpdate', `${permissionPrefix}:edit`)
|
||||||
|
assertButtonsUsePermission(source, 'handleDelete', `${permissionPrefix}:remove`)
|
||||||
|
|
||||||
|
for (const button of extractButtonBlocks(source, 'handleUpdate')) {
|
||||||
|
assert.match(
|
||||||
|
button,
|
||||||
|
new RegExp(`v-if="proxy\\.\\$auth\\.hasPermiAnd\\(\\['${permissionPrefix}:query', '${permissionPrefix}:edit'\\]\\)"`),
|
||||||
|
`${resource} 修改按钮必须同时校验 query 与 edit`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.match(source, /proxy\.useDict\(['"]sys_normal_disable['"]\)/)
|
||||||
|
assert.match(source, /<dict-tag\s+:options="sys_normal_disable"/)
|
||||||
|
assert.match(source, /\.value\s*=\s*response\.rows/)
|
||||||
|
assert.match(source, /total\.value\s*=\s*response\.total/)
|
||||||
|
assert.match(source, /const detail\s*=\s*response\.data/)
|
||||||
|
assert.match(source, /function handleQuery\(\)\s*{[\s\S]*?queryParams\.value\.pageNum\s*=\s*1[\s\S]*?getList\(\)/)
|
||||||
|
assert.match(source, /function resetQuery\(\)\s*{[\s\S]*?resetForm\(['"]queryRef['"]\)[\s\S]*?handleQuery\(\)/)
|
||||||
|
assert.match(source, /<pagination\b[\s\S]*?v-model:page="queryParams\.pageNum"[\s\S]*?v-model:limit="queryParams\.pageSize"[\s\S]*?@pagination="getList"/)
|
||||||
|
assert.match(source, /<el-table\b[^>]*v-loading="loading"[^>]*empty-text="暂无数据"/)
|
||||||
|
assert.match(source, /<el-alert\b[^>]*v-if="loadError"/)
|
||||||
|
assert.match(source, /<el-alert\b[^>]*v-if="formError"/)
|
||||||
|
assert.match(source, /const formError = ref\(['"]['"]\)/)
|
||||||
|
assert.doesNotMatch(source, /\.catch\(\(\) => \{\}\)/, `${resource} 页面禁止空 catch`)
|
||||||
|
assert.doesNotMatch(source, />\s*(?:导入|导出)\s*<\/el-button>/)
|
||||||
|
assert.doesNotMatch(source, /\bhandle(?:Import|Export)\b|proxy\.download\(/)
|
||||||
|
|
||||||
|
assert.match(source, /<el-table-column\b[^>]*type="selection"[^>]*:selectable="isRowSelectable"/)
|
||||||
|
assert.match(source, /function isRowSelectable\(row\)\s*{\s*return row\.canRemove === true;?\s*}/)
|
||||||
|
assert.match(source, /ids\.value\s*=\s*selection\s*\.filter\(\(item\) => item\.canRemove === true\)/)
|
||||||
|
const rowDeleteButtons = extractButtonBlocks(source, 'handleDelete')
|
||||||
|
.filter((button) => button.includes('handleDelete(scope.row)'))
|
||||||
|
assert.ok(rowDeleteButtons.length > 0, `${resource} 缺少行删除按钮`)
|
||||||
|
for (const button of rowDeleteButtons) {
|
||||||
|
assert.match(button, /v-if="scope\.row\.canRemove === true"/)
|
||||||
|
}
|
||||||
|
|
||||||
|
const suffix = resource[0].toUpperCase() + resource.slice(1)
|
||||||
|
assert.deepEqual(extractCallObjectKeys(source, `add${suffix}`), contract.addPayloadKeys)
|
||||||
|
assert.deepEqual(extractCallObjectKeys(source, `update${suffix}`), contract.editPayloadKeys)
|
||||||
|
|
||||||
|
assert.match(source, /validator:\s*validateRequiredText/)
|
||||||
|
assert.match(source, /maxlength="500"/)
|
||||||
|
if (resource !== 'pallet') {
|
||||||
|
assert.match(source, /maxlength="64"/)
|
||||||
|
assert.match(source, /maxlength="100"/)
|
||||||
|
}
|
||||||
|
if (resource === 'site' || resource === 'line' || resource === 'pallet') {
|
||||||
|
assert.match(source, /validator:\s*validatePositiveInteger/)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resource === 'site' || resource === 'warehouse') {
|
||||||
|
assertButtonsUsePermission(source, 'handleAssign', `${permissionPrefix}:assign`)
|
||||||
|
assert.match(source, /import BusinessUserAssignDialog from ['"]@\/components\/BusinessUserAssignDialog['"]/)
|
||||||
|
assert.match(source, /<business-user-assign-dialog\s+ref="assignDialogRef"\s+@ok="getList"\s*\/>/)
|
||||||
|
assert.match(
|
||||||
|
source,
|
||||||
|
new RegExp(`assignDialogRef\\.value\\.show\\(\\{[\\s\\S]*?resourceType: ['"]${resource}['"][\\s\\S]*?resourceId: row\\.${resource}Id[\\s\\S]*?resourceName: row\\.${resource}Name[\\s\\S]*?}\\)`)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resource === 'pallet') {
|
||||||
|
assertButtonsUsePermission(source, 'handlePrint', 'master:pallet:print')
|
||||||
|
const printHandler = source.slice(source.indexOf('function handlePrint'))
|
||||||
|
assert.match(printHandler, /const printWindow = window\.open\('', '_blank'\)/)
|
||||||
|
assert.ok(
|
||||||
|
printHandler.indexOf("window.open('', '_blank')") < printHandler.indexOf('getPalletQrcode('),
|
||||||
|
'打印窗口必须在异步二维码请求前同步打开'
|
||||||
|
)
|
||||||
|
assert.match(printHandler, /getPalletQrcode\(row\.palletId\)/)
|
||||||
|
assert.match(printHandler, /instanceof Blob/)
|
||||||
|
assert.match(printHandler, /URL\.createObjectURL\(/)
|
||||||
|
assert.match(printHandler, /URL\.revokeObjectURL\(/)
|
||||||
|
assert.match(printHandler, /document\.createElement\(['"](?:h1|img|style)['"]\)/)
|
||||||
|
assert.match(printHandler, /\.textContent\s*=/)
|
||||||
|
assert.match(printHandler, /['"]load['"][\s\S]*?printWindow\.print\(\)/)
|
||||||
|
assert.match(printHandler, /['"]afterprint['"][\s\S]*?URL\.revokeObjectURL/)
|
||||||
|
assert.doesNotMatch(printHandler, /document\.write|innerHTML|BarcodeDetector|getUserMedia|camera/i)
|
||||||
|
assert.match(source, /v-if="isEdit"[\s\S]*?v-model="form\.palletCode"[\s\S]*?readonly/)
|
||||||
|
assert.match(source, /v-if="isEdit"[\s\S]*?v-model="form\.qrToken"[\s\S]*?readonly/)
|
||||||
|
assert.doesNotMatch(contract.editPayloadKeys.join(','), /palletCode|qrToken/)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
test('业务用户分配组件使用固定映射并允许空数组完整替换', async () => {
|
||||||
|
const relativePath = 'src/components/BusinessUserAssignDialog/index.vue'
|
||||||
|
const source = await readFile(path.join(frontendRoot, relativePath), 'utf8')
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
extractImportedNames(source, '@/api/master/site'),
|
||||||
|
['assignSiteUsers', 'getSiteUsers']
|
||||||
|
)
|
||||||
|
assert.deepEqual(
|
||||||
|
extractImportedNames(source, '@/api/master/warehouse'),
|
||||||
|
['assignWarehouseUsers', 'getWarehouseUsers']
|
||||||
|
)
|
||||||
|
assert.match(source, /const resourceApiMap = Object\.freeze\(\{[\s\S]*?site:\s*Object\.freeze\(\{\s*getUsers:\s*getSiteUsers,\s*assignUsers:\s*assignSiteUsers\s*}\)[\s\S]*?warehouse:\s*Object\.freeze\(\{\s*getUsers:\s*getWarehouseUsers,\s*assignUsers:\s*assignWarehouseUsers\s*}\)[\s\S]*?}\)/)
|
||||||
|
assert.doesNotMatch(source, /defineProps\(/)
|
||||||
|
assert.match(source, /function show\(\{ resourceType, resourceId, resourceName }\)/)
|
||||||
|
assert.match(source, /response\.data/)
|
||||||
|
assert.match(source, /userId:\s*row\.userId,\s*userName:\s*row\.userName,\s*nickName:\s*row\.nickName,\s*assigned:\s*row\.assigned === true/)
|
||||||
|
assert.doesNotMatch(source, /\.\.\.row|email:\s*row\.|phonenumber:\s*row\.|status:\s*row\./)
|
||||||
|
assert.match(source, /filteredUsers\s*=\s*computed\([\s\S]*?user\.userName[\s\S]*?user\.nickName/)
|
||||||
|
assert.match(source, /nextTick\([\s\S]*?toggleRowSelection\(row, selectedUserIds\.value\.includes\(row\.userId\)\)/)
|
||||||
|
assert.match(source, /@row-click="handleRowClick"/)
|
||||||
|
assert.match(source, /const userIds = \[\.\.\.new Set\(selectedUserIds\.value\.filter\(\(userId\) => Number\.isInteger\(userId\) && userId > 0\)\)\]/)
|
||||||
|
assert.match(source, /assignUsers\(resourceId\.value, \{ userIds }\)/)
|
||||||
|
assert.doesNotMatch(source, /请选择要分配的用户|userIds\.length\s*===?\s*0/)
|
||||||
|
assert.match(source, /:loading="submitLoading"/)
|
||||||
|
assert.match(source, /const loadFailed = ref\(false\)/)
|
||||||
|
assert.match(source, /:disabled="loading \|\| submitLoading \|\| loadFailed"/)
|
||||||
|
assert.doesNotMatch(source, /\.catch\(\(\) => \{\}\)/, '分配组件禁止空 catch')
|
||||||
|
const submitButtons = extractButtonBlocks(source, 'submitAssignment')
|
||||||
|
const submitPermissions = submitButtons.flatMap((button) =>
|
||||||
|
[...button.matchAll(/v-hasPermi="\['(master:(?:site|warehouse):assign)'\]"/g)].map((match) => match[1])
|
||||||
|
).sort()
|
||||||
|
assert.deepEqual(submitPermissions, ['master:site:assign', 'master:warehouse:assign'])
|
||||||
|
assert.match(source, /proxy\.\$modal\.msgSuccess\(response\.msg \|\| ['"]分配成功['"]\)/)
|
||||||
|
assert.match(source, /visible\.value = false[\s\S]*?emit\(['"]ok['"]\)/)
|
||||||
|
assert.match(source, /<el-alert\b[^>]*v-if="loadError"/)
|
||||||
|
assert.match(source, /width="min\(720px, 92vw\)"/)
|
||||||
|
})
|
||||||
|
|||||||
@@ -0,0 +1,259 @@
|
|||||||
|
<template>
|
||||||
|
<el-dialog
|
||||||
|
v-model="visible"
|
||||||
|
:title="dialogTitle"
|
||||||
|
width="min(720px, 92vw)"
|
||||||
|
top="6vh"
|
||||||
|
append-to-body
|
||||||
|
destroy-on-close
|
||||||
|
@closed="resetDialogState"
|
||||||
|
>
|
||||||
|
<el-form :inline="true" class="assign-search" @submit.prevent>
|
||||||
|
<el-form-item label="用户搜索">
|
||||||
|
<el-input
|
||||||
|
v-model="keyword"
|
||||||
|
class="assign-search__input"
|
||||||
|
placeholder="请输入账号或昵称"
|
||||||
|
clearable
|
||||||
|
:disabled="loading || submitLoading || loadFailed"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<el-alert
|
||||||
|
v-if="loadError"
|
||||||
|
:title="loadError"
|
||||||
|
type="error"
|
||||||
|
:closable="false"
|
||||||
|
show-icon
|
||||||
|
class="mb8"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<el-table
|
||||||
|
ref="userTableRef"
|
||||||
|
v-loading="loading"
|
||||||
|
:data="filteredUsers"
|
||||||
|
row-key="userId"
|
||||||
|
height="360"
|
||||||
|
empty-text="暂无可分配用户"
|
||||||
|
@row-click="handleRowClick"
|
||||||
|
@selection-change="handleSelectionChange"
|
||||||
|
>
|
||||||
|
<el-table-column type="selection" width="55" :reserve-selection="true" />
|
||||||
|
<el-table-column label="用户账号" prop="userName" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="用户昵称" prop="nickName" :show-overflow-tooltip="true">
|
||||||
|
<template #default="scope">
|
||||||
|
<span>{{ scope.row.nickName || "-" }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="当前状态" width="100" align="center">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-tag :type="scope.row.assigned ? 'success' : 'info'">
|
||||||
|
{{ scope.row.assigned ? "已分配" : "未分配" }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button :disabled="submitLoading" @click="visible = false">取 消</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="resourceType === 'site'"
|
||||||
|
type="primary"
|
||||||
|
:loading="submitLoading"
|
||||||
|
:disabled="loading || submitLoading || loadFailed"
|
||||||
|
@click="submitAssignment"
|
||||||
|
v-hasPermi="['master:site:assign']"
|
||||||
|
>确 定</el-button>
|
||||||
|
<el-button
|
||||||
|
v-else-if="resourceType === 'warehouse'"
|
||||||
|
type="primary"
|
||||||
|
:loading="submitLoading"
|
||||||
|
:disabled="loading || submitLoading || loadFailed"
|
||||||
|
@click="submitAssignment"
|
||||||
|
v-hasPermi="['master:warehouse:assign']"
|
||||||
|
>确 定</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="BusinessUserAssignDialog">
|
||||||
|
import { assignSiteUsers, getSiteUsers } from "@/api/master/site";
|
||||||
|
import { assignWarehouseUsers, getWarehouseUsers } from "@/api/master/warehouse";
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance();
|
||||||
|
const emit = defineEmits(["ok"]);
|
||||||
|
|
||||||
|
const resourceApiMap = Object.freeze({
|
||||||
|
site: Object.freeze({ getUsers: getSiteUsers, assignUsers: assignSiteUsers }),
|
||||||
|
warehouse: Object.freeze({ getUsers: getWarehouseUsers, assignUsers: assignWarehouseUsers })
|
||||||
|
});
|
||||||
|
|
||||||
|
const visible = ref(false);
|
||||||
|
const loading = ref(false);
|
||||||
|
const loadFailed = ref(false);
|
||||||
|
const submitLoading = ref(false);
|
||||||
|
const loadError = ref("");
|
||||||
|
const keyword = ref("");
|
||||||
|
const resourceType = ref("");
|
||||||
|
const resourceId = ref();
|
||||||
|
const resourceName = ref("");
|
||||||
|
const users = ref([]);
|
||||||
|
const selectedUserIds = ref([]);
|
||||||
|
const userTableRef = ref();
|
||||||
|
const restoringSelection = ref(false);
|
||||||
|
|
||||||
|
const dialogTitle = computed(() => {
|
||||||
|
const label = resourceType.value === "site" ? "客户现场" : "仓库";
|
||||||
|
return `分配${label}用户${resourceName.value ? ` - ${resourceName.value}` : ""}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
const filteredUsers = computed(() => {
|
||||||
|
const normalizedKeyword = keyword.value.trim().toLowerCase();
|
||||||
|
if (!normalizedKeyword) {
|
||||||
|
return users.value;
|
||||||
|
}
|
||||||
|
return users.value.filter((user) =>
|
||||||
|
user.userName.toLowerCase().includes(normalizedKeyword)
|
||||||
|
|| (user.nickName || "").toLowerCase().includes(normalizedKeyword)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
function normalizeUserRows(rows) {
|
||||||
|
return rows
|
||||||
|
.filter((row) => Number.isInteger(row.userId) && row.userId > 0 && typeof row.userName === "string")
|
||||||
|
.map((row) => ({
|
||||||
|
userId: row.userId,
|
||||||
|
userName: row.userName,
|
||||||
|
nickName: row.nickName,
|
||||||
|
assigned: row.assigned === true
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
function restoreSelection() {
|
||||||
|
nextTick(() => {
|
||||||
|
restoringSelection.value = true;
|
||||||
|
userTableRef.value?.clearSelection();
|
||||||
|
filteredUsers.value.forEach((row) => {
|
||||||
|
userTableRef.value?.toggleRowSelection(row, selectedUserIds.value.includes(row.userId));
|
||||||
|
});
|
||||||
|
nextTick(() => {
|
||||||
|
restoringSelection.value = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSelectionChange(selection) {
|
||||||
|
if (restoringSelection.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const visibleIds = new Set(filteredUsers.value.map((user) => user.userId));
|
||||||
|
const hiddenSelectedIds = selectedUserIds.value.filter((userId) => !visibleIds.has(userId));
|
||||||
|
selectedUserIds.value = [...new Set([
|
||||||
|
...hiddenSelectedIds,
|
||||||
|
...selection.map((user) => user.userId)
|
||||||
|
])];
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleRowClick(row, column) {
|
||||||
|
if (column?.type === "selection" || loading.value || submitLoading.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const selectedIds = new Set(selectedUserIds.value);
|
||||||
|
if (selectedIds.has(row.userId)) {
|
||||||
|
selectedIds.delete(row.userId);
|
||||||
|
} else {
|
||||||
|
selectedIds.add(row.userId);
|
||||||
|
}
|
||||||
|
selectedUserIds.value = [...selectedIds];
|
||||||
|
restoreSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadUsers() {
|
||||||
|
const resourceApi = resourceApiMap[resourceType.value];
|
||||||
|
loading.value = true;
|
||||||
|
loadFailed.value = false;
|
||||||
|
loadError.value = "";
|
||||||
|
resourceApi.getUsers(resourceId.value).then((response) => {
|
||||||
|
const rows = Array.isArray(response.data) ? response.data : [];
|
||||||
|
users.value = normalizeUserRows(rows);
|
||||||
|
selectedUserIds.value = users.value
|
||||||
|
.filter((user) => user.assigned === true)
|
||||||
|
.map((user) => user.userId);
|
||||||
|
restoreSelection();
|
||||||
|
}).catch(() => {
|
||||||
|
users.value = [];
|
||||||
|
selectedUserIds.value = [];
|
||||||
|
loadError.value = "用户列表加载失败,请稍后重试";
|
||||||
|
loadFailed.value = true;
|
||||||
|
}).finally(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetDialogState() {
|
||||||
|
loadError.value = "";
|
||||||
|
keyword.value = "";
|
||||||
|
resourceType.value = "";
|
||||||
|
resourceId.value = undefined;
|
||||||
|
resourceName.value = "";
|
||||||
|
users.value = [];
|
||||||
|
selectedUserIds.value = [];
|
||||||
|
restoringSelection.value = false;
|
||||||
|
loadFailed.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function show({ resourceType, resourceId, resourceName }) {
|
||||||
|
openDialog(resourceType, resourceId, resourceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
function openDialog(nextResourceType, nextResourceId, nextResourceName) {
|
||||||
|
const normalizedId = Number(nextResourceId);
|
||||||
|
if (!resourceApiMap[nextResourceType] || !Number.isInteger(normalizedId) || normalizedId <= 0) {
|
||||||
|
proxy.$modal.msgError("分配对象无效");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resetDialogState();
|
||||||
|
resourceType.value = nextResourceType;
|
||||||
|
resourceId.value = normalizedId;
|
||||||
|
resourceName.value = nextResourceName || "";
|
||||||
|
visible.value = true;
|
||||||
|
loadUsers();
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitAssignment() {
|
||||||
|
const resourceApi = resourceApiMap[resourceType.value];
|
||||||
|
const userIds = [...new Set(selectedUserIds.value.filter((userId) => Number.isInteger(userId) && userId > 0))];
|
||||||
|
loadError.value = "";
|
||||||
|
submitLoading.value = true;
|
||||||
|
resourceApi.assignUsers(resourceId.value, { userIds }).then((response) => {
|
||||||
|
proxy.$modal.msgSuccess(response.msg || "分配成功");
|
||||||
|
visible.value = false;
|
||||||
|
emit("ok");
|
||||||
|
}).catch(() => {
|
||||||
|
loadError.value = "用户分配失败,请根据提示重试";
|
||||||
|
}).finally(() => {
|
||||||
|
submitLoading.value = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(keyword, restoreSelection);
|
||||||
|
|
||||||
|
defineExpose({ show });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.assign-search__input {
|
||||||
|
width: 260px;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.assign-search :deep(.el-form-item),
|
||||||
|
.assign-search__input {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,230 @@
|
|||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<el-form ref="queryRef" :model="queryParams" :inline="true">
|
||||||
|
<el-form-item label="客户编码" prop="customerCode">
|
||||||
|
<el-input v-model="queryParams.customerCode" placeholder="请输入客户编码" clearable maxlength="64" @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="客户名称" prop="customerName">
|
||||||
|
<el-input v-model="queryParams.customerName" placeholder="请输入客户名称" clearable maxlength="100" @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable style="width: 160px">
|
||||||
|
<el-option v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="Search" @click="handleQuery" v-hasPermi="['master:customer:list']">搜索</el-button>
|
||||||
|
<el-button icon="Refresh" @click="resetQuery" v-hasPermi="['master:customer:list']">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5"><el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['master:customer:add']">新增</el-button></el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button
|
||||||
|
v-if="proxy.$auth.hasPermiAnd(['master:customer:query', 'master:customer:edit'])"
|
||||||
|
type="success" plain icon="Edit" :disabled="single || detailLoading" :loading="detailLoading"
|
||||||
|
@click="handleUpdate()" v-hasPermi="['master:customer:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5"><el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['master:customer:remove']">删除</el-button></el-col>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
<el-alert v-if="loadError" :title="loadError" type="error" :closable="false" show-icon class="mb8" />
|
||||||
|
<el-table v-loading="loading" empty-text="暂无数据" :data="customerList" @selection-change="handleSelectionChange">
|
||||||
|
<el-table-column type="selection" :selectable="isRowSelectable" width="55" align="center" />
|
||||||
|
<el-table-column label="客户ID" prop="customerId" align="center" />
|
||||||
|
<el-table-column label="客户编码" prop="customerCode" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="客户名称" prop="customerName" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="状态" prop="status" align="center" width="100">
|
||||||
|
<template #default="scope"><dict-tag :options="sys_normal_disable" :value="scope.row.status" /></template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="创建时间" prop="createTime" align="center" width="180">
|
||||||
|
<template #default="scope"><span>{{ parseTime(scope.row.createTime) }}</span></template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button
|
||||||
|
v-if="proxy.$auth.hasPermiAnd(['master:customer:query', 'master:customer:edit'])"
|
||||||
|
link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['master:customer:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="scope.row.canRemove === true"
|
||||||
|
link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['master:customer:remove']"
|
||||||
|
>删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<pagination
|
||||||
|
v-show="total > 0" :total="total"
|
||||||
|
v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<el-dialog v-model="open" :title="title" width="min(520px, 92vw)" append-to-body>
|
||||||
|
<el-alert v-if="formError" :title="formError" type="error" :closable="false" show-icon class="mb8" />
|
||||||
|
<el-form ref="customerRef" :model="form" :rules="rules" label-width="90px">
|
||||||
|
<el-form-item label="客户编码" prop="customerCode">
|
||||||
|
<el-input v-model="form.customerCode" placeholder="请输入客户编码" maxlength="64" show-word-limit />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="客户名称" prop="customerName">
|
||||||
|
<el-input v-model="form.customerName" placeholder="请输入客户名称" maxlength="100" show-word-limit />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-radio-group v-model="form.status">
|
||||||
|
<el-radio v-for="dict in sys_normal_disable" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="备注" prop="remark">
|
||||||
|
<el-input v-model="form.remark" type="textarea" :rows="3" maxlength="500" show-word-limit placeholder="请输入备注" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button v-if="!form.customerId" type="primary" :loading="submitLoading" @click="submitCreate" v-hasPermi="['master:customer:add']">确 定</el-button>
|
||||||
|
<el-button v-else type="primary" :loading="submitLoading" @click="submitUpdate" v-hasPermi="['master:customer:edit']">确 定</el-button>
|
||||||
|
<el-button :disabled="submitLoading" @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="Customer">
|
||||||
|
import { addCustomer, delCustomer, getCustomer, listCustomer, updateCustomer } from "@/api/master/customer";
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance();
|
||||||
|
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
|
||||||
|
const customerList = ref([]);
|
||||||
|
const ids = ref([]);
|
||||||
|
const loading = ref(false);
|
||||||
|
const detailLoading = ref(false);
|
||||||
|
const submitLoading = ref(false);
|
||||||
|
const loadError = ref("");
|
||||||
|
const formError = ref("");
|
||||||
|
const open = ref(false);
|
||||||
|
const single = ref(true);
|
||||||
|
const multiple = ref(true);
|
||||||
|
const total = ref(0);
|
||||||
|
const title = ref("");
|
||||||
|
|
||||||
|
function validateRequiredText(rule, value, callback) {
|
||||||
|
if (typeof value !== "string" || value.trim() === "") {
|
||||||
|
callback(new Error(`${rule.field === "customerCode" ? "客户编码" : "客户名称"}不能为空`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = reactive({
|
||||||
|
form: {},
|
||||||
|
queryParams: { pageNum: 1, pageSize: 10, customerCode: undefined, customerName: undefined, status: undefined },
|
||||||
|
rules: {
|
||||||
|
customerCode: [{ required: true, validator: validateRequiredText, trigger: "blur" }],
|
||||||
|
customerName: [{ required: true, validator: validateRequiredText, trigger: "blur" }],
|
||||||
|
status: [{ required: true, message: "请选择状态", trigger: "change" }]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const { form, queryParams, rules } = toRefs(data);
|
||||||
|
|
||||||
|
function getList() {
|
||||||
|
loading.value = true;
|
||||||
|
loadError.value = "";
|
||||||
|
listCustomer(queryParams.value).then((response) => {
|
||||||
|
customerList.value = response.rows;
|
||||||
|
total.value = response.total;
|
||||||
|
}).catch(() => {
|
||||||
|
customerList.value = [];
|
||||||
|
total.value = 0;
|
||||||
|
loadError.value = "客户列表加载失败,请稍后重试";
|
||||||
|
}).finally(() => { loading.value = false; });
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
formError.value = "";
|
||||||
|
form.value = { customerId: undefined, customerCode: "", customerName: "", status: "0", remark: "" };
|
||||||
|
proxy.resetForm("customerRef");
|
||||||
|
}
|
||||||
|
function cancel() { open.value = false; reset(); }
|
||||||
|
function handleQuery() { queryParams.value.pageNum = 1; getList(); }
|
||||||
|
function resetQuery() { proxy.resetForm("queryRef"); handleQuery(); }
|
||||||
|
function isRowSelectable(row) {
|
||||||
|
return row.canRemove === true;
|
||||||
|
}
|
||||||
|
function handleSelectionChange(selection) {
|
||||||
|
ids.value = selection
|
||||||
|
.filter((item) => item.canRemove === true)
|
||||||
|
.map((item) => item.customerId);
|
||||||
|
single.value = ids.value.length !== 1;
|
||||||
|
multiple.value = ids.value.length === 0;
|
||||||
|
}
|
||||||
|
function handleAdd() { reset(); title.value = "新增客户"; open.value = true; }
|
||||||
|
|
||||||
|
function handleUpdate(row = {}) {
|
||||||
|
reset();
|
||||||
|
const customerId = row.customerId || ids.value[0];
|
||||||
|
detailLoading.value = true;
|
||||||
|
getCustomer(customerId).then((response) => {
|
||||||
|
const detail = response.data;
|
||||||
|
form.value = {
|
||||||
|
customerId: detail.customerId,
|
||||||
|
customerCode: detail.customerCode,
|
||||||
|
customerName: detail.customerName,
|
||||||
|
status: detail.status,
|
||||||
|
remark: detail.remark || ""
|
||||||
|
};
|
||||||
|
title.value = "修改客户";
|
||||||
|
open.value = true;
|
||||||
|
}).catch(() => {
|
||||||
|
loadError.value = "客户详情加载失败,请稍后重试";
|
||||||
|
}).finally(() => { detailLoading.value = false; });
|
||||||
|
}
|
||||||
|
|
||||||
|
function afterSubmit(response) {
|
||||||
|
proxy.$modal.msgSuccess(response.msg || "操作成功");
|
||||||
|
open.value = false;
|
||||||
|
getList();
|
||||||
|
}
|
||||||
|
function submitCreate() {
|
||||||
|
proxy.$refs.customerRef.validate((valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
submitLoading.value = true;
|
||||||
|
formError.value = "";
|
||||||
|
addCustomer({
|
||||||
|
customerCode: form.value.customerCode.trim(),
|
||||||
|
customerName: form.value.customerName.trim(),
|
||||||
|
status: form.value.status,
|
||||||
|
remark: form.value.remark?.trim() || undefined
|
||||||
|
}).then(afterSubmit).catch(() => {
|
||||||
|
formError.value = "新增失败,请根据提示修正后重试";
|
||||||
|
}).finally(() => { submitLoading.value = false; });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function submitUpdate() {
|
||||||
|
proxy.$refs.customerRef.validate((valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
submitLoading.value = true;
|
||||||
|
formError.value = "";
|
||||||
|
updateCustomer({
|
||||||
|
customerId: form.value.customerId,
|
||||||
|
customerCode: form.value.customerCode.trim(),
|
||||||
|
customerName: form.value.customerName.trim(),
|
||||||
|
status: form.value.status,
|
||||||
|
remark: form.value.remark?.trim() || undefined
|
||||||
|
}).then(afterSubmit).catch(() => {
|
||||||
|
formError.value = "修改失败,请根据提示修正后重试";
|
||||||
|
}).finally(() => { submitLoading.value = false; });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function handleDelete(row) {
|
||||||
|
const targetIds = row?.customerId ? (row.canRemove === true ? [row.customerId] : []) : ids.value;
|
||||||
|
if (!targetIds.length) { proxy.$modal.msgWarning("请选择允许删除的客户"); return; }
|
||||||
|
proxy.$modal.confirm(`是否确认删除客户编号为“${targetIds.join(",")}”的数据项?`).then(() =>
|
||||||
|
delCustomer(targetIds.join(","))
|
||||||
|
).then(() => { proxy.$modal.msgSuccess("删除成功"); getList(); }).catch((error) => {
|
||||||
|
if (error !== "cancel" && error !== "close") loadError.value = "客户删除失败,请稍后重试";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getList();
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,246 @@
|
|||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<el-form ref="queryRef" :model="queryParams" :inline="true">
|
||||||
|
<el-form-item label="现场ID" prop="siteId">
|
||||||
|
<el-input-number v-model="queryParams.siteId" :min="1" :step="1" step-strictly controls-position="right" placeholder="请输入现场ID" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="产线编码" prop="lineCode">
|
||||||
|
<el-input v-model="queryParams.lineCode" placeholder="请输入产线编码" clearable maxlength="64" @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="产线名称" prop="lineName">
|
||||||
|
<el-input v-model="queryParams.lineName" placeholder="请输入产线名称" clearable maxlength="100" @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable style="width: 160px">
|
||||||
|
<el-option v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="Search" @click="handleQuery" v-hasPermi="['master:line:list']">搜索</el-button>
|
||||||
|
<el-button icon="Refresh" @click="resetQuery" v-hasPermi="['master:line:list']">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5"><el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['master:line:add']">新增</el-button></el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button
|
||||||
|
v-if="proxy.$auth.hasPermiAnd(['master:line:query', 'master:line:edit'])"
|
||||||
|
type="success" plain icon="Edit" :disabled="single || detailLoading" :loading="detailLoading"
|
||||||
|
@click="handleUpdate()" v-hasPermi="['master:line:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5"><el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['master:line:remove']">删除</el-button></el-col>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
<el-alert v-if="loadError" :title="loadError" type="error" :closable="false" show-icon class="mb8" />
|
||||||
|
<el-table v-loading="loading" empty-text="暂无数据" :data="lineList" @selection-change="handleSelectionChange">
|
||||||
|
<el-table-column type="selection" :selectable="isRowSelectable" width="55" align="center" />
|
||||||
|
<el-table-column label="产线ID" prop="lineId" align="center" />
|
||||||
|
<el-table-column label="现场ID" prop="siteId" align="center" />
|
||||||
|
<el-table-column label="产线编码" prop="lineCode" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="产线名称" prop="lineName" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="状态" prop="status" align="center" width="100">
|
||||||
|
<template #default="scope"><dict-tag :options="sys_normal_disable" :value="scope.row.status" /></template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="创建时间" prop="createTime" align="center" width="180">
|
||||||
|
<template #default="scope"><span>{{ parseTime(scope.row.createTime) }}</span></template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button
|
||||||
|
v-if="proxy.$auth.hasPermiAnd(['master:line:query', 'master:line:edit'])"
|
||||||
|
link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['master:line:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="scope.row.canRemove === true"
|
||||||
|
link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['master:line:remove']"
|
||||||
|
>删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<pagination
|
||||||
|
v-show="total > 0" :total="total"
|
||||||
|
v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<el-dialog v-model="open" :title="title" width="min(520px, 92vw)" append-to-body>
|
||||||
|
<el-alert v-if="formError" :title="formError" type="error" :closable="false" show-icon class="mb8" />
|
||||||
|
<el-form ref="lineRef" :model="form" :rules="rules" label-width="90px">
|
||||||
|
<el-form-item label="现场ID" prop="siteId">
|
||||||
|
<el-input-number v-model="form.siteId" :min="1" :step="1" step-strictly controls-position="right" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="产线编码" prop="lineCode">
|
||||||
|
<el-input v-model="form.lineCode" placeholder="请输入产线编码" maxlength="64" show-word-limit />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="产线名称" prop="lineName">
|
||||||
|
<el-input v-model="form.lineName" placeholder="请输入产线名称" maxlength="100" show-word-limit />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-radio-group v-model="form.status">
|
||||||
|
<el-radio v-for="dict in sys_normal_disable" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="备注" prop="remark">
|
||||||
|
<el-input v-model="form.remark" type="textarea" :rows="3" maxlength="500" show-word-limit placeholder="请输入备注" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button v-if="!form.lineId" type="primary" :loading="submitLoading" @click="submitCreate" v-hasPermi="['master:line:add']">确 定</el-button>
|
||||||
|
<el-button v-else type="primary" :loading="submitLoading" @click="submitUpdate" v-hasPermi="['master:line:edit']">确 定</el-button>
|
||||||
|
<el-button :disabled="submitLoading" @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="Line">
|
||||||
|
import { addLine, delLine, getLine, listLine, updateLine } from "@/api/master/line";
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance();
|
||||||
|
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
|
||||||
|
const lineList = ref([]);
|
||||||
|
const ids = ref([]);
|
||||||
|
const loading = ref(false);
|
||||||
|
const detailLoading = ref(false);
|
||||||
|
const submitLoading = ref(false);
|
||||||
|
const loadError = ref("");
|
||||||
|
const formError = ref("");
|
||||||
|
const open = ref(false);
|
||||||
|
const single = ref(true);
|
||||||
|
const multiple = ref(true);
|
||||||
|
const total = ref(0);
|
||||||
|
const title = ref("");
|
||||||
|
|
||||||
|
function validateRequiredText(rule, value, callback) {
|
||||||
|
const labels = { lineCode: "产线编码", lineName: "产线名称" };
|
||||||
|
if (typeof value !== "string" || value.trim() === "") {
|
||||||
|
callback(new Error(`${labels[rule.field]}不能为空`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
function validatePositiveInteger(rule, value, callback) {
|
||||||
|
if (!Number.isInteger(value) || value <= 0) {
|
||||||
|
callback(new Error("现场ID必须为正整数"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = reactive({
|
||||||
|
form: {},
|
||||||
|
queryParams: { pageNum: 1, pageSize: 10, siteId: undefined, lineCode: undefined, lineName: undefined, status: undefined },
|
||||||
|
rules: {
|
||||||
|
siteId: [{ required: true, validator: validatePositiveInteger, trigger: "change" }],
|
||||||
|
lineCode: [{ required: true, validator: validateRequiredText, trigger: "blur" }],
|
||||||
|
lineName: [{ required: true, validator: validateRequiredText, trigger: "blur" }],
|
||||||
|
status: [{ required: true, message: "请选择状态", trigger: "change" }]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const { form, queryParams, rules } = toRefs(data);
|
||||||
|
|
||||||
|
function getList() {
|
||||||
|
loading.value = true;
|
||||||
|
loadError.value = "";
|
||||||
|
listLine(queryParams.value).then((response) => {
|
||||||
|
lineList.value = response.rows;
|
||||||
|
total.value = response.total;
|
||||||
|
}).catch(() => {
|
||||||
|
lineList.value = [];
|
||||||
|
total.value = 0;
|
||||||
|
loadError.value = "生产线列表加载失败,请稍后重试";
|
||||||
|
}).finally(() => { loading.value = false; });
|
||||||
|
}
|
||||||
|
function reset() {
|
||||||
|
formError.value = "";
|
||||||
|
form.value = { lineId: undefined, siteId: undefined, lineCode: "", lineName: "", status: "0", remark: "" };
|
||||||
|
proxy.resetForm("lineRef");
|
||||||
|
}
|
||||||
|
function cancel() { open.value = false; reset(); }
|
||||||
|
function handleQuery() { queryParams.value.pageNum = 1; getList(); }
|
||||||
|
function resetQuery() { proxy.resetForm("queryRef"); handleQuery(); }
|
||||||
|
function isRowSelectable(row) {
|
||||||
|
return row.canRemove === true;
|
||||||
|
}
|
||||||
|
function handleSelectionChange(selection) {
|
||||||
|
ids.value = selection
|
||||||
|
.filter((item) => item.canRemove === true)
|
||||||
|
.map((item) => item.lineId);
|
||||||
|
single.value = ids.value.length !== 1;
|
||||||
|
multiple.value = ids.value.length === 0;
|
||||||
|
}
|
||||||
|
function handleAdd() { reset(); title.value = "新增生产线"; open.value = true; }
|
||||||
|
function handleUpdate(row = {}) {
|
||||||
|
reset();
|
||||||
|
const lineId = row.lineId || ids.value[0];
|
||||||
|
detailLoading.value = true;
|
||||||
|
getLine(lineId).then((response) => {
|
||||||
|
const detail = response.data;
|
||||||
|
form.value = {
|
||||||
|
lineId: detail.lineId,
|
||||||
|
siteId: detail.siteId,
|
||||||
|
lineCode: detail.lineCode,
|
||||||
|
lineName: detail.lineName,
|
||||||
|
status: detail.status,
|
||||||
|
remark: detail.remark || ""
|
||||||
|
};
|
||||||
|
title.value = "修改生产线";
|
||||||
|
open.value = true;
|
||||||
|
}).catch(() => {
|
||||||
|
loadError.value = "生产线详情加载失败,请稍后重试";
|
||||||
|
}).finally(() => { detailLoading.value = false; });
|
||||||
|
}
|
||||||
|
function afterSubmit(response) {
|
||||||
|
proxy.$modal.msgSuccess(response.msg || "操作成功");
|
||||||
|
open.value = false;
|
||||||
|
getList();
|
||||||
|
}
|
||||||
|
function submitCreate() {
|
||||||
|
proxy.$refs.lineRef.validate((valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
submitLoading.value = true;
|
||||||
|
formError.value = "";
|
||||||
|
addLine({
|
||||||
|
siteId: form.value.siteId,
|
||||||
|
lineCode: form.value.lineCode.trim(),
|
||||||
|
lineName: form.value.lineName.trim(),
|
||||||
|
status: form.value.status,
|
||||||
|
remark: form.value.remark?.trim() || undefined
|
||||||
|
}).then(afterSubmit).catch(() => {
|
||||||
|
formError.value = "新增失败,请根据提示修正后重试";
|
||||||
|
}).finally(() => { submitLoading.value = false; });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function submitUpdate() {
|
||||||
|
proxy.$refs.lineRef.validate((valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
submitLoading.value = true;
|
||||||
|
formError.value = "";
|
||||||
|
updateLine({
|
||||||
|
lineId: form.value.lineId,
|
||||||
|
siteId: form.value.siteId,
|
||||||
|
lineCode: form.value.lineCode.trim(),
|
||||||
|
lineName: form.value.lineName.trim(),
|
||||||
|
status: form.value.status,
|
||||||
|
remark: form.value.remark?.trim() || undefined
|
||||||
|
}).then(afterSubmit).catch(() => {
|
||||||
|
formError.value = "修改失败,请根据提示修正后重试";
|
||||||
|
}).finally(() => { submitLoading.value = false; });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function handleDelete(row) {
|
||||||
|
const targetIds = row?.lineId ? (row.canRemove === true ? [row.lineId] : []) : ids.value;
|
||||||
|
if (!targetIds.length) { proxy.$modal.msgWarning("请选择允许删除的生产线"); return; }
|
||||||
|
proxy.$modal.confirm(`是否确认删除产线编号为“${targetIds.join(",")}”的数据项?`).then(() =>
|
||||||
|
delLine(targetIds.join(","))
|
||||||
|
).then(() => { proxy.$modal.msgSuccess("删除成功"); getList(); }).catch((error) => {
|
||||||
|
if (error !== "cancel" && error !== "close") loadError.value = "生产线删除失败,请稍后重试";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getList();
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,309 @@
|
|||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<el-form ref="queryRef" :model="queryParams" :inline="true">
|
||||||
|
<el-form-item label="托盘编码" prop="palletCode">
|
||||||
|
<el-input v-model="queryParams.palletCode" placeholder="请输入托盘编码" clearable maxlength="64" @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="资产状态" prop="assetStatus">
|
||||||
|
<el-select v-model="queryParams.assetStatus" placeholder="请选择资产状态" clearable style="width: 160px">
|
||||||
|
<el-option v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="Search" @click="handleQuery" v-hasPermi="['master:pallet:list']">搜索</el-button>
|
||||||
|
<el-button icon="Refresh" @click="resetQuery" v-hasPermi="['master:pallet:list']">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5"><el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['master:pallet:add']">新增</el-button></el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button
|
||||||
|
v-if="proxy.$auth.hasPermiAnd(['master:pallet:query', 'master:pallet:edit'])"
|
||||||
|
type="success" plain icon="Edit" :disabled="single || detailLoading" :loading="detailLoading"
|
||||||
|
@click="handleUpdate()" v-hasPermi="['master:pallet:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5"><el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['master:pallet:remove']">删除</el-button></el-col>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
<el-alert v-if="loadError" :title="loadError" type="error" :closable="false" show-icon class="mb8" />
|
||||||
|
<el-table v-loading="loading" empty-text="暂无数据" :data="palletList" @selection-change="handleSelectionChange">
|
||||||
|
<el-table-column type="selection" :selectable="isRowSelectable" width="55" align="center" />
|
||||||
|
<el-table-column label="托盘ID" prop="palletId" align="center" />
|
||||||
|
<el-table-column label="托盘编码" prop="palletCode" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="容量(包)" prop="capacityPackages" align="center" />
|
||||||
|
<el-table-column label="资产状态" prop="assetStatus" align="center" width="110">
|
||||||
|
<template #default="scope"><dict-tag :options="sys_normal_disable" :value="scope.row.assetStatus" /></template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="创建时间" prop="createTime" align="center" width="180">
|
||||||
|
<template #default="scope"><span>{{ parseTime(scope.row.createTime) }}</span></template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button
|
||||||
|
link type="primary" icon="Printer" :loading="isPrinting(scope.row.palletId)"
|
||||||
|
@click="handlePrint(scope.row)" v-hasPermi="['master:pallet:print']"
|
||||||
|
>打印</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="proxy.$auth.hasPermiAnd(['master:pallet:query', 'master:pallet:edit'])"
|
||||||
|
link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['master:pallet:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="scope.row.canRemove === true"
|
||||||
|
link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['master:pallet:remove']"
|
||||||
|
>删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<pagination
|
||||||
|
v-show="total > 0" :total="total"
|
||||||
|
v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<el-dialog v-model="open" :title="title" width="min(560px, 92vw)" append-to-body>
|
||||||
|
<el-alert v-if="formError" :title="formError" type="error" :closable="false" show-icon class="mb8" />
|
||||||
|
<el-form ref="palletRef" :model="form" :rules="rules" label-width="100px">
|
||||||
|
<el-form-item v-if="!isEdit" label="托盘编码" prop="palletCode">
|
||||||
|
<el-input v-model="form.palletCode" placeholder="请输入托盘编码" maxlength="64" show-word-limit />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item v-if="isEdit" label="托盘编码" prop="palletCode">
|
||||||
|
<el-input v-model="form.palletCode" readonly />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item v-if="isEdit" label="二维码标识">
|
||||||
|
<el-input v-model="form.qrToken" readonly />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="容量(包)" prop="capacityPackages">
|
||||||
|
<el-input-number v-model="form.capacityPackages" :min="1" :step="1" step-strictly controls-position="right" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item v-if="isEdit" label="资产状态" prop="assetStatus">
|
||||||
|
<el-radio-group v-model="form.assetStatus">
|
||||||
|
<el-radio v-for="dict in sys_normal_disable" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="备注" prop="remark">
|
||||||
|
<el-input v-model="form.remark" type="textarea" :rows="3" maxlength="500" show-word-limit placeholder="请输入备注" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button v-if="!isEdit" type="primary" :loading="submitLoading" @click="submitCreate" v-hasPermi="['master:pallet:add']">确 定</el-button>
|
||||||
|
<el-button v-else type="primary" :loading="submitLoading" @click="submitUpdate" v-hasPermi="['master:pallet:edit']">确 定</el-button>
|
||||||
|
<el-button :disabled="submitLoading" @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="Pallet">
|
||||||
|
import { addPallet, delPallet, getPallet, getPalletQrcode, listPallet, updatePallet } from "@/api/master/pallet";
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance();
|
||||||
|
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
|
||||||
|
const palletList = ref([]);
|
||||||
|
const ids = ref([]);
|
||||||
|
const loading = ref(false);
|
||||||
|
const detailLoading = ref(false);
|
||||||
|
const submitLoading = ref(false);
|
||||||
|
const loadError = ref("");
|
||||||
|
const formError = ref("");
|
||||||
|
const open = ref(false);
|
||||||
|
const single = ref(true);
|
||||||
|
const multiple = ref(true);
|
||||||
|
const total = ref(0);
|
||||||
|
const title = ref("");
|
||||||
|
const printingIds = ref([]);
|
||||||
|
|
||||||
|
function validateRequiredText(rule, value, callback) {
|
||||||
|
if (typeof value !== "string" || value.trim() === "") {
|
||||||
|
callback(new Error("托盘编码不能为空"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
function validatePositiveInteger(rule, value, callback) {
|
||||||
|
if (!Number.isInteger(value) || value <= 0) {
|
||||||
|
callback(new Error("容量必须为正整数"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = reactive({
|
||||||
|
form: {},
|
||||||
|
queryParams: { pageNum: 1, pageSize: 10, palletCode: undefined, assetStatus: undefined },
|
||||||
|
rules: {
|
||||||
|
palletCode: [{ required: true, validator: validateRequiredText, trigger: "blur" }],
|
||||||
|
capacityPackages: [{ required: true, validator: validatePositiveInteger, trigger: "change" }],
|
||||||
|
assetStatus: [{ required: true, message: "请选择资产状态", trigger: "change" }]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const { form, queryParams, rules } = toRefs(data);
|
||||||
|
const isEdit = computed(() => Number.isInteger(form.value.palletId) && form.value.palletId > 0);
|
||||||
|
|
||||||
|
function getList() {
|
||||||
|
loading.value = true;
|
||||||
|
loadError.value = "";
|
||||||
|
listPallet(queryParams.value).then((response) => {
|
||||||
|
palletList.value = response.rows;
|
||||||
|
total.value = response.total;
|
||||||
|
}).catch(() => {
|
||||||
|
palletList.value = [];
|
||||||
|
total.value = 0;
|
||||||
|
loadError.value = "托盘列表加载失败,请稍后重试";
|
||||||
|
}).finally(() => { loading.value = false; });
|
||||||
|
}
|
||||||
|
function reset() {
|
||||||
|
formError.value = "";
|
||||||
|
form.value = { palletId: undefined, palletCode: "", qrToken: "", capacityPackages: 1, assetStatus: "0", remark: "" };
|
||||||
|
proxy.resetForm("palletRef");
|
||||||
|
}
|
||||||
|
function cancel() { open.value = false; reset(); }
|
||||||
|
function handleQuery() { queryParams.value.pageNum = 1; getList(); }
|
||||||
|
function resetQuery() { proxy.resetForm("queryRef"); handleQuery(); }
|
||||||
|
function isRowSelectable(row) {
|
||||||
|
return row.canRemove === true;
|
||||||
|
}
|
||||||
|
function handleSelectionChange(selection) {
|
||||||
|
ids.value = selection
|
||||||
|
.filter((item) => item.canRemove === true)
|
||||||
|
.map((item) => item.palletId);
|
||||||
|
single.value = ids.value.length !== 1;
|
||||||
|
multiple.value = ids.value.length === 0;
|
||||||
|
}
|
||||||
|
function handleAdd() { reset(); title.value = "新增托盘"; open.value = true; }
|
||||||
|
function handleUpdate(row = {}) {
|
||||||
|
reset();
|
||||||
|
const palletId = row.palletId || ids.value[0];
|
||||||
|
detailLoading.value = true;
|
||||||
|
getPallet(palletId).then((response) => {
|
||||||
|
const detail = response.data;
|
||||||
|
form.value = {
|
||||||
|
palletId: detail.palletId,
|
||||||
|
palletCode: detail.palletCode,
|
||||||
|
qrToken: detail.qrToken,
|
||||||
|
capacityPackages: detail.capacityPackages,
|
||||||
|
assetStatus: detail.assetStatus,
|
||||||
|
remark: detail.remark || ""
|
||||||
|
};
|
||||||
|
title.value = "修改托盘";
|
||||||
|
open.value = true;
|
||||||
|
}).catch(() => {
|
||||||
|
loadError.value = "托盘详情加载失败,请稍后重试";
|
||||||
|
}).finally(() => { detailLoading.value = false; });
|
||||||
|
}
|
||||||
|
function afterSubmit(response) {
|
||||||
|
proxy.$modal.msgSuccess(response.msg || "操作成功");
|
||||||
|
open.value = false;
|
||||||
|
getList();
|
||||||
|
}
|
||||||
|
function submitCreate() {
|
||||||
|
proxy.$refs.palletRef.validate((valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
submitLoading.value = true;
|
||||||
|
formError.value = "";
|
||||||
|
addPallet({
|
||||||
|
palletCode: form.value.palletCode.trim(),
|
||||||
|
capacityPackages: form.value.capacityPackages,
|
||||||
|
remark: form.value.remark?.trim() || undefined
|
||||||
|
}).then(afterSubmit).catch(() => {
|
||||||
|
formError.value = "新增失败,请根据提示修正后重试";
|
||||||
|
}).finally(() => { submitLoading.value = false; });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function submitUpdate() {
|
||||||
|
proxy.$refs.palletRef.validate((valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
submitLoading.value = true;
|
||||||
|
formError.value = "";
|
||||||
|
updatePallet({
|
||||||
|
palletId: form.value.palletId,
|
||||||
|
capacityPackages: form.value.capacityPackages,
|
||||||
|
assetStatus: form.value.assetStatus,
|
||||||
|
remark: form.value.remark?.trim() || undefined
|
||||||
|
}).then(afterSubmit).catch(() => {
|
||||||
|
formError.value = "修改失败,请根据提示修正后重试";
|
||||||
|
}).finally(() => { submitLoading.value = false; });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function handleDelete(row) {
|
||||||
|
const targetIds = row?.palletId ? (row.canRemove === true ? [row.palletId] : []) : ids.value;
|
||||||
|
if (!targetIds.length) { proxy.$modal.msgWarning("请选择允许删除的托盘"); return; }
|
||||||
|
proxy.$modal.confirm(`是否确认删除托盘编号为“${targetIds.join(",")}”的数据项?`).then(() =>
|
||||||
|
delPallet(targetIds.join(","))
|
||||||
|
).then(() => { proxy.$modal.msgSuccess("删除成功"); getList(); }).catch((error) => {
|
||||||
|
if (error !== "cancel" && error !== "close") loadError.value = "托盘删除失败,请稍后重试";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPrinting(palletId) {
|
||||||
|
return printingIds.value.includes(palletId);
|
||||||
|
}
|
||||||
|
function setPrinting(palletId, printing) {
|
||||||
|
const nextIds = new Set(printingIds.value);
|
||||||
|
if (printing) nextIds.add(palletId);
|
||||||
|
else nextIds.delete(palletId);
|
||||||
|
printingIds.value = [...nextIds];
|
||||||
|
}
|
||||||
|
function handlePrint(row) {
|
||||||
|
const printWindow = window.open('', '_blank');
|
||||||
|
if (!printWindow) {
|
||||||
|
proxy.$modal.msgError("打印窗口被浏览器拦截,请允许弹出窗口后重试");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let objectUrl;
|
||||||
|
setPrinting(row.palletId, true);
|
||||||
|
const revokeObjectUrl = () => {
|
||||||
|
if (objectUrl) {
|
||||||
|
URL.revokeObjectURL(objectUrl);
|
||||||
|
objectUrl = undefined;
|
||||||
|
}
|
||||||
|
setPrinting(row.palletId, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
getPalletQrcode(row.palletId).then((qrCodeBlob) => {
|
||||||
|
if (printWindow.closed) throw new Error("打印窗口已关闭");
|
||||||
|
const blob = qrCodeBlob instanceof Blob ? qrCodeBlob : new Blob([qrCodeBlob], { type: "image/png" });
|
||||||
|
objectUrl = URL.createObjectURL(blob);
|
||||||
|
printWindow.document.title = `托盘二维码 - ${row.palletCode}`;
|
||||||
|
|
||||||
|
const styleElement = printWindow.document.createElement("style");
|
||||||
|
styleElement.textContent = "body{margin:0;padding:32px;text-align:center;font-family:sans-serif}h1{font-size:20px;margin:0 0 20px}img{width:min(80vw,420px);height:auto}";
|
||||||
|
const titleElement = printWindow.document.createElement("h1");
|
||||||
|
titleElement.textContent = `托盘 ${row.palletCode}`;
|
||||||
|
const imageElement = printWindow.document.createElement("img");
|
||||||
|
imageElement.alt = `托盘 ${row.palletCode} 二维码`;
|
||||||
|
|
||||||
|
imageElement.addEventListener("load", () => {
|
||||||
|
printWindow.focus();
|
||||||
|
printWindow.print();
|
||||||
|
}, { once: true });
|
||||||
|
imageElement.addEventListener("error", () => {
|
||||||
|
revokeObjectUrl();
|
||||||
|
printWindow.close();
|
||||||
|
proxy.$modal.msgError("二维码图片加载失败");
|
||||||
|
}, { once: true });
|
||||||
|
printWindow.addEventListener("afterprint", () => {
|
||||||
|
if (objectUrl) {
|
||||||
|
URL.revokeObjectURL(objectUrl);
|
||||||
|
objectUrl = undefined;
|
||||||
|
}
|
||||||
|
setPrinting(row.palletId, false);
|
||||||
|
printWindow.close();
|
||||||
|
}, { once: true });
|
||||||
|
|
||||||
|
imageElement.src = objectUrl;
|
||||||
|
printWindow.document.head.append(styleElement);
|
||||||
|
printWindow.document.body.replaceChildren(titleElement, imageElement);
|
||||||
|
}).catch(() => {
|
||||||
|
revokeObjectUrl();
|
||||||
|
if (!printWindow.closed) printWindow.close();
|
||||||
|
proxy.$modal.msgError("二维码获取失败");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getList();
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,270 @@
|
|||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<el-form ref="queryRef" :model="queryParams" :inline="true">
|
||||||
|
<el-form-item label="客户ID" prop="customerId">
|
||||||
|
<el-input-number v-model="queryParams.customerId" :min="1" :step="1" step-strictly controls-position="right" placeholder="请输入客户ID" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="现场编码" prop="siteCode">
|
||||||
|
<el-input v-model="queryParams.siteCode" placeholder="请输入现场编码" clearable maxlength="64" @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="现场名称" prop="siteName">
|
||||||
|
<el-input v-model="queryParams.siteName" placeholder="请输入现场名称" clearable maxlength="100" @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable style="width: 160px">
|
||||||
|
<el-option v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="Search" @click="handleQuery" v-hasPermi="['master:site:list']">搜索</el-button>
|
||||||
|
<el-button icon="Refresh" @click="resetQuery" v-hasPermi="['master:site:list']">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5"><el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['master:site:add']">新增</el-button></el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button
|
||||||
|
v-if="proxy.$auth.hasPermiAnd(['master:site:query', 'master:site:edit'])"
|
||||||
|
type="success" plain icon="Edit" :disabled="single || detailLoading" :loading="detailLoading"
|
||||||
|
@click="handleUpdate()" v-hasPermi="['master:site:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5"><el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['master:site:remove']">删除</el-button></el-col>
|
||||||
|
<el-col :span="1.5"><el-button type="warning" plain icon="User" :disabled="single" @click="handleAssign()" v-hasPermi="['master:site:assign']">分配用户</el-button></el-col>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
<el-alert v-if="loadError" :title="loadError" type="error" :closable="false" show-icon class="mb8" />
|
||||||
|
<el-table v-loading="loading" empty-text="暂无数据" :data="siteList" @selection-change="handleSelectionChange">
|
||||||
|
<el-table-column type="selection" :selectable="isRowSelectable" width="55" align="center" />
|
||||||
|
<el-table-column label="现场ID" prop="siteId" align="center" />
|
||||||
|
<el-table-column label="客户ID" prop="customerId" align="center" />
|
||||||
|
<el-table-column label="现场编码" prop="siteCode" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="现场名称" prop="siteName" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="地址" prop="address" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="状态" prop="status" align="center" width="100">
|
||||||
|
<template #default="scope"><dict-tag :options="sys_normal_disable" :value="scope.row.status" /></template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="创建时间" prop="createTime" align="center" width="180">
|
||||||
|
<template #default="scope"><span>{{ parseTime(scope.row.createTime) }}</span></template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" align="center" width="260" class-name="small-padding fixed-width">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button link type="primary" icon="User" @click="handleAssign(scope.row)" v-hasPermi="['master:site:assign']">分配</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="proxy.$auth.hasPermiAnd(['master:site:query', 'master:site:edit'])"
|
||||||
|
link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['master:site:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="scope.row.canRemove === true"
|
||||||
|
link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['master:site:remove']"
|
||||||
|
>删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<pagination
|
||||||
|
v-show="total > 0" :total="total"
|
||||||
|
v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<el-dialog v-model="open" :title="title" width="min(560px, 92vw)" append-to-body>
|
||||||
|
<el-alert v-if="formError" :title="formError" type="error" :closable="false" show-icon class="mb8" />
|
||||||
|
<el-form ref="siteRef" :model="form" :rules="rules" label-width="90px">
|
||||||
|
<el-form-item label="客户ID" prop="customerId">
|
||||||
|
<el-input-number v-model="form.customerId" :min="1" :step="1" step-strictly controls-position="right" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="现场编码" prop="siteCode">
|
||||||
|
<el-input v-model="form.siteCode" placeholder="请输入现场编码" maxlength="64" show-word-limit />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="现场名称" prop="siteName">
|
||||||
|
<el-input v-model="form.siteName" placeholder="请输入现场名称" maxlength="100" show-word-limit />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="地址" prop="address">
|
||||||
|
<el-input v-model="form.address" type="textarea" :rows="2" maxlength="500" show-word-limit placeholder="请输入地址" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-radio-group v-model="form.status">
|
||||||
|
<el-radio v-for="dict in sys_normal_disable" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="备注" prop="remark">
|
||||||
|
<el-input v-model="form.remark" type="textarea" :rows="3" maxlength="500" show-word-limit placeholder="请输入备注" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button v-if="!form.siteId" type="primary" :loading="submitLoading" @click="submitCreate" v-hasPermi="['master:site:add']">确 定</el-button>
|
||||||
|
<el-button v-else type="primary" :loading="submitLoading" @click="submitUpdate" v-hasPermi="['master:site:edit']">确 定</el-button>
|
||||||
|
<el-button :disabled="submitLoading" @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
|
||||||
|
<business-user-assign-dialog ref="assignDialogRef" @ok="getList" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="Site">
|
||||||
|
import BusinessUserAssignDialog from "@/components/BusinessUserAssignDialog";
|
||||||
|
import { addSite, delSite, getSite, listSite, updateSite } from "@/api/master/site";
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance();
|
||||||
|
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
|
||||||
|
const siteList = ref([]);
|
||||||
|
const ids = ref([]);
|
||||||
|
const selectedRows = ref([]);
|
||||||
|
const assignDialogRef = ref();
|
||||||
|
const loading = ref(false);
|
||||||
|
const detailLoading = ref(false);
|
||||||
|
const submitLoading = ref(false);
|
||||||
|
const loadError = ref("");
|
||||||
|
const formError = ref("");
|
||||||
|
const open = ref(false);
|
||||||
|
const single = ref(true);
|
||||||
|
const multiple = ref(true);
|
||||||
|
const total = ref(0);
|
||||||
|
const title = ref("");
|
||||||
|
|
||||||
|
function validateRequiredText(rule, value, callback) {
|
||||||
|
const labels = { siteCode: "现场编码", siteName: "现场名称" };
|
||||||
|
if (typeof value !== "string" || value.trim() === "") {
|
||||||
|
callback(new Error(`${labels[rule.field]}不能为空`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
function validatePositiveInteger(rule, value, callback) {
|
||||||
|
if (!Number.isInteger(value) || value <= 0) {
|
||||||
|
callback(new Error("客户ID必须为正整数"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = reactive({
|
||||||
|
form: {},
|
||||||
|
queryParams: { pageNum: 1, pageSize: 10, customerId: undefined, siteCode: undefined, siteName: undefined, status: undefined },
|
||||||
|
rules: {
|
||||||
|
customerId: [{ required: true, validator: validatePositiveInteger, trigger: "change" }],
|
||||||
|
siteCode: [{ required: true, validator: validateRequiredText, trigger: "blur" }],
|
||||||
|
siteName: [{ required: true, validator: validateRequiredText, trigger: "blur" }],
|
||||||
|
status: [{ required: true, message: "请选择状态", trigger: "change" }]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const { form, queryParams, rules } = toRefs(data);
|
||||||
|
|
||||||
|
function getList() {
|
||||||
|
loading.value = true;
|
||||||
|
loadError.value = "";
|
||||||
|
listSite(queryParams.value).then((response) => {
|
||||||
|
siteList.value = response.rows;
|
||||||
|
total.value = response.total;
|
||||||
|
}).catch(() => {
|
||||||
|
siteList.value = [];
|
||||||
|
total.value = 0;
|
||||||
|
loadError.value = "客户现场列表加载失败,请稍后重试";
|
||||||
|
}).finally(() => { loading.value = false; });
|
||||||
|
}
|
||||||
|
function reset() {
|
||||||
|
formError.value = "";
|
||||||
|
form.value = { siteId: undefined, customerId: undefined, siteCode: "", siteName: "", address: "", status: "0", remark: "" };
|
||||||
|
proxy.resetForm("siteRef");
|
||||||
|
}
|
||||||
|
function cancel() { open.value = false; reset(); }
|
||||||
|
function handleQuery() { queryParams.value.pageNum = 1; getList(); }
|
||||||
|
function resetQuery() { proxy.resetForm("queryRef"); handleQuery(); }
|
||||||
|
function isRowSelectable(row) {
|
||||||
|
return row.canRemove === true;
|
||||||
|
}
|
||||||
|
function handleSelectionChange(selection) {
|
||||||
|
selectedRows.value = selection.filter((item) => item.canRemove === true);
|
||||||
|
ids.value = selection
|
||||||
|
.filter((item) => item.canRemove === true)
|
||||||
|
.map((item) => item.siteId);
|
||||||
|
single.value = ids.value.length !== 1;
|
||||||
|
multiple.value = ids.value.length === 0;
|
||||||
|
}
|
||||||
|
function handleAdd() { reset(); title.value = "新增客户现场"; open.value = true; }
|
||||||
|
function handleUpdate(row = {}) {
|
||||||
|
reset();
|
||||||
|
const siteId = row.siteId || ids.value[0];
|
||||||
|
detailLoading.value = true;
|
||||||
|
getSite(siteId).then((response) => {
|
||||||
|
const detail = response.data;
|
||||||
|
form.value = {
|
||||||
|
siteId: detail.siteId,
|
||||||
|
customerId: detail.customerId,
|
||||||
|
siteCode: detail.siteCode,
|
||||||
|
siteName: detail.siteName,
|
||||||
|
address: detail.address || "",
|
||||||
|
status: detail.status,
|
||||||
|
remark: detail.remark || ""
|
||||||
|
};
|
||||||
|
title.value = "修改客户现场";
|
||||||
|
open.value = true;
|
||||||
|
}).catch(() => {
|
||||||
|
loadError.value = "客户现场详情加载失败,请稍后重试";
|
||||||
|
}).finally(() => { detailLoading.value = false; });
|
||||||
|
}
|
||||||
|
function handleAssign(row = {}) {
|
||||||
|
if (!row.siteId) row = selectedRows.value[0];
|
||||||
|
if (!row) return;
|
||||||
|
assignDialogRef.value.show({
|
||||||
|
resourceType: "site",
|
||||||
|
resourceId: row.siteId,
|
||||||
|
resourceName: row.siteName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function afterSubmit(response) {
|
||||||
|
proxy.$modal.msgSuccess(response.msg || "操作成功");
|
||||||
|
open.value = false;
|
||||||
|
getList();
|
||||||
|
}
|
||||||
|
function submitCreate() {
|
||||||
|
proxy.$refs.siteRef.validate((valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
submitLoading.value = true;
|
||||||
|
formError.value = "";
|
||||||
|
addSite({
|
||||||
|
customerId: form.value.customerId,
|
||||||
|
siteCode: form.value.siteCode.trim(),
|
||||||
|
siteName: form.value.siteName.trim(),
|
||||||
|
address: form.value.address?.trim() || undefined,
|
||||||
|
status: form.value.status,
|
||||||
|
remark: form.value.remark?.trim() || undefined
|
||||||
|
}).then(afterSubmit).catch(() => {
|
||||||
|
formError.value = "新增失败,请根据提示修正后重试";
|
||||||
|
}).finally(() => { submitLoading.value = false; });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function submitUpdate() {
|
||||||
|
proxy.$refs.siteRef.validate((valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
submitLoading.value = true;
|
||||||
|
formError.value = "";
|
||||||
|
updateSite({
|
||||||
|
siteId: form.value.siteId,
|
||||||
|
customerId: form.value.customerId,
|
||||||
|
siteCode: form.value.siteCode.trim(),
|
||||||
|
siteName: form.value.siteName.trim(),
|
||||||
|
address: form.value.address?.trim() || undefined,
|
||||||
|
status: form.value.status,
|
||||||
|
remark: form.value.remark?.trim() || undefined
|
||||||
|
}).then(afterSubmit).catch(() => {
|
||||||
|
formError.value = "修改失败,请根据提示修正后重试";
|
||||||
|
}).finally(() => { submitLoading.value = false; });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function handleDelete(row) {
|
||||||
|
const targetIds = row?.siteId ? (row.canRemove === true ? [row.siteId] : []) : ids.value;
|
||||||
|
if (!targetIds.length) { proxy.$modal.msgWarning("请选择允许删除的客户现场"); return; }
|
||||||
|
proxy.$modal.confirm(`是否确认删除现场编号为“${targetIds.join(",")}”的数据项?`).then(() =>
|
||||||
|
delSite(targetIds.join(","))
|
||||||
|
).then(() => { proxy.$modal.msgSuccess("删除成功"); getList(); }).catch((error) => {
|
||||||
|
if (error !== "cancel" && error !== "close") loadError.value = "客户现场删除失败,请稍后重试";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getList();
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,292 @@
|
|||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<el-form ref="queryRef" :model="queryParams" :inline="true">
|
||||||
|
<el-form-item label="菌种编码" prop="strainCode">
|
||||||
|
<el-input v-model="queryParams.strainCode" placeholder="请输入菌种编码" clearable maxlength="64" @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="菌种名称" prop="strainName">
|
||||||
|
<el-input v-model="queryParams.strainName" placeholder="请输入菌种名称" clearable maxlength="100" @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable style="width: 160px">
|
||||||
|
<el-option v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="Search" @click="handleQuery" v-hasPermi="['master:strain:list']">搜索</el-button>
|
||||||
|
<el-button icon="Refresh" @click="resetQuery" v-hasPermi="['master:strain:list']">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['master:strain:add']">新增</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button
|
||||||
|
v-if="proxy.$auth.hasPermiAnd(['master:strain:query', 'master:strain:edit'])"
|
||||||
|
type="success"
|
||||||
|
plain
|
||||||
|
icon="Edit"
|
||||||
|
:disabled="single || detailLoading"
|
||||||
|
:loading="detailLoading"
|
||||||
|
@click="handleUpdate()"
|
||||||
|
v-hasPermi="['master:strain:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['master:strain:remove']">删除</el-button>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
<el-alert v-if="loadError" :title="loadError" type="error" :closable="false" show-icon class="mb8" />
|
||||||
|
|
||||||
|
<el-table v-loading="loading" empty-text="暂无数据" :data="strainList" @selection-change="handleSelectionChange">
|
||||||
|
<el-table-column type="selection" :selectable="isRowSelectable" width="55" align="center" />
|
||||||
|
<el-table-column label="菌种ID" prop="strainId" align="center" />
|
||||||
|
<el-table-column label="菌种编码" prop="strainCode" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="菌种名称" prop="strainName" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="状态" prop="status" align="center" width="100">
|
||||||
|
<template #default="scope">
|
||||||
|
<dict-tag :options="sys_normal_disable" :value="scope.row.status" />
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="创建时间" prop="createTime" align="center" width="180">
|
||||||
|
<template #default="scope"><span>{{ parseTime(scope.row.createTime) }}</span></template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button
|
||||||
|
v-if="proxy.$auth.hasPermiAnd(['master:strain:query', 'master:strain:edit'])"
|
||||||
|
link
|
||||||
|
type="primary"
|
||||||
|
icon="Edit"
|
||||||
|
@click="handleUpdate(scope.row)"
|
||||||
|
v-hasPermi="['master:strain:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="scope.row.canRemove === true"
|
||||||
|
link
|
||||||
|
type="primary"
|
||||||
|
icon="Delete"
|
||||||
|
@click="handleDelete(scope.row)"
|
||||||
|
v-hasPermi="['master:strain:remove']"
|
||||||
|
>删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<pagination
|
||||||
|
v-show="total > 0"
|
||||||
|
:total="total"
|
||||||
|
v-model:page="queryParams.pageNum"
|
||||||
|
v-model:limit="queryParams.pageSize"
|
||||||
|
@pagination="getList"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<el-dialog v-model="open" :title="title" width="min(520px, 92vw)" append-to-body>
|
||||||
|
<el-alert v-if="formError" :title="formError" type="error" :closable="false" show-icon class="mb8" />
|
||||||
|
<el-form ref="strainRef" :model="form" :rules="rules" label-width="90px">
|
||||||
|
<el-form-item label="菌种编码" prop="strainCode">
|
||||||
|
<el-input v-model="form.strainCode" placeholder="请输入菌种编码" maxlength="64" show-word-limit />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="菌种名称" prop="strainName">
|
||||||
|
<el-input v-model="form.strainName" placeholder="请输入菌种名称" maxlength="100" show-word-limit />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-radio-group v-model="form.status">
|
||||||
|
<el-radio v-for="dict in sys_normal_disable" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="备注" prop="remark">
|
||||||
|
<el-input v-model="form.remark" type="textarea" :rows="3" maxlength="500" show-word-limit placeholder="请输入备注" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button v-if="!form.strainId" type="primary" :loading="submitLoading" @click="submitCreate" v-hasPermi="['master:strain:add']">确 定</el-button>
|
||||||
|
<el-button v-else type="primary" :loading="submitLoading" @click="submitUpdate" v-hasPermi="['master:strain:edit']">确 定</el-button>
|
||||||
|
<el-button :disabled="submitLoading" @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="Strain">
|
||||||
|
import { addStrain, delStrain, getStrain, listStrain, updateStrain } from "@/api/master/strain";
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance();
|
||||||
|
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
|
||||||
|
|
||||||
|
const strainList = ref([]);
|
||||||
|
const ids = ref([]);
|
||||||
|
const loading = ref(false);
|
||||||
|
const detailLoading = ref(false);
|
||||||
|
const submitLoading = ref(false);
|
||||||
|
const loadError = ref("");
|
||||||
|
const formError = ref("");
|
||||||
|
const open = ref(false);
|
||||||
|
const single = ref(true);
|
||||||
|
const multiple = ref(true);
|
||||||
|
const total = ref(0);
|
||||||
|
const title = ref("");
|
||||||
|
|
||||||
|
function validateRequiredText(rule, value, callback) {
|
||||||
|
if (typeof value !== "string" || value.trim() === "") {
|
||||||
|
callback(new Error(`${rule.field === "strainCode" ? "菌种编码" : "菌种名称"}不能为空`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = reactive({
|
||||||
|
form: {},
|
||||||
|
queryParams: { pageNum: 1, pageSize: 10, strainCode: undefined, strainName: undefined, status: undefined },
|
||||||
|
rules: {
|
||||||
|
strainCode: [{ required: true, validator: validateRequiredText, trigger: "blur" }],
|
||||||
|
strainName: [{ required: true, validator: validateRequiredText, trigger: "blur" }],
|
||||||
|
status: [{ required: true, message: "请选择状态", trigger: "change" }]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const { form, queryParams, rules } = toRefs(data);
|
||||||
|
|
||||||
|
function getList() {
|
||||||
|
loading.value = true;
|
||||||
|
loadError.value = "";
|
||||||
|
listStrain(queryParams.value).then((response) => {
|
||||||
|
strainList.value = response.rows;
|
||||||
|
total.value = response.total;
|
||||||
|
}).catch(() => {
|
||||||
|
strainList.value = [];
|
||||||
|
total.value = 0;
|
||||||
|
loadError.value = "菌种列表加载失败,请稍后重试";
|
||||||
|
}).finally(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
formError.value = "";
|
||||||
|
form.value = { strainId: undefined, strainCode: "", strainName: "", status: "0", remark: "" };
|
||||||
|
proxy.resetForm("strainRef");
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancel() {
|
||||||
|
open.value = false;
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleQuery() {
|
||||||
|
queryParams.value.pageNum = 1;
|
||||||
|
getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetQuery() {
|
||||||
|
proxy.resetForm("queryRef");
|
||||||
|
handleQuery();
|
||||||
|
}
|
||||||
|
|
||||||
|
function isRowSelectable(row) {
|
||||||
|
return row.canRemove === true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSelectionChange(selection) {
|
||||||
|
ids.value = selection
|
||||||
|
.filter((item) => item.canRemove === true)
|
||||||
|
.map((item) => item.strainId);
|
||||||
|
single.value = ids.value.length !== 1;
|
||||||
|
multiple.value = ids.value.length === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleAdd() {
|
||||||
|
reset();
|
||||||
|
title.value = "新增菌种";
|
||||||
|
open.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleUpdate(row = {}) {
|
||||||
|
reset();
|
||||||
|
const strainId = row.strainId || ids.value[0];
|
||||||
|
detailLoading.value = true;
|
||||||
|
getStrain(strainId).then((response) => {
|
||||||
|
const detail = response.data;
|
||||||
|
form.value = {
|
||||||
|
strainId: detail.strainId,
|
||||||
|
strainCode: detail.strainCode,
|
||||||
|
strainName: detail.strainName,
|
||||||
|
status: detail.status,
|
||||||
|
remark: detail.remark || ""
|
||||||
|
};
|
||||||
|
title.value = "修改菌种";
|
||||||
|
open.value = true;
|
||||||
|
}).catch(() => {
|
||||||
|
loadError.value = "菌种详情加载失败,请稍后重试";
|
||||||
|
}).finally(() => {
|
||||||
|
detailLoading.value = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function afterSubmit(response) {
|
||||||
|
proxy.$modal.msgSuccess(response.msg || "操作成功");
|
||||||
|
open.value = false;
|
||||||
|
getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitCreate() {
|
||||||
|
proxy.$refs.strainRef.validate((valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
submitLoading.value = true;
|
||||||
|
formError.value = "";
|
||||||
|
addStrain({
|
||||||
|
strainCode: form.value.strainCode.trim(),
|
||||||
|
strainName: form.value.strainName.trim(),
|
||||||
|
status: form.value.status,
|
||||||
|
remark: form.value.remark?.trim() || undefined
|
||||||
|
}).then(afterSubmit).catch(() => {
|
||||||
|
formError.value = "新增失败,请根据提示修正后重试";
|
||||||
|
}).finally(() => {
|
||||||
|
submitLoading.value = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitUpdate() {
|
||||||
|
proxy.$refs.strainRef.validate((valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
submitLoading.value = true;
|
||||||
|
formError.value = "";
|
||||||
|
updateStrain({
|
||||||
|
strainId: form.value.strainId,
|
||||||
|
strainCode: form.value.strainCode.trim(),
|
||||||
|
strainName: form.value.strainName.trim(),
|
||||||
|
status: form.value.status,
|
||||||
|
remark: form.value.remark?.trim() || undefined
|
||||||
|
}).then(afterSubmit).catch(() => {
|
||||||
|
formError.value = "修改失败,请根据提示修正后重试";
|
||||||
|
}).finally(() => {
|
||||||
|
submitLoading.value = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDelete(row) {
|
||||||
|
const targetIds = row?.strainId
|
||||||
|
? (row.canRemove === true ? [row.strainId] : [])
|
||||||
|
: ids.value;
|
||||||
|
if (!targetIds.length) {
|
||||||
|
proxy.$modal.msgWarning("请选择允许删除的菌种");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
proxy.$modal.confirm(`是否确认删除菌种编号为“${targetIds.join(",")}”的数据项?`).then(() =>
|
||||||
|
delStrain(targetIds.join(","))
|
||||||
|
).then(() => {
|
||||||
|
proxy.$modal.msgSuccess("删除成功");
|
||||||
|
getList();
|
||||||
|
}).catch((error) => {
|
||||||
|
if (error !== "cancel" && error !== "close") loadError.value = "菌种删除失败,请稍后重试";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getList();
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<el-form ref="queryRef" :model="queryParams" :inline="true">
|
||||||
|
<el-form-item label="仓库编码" prop="warehouseCode">
|
||||||
|
<el-input v-model="queryParams.warehouseCode" placeholder="请输入仓库编码" clearable maxlength="64" @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="仓库名称" prop="warehouseName">
|
||||||
|
<el-input v-model="queryParams.warehouseName" placeholder="请输入仓库名称" clearable maxlength="100" @keyup.enter="handleQuery" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable style="width: 160px">
|
||||||
|
<el-option v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="Search" @click="handleQuery" v-hasPermi="['master:warehouse:list']">搜索</el-button>
|
||||||
|
<el-button icon="Refresh" @click="resetQuery" v-hasPermi="['master:warehouse:list']">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5"><el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['master:warehouse:add']">新增</el-button></el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button
|
||||||
|
v-if="proxy.$auth.hasPermiAnd(['master:warehouse:query', 'master:warehouse:edit'])"
|
||||||
|
type="success" plain icon="Edit" :disabled="single || detailLoading" :loading="detailLoading"
|
||||||
|
@click="handleUpdate()" v-hasPermi="['master:warehouse:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5"><el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['master:warehouse:remove']">删除</el-button></el-col>
|
||||||
|
<el-col :span="1.5"><el-button type="warning" plain icon="User" :disabled="single" @click="handleAssign()" v-hasPermi="['master:warehouse:assign']">分配用户</el-button></el-col>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
<el-alert v-if="loadError" :title="loadError" type="error" :closable="false" show-icon class="mb8" />
|
||||||
|
<el-table v-loading="loading" empty-text="暂无数据" :data="warehouseList" @selection-change="handleSelectionChange">
|
||||||
|
<el-table-column type="selection" :selectable="isRowSelectable" width="55" align="center" />
|
||||||
|
<el-table-column label="仓库ID" prop="warehouseId" align="center" />
|
||||||
|
<el-table-column label="仓库编码" prop="warehouseCode" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="仓库名称" prop="warehouseName" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="地址" prop="address" align="center" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="状态" prop="status" align="center" width="100">
|
||||||
|
<template #default="scope"><dict-tag :options="sys_normal_disable" :value="scope.row.status" /></template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="创建时间" prop="createTime" align="center" width="180">
|
||||||
|
<template #default="scope"><span>{{ parseTime(scope.row.createTime) }}</span></template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="操作" align="center" width="260" class-name="small-padding fixed-width">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-button link type="primary" icon="User" @click="handleAssign(scope.row)" v-hasPermi="['master:warehouse:assign']">分配</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="proxy.$auth.hasPermiAnd(['master:warehouse:query', 'master:warehouse:edit'])"
|
||||||
|
link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['master:warehouse:edit']"
|
||||||
|
>修改</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="scope.row.canRemove === true"
|
||||||
|
link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['master:warehouse:remove']"
|
||||||
|
>删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<pagination
|
||||||
|
v-show="total > 0" :total="total"
|
||||||
|
v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<el-dialog v-model="open" :title="title" width="min(560px, 92vw)" append-to-body>
|
||||||
|
<el-alert v-if="formError" :title="formError" type="error" :closable="false" show-icon class="mb8" />
|
||||||
|
<el-form ref="warehouseRef" :model="form" :rules="rules" label-width="90px">
|
||||||
|
<el-form-item label="仓库编码" prop="warehouseCode">
|
||||||
|
<el-input v-model="form.warehouseCode" placeholder="请输入仓库编码" maxlength="64" show-word-limit />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="仓库名称" prop="warehouseName">
|
||||||
|
<el-input v-model="form.warehouseName" placeholder="请输入仓库名称" maxlength="100" show-word-limit />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="地址" prop="address">
|
||||||
|
<el-input v-model="form.address" type="textarea" :rows="2" maxlength="500" show-word-limit placeholder="请输入地址" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="状态" prop="status">
|
||||||
|
<el-radio-group v-model="form.status">
|
||||||
|
<el-radio v-for="dict in sys_normal_disable" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="备注" prop="remark">
|
||||||
|
<el-input v-model="form.remark" type="textarea" :rows="3" maxlength="500" show-word-limit placeholder="请输入备注" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button v-if="!form.warehouseId" type="primary" :loading="submitLoading" @click="submitCreate" v-hasPermi="['master:warehouse:add']">确 定</el-button>
|
||||||
|
<el-button v-else type="primary" :loading="submitLoading" @click="submitUpdate" v-hasPermi="['master:warehouse:edit']">确 定</el-button>
|
||||||
|
<el-button :disabled="submitLoading" @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
|
||||||
|
<business-user-assign-dialog ref="assignDialogRef" @ok="getList" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup name="Warehouse">
|
||||||
|
import BusinessUserAssignDialog from "@/components/BusinessUserAssignDialog";
|
||||||
|
import { addWarehouse, delWarehouse, getWarehouse, listWarehouse, updateWarehouse } from "@/api/master/warehouse";
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance();
|
||||||
|
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
|
||||||
|
const warehouseList = ref([]);
|
||||||
|
const ids = ref([]);
|
||||||
|
const selectedRows = ref([]);
|
||||||
|
const assignDialogRef = ref();
|
||||||
|
const loading = ref(false);
|
||||||
|
const detailLoading = ref(false);
|
||||||
|
const submitLoading = ref(false);
|
||||||
|
const loadError = ref("");
|
||||||
|
const formError = ref("");
|
||||||
|
const open = ref(false);
|
||||||
|
const single = ref(true);
|
||||||
|
const multiple = ref(true);
|
||||||
|
const total = ref(0);
|
||||||
|
const title = ref("");
|
||||||
|
|
||||||
|
function validateRequiredText(rule, value, callback) {
|
||||||
|
const labels = { warehouseCode: "仓库编码", warehouseName: "仓库名称" };
|
||||||
|
if (typeof value !== "string" || value.trim() === "") {
|
||||||
|
callback(new Error(`${labels[rule.field]}不能为空`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = reactive({
|
||||||
|
form: {},
|
||||||
|
queryParams: { pageNum: 1, pageSize: 10, warehouseCode: undefined, warehouseName: undefined, status: undefined },
|
||||||
|
rules: {
|
||||||
|
warehouseCode: [{ required: true, validator: validateRequiredText, trigger: "blur" }],
|
||||||
|
warehouseName: [{ required: true, validator: validateRequiredText, trigger: "blur" }],
|
||||||
|
status: [{ required: true, message: "请选择状态", trigger: "change" }]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const { form, queryParams, rules } = toRefs(data);
|
||||||
|
|
||||||
|
function getList() {
|
||||||
|
loading.value = true;
|
||||||
|
loadError.value = "";
|
||||||
|
listWarehouse(queryParams.value).then((response) => {
|
||||||
|
warehouseList.value = response.rows;
|
||||||
|
total.value = response.total;
|
||||||
|
}).catch(() => {
|
||||||
|
warehouseList.value = [];
|
||||||
|
total.value = 0;
|
||||||
|
loadError.value = "仓库列表加载失败,请稍后重试";
|
||||||
|
}).finally(() => { loading.value = false; });
|
||||||
|
}
|
||||||
|
function reset() {
|
||||||
|
formError.value = "";
|
||||||
|
form.value = { warehouseId: undefined, warehouseCode: "", warehouseName: "", address: "", status: "0", remark: "" };
|
||||||
|
proxy.resetForm("warehouseRef");
|
||||||
|
}
|
||||||
|
function cancel() { open.value = false; reset(); }
|
||||||
|
function handleQuery() { queryParams.value.pageNum = 1; getList(); }
|
||||||
|
function resetQuery() { proxy.resetForm("queryRef"); handleQuery(); }
|
||||||
|
function isRowSelectable(row) {
|
||||||
|
return row.canRemove === true;
|
||||||
|
}
|
||||||
|
function handleSelectionChange(selection) {
|
||||||
|
selectedRows.value = selection.filter((item) => item.canRemove === true);
|
||||||
|
ids.value = selection
|
||||||
|
.filter((item) => item.canRemove === true)
|
||||||
|
.map((item) => item.warehouseId);
|
||||||
|
single.value = ids.value.length !== 1;
|
||||||
|
multiple.value = ids.value.length === 0;
|
||||||
|
}
|
||||||
|
function handleAdd() { reset(); title.value = "新增仓库"; open.value = true; }
|
||||||
|
function handleUpdate(row = {}) {
|
||||||
|
reset();
|
||||||
|
const warehouseId = row.warehouseId || ids.value[0];
|
||||||
|
detailLoading.value = true;
|
||||||
|
getWarehouse(warehouseId).then((response) => {
|
||||||
|
const detail = response.data;
|
||||||
|
form.value = {
|
||||||
|
warehouseId: detail.warehouseId,
|
||||||
|
warehouseCode: detail.warehouseCode,
|
||||||
|
warehouseName: detail.warehouseName,
|
||||||
|
address: detail.address || "",
|
||||||
|
status: detail.status,
|
||||||
|
remark: detail.remark || ""
|
||||||
|
};
|
||||||
|
title.value = "修改仓库";
|
||||||
|
open.value = true;
|
||||||
|
}).catch(() => {
|
||||||
|
loadError.value = "仓库详情加载失败,请稍后重试";
|
||||||
|
}).finally(() => { detailLoading.value = false; });
|
||||||
|
}
|
||||||
|
function handleAssign(row = {}) {
|
||||||
|
if (!row.warehouseId) row = selectedRows.value[0];
|
||||||
|
if (!row) return;
|
||||||
|
assignDialogRef.value.show({
|
||||||
|
resourceType: "warehouse",
|
||||||
|
resourceId: row.warehouseId,
|
||||||
|
resourceName: row.warehouseName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function afterSubmit(response) {
|
||||||
|
proxy.$modal.msgSuccess(response.msg || "操作成功");
|
||||||
|
open.value = false;
|
||||||
|
getList();
|
||||||
|
}
|
||||||
|
function submitCreate() {
|
||||||
|
proxy.$refs.warehouseRef.validate((valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
submitLoading.value = true;
|
||||||
|
formError.value = "";
|
||||||
|
addWarehouse({
|
||||||
|
warehouseCode: form.value.warehouseCode.trim(),
|
||||||
|
warehouseName: form.value.warehouseName.trim(),
|
||||||
|
address: form.value.address?.trim() || undefined,
|
||||||
|
status: form.value.status,
|
||||||
|
remark: form.value.remark?.trim() || undefined
|
||||||
|
}).then(afterSubmit).catch(() => {
|
||||||
|
formError.value = "新增失败,请根据提示修正后重试";
|
||||||
|
}).finally(() => { submitLoading.value = false; });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function submitUpdate() {
|
||||||
|
proxy.$refs.warehouseRef.validate((valid) => {
|
||||||
|
if (!valid) return;
|
||||||
|
submitLoading.value = true;
|
||||||
|
formError.value = "";
|
||||||
|
updateWarehouse({
|
||||||
|
warehouseId: form.value.warehouseId,
|
||||||
|
warehouseCode: form.value.warehouseCode.trim(),
|
||||||
|
warehouseName: form.value.warehouseName.trim(),
|
||||||
|
address: form.value.address?.trim() || undefined,
|
||||||
|
status: form.value.status,
|
||||||
|
remark: form.value.remark?.trim() || undefined
|
||||||
|
}).then(afterSubmit).catch(() => {
|
||||||
|
formError.value = "修改失败,请根据提示修正后重试";
|
||||||
|
}).finally(() => { submitLoading.value = false; });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function handleDelete(row) {
|
||||||
|
const targetIds = row?.warehouseId ? (row.canRemove === true ? [row.warehouseId] : []) : ids.value;
|
||||||
|
if (!targetIds.length) { proxy.$modal.msgWarning("请选择允许删除的仓库"); return; }
|
||||||
|
proxy.$modal.confirm(`是否确认删除仓库编号为“${targetIds.join(",")}”的数据项?`).then(() =>
|
||||||
|
delWarehouse(targetIds.join(","))
|
||||||
|
).then(() => { proxy.$modal.msgSuccess("删除成功"); getList(); }).catch((error) => {
|
||||||
|
if (error !== "cancel" && error !== "close") loadError.value = "仓库删除失败,请稍后重试";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getList();
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user