248 lines
7.8 KiB
Vue
248 lines
7.8 KiB
Vue
<template>
|
|
<div class="AddBuildingBox">
|
|
<PageHeader></PageHeader>
|
|
<div class="AddBuildingBody">
|
|
<div class="title">基本信息</div>
|
|
<div class="addBuildingFormBody">
|
|
<el-form class="formBody" label-position="right" ref="formRef" :model="form" :rules="rules" label-width="130px">
|
|
<el-form-item label="设备分类" prop="categoryId">
|
|
<el-select v-model="form.categoryId">
|
|
<el-option v-for="(item, index) in deviceCategoryList" :key="index" :value="item.id" :label="item.categoryName"></el-option>
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item label="设备名称" prop="deviceName">
|
|
<el-input maxlength="20" v-model.trim="form.deviceName" placeholder="请输入设备名称" />
|
|
</el-form-item>
|
|
<el-form-item label="设备唯一编号" prop="deviceCode">
|
|
<el-input maxlength="20" v-model.trim="form.deviceCode" placeholder="请输入设备唯一编号" />
|
|
</el-form-item>
|
|
<el-form-item label="设备型号" prop="deviceModel">
|
|
<el-input maxlength="20" v-model.trim="form.deviceModel" placeholder="请输入设备型号" />
|
|
</el-form-item>
|
|
<el-form-item label="位置区域" prop="area">
|
|
<el-input maxlength="100" show-word-limit type="textarea" :rows="2" v-model.trim="form.area" placeholder="请输入位置区域" />
|
|
</el-form-item>
|
|
<el-form-item label="维护人员" prop="maintainUserIds">
|
|
<repairUser
|
|
userType="repair"
|
|
:userid="checkoutUseId"
|
|
ref="repairUserRef"
|
|
returnvalue="*"
|
|
:is-multiple="true"
|
|
title-name="维护人员"
|
|
@change="handleCheckoutUser"
|
|
>
|
|
<template #default>
|
|
<div class="checkoutUserBox flex flex-items-center justify-around" v-for="(item, index) in checkoutUser" :key="index">
|
|
<span>{{ item.nickName }}</span>
|
|
<div @click="handleDelete(item.id)">
|
|
<el-icon>
|
|
<Delete></Delete>
|
|
</el-icon>
|
|
</div>
|
|
</div>
|
|
<div class="checkoutUserBox add flex flex-items-center justify-center" @click="() => repairUserRef.open()">
|
|
<el-icon>
|
|
<Plus></Plus>
|
|
</el-icon>
|
|
<span>添加</span>
|
|
</div>
|
|
</template>
|
|
</repairUser>
|
|
</el-form-item>
|
|
<el-form-item label="设备状态" prop="status">
|
|
<el-radio-group v-model.trim="form.status">
|
|
<el-radio v-for="(item, index) in com_equipment_archive_status" :value="item.value" :label="item.label" :key="index"></el-radio>
|
|
</el-radio-group>
|
|
</el-form-item>
|
|
<el-form-item label="设备保质期" prop="shelfLife">
|
|
<el-input maxlength="20" v-model.trim="form.shelfLife" placeholder="请输入" />
|
|
</el-form-item>
|
|
<el-form-item label="备注" prop="remark">
|
|
<el-input maxlength="200" show-word-limit type="textarea" :row="5" v-model.trim="form.remark" placeholder="请输入" />
|
|
</el-form-item>
|
|
<el-form-item style="margin-top: 30px">
|
|
<el-button type="primary" @click="submitForm">提交</el-button>
|
|
<el-button @click="cancelForm">返回</el-button>
|
|
</el-form-item>
|
|
</el-form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref } from 'vue';
|
|
import repairUser from '@/components/Holder/repairUser.vue';
|
|
import PageHeader from '@/components/Pageheader/index.vue';
|
|
import { listDeviceCategory } from '@/api/system/equipment/Category';
|
|
import { addDevice, getDevice, updateDevice } from '@/api/system/equipment/archive';
|
|
import { Delete, Plus } from '@element-plus/icons-vue';
|
|
|
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
const { com_equipment_archive_status } = toRefs<any>(proxy?.useDict('com_equipment_archive_status'));
|
|
|
|
const router = useRouter();
|
|
const route = useRoute();
|
|
|
|
const formRef = ref();
|
|
const repairUserRef = ref();
|
|
const form = ref({
|
|
id: null,
|
|
categoryId: '', // 分类id、
|
|
deviceName: '', // 设备名称
|
|
deviceCode: '', // 编号
|
|
deviceModel: '', // 型号
|
|
area: '', // 区域
|
|
status: '0', // 区域
|
|
shelfLife: '', // 设备保质期
|
|
maintainUserIds: '', // 设备维护人员
|
|
remark: '' // 备注
|
|
});
|
|
const rules = ref({
|
|
categoryId: [{ required: true, message: '请选择 设备类型', trigger: 'blur' }],
|
|
deviceCode: [{ required: true, message: '请选择 设备唯一编号', trigger: 'blur' }],
|
|
deviceName: [{ required: true, message: '请输入 设备名称', trigger: 'blur' }]
|
|
});
|
|
const userid = ref(null);
|
|
|
|
const deviceCategoryList = ref([]);
|
|
function init() {
|
|
listDeviceCategory().then((res) => {
|
|
deviceCategoryList.value = res.rows;
|
|
});
|
|
if (route.query.id) {
|
|
userid.value = route.query.id;
|
|
getDevice(userid.value).then((res) => {
|
|
form.value = {
|
|
id: res.data.id,
|
|
categoryId: res.data.categoryId,
|
|
deviceName: res.data.deviceName,
|
|
deviceCode: res.data.deviceCode,
|
|
deviceModel: res.data.deviceModel,
|
|
area: res.data.area,
|
|
shelfLife: res.data.shelfLife,
|
|
status: res.data.status,
|
|
maintainUserIds: res.data.maintainUserIds,
|
|
remark: res.data.remark
|
|
};
|
|
|
|
checkoutUser.value = [];
|
|
checkoutUser.value = res.data.maintainUserList ?? [];
|
|
});
|
|
}
|
|
}
|
|
init();
|
|
|
|
const checkoutUseId = computed(() => {
|
|
return checkoutUser.value
|
|
.map((item) => item.userId)
|
|
.filter((item) => item)
|
|
.join(',');
|
|
});
|
|
const checkoutUser = ref([]);
|
|
function handleCheckoutUser(row: string[]) {
|
|
checkoutUser.value = row;
|
|
}
|
|
|
|
function handleDelete(id: string) {
|
|
checkoutUser.value = checkoutUser.value.filter((item) => item.id !== id);
|
|
}
|
|
|
|
// !== 提交 =============================================================================
|
|
// 提交
|
|
const submitForm = () => {
|
|
form.value.maintainUserIds = checkoutUser.value
|
|
.map((item) => item.userId)
|
|
.filter((item) => item)
|
|
.join(',');
|
|
formRef.value?.validate(async (valid: boolean) => {
|
|
if (valid) {
|
|
if (userid.value) {
|
|
updateDevice(form.value).then(() => {
|
|
ElMessage.success('编辑成功');
|
|
cancelForm();
|
|
});
|
|
} else {
|
|
addDevice(form.value).then(() => {
|
|
ElMessage.success('添加成功');
|
|
cancelForm();
|
|
});
|
|
}
|
|
}
|
|
});
|
|
};
|
|
// 推出
|
|
const cancelForm = () => {
|
|
router.back();
|
|
};
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
.AddBuildingBox {
|
|
padding: 15px;
|
|
height: 100%;
|
|
width: 100%;
|
|
}
|
|
.AddBuildingBody {
|
|
margin-top: 20px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
background-color: white;
|
|
padding: 15px;
|
|
.title {
|
|
height: 40px;
|
|
line-height: 40px;
|
|
padding-left: 20px;
|
|
background-color: rgba(255, 255, 255, 1);
|
|
color: rgba(16, 16, 16, 1);
|
|
border-bottom: 1px solid #bbbbbb;
|
|
margin-bottom: 60px;
|
|
}
|
|
|
|
.formBody {
|
|
width: 650px;
|
|
margin: 0 auto;
|
|
|
|
.checkoutUserBox {
|
|
width: 120px;
|
|
margin: 5px;
|
|
border: 1px solid #ccc;
|
|
padding: 5px 10px;
|
|
border-radius: 5px;
|
|
&.add {
|
|
cursor: pointer;
|
|
border-style: dashed;
|
|
&:hover {
|
|
color: #409eff;
|
|
border-color: #409eff;
|
|
}
|
|
}
|
|
& > div {
|
|
cursor: pointer;
|
|
&:hover {
|
|
color: red;
|
|
}
|
|
}
|
|
}
|
|
&:deep(.el-form-item__content, .el-select, .el-input) {
|
|
width: 350px !important;
|
|
margin-right: 10px;
|
|
.el-cascader {
|
|
width: 100%;
|
|
}
|
|
}
|
|
.el-form-item {
|
|
margin-bottom: 20px;
|
|
align-items: center;
|
|
}
|
|
.el-button {
|
|
width: 80px;
|
|
height: 35px;
|
|
margin-right: 20px;
|
|
}
|
|
}
|
|
}
|
|
</style>
|