<template>
|
<div>
|
<el-dialog :close-on-click-modal="false" :close-on-press-escape="false"
|
:visible.sync="applicationForm" title="添加设备校准计划"
|
width="80%" @close="closeDialog">
|
<div style="display: flex;align-items: center;">
|
<el-button style="margin-right: 10px" size="small" type="primary" @click="addTableRow">添加</el-button>
|
<span style="width: 80px">计划名称:</span>
|
<el-input style="width: 300px;margin-right: 10px" v-model="form.planName" clearable size="small"></el-input>
|
<span style="width: 60px">年份:</span>
|
<el-date-picker
|
v-model="form.planYear"
|
type="year"
|
value-format="yyyy"
|
clearable
|
size="small"
|
format="yyyy"
|
placeholder="选择年">
|
</el-date-picker>
|
</div>
|
<div style="margin: 10px 0">
|
<el-table ref="yearTable" :data="calibrationPlanDetailList"
|
id="templateParamTable" row-key="deviceId"
|
height="300px" style="width: 100% ;">
|
<el-table-column label="设备名称及型号" min-width="190" prop="deviceName">
|
<template slot-scope="scope">
|
<el-input v-model="scope.row.deviceName" clearable size="small"></el-input>
|
</template>
|
</el-table-column>
|
<el-table-column label="仪器编号" min-width="190" prop="deviceNumber">
|
<template slot-scope="scope">
|
<el-input v-model="scope.row.deviceNumber" clearable size="small"></el-input>
|
</template>
|
</el-table-column>
|
<el-table-column label="设备数量" min-width="120" prop="deviceAmount">
|
<template slot-scope="scope">
|
<el-input v-model="scope.row.deviceAmount" clearable size="small"></el-input>
|
</template>
|
</el-table-column>
|
<el-table-column label="检定单位" min-width="120" prop="verificationUnit">
|
<template slot-scope="scope">
|
<el-input v-model="scope.row.verificationUnit" clearable size="small"></el-input>
|
</template>
|
</el-table-column>
|
<el-table-column label="检定周期" min-width="120" prop="verificationCycles">
|
<template slot-scope="scope">
|
<el-input v-model="scope.row.verificationCycles" clearable size="small"></el-input>
|
</template>
|
</el-table-column>
|
<el-table-column label="最近检定时间" min-width="170" prop="lastDate">
|
<template slot-scope="scope">
|
<el-date-picker v-model="scope.row.lastDate"
|
clearable
|
format="yyyy-MM-dd"
|
placeholder="选择日期"
|
size="small"
|
style="width:100%"
|
type="date"
|
value-format="yyyy-MM-dd">
|
</el-date-picker>
|
</template>
|
</el-table-column>
|
<el-table-column label="本年计划校准时间" min-width="170" prop="planDate">
|
<template slot-scope="scope">
|
<el-date-picker v-model="scope.row.planDate"
|
clearable
|
format="yyyy-MM-dd"
|
placeholder="选择日期"
|
size="small"
|
style="width:100%"
|
type="date"
|
value-format="yyyy-MM-dd">
|
</el-date-picker>
|
</template>
|
</el-table-column>
|
<el-table-column label="备注" min-width="170" prop="remark">
|
<template slot-scope="scope">
|
<el-input v-model="scope.row.remark" clearable size="small"></el-input>
|
</template>
|
</el-table-column>
|
<el-table-column fixed="right" label="操作" width="80" align="center">
|
<template slot-scope="scope">
|
<el-button style="color: #f56c6c" type="text" @click="deleteRow(scope.$index)">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="closeDialog">取 消</el-button>
|
<el-button :loading="submitFormLoading" type="primary" @click="submitForm">确 认</el-button>
|
</span>
|
</el-dialog>
|
<el-dialog :close-on-click-modal="false" :close-on-press-escape="false"
|
:visible.sync="addEquipDia" title="新增年度计划" width="50%">
|
<el-table ref="multipleTable" :data="equipOptions" tooltip-effect="dark" height="500"
|
style="width: 100%" @selection-change="handleSelectionChange">
|
<el-table-column type="selection" width="55"></el-table-column>
|
<el-table-column label="设备名称" prop="label"></el-table-column>
|
<el-table-column prop="value" label="设备编号"></el-table-column>
|
</el-table>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="addEquipDia = false">取 消</el-button>
|
<el-button :loading="submitFormLoading" type="primary" @click="changeMachineName">确 认</el-button>
|
</span>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import Sortable from "sortablejs";
|
|
export default {
|
name: "addYearPlanDia",
|
// import 引入的组件需要注入到对象中才能使用
|
components: {},
|
data() {
|
// 这里存放数据
|
return {
|
applicationForm: false,
|
addEquipDia: false,
|
submitFormLoading: false,
|
equipOptions: [],
|
calibrationPlanDetailList: [],
|
selectionRows: [],
|
form: {
|
planName: '',
|
planYear: '',
|
calibrationPlanDetailList: [],
|
}
|
}
|
},
|
mounted() {
|
|
},
|
// 方法集合
|
methods: {
|
openDialog () {
|
this.form = {
|
planName: '',
|
planYear: '',
|
examinePlanDetailsList: [],
|
}
|
this.applicationForm = true
|
},
|
// 添加设备
|
addTableRow () {
|
this.addEquipDia = true
|
this.getEquipOptions()
|
},
|
handleSelectionChange (selection) {
|
this.selectionRows = selection
|
},
|
changeMachineName () {
|
this.calibrationPlanDetailList = []
|
this.selectionRows.map(val => {
|
this.calibrationPlanDetailList.push({deviceId: val.id, deviceName: val.label, deviceNumber: val.value, specificationModel: val.specificationModel})
|
})
|
this.addEquipDia = false
|
this.rowDrop()
|
},
|
rowDrop() {
|
const that = this
|
const tbody = document.querySelector(
|
'#templateParamTable .el-table__body-wrapper tbody'
|
)
|
if (!this.sortTable) {
|
this.sortTable = Sortable.create(tbody, {
|
animation: 200, //动画时长
|
handle: ".el-table__row", //可拖拽区域class
|
//拖拽中事件
|
onMove: ({ dragged, related }) => {
|
const oldRow = that.calibrationPlanDetailList[dragged.rowIndex] //旧位置数据
|
const newRow = that.calibrationPlanDetailList[related.rowIndex] //被拖拽的新数据
|
},
|
//拖拽结束事件
|
onEnd: evt => {
|
const curRow = that.calibrationPlanDetailList.splice(evt.oldIndex, 1)[0];
|
that.calibrationPlanDetailList.splice(evt.newIndex, 0, curRow);
|
}
|
})
|
}
|
},
|
// 删除表格行
|
deleteRow (index) {
|
this.calibrationPlanDetailList.splice(index, 1)
|
},
|
// 提交新增
|
submitForm() {
|
this.form.calibrationPlanDetailList = this.HaveJson(this.calibrationPlanDetailList)
|
this.submitFormLoading = true
|
this.$axios.post(this.$api.deviceCalibrationPlan.addDeviceCalibrationPlan,
|
this.form, {
|
headers: {
|
'Content-Type': 'application/json'
|
},
|
noQs: true
|
}).then(res => {
|
if (res.code == 200) {
|
this.$message.success('新增成功')
|
this.closeDialog()
|
this.$emit('closeDia')
|
}
|
this.submitFormLoading = false
|
}).catch(err => {
|
this.submitFormLoading = false
|
})
|
},
|
closeDialog () {
|
this.applicationForm = false
|
},
|
// 获取所有设备
|
getEquipOptions() {
|
this.equipOptions = []
|
this.$axios.get(this.$api.deviceScope.deviceScopeSearch+'?status=0').then(res => {
|
if (res.code === 200 && res.data) {
|
this.equipOptions = res.data.map(m => {
|
m.value = m.managementNumber
|
m.label = m.deviceName
|
return m
|
})
|
}
|
}).catch(error => {
|
console.error(error)
|
})
|
},
|
},
|
}
|
</script>
|
|
<style scoped>
|
</style>
|