<template>
|
<div class="mod-taskReliability-taskPhaseModel fa-card-a" style="margin-left: 5px;">
|
<zt-table-wraper ref="tableObj" defaultNotQuery="true" query-url="/taskReliability/TaskPhaseModel/page"
|
:paging='false'
|
@dataLoaded="dataLoaded"
|
delete-url="/taskReliability/TaskPhaseModel/" v-slot="{ table }">
|
<el-form :inline="true" :model="dataForm" @keyup.enter.native="table.query()">
|
<el-form-item>
|
<zt-button type="warning" @click="handleSaveRows">保存</zt-button>
|
</el-form-item>
|
</el-form>
|
<el-table v-loading="table.dataLoading" :data="table.dataList" height="100px"
|
v-adaptive="{bottomOffset:30}" border
|
@cell-click="handleCellClick"
|
@selection-change="table.selectionChangeHandle">
|
<el-table-column prop="operatConditName" label="工况名称" width="160"/>
|
<el-table-column prop="operatConditDurationRate" label="工况时长比">
|
<template slot-scope="scope">
|
<span
|
v-if="editingCell && editingCell.row === scope.row && editingCell.column.property === scope.column.property">
|
<el-input ref="editInput"
|
autosize v-model="scope.row.operatConditDurationRate"
|
placeholder="工况时长比"></el-input>
|
</span>
|
<span v-else>{{scope.row.operatConditDurationRate}}</span>
|
</template>
|
</el-table-column>
|
<el-table-column align="center" label="选用">
|
<template v-slot="{ row }">
|
<el-checkbox true-label="1" false-label="0" v-model="row.isCheck"></el-checkbox>
|
</template>
|
</el-table-column>
|
</el-table>
|
</zt-table-wraper>
|
</div>
|
</template>
|
|
<script>
|
|
export default {
|
name: 'TaskPhaseModel',
|
data() {
|
return {
|
dataForm: {
|
productId: '',
|
phaseId: '',
|
operatConditName: '',
|
operatConditId: '',
|
operatConditDurationRate: '',
|
dataList: [],
|
isCheck: ''
|
},
|
editingCell: null,
|
dataList: [],
|
originalTableData: [],
|
originalData: null,
|
}
|
},
|
components: {},
|
methods: {
|
init(param) {
|
console.log(param, '')
|
this.dataForm.phaseId = param.row.id
|
this.dataForm.productId = param.productId
|
this.$refs.tableObj.query()
|
},
|
//批量保存
|
async handleSaveRows() {
|
let time = null
|
let flag = true
|
let list = []
|
this.dataForm.dataThreeList = this.$refs.tableObj.dataList
|
for (let i = 0; i < this.dataForm.dataThreeList.length; i++) {
|
time = time + Number(this.dataForm.dataThreeList[i].operatConditDurationRate)
|
if (this.dataForm.dataThreeList[i].isCheck === '0' && this.dataForm.dataThreeList[i].operatConditDurationRate != null) {
|
this.$alert("有未勾选的工况")
|
flag = false
|
} else if (this.dataForm.dataThreeList[i].isCheck === '1' && this.dataForm.dataThreeList[i].operatConditDurationRate == null) {
|
this.$alert("有未填写的工况时长")
|
flag = false
|
}
|
|
if (this.dataForm.dataThreeList[i].isCheck==='1'){
|
list.push(this.dataForm.dataThreeList[i])
|
}
|
}
|
this.dataForm.dataThreeList = list
|
console.log(time, 'async handleSaveRows')
|
if (time!== 1) {
|
this.$alert("请重新设置当前时长比分配")
|
return
|
}
|
if (!flag) {
|
return
|
}
|
let res = await this.$http.post('/taskReliability/TaskPhaseModel/save', this.dataForm)
|
if (res.success) {
|
console.log(res.data)
|
await this.$tip.success()
|
this.originalData = null
|
this.dataForm.dataThreeList = null
|
this.$refs.tableObj.query()
|
this.originalTableData = JSON.parse(JSON.stringify(this.dataList)); // 更新初始数据为当前数据
|
console.log(this.originalTableData, 'this.originalTableData 当前表格json数据')
|
}
|
},
|
dataLoaded(data) {
|
this.dataList = data
|
for (let i = 0; i < this.dataList.length; i++) {
|
this.dataList[i].productId = this.dataForm.productId
|
this.dataList[i].phaseId = this.dataForm.phaseId
|
}
|
},
|
handleCellClick(row, column) {
|
this.editingCell = {row, column}
|
this.$nextTick(() => {
|
if (this.$refs.editInput) {
|
this.$refs.editInput.focus()
|
}
|
})
|
console.log(this.editingCell, 'this.editingCell')
|
}
|
,
|
|
}
|
}
|
</script>
|