lanan-system-vue/src/views/repair/tickets/Components/TicketItem.vue

174 lines
5.1 KiB
Vue
Raw Normal View History

2024-09-12 18:29:04 +08:00
<template>
<div>
2024-09-19 19:46:32 +08:00
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"
@cell-mouse-enter="handleCellEnter"
@cell-mouse-leave="handleCellLeave"
@cell-click="handleCellClick"
>
2024-09-12 18:29:04 +08:00
<el-table-column label="序号" align="center">
<template scope="scope">
<span>{{ scope.$index + 1 }}</span>
</template>
</el-table-column>
2024-09-19 19:46:32 +08:00
<el-table-column align="center" :label="getLabelName" width="200" prop="goods">
<div class="item" slot-scope="scope">
<PartChoose @input-blur="save(scope.row)" class="item__input" @selected="getPart" :select-width="'15rem'"/>
<span class="item__txt">{{ scope.row.name ? scope.row.name : scope.row.goods }}</span>
</div>
2024-09-12 18:29:04 +08:00
</el-table-column>
2024-09-19 19:46:32 +08:00
<el-table-column align="center" label="规格" width="180" prop="model"/>
<el-table-column align="center" label="编码" width="180" prop="code"/>
<el-table-column align="center" label="数量" width="180" prop="count"/>
<el-table-column align="center" label="单位" width="180" prop="unit"/>
<el-table-column align="center" label="折扣" width="180"/>
<el-table-column align="center" label="金额" width="180"/>
<el-table-column align="center" label="施工人员" width="180"/>
<el-table-column align="center" label="销售人员" width="180"/>
<el-table-column align="center" label="类型" width="180"/>
<el-table-column align="center" label="账类" width="180"/>
<el-table-column align="center" label="状态" width="180"/>
<el-table-column align="center" label="备注" width="180"/>
2024-09-12 18:29:04 +08:00
<el-table-column label="操作" fixed="right" align="center" width="150">
<template v-slot="scope">
<el-button size="mini" type="text" icon="el-icon-delete"
>新增
</el-button>
<el-button size="mini" type="text" icon="el-icon-delete"
>删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
import PartChoose from "@/views/repair/Components/PartChoose.vue";
export default {
name: "TicketItem",
components: {PartChoose},
props:{
itemType:{
type: String,
2024-09-19 19:46:32 +08:00
default: 'project',
2024-09-12 18:29:04 +08:00
required: true
}
},
data() {
return {
loading: false,
2024-09-19 19:46:32 +08:00
list: [{}],
// 需要编辑的属性
editProp: ["goods"],
// 保存进入编辑的cell
clickCellMap: {}
2024-09-12 18:29:04 +08:00
}
},
computed:{
getLabelName(){
switch (this.itemType){
case "project":
return "维修项目";
case "part":
return "维修配件";
case "other":
return "附加费用";
default:
return '';
}
}
},
2024-09-19 19:46:32 +08:00
methods: {
/** 鼠标移入cell */
handleCellEnter(row, column, cell, event) {
const property = column.property
if (this.editProp.includes(property)) {
cell.querySelector('.item__txt').classList.add('item__txt--hover')
}
},
/** 鼠标移出cell */
handleCellLeave(row, column, cell, event) {
const property = column.property
if (this.editProp.includes(property)) {
cell.querySelector('.item__txt').classList.remove('item__txt--hover')
}
},
/** 点击cell */
handleCellClick(row, column, cell, event) {
const property = column.property
if (this.editProp.includes(property)) {
// 保存cell
this.saveCellClick(row, cell)
cell.querySelector('.item__txt').style.display = 'none'
cell.querySelector('.item__input').style.display = 'inline'
cell.querySelector('input').focus()
}
},
/** 取消编辑状态 */
cancelEditable(cell) {
cell.querySelector('.item__txt').style.display = 'inline'
cell.querySelector('.item__input').style.display = 'none'
},
/** 保存进入编辑的cell */
saveCellClick(row, cell) {
const id = row.id
if (this.clickCellMap[id] !== undefined) {
if (!this.clickCellMap[id].includes(cell)) {
this.clickCellMap[id].push(cell)
}
} else {
this.clickCellMap[id] = [cell]
}
},
/** 保存数据 */
save (row) {
const id = row.id
// 取消本行所有cell的编辑状态
this.clickCellMap[id].forEach(cell => {
this.cancelEditable(cell)
})
this.clickCellMap[id] = []
},
getPart(data){
this.list.splice(this.list.length - 1, 0, data)
}
}
2024-09-12 18:29:04 +08:00
}
</script>
<style scoped lang="scss">
2024-09-19 19:46:32 +08:00
.item {
.item__input {
display: none;
width: 100px;
/* 调整elementUI中样式 如果不需要调整请忽略 */
.el-input__inner {
height: 24px !important;
}
2024-09-12 18:29:04 +08:00
2024-09-19 19:46:32 +08:00
/* 调整elementUI中样式 如果不需要调整请忽略 */
.el-input__suffix {
i {
font-size: 12px !important;
line-height: 26px !important;
}
}
}
.item__txt {
box-sizing: border-box;
border: 1px solid transparent;
width: 100px;
line-height: 24px;
padding: 0 8px;
}
.item__txt--hover {
border: 1px solid #dddddd;
border-radius: 4px;
cursor: text;
}
}
2024-09-12 18:29:04 +08:00
</style>