592 lines
14 KiB
Vue
592 lines
14 KiB
Vue
<!--
|
||
filename: dialogForm.vue
|
||
author: liubin
|
||
date: 2023-08-15 10:32:36
|
||
description: 弹窗的表单组件
|
||
-->
|
||
|
||
<template>
|
||
<el-form
|
||
ref="form"
|
||
:model="form"
|
||
:label-position="labelPosition"
|
||
v-loading="formLoading">
|
||
<el-row :gutter="20">
|
||
<!-- 是否计划保养 -->
|
||
<el-col :span="8">
|
||
<el-form-item
|
||
label="是否计划保养"
|
||
prop="relatePlan"
|
||
:rules="[
|
||
{
|
||
required: true,
|
||
message: '是否计划保养不能为空',
|
||
trigger: 'blur',
|
||
},
|
||
]">
|
||
<el-select
|
||
v-model="form.relatePlan"
|
||
:placeholder="`是否计划保养`"
|
||
:disabled="disabled"
|
||
@change="handlePlanChange">
|
||
<el-option
|
||
v-for="opt in [
|
||
{ label: '是', value: 1 },
|
||
{ label: '否', value: 2 },
|
||
]"
|
||
:key="opt.value"
|
||
:label="opt.label"
|
||
:value="opt.value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
|
||
<!-- 所属计划 -->
|
||
<el-col :span="8" v-if="form.relatePlan == 1">
|
||
<el-form-item label="所属计划" prop="maintainPlanId">
|
||
<el-select
|
||
v-model="form.maintainPlanId"
|
||
:placeholder="`请选择所属计划`"
|
||
:disabled="disabled"
|
||
filterable
|
||
clearable
|
||
@change="$emit('update', form)">
|
||
<el-option
|
||
v-for="opt in planOptions"
|
||
:key="opt.value"
|
||
:label="opt.label"
|
||
:value="opt.value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
|
||
<!-- 设备大类 -->
|
||
<el-col :span="8" v-if="form.relatePlan == 1">
|
||
<el-form-item
|
||
label="设备大类"
|
||
prop="equipmentCategory"
|
||
:rules="[
|
||
{ required: true, message: '设备大类不能为空', trigger: 'blur' },
|
||
]">
|
||
<el-select
|
||
v-model="form.equipmentCategory"
|
||
:placeholder="`请选择设备大类`"
|
||
:disabled="disabled"
|
||
clearable
|
||
filterable
|
||
@change="handleEqTypeChange">
|
||
<el-option
|
||
v-for="opt in equipmentTypeOptions"
|
||
:key="opt.value"
|
||
:label="opt.label"
|
||
:value="opt.value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
|
||
<!-- 设备名称 -->
|
||
<el-col :span="8">
|
||
<el-form-item
|
||
label="设备名称"
|
||
prop="equipmentId"
|
||
:rules="[
|
||
{ required: true, message: '设备不能为空', trigger: 'blur' },
|
||
]">
|
||
<el-select
|
||
v-model="form.equipmentId"
|
||
:placeholder="`请选择设备`"
|
||
:disabled="disabled"
|
||
filterable
|
||
clearable
|
||
@change="handleEqChange">
|
||
<el-option
|
||
v-for="opt in equipmentOptions"
|
||
:key="opt.value"
|
||
:label="opt.label"
|
||
:value="opt.value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
|
||
<!-- 开始时间 -->
|
||
<el-col :span="8">
|
||
<el-form-item
|
||
label="开始时间"
|
||
prop="startTime"
|
||
:rules="[
|
||
{ required: true, message: '开始时间不能为空', trigger: 'blur' },
|
||
]">
|
||
<el-date-picker
|
||
v-model="form.startTime"
|
||
type="datetime"
|
||
:disabled="disabled"
|
||
:placeholder="`请选择开始时间`"
|
||
value-format="timestamp"
|
||
format="yyyy-MM-dd HH:mm:ss"
|
||
clearable
|
||
@change="$emit('update', form)" />
|
||
</el-form-item>
|
||
</el-col>
|
||
|
||
<!-- 结束时间 -->
|
||
<el-col :span="8">
|
||
<el-form-item
|
||
label="结束时间"
|
||
prop="endTime"
|
||
:rules="[
|
||
{ required: true, message: '开始时间不能为空', trigger: 'blur' },
|
||
]">
|
||
<el-date-picker
|
||
v-model="form.endTime"
|
||
type="datetime"
|
||
:disabled="disabled"
|
||
:placeholder="`请选择结束时间`"
|
||
value-format="timestamp"
|
||
format="yyyy-MM-dd HH:mm:ss"
|
||
clearable
|
||
@change="$emit('update', form)" />
|
||
</el-form-item>
|
||
</el-col>
|
||
|
||
<!-- 保养人员 -->
|
||
<el-col :span="8">
|
||
<el-form-item
|
||
label="保养人员"
|
||
prop="maintainWorker"
|
||
:rules="[
|
||
{ required: true, message: '保养人员不能为空', trigger: 'blur' },
|
||
]">
|
||
<el-select
|
||
v-model="form.maintainWorker"
|
||
:placeholder="`请选择保养人员`"
|
||
:disabled="disabled"
|
||
filterable
|
||
clearable
|
||
multiple
|
||
@change="$emit('update', form)">
|
||
<el-option
|
||
v-for="opt in workerOptions"
|
||
:key="opt.value"
|
||
:label="opt.label"
|
||
:value="opt.value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
|
||
<!-- 保养单号 -->
|
||
<el-col :span="8">
|
||
<el-form-item label="保养单号" prop="maintainOrderNumber">
|
||
<el-input
|
||
v-model="form.maintainOrderNumber"
|
||
@change="$emit('update', form)"
|
||
:placeholder="`请输入保养单号`"
|
||
:disabled="disabled" />
|
||
</el-form-item>
|
||
</el-col>
|
||
|
||
<!-- 保养用时 -->
|
||
<el-col :span="8">
|
||
<el-form-item label="保养用时(h)" prop="timeUsed">
|
||
<el-input
|
||
v-model="form.timeUsed"
|
||
@change="$emit('update', form)"
|
||
:placeholder="`请输入保养用时(h)`"
|
||
:disabled="disabled" />
|
||
</el-form-item>
|
||
</el-col>
|
||
|
||
<!-- 上传文件 -->
|
||
<el-col :span="24">
|
||
<el-form-item label="上传文件" prop="files">
|
||
<div
|
||
class="upload-area"
|
||
:class="uploadOpen ? '' : 'height-48'"
|
||
ref="uploadArea">
|
||
<span class="close-icon" :class="uploadOpen ? 'open' : ''">
|
||
<el-button
|
||
type="text"
|
||
icon="el-icon-arrow-right"
|
||
@click="handleFilesOpen" />
|
||
</span>
|
||
<!-- :file-list="uploadedFileList" -->
|
||
<el-upload
|
||
class="upload-in-dialog"
|
||
:action="uploadUrl"
|
||
:headers="uploadHeaders"
|
||
:show-file-list="false"
|
||
icon="el-icon-upload2"
|
||
:disabled="disabled"
|
||
:before-upload="beforeUpload"
|
||
:on-success="handleUploadSuccess">
|
||
<el-button size="mini" :disabled="disabled">
|
||
<svg-icon
|
||
icon-class="icon-upload"
|
||
style="color: inherit"></svg-icon>
|
||
上传文件
|
||
</el-button>
|
||
<div class="el-upload__tip" slot="tip" v-if="false">
|
||
只能上传jpg/png文件, 大小不超过2MB
|
||
</div>
|
||
</el-upload>
|
||
|
||
<uploadedFile
|
||
class="file"
|
||
v-for="file in form.files"
|
||
:file="file"
|
||
:key="file.fileUrl"
|
||
:disabled="disabled"
|
||
@delete="!disabled && handleDeleteFile(file)" />
|
||
</div>
|
||
</el-form-item>
|
||
</el-col>
|
||
|
||
<!-- 保养描述 -->
|
||
<el-col :span="24">
|
||
<el-form-item label="保养描述" prop="maintenanceDes">
|
||
<div style="position: relative">
|
||
<div
|
||
v-if="disabled"
|
||
class="modal"
|
||
style="
|
||
position: absolute;
|
||
top: 0;
|
||
left: 0;
|
||
z-index: 1000;
|
||
width: 100%;
|
||
height: 100%;
|
||
background: #ccc3;
|
||
user-select: none;
|
||
cursor: not-allowed;
|
||
"></div>
|
||
<Editor
|
||
class="record-add__editor"
|
||
:value="form.maintenanceDes"
|
||
:min-height="192"
|
||
:disabled="disabled"
|
||
@input="handleEditorInput" />
|
||
</div>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</el-form>
|
||
</template>
|
||
|
||
<script>
|
||
import { getAccessToken } from '@/utils/auth';
|
||
import Editor from '@/components/Editor';
|
||
|
||
import tupleImg from '@/assets/images/tuple.png';
|
||
const uploadedFile = {
|
||
name: 'UploadedFile',
|
||
props: ['file', 'disabled'],
|
||
data() {
|
||
return {};
|
||
},
|
||
methods: {
|
||
handleDelete() {
|
||
this.$emit('delete', this.file);
|
||
},
|
||
async handleDownload() {
|
||
const data = await this.$axios({
|
||
url: this.file.fileUrl,
|
||
method: 'get',
|
||
responseType: 'blob',
|
||
});
|
||
|
||
await this.$message.success('开始下载');
|
||
// create download link
|
||
const url = window.URL.createObjectURL(data);
|
||
const link = document.createElement('a');
|
||
link.href = url;
|
||
link.download = this.file.fileName;
|
||
document.body.appendChild(link);
|
||
link.click();
|
||
document.body.removeChild(link);
|
||
},
|
||
},
|
||
mounted() {},
|
||
render: function (h) {
|
||
return (
|
||
<div
|
||
title={this.file.fileName}
|
||
onClick={this.handleDownload}
|
||
style={{
|
||
background: `url(${tupleImg}) no-repeat`,
|
||
backgroundSize: '14px',
|
||
backgroundPosition: '0 55%',
|
||
paddingLeft: '20px',
|
||
paddingRight: '24px',
|
||
textOverflow: 'ellipsis',
|
||
whiteSpace: 'nowrap',
|
||
overflow: 'hidden',
|
||
cursor: 'pointer',
|
||
display: 'inline-block',
|
||
}}>
|
||
{this.file.fileName}
|
||
{!this.disabled && (
|
||
<el-button
|
||
type="text"
|
||
icon="el-icon-close"
|
||
style="float: right; position: relative; top: 2px; left: 8px; z-index: 100"
|
||
class="dialog__upload_component__close"
|
||
onClick={this.handleDelete}
|
||
/>
|
||
)}
|
||
</div>
|
||
);
|
||
},
|
||
};
|
||
|
||
export default {
|
||
name: 'DialogForm',
|
||
model: {
|
||
prop: 'dataForm',
|
||
event: 'update',
|
||
},
|
||
emits: ['update'],
|
||
components: { Editor, uploadedFile },
|
||
props: {
|
||
dataForm: {
|
||
type: Object,
|
||
default: () => ({}),
|
||
},
|
||
disabled: {
|
||
type: Boolean,
|
||
default: false,
|
||
},
|
||
labelPosition: {
|
||
type: String,
|
||
default: 'top',
|
||
},
|
||
},
|
||
data() {
|
||
return {
|
||
allSpeicalEquipments: [],
|
||
uploadOpen: false,
|
||
form: {},
|
||
formLoading: true,
|
||
dataLoaded: false,
|
||
equipmentList: [],
|
||
equipmentOptions: [],
|
||
equipmentTypeOptions: [
|
||
{ label: '安全设备', value: 1 },
|
||
{ label: '消防设备', value: 2 },
|
||
{ label: '特种设备', value: 3 },
|
||
],
|
||
workerOptions: [],
|
||
planOptions: [],
|
||
uploadHeaders: { Authorization: 'Bearer ' + getAccessToken() },
|
||
uploadUrl: process.env.VUE_APP_BASE_API + '/admin-api/infra/file/upload', // 上传有关的headers,url都是固定的
|
||
};
|
||
},
|
||
watch: {
|
||
dataForm: {
|
||
handler(val) {
|
||
this.form = JSON.parse(JSON.stringify(val));
|
||
if (this.form.equipmentCategory != null) {
|
||
setTimeout(() => {
|
||
this.equipmentOptions = this.equipmentList
|
||
.filter((item) => item.special)
|
||
.filter(
|
||
(item) => item.specialType === this.form.equipmentCategory
|
||
)
|
||
.map((item) => ({ label: item.name, value: item.id }));
|
||
}, 1000);
|
||
}
|
||
if (this.hasFiles) {
|
||
if (typeof this.hasFiles == 'boolean' && this.hasFiles) {
|
||
this.form.files = this.form.files ?? [];
|
||
} else if (Array.isArray(this.hasFiles)) {
|
||
this.hasFiles.forEach((prop) => {
|
||
this.form[prop] = this.form[prop] ?? [];
|
||
});
|
||
}
|
||
}
|
||
},
|
||
deep: true,
|
||
immediate: true,
|
||
},
|
||
},
|
||
mounted() {
|
||
this.initOptions();
|
||
this.getCode('/base/equipment-maintain-plan/getCode');
|
||
},
|
||
methods: {
|
||
/** 模拟透传 ref */
|
||
validate(cb) {
|
||
return this.$refs.form.validate(cb);
|
||
},
|
||
resetFields(args) {
|
||
return this.$refs.form.resetFields(args);
|
||
},
|
||
// getCode
|
||
async getCode(url) {
|
||
this.formLoading = true;
|
||
const response = await this.$axios(url);
|
||
this.formLoading = false;
|
||
this.form.code = response.data || '';
|
||
},
|
||
|
||
// initialize
|
||
async initOptions() {
|
||
this.initEquipment();
|
||
this.initWorker();
|
||
this.initPlan();
|
||
},
|
||
|
||
async initEquipment(type = 'special-equipment') {
|
||
this.formLoading = true;
|
||
const response = await this.$axios('/base/core-equipment/listAll');
|
||
this.equipmentList = response.data || [];
|
||
const equipmentOptions = (response.data || [])
|
||
.filter((item) => (type == 'special-equipment' ? item.special : true))
|
||
.map((item) => ({
|
||
label: item.name,
|
||
value: item.id,
|
||
}));
|
||
this.equipmentOptions = equipmentOptions;
|
||
this.allSpeicalEquipments = equipmentOptions;
|
||
this.formLoading = false;
|
||
},
|
||
|
||
async initWorker() {
|
||
this.formLoading = true;
|
||
const response = await this.$axios({
|
||
url: '/base/core-worker/listAll',
|
||
});
|
||
this.workerOptions = (response.data || []).map((item) => ({
|
||
label: item.name,
|
||
value: item.id,
|
||
}));
|
||
this.formLoading = false;
|
||
},
|
||
|
||
async initPlan() {
|
||
this.formLoading = true;
|
||
const response = await this.$axios({
|
||
url: '/base/equipment-maintain-plan/page',
|
||
params: { pageNo: 1, pageSize: 100, speical: true },
|
||
});
|
||
this.planOptions = (response.data?.list || []).map((item) => ({
|
||
label: item.name,
|
||
value: item.id,
|
||
}));
|
||
this.formLoading = false;
|
||
},
|
||
|
||
// handlers
|
||
handleEqTypeChange(type) {
|
||
this.form.equipmentId = null;
|
||
if (type) {
|
||
this.equipmentOptions = this.equipmentList
|
||
.filter((item) => item.special)
|
||
.filter((item) => item.specialType === type)
|
||
.map((item) => ({ label: item.name, value: item.id }));
|
||
} else
|
||
this.equipmentOptions = this.equipmentList.map((item) => ({
|
||
label: item.name,
|
||
value: item.id,
|
||
}));
|
||
// this.$emit('update', this.form)
|
||
},
|
||
|
||
handleEqChange() {
|
||
this.$emit('update', this.form);
|
||
},
|
||
|
||
// 修改 是否计划保养 时
|
||
handlePlanChange(val) {
|
||
console.log('handlePlanChange', val);
|
||
this.form.equipmentCategory = null;
|
||
this.form.equipmentId = null;
|
||
this.$emit('update', { ...this.form, relatePlan: val });
|
||
this.initEquipment(val == 1 ? 'special-equipment' : null);
|
||
},
|
||
|
||
handleEditorInput(html) {
|
||
this.$emit('update', {
|
||
...this.form,
|
||
maintenanceDes: html,
|
||
});
|
||
},
|
||
|
||
// upload
|
||
handleFilesOpen() {},
|
||
|
||
beforeUpload() {},
|
||
|
||
handleUploadSuccess(response, file) {
|
||
this.$modal.msgSuccess('上传成功');
|
||
console.log('file', file);
|
||
this.form.files.push({
|
||
fileName: file.name,
|
||
fileUrl: response.data,
|
||
});
|
||
this.$emit('update', this.form);
|
||
},
|
||
|
||
handleDeleteFile(file) {},
|
||
},
|
||
};
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.el-date-editor,
|
||
.el-select {
|
||
width: 100%;
|
||
}
|
||
|
||
.upload-area {
|
||
// background: #ccc;
|
||
// display: grid;
|
||
// grid-auto-rows: 34px;
|
||
// grid-template-columns: repeat(6, minmax(32px, max-content));
|
||
// gap: 8px;
|
||
// align-items: center;
|
||
position: relative;
|
||
overflow: hidden;
|
||
transition: height 0.3s ease-out;
|
||
// margin-top: 40px;
|
||
}
|
||
|
||
.upload-in-dialog {
|
||
// display: inline-block;
|
||
margin-right: 24px;
|
||
// background: #ccc;
|
||
position: relative;
|
||
// top: -13px;
|
||
float: left;
|
||
}
|
||
|
||
.close-icon {
|
||
// background: #ccc;
|
||
position: absolute;
|
||
top: 0;
|
||
right: 12px;
|
||
z-index: 100;
|
||
transition: transform 0.3s ease-out;
|
||
}
|
||
|
||
.close-icon.open {
|
||
transform: rotateZ(90deg);
|
||
}
|
||
|
||
.dialog__upload_component__close {
|
||
color: #ccc;
|
||
}
|
||
.dialog__upload_component__close:hover {
|
||
/* color: #777; */
|
||
color: red;
|
||
}
|
||
|
||
.height-48 {
|
||
height: 35px !important;
|
||
}
|
||
|
||
:deep(.record-add__editor) {
|
||
.ql-picker-label {
|
||
display: flex;
|
||
}
|
||
}
|
||
</style>
|