<script setup name="KeyManage">
|
import { ref, onMounted, reactive, computed } from 'vue';
|
import addEdit from './addEdit.vue';
|
import useElement from "@/hooks/useElement.js";
|
import store from '@/store';
|
|
import { Search, Plus } from "@element-plus/icons-vue";
|
|
import {
|
getAllKeyList,
|
addKey,
|
delKey,
|
} from '@/api/keys.js';
|
|
const dialogTitle = ref('添加钥匙');
|
const addEditVisible = ref(false);
|
const background = ref(true);
|
const disabled = ref(false);
|
|
const isAdd = ref(false);
|
|
const { $loading, $message, $confirm } = useElement();
|
|
const pageCurr = ref(1);
|
const pageSize = ref(10);
|
const total = ref(0);
|
|
const datas = reactive({
|
tableData: [],
|
keyInfo: {},
|
});
|
|
const urole = computed(() => {
|
return store.user().urole;
|
});
|
|
function onOk() {
|
addEditVisible.value = false;
|
getList();
|
}
|
|
function onCanel() {
|
addEditVisible.value = false;
|
}
|
|
|
const filter = reactive({
|
keyName: '',
|
userName: ''
|
});
|
|
function add() {
|
dialogTitle.value = '添加钥匙';
|
datas.keyInfo = {};
|
addEditVisible.value = true;
|
}
|
|
function del(scope) {
|
$confirm('删除该钥匙', () => {
|
let loading = $loading();
|
delKey(scope.row.keyId).then((res) => {
|
let { code, data } = res;
|
if (code && data) {
|
$message({
|
type: 'success',
|
message: '删除成功!'
|
});
|
getList();
|
} else {
|
$message({
|
type: 'error',
|
message: '删除失败!'
|
});
|
}
|
loading.close();
|
});
|
});
|
}
|
|
function edit(scope) {
|
dialogTitle.value = '编辑钥匙';
|
datas.keyInfo = scope.row;
|
// console.log('edit', scope.row, '=============');
|
|
addEditVisible.value = true;
|
}
|
|
function getList() {
|
// keyName, pageNum, pageSize, uname
|
let params = {
|
pageNum: pageCurr.value,
|
pageSize: pageSize.value,
|
keyName: filter.keyName || undefined,
|
uname: filter.userName || undefined
|
};
|
|
let loading = $loading();
|
getAllKeyList(params).then((res) => {
|
let { code, data, data2 } = res;
|
let _total = 0;
|
let _list = [];
|
if (code && data) {
|
let { list, total } = data2;
|
_list = list.map(v => {
|
v.type = { 1: 'ID钥匙', 2: '机械钥匙' }[v.keyType];
|
return v;
|
});
|
_total = total;
|
}
|
datas.tableData = _list;
|
total.value = _total;
|
loading.close();
|
})
|
.catch((err) => {
|
console.log(err);
|
loading.close();
|
});
|
|
}
|
|
function handleSizeChange(val) {
|
pageSize.value = val;
|
getList();
|
}
|
|
function handleCurrentChange(val) {
|
pageCurr.value = val;
|
getList();
|
}
|
|
onMounted(() => {
|
getList();
|
});
|
|
|
</script>
|
|
<template>
|
<div class="page-wrapper">
|
<div class="page-header">
|
</div>
|
<div class="page-content">
|
<hdw-card is-full>
|
<div class="page-content-wrapper">
|
<div class="page-content-tools">
|
<el-button type="primary" size="small" :icon="Plus" @click="add">添加钥匙</el-button>
|
|
|
<div class="tools-filter">
|
<div class="tools-filter-item">
|
<div class="filter-label">钥匙名称:</div>
|
<div class="filter-content">
|
<el-input v-model="filter.keyName" size="small" @input="getList"></el-input>
|
</div>
|
</div>
|
<div class="tools-filter-item">
|
<div class="filter-label">员工名称:</div>
|
<div class="filter-content">
|
<el-input v-model="filter.userName" size="small" @input="getList"></el-input>
|
</div>
|
</div>
|
</div>
|
<el-button type="primary" size="small" :icon="Search" @click="getList">查询</el-button>
|
</div>
|
<div class="page-content-table">
|
<div class="pos-rel">
|
<div class="pos-abs">
|
<el-table :data="datas.tableData" border style="width: 100%; height: 100%">
|
<el-table-column type="index" width="50" />
|
<el-table-column prop="type" align="center" label="钥匙类型" width="120" />
|
<el-table-column prop="keyName" align="center" label="钥匙名称" width="180" />
|
<el-table-column prop="keyNumber" align="center" label="钥匙编号" width="180" />
|
<el-table-column prop="uname" align="center" label="保管人" width="180" />
|
<el-table-column prop="createTime" label="创建时间" />
|
<el-table-column align="center" fixed="right" label="操作" width="180" v-if="urole > 0">
|
<template #default="scope">
|
<el-button type="primary" size="small" @click="edit(scope)">编辑</el-button>
|
<el-button type="danger" size="small" @click="del(scope)">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
</div>
|
</div>
|
<div class="page-content-page">
|
<div class="page-tool"></div>
|
<div class="el-page-container">
|
<el-pagination v-model:current-page="pageCurr" v-model:page-size="pageSize"
|
:page-sizes="[20, 40, 60, 80, 100, 200, 300, 400]" size="small" :disabled="disabled"
|
:background="background" layout="total, sizes, prev, pager, next, jumper" :total="total"
|
@size-change="handleSizeChange" @current-change="handleCurrentChange" />
|
</div>
|
<div class="page-tool"></div>
|
</div>
|
</div>
|
</hdw-card>
|
</div>
|
<div class="page-footer"></div>
|
<!-- 弹窗 -->
|
<el-dialog :title="dialogTitle" v-model="addEditVisible" top="0" :close-on-click-modal="false" class="dialog-center"
|
width="700px" center>
|
<add-edit v-if="addEditVisible" @success="onOk" :info="datas.keyInfo" @cancel="onCanel"></add-edit>
|
</el-dialog>
|
</div>
|
</template>
|
|
<style scoped lang="scss">
|
.page-wrapper {
|
display: flex;
|
flex-direction: row;
|
padding: 8px;
|
height: 100%;
|
|
.page-content {
|
flex: 1;
|
}
|
}
|
|
.page-content-wrapper {
|
display: flex;
|
flex-direction: column;
|
height: 100%;
|
|
.page-content-tools {
|
padding-bottom: 8px;
|
}
|
|
.page-content-table {
|
flex: 1;
|
margin-left: -8px;
|
margin-right: -8px;
|
}
|
|
.page-content-page {
|
padding: 8px 8px 0 8px;
|
text-align: center;
|
|
.el-page-container {
|
display: inline-block;
|
padding: 0 16px;
|
}
|
|
.page-tool {
|
display: inline-block;
|
}
|
}
|
}
|
|
.hdw-card-container {
|
width: 240px;
|
padding-right: 8px;
|
height: 100%;
|
}
|
|
.pos-rel {
|
position: relative;
|
width: 100%;
|
height: 100%;
|
|
.pos-abs {
|
position: absolute;
|
top: 0;
|
bottom: 0;
|
left: 0;
|
right: 0;
|
width: 100%;
|
height: 100%;
|
}
|
}
|
|
.tools-filter {
|
display: inline-block;
|
font-size: 14px;
|
|
.tools-filter-item {
|
display: inline-block;
|
margin-right: 8px;
|
|
.filter-label {
|
display: inline-block;
|
}
|
|
.filter-content {
|
display: inline-block;
|
}
|
}
|
}
|
</style>
|