<template>
|
<div class="app-container">
|
|
<el-row :gutter="10" class="mb8">
|
<el-col :span="1.5">
|
<el-button
|
type="primary"
|
plain
|
icon="Plus"
|
@click="handleAdd"
|
v-hasPermi="['shop:add']"
|
>新增</el-button>
|
</el-col>
|
<el-col :span="1.5">
|
<el-button
|
type="success"
|
plain
|
icon="Edit"
|
:disabled="single"
|
@click="handleUpdate"
|
v-hasPermi="['shop:edit']"
|
>修改</el-button>
|
</el-col>
|
|
<el-col :span="1.5">
|
<el-button
|
type="warning"
|
plain
|
icon="Download"
|
@click="handleExport"
|
v-hasPermi="['shop:export']"
|
>导出</el-button>
|
</el-col>
|
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
</el-row>
|
|
<HxlhTable
|
style="width: 100%"
|
:columns="columns"
|
:data="aps_shopList"
|
:loading="loading"
|
:height="height"
|
:page="page"
|
@changePageNo="changePageNo"
|
@changePageSize="changePageSize"
|
@on-checkbox="handleCheckboxChange"
|
>
|
<template #buttons="{row}">
|
<vxe-button mode="text" @click="handleUpdate(row)" v-hasPermi="['plant:edit']" >编辑</vxe-button>
|
</template>
|
</HxlhTable>
|
|
|
<!-- 添加或修改车间对话框 -->
|
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
|
<el-form ref="aps_shopRef" :model="form" :rules="rules" label-width="80px">
|
<el-form-item label="车间名称" prop="shopName">
|
<el-input v-model="form.shopName" placeholder="请输入车间名称" ref="shopNameInputRef"/>
|
</el-form-item>
|
<el-form-item label="车间代码" prop="shopCode">
|
<el-input v-model="form.shopCode" placeholder="请输入车间代码" :disabled=shopCodeDisabled ref="shopCodeInputRef" />
|
|
</el-form-item>
|
<el-form-item label="工厂编码" prop="plantCode">
|
<el-select v-model="form.plantCode"
|
placeholder="请选择工厂编码"
|
value-key="plantCode"
|
>
|
<el-option
|
v-for="plant in plantList"
|
:key="plant.plantCode"
|
:label="plant.plantName"
|
:value="plant.plantCode"
|
> {{plant.plantName}} </el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="启用状态" prop="status">
|
<el-radio-group v-model="form.status">
|
<el-radio
|
v-for="dict in aps_plant_status"
|
:key="dict.value"
|
:label="dict.value"
|
>{{dict.label}}</el-radio>
|
</el-radio-group>
|
</el-form-item>
|
</el-form>
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
<el-button @click="cancel">取 消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup name="Aps_shop">
|
import { listAps_shop, getAps_shop, delAps_shop, addAps_shop, updateAps_shop } from "@/api/basicData/shop";
|
import { listAps_plant } from "@/api/basicData/plant";
|
import { ref } from "vue";
|
import HxlhTable from '@/components/HxlhTable'
|
|
const { proxy } = getCurrentInstance();
|
const { aps_plant_status } = proxy.useDict('aps_plant_status');
|
const height = ref(document.documentElement.clientHeight - 170 + "px;");
|
const shopNameRules = ref(null);
|
const shopCodeRules = ref(null);
|
const plantCodeRules = ref(null);
|
const aps_shopList = ref([]);
|
const open = ref(false);
|
const loading = ref(true);
|
const showSearch = ref(false);
|
const ids = ref([]);
|
const single = ref(true);
|
const multiple = ref(true);
|
const total = ref(0);
|
const title = ref("");
|
const plantList = ref([]);
|
const shopCodeDisabled = ref(false);
|
const data = reactive({
|
form: {},
|
queryParams: {
|
pageNum: 1,
|
pageSize: 10,
|
shopName: null,
|
shopCode: null,
|
plantCode: null,
|
status: null,
|
},
|
rules: {
|
shopName: [
|
{ required: true, message: "车间名称不能为空", trigger: "blur" },
|
{
|
validator: async (rule, value, callback) => {
|
if (!value) {
|
return callback();
|
}
|
try {
|
if(value === shopNameRules.value && plantCodeRules.value === form.value.plantCode){
|
callback();
|
}else{
|
const isExists = await checkShopNameExists(value);
|
if (isExists) {
|
return callback(new Error('车间名称已存在,请更换'));
|
} else {
|
callback();
|
}
|
}
|
} catch (error) {
|
return callback(new Error('校验用户名时发生错误,请稍后重试'));
|
}
|
},
|
trigger: 'blur'
|
}
|
],
|
shopCode: [
|
{ required: true, message: "车间编码不能为空", trigger: "blur" },
|
{
|
validator: async (rule, value, callback) => {
|
if (!value) {
|
return callback();
|
}
|
try {
|
if(form.value.shopCode){
|
callback();
|
}else{
|
const isExists = await checkShopCodeExists(value);
|
if (isExists) {
|
return callback(new Error('该车间编码已存在,请更换'));
|
} else {
|
callback();
|
}
|
}
|
} catch (error) {
|
return callback(new Error('校验用户名时发生错误,请稍后重试'));
|
}
|
},
|
trigger: 'blur'
|
}
|
],
|
plantCode: [
|
{ required: true, message: "工厂编码不能为空", trigger: "blur" },
|
],
|
status: [
|
{ required: true, message: "启用状态不能为空", trigger: "blur" },
|
],
|
}
|
});
|
|
const { queryParams, form, rules } = toRefs(data);
|
|
// 分页属性
|
const page = ref({
|
total: 0,
|
current: 1,
|
size: 10
|
});
|
|
// 表格配置
|
const columns = ref([
|
{ type: 'checkbox', width: 60, align:"center"},
|
{ type: 'seq', title: '序号', width: 60 },
|
{
|
title: '车间名称',
|
field: 'shopName',
|
},
|
{
|
title: '车间代码',
|
field: 'shopCode',
|
},
|
{
|
title: '工厂代码',
|
field: 'plantCode',
|
},
|
{
|
title: '启用状态',
|
field: 'status',
|
},
|
{
|
title: '创建者',
|
field: 'createBy',
|
},
|
{
|
title: '创建时间',
|
field: 'createTime',
|
},
|
{ title: '操作', width: 100, fixed:"right", slots: { default: 'buttons' } }
|
]);
|
|
/** 查询车间列表 */
|
function getList() {
|
loading.value = true;
|
listAps_shop(queryParams.value).then(response => {
|
aps_shopList.value = response.rows;
|
page.value.total = response.total;
|
loading.value = false;
|
});
|
}
|
|
// 取消按钮
|
function cancel() {
|
open.value = false;
|
reset();
|
}
|
|
// 表单重置
|
function reset() {
|
form.value = {
|
id: null,
|
shopName: null,
|
shopCode: null,
|
plantCode: null,
|
status: null,
|
createBy: null,
|
createTime: null,
|
updateBy: null,
|
updateTime: null
|
};
|
proxy.resetForm("aps_shopRef");
|
shopNameRules.value = null;
|
shopCodeRules.value = null;
|
plantCodeRules.value = null;
|
}
|
|
/** 搜索按钮操作 */
|
function handleQuery() {
|
page.value.current = 1;
|
queryParams.value.pageNum = 1;
|
getList();
|
}
|
|
/** 重置按钮操作 */
|
function resetQuery() {
|
proxy.resetForm("queryRef");
|
handleQuery();
|
}
|
|
// 多选框选中数据
|
function handleSelectionChange(selection) {
|
ids.value = selection.map(item => item.id);
|
single.value = selection.length != 1;
|
multiple.value = !selection.length;
|
}
|
|
/** 新增按钮操作 */
|
function handleAdd() {
|
reset();
|
open.value = true;
|
shopCodeDisabled.value = false;
|
title.value = "添加车间";
|
}
|
|
/** 修改按钮操作 */
|
function handleUpdate(row) {
|
reset();
|
const _id = row.id || ids.value
|
shopCodeDisabled.value = true;
|
getAps_shop(_id).then(response => {
|
form.value = response.data;
|
open.value = true;
|
title.value = "修改车间";
|
shopNameRules.value = form.value.shopName;
|
shopCodeRules.value = form.value.shopCode;
|
plantCodeRules.value = form.value.plantCode;
|
});
|
}
|
|
/** 提交按钮 */
|
function submitForm() {
|
proxy.$refs["aps_shopRef"].validate(valid => {
|
if (valid) {
|
if (form.value.id != null) {
|
updateAps_shop(form.value).then(response => {
|
proxy.$modal.msgSuccess("修改成功");
|
open.value = false;
|
getList();
|
});
|
} else {
|
addAps_shop(form.value).then(response => {
|
proxy.$modal.msgSuccess("新增成功");
|
open.value = false;
|
getList();
|
});
|
}
|
}
|
});
|
}
|
|
/** 删除按钮操作 */
|
function handleDelete(row) {
|
const _ids = row.id || ids.value;
|
proxy.$modal.confirm('是否确认删除车间编号为"' + _ids + '"的数据项?').then(function() {
|
return delAps_shop(_ids);
|
}).then(() => {
|
getList();
|
proxy.$modal.msgSuccess("删除成功");
|
}).catch(() => {});
|
}
|
|
/** 导出按钮操作 */
|
function handleExport() {
|
proxy.download('aps_shop/aps_shop/export', {
|
...queryParams.value
|
}, `aps_shop_${new Date().getTime()}.xlsx`)
|
}
|
/** 查询车间列表 */
|
function getPlantList() {
|
loading.value = true;
|
listAps_plant({}).then(response => {
|
plantList.value = response.rows;
|
|
loading.value = false;
|
});
|
}
|
|
/** 检查车间名字重复 */
|
const checkShopNameExists = async (value) => {
|
return new Promise((resolve) => {
|
queryParams.value = {};
|
queryParams.value.shopName = value;
|
queryParams.value.plantCode = form.value.plantCode;
|
listAps_shop(queryParams.value).then(response => {
|
console.log(response);
|
if(response.total === 0){
|
resolve(false);
|
}else{
|
resolve(true);
|
}
|
});
|
queryParams.value = {};
|
});
|
};
|
|
/** 检查车间编码重复 */
|
const checkShopCodeExists = async (value) => {
|
return new Promise((resolve) => {
|
queryParams.value = {};
|
queryParams.value.shopCode = value;
|
queryParams.value.plantCode = form.value.plantCode;
|
listAps_shop(queryParams.value).then(response => {
|
if(response.total === 0){
|
resolve(false);
|
}else{
|
resolve(true);
|
}
|
});
|
queryParams.value = {};
|
});
|
};
|
|
getPlantList();
|
getList();
|
|
const shopNameInputRef = ref(null);
|
const aps_shopRef = ref(null);
|
|
watch(() => form.value.shopName, (newValue, oldValue) => {
|
nextTick(() => {
|
if (newValue!== oldValue && proxy.$refs["aps_shopRef"] != null) {
|
proxy.$refs["aps_shopRef"].validateField('shopCode');
|
}
|
});
|
});
|
|
watch(() => form.value.shopCode, (newValue, oldValue) => {
|
nextTick(() => {
|
if (newValue!== oldValue && proxy.$refs["aps_shopRef"] != null) {
|
proxy.$refs["aps_shopRef"].validateField('shopName');
|
}
|
});
|
});
|
|
watch(() => form.value.plantCode, (newValue, oldValue) => {
|
nextTick(() => {
|
if (newValue!== oldValue && proxy.$refs["aps_shopRef"] != null) {
|
proxy.$refs["aps_shopRef"].validateField('shopName');
|
proxy.$refs["aps_shopRef"].validateField('shopCode');
|
}
|
});
|
});
|
|
function changePageNo(currentPage) {
|
page.value.current = currentPage;
|
queryParams.value.pageNum = currentPage;
|
getList();
|
}
|
|
function changePageSize(pageSize) {
|
page.value.current = 1;
|
queryParams.value.pageNum = 1;
|
queryParams.value.pageSize = pageSize;
|
getList();
|
}
|
|
// 多选框选中数据
|
const handleCheckboxChange = (data) => {
|
ids.value = data.records.map(item => item.id);
|
single.value = data.records.length != 1;
|
multiple.value = !data.records.length;
|
};
|
|
</script>
|