<template>
<div>
<div class="app-container">
<div class="search-div">
<el-form ref="searchForm" :inline="true" :model="listQuery" class="form-container">
<el-row>
<el-form-item class="selectForm-container-item" prop="markerId">
<el-input v-model.trim="listQuery.markerId" placeholder="标识器ID" clearable />
</el-form-item>
<el-form-item class="selectForm-container-item" prop="status">
<el-select v-model.trim="listQuery.status" placeholder="工单状态" clearable >
<el-option key="0" label="待派发" value="0"/>
<el-option key="1" label="待处理" value="1"/>
<el-option key="2" label="已完成" value="2"/>
</el-select>
</el-form-item>
<el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
</el-row>
</el-form>
</div>
<el-row class="table-title">
<el-col :span="6"><div class="title-header"><i class="el-icon-menu"/>数据列表</div></el-col>
<el-col :span="12" :offset="6" class="edit_btns">
<el-button v-if="hasPerm('/inspection/distribute')" class="edit_btn" size="small" @click="distribute">派发</el-button>
<el-button v-if="hasPerm('/inspection/delete')" class="edit_btn" size="small" @click="del">删除</el-button>
</el-col>
</el-row>
<el-table v-loading="listLoading" ref="table" :data="jobList" class="table" border @selection-change="handleSelectionChange">
<el-table-column align="center" type="selection" width="50" />
<el-table-column :index="indexMethod" align="center" type="index" />
<el-table-column v-for="column in tableColumns" :key="column.value" :label="column.text" :width="column.width" align="center" show-overflow-tooltip>
<template slot-scope="scope">
<span :class="column.class">{{ scope.row[column.value] }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center">
<template slot-scope="scope">
<el-button type="text" @click="showDetail(scope.row)">查看</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!--分页-->
<div class="pagination-container">
<el-pagination
:current-page="listQuery.offset"
:page-sizes="[5,10,20,30,50]"
:page-size="listQuery.limit"
:total="total"
align="center"
layout="total, sizes, prev, pager, next"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"/>
</div>
<inspection-detail v-show="detailShow" ref="inspectionDetail"/>
<distribute ref="distribute" @watchData="fetchData"/>
</div>
</template>
<script>
import { getInspectionList, inspectionDelete } from '@/api/job'
import InspectionDetail from '@/views/job/inspection/inspectionDetail'
import Distribute from '@/views/job/inspection/distribute'
export default {
name: 'InspectionList',
components: { InspectionDetail, Distribute },
data() {
return {
jobList: [],
listQuery: {
markerId: '',
status: '',
limit: 5,
offset: 1,
sort: '',
order: ''
},
total: 0,
multipleSelection: [],
listLoading: false,
detailShow: false, // 是否显示详情框
tableColumns: [
// {
// text: '工单id',
// value: 'id'
// },
{
text: '标识器ID',
value: 'markerId'
},
{
text: '产品信息',
value: 'productInfo'
},
{
text: '详细地址',
value: 'position'
},
{
text: '工单状态',
value: 'status'
},
{
text: '创建时间',
value: 'createTime'
},
{
text: '巡检人员',
value: 'username'
}
]
}
},
mounted() {
if (this.$route.params) {
this.listQuery.markerId = this.$route.params.markerId
}
this.fetchData()
},
activated() {
if (this.$route.params) {
this.listQuery.markerId = this.$route.params.markerId
}
this.fetchData()
},
methods: {
async fetchData() {
this.listLoading = true
// console.log('fetch', this.listQuery)
const res = await getInspectionList(this.listQuery)
this.jobList = res.data.rows
this.total = res.data.total
this.listLoading = false
},
search() {
this.listQuery.offset = 1
this.fetchData()
},
indexMethod(index) {
return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1
},
// 改变页容量
handleSizeChange(val) {
this.listQuery.limit = val
this.fetchData()
},
// 改变当前页
handleCurrentChange(val) {
this.listQuery.offset = val
this.fetchData()
},
// 多选触发方法
handleSelectionChange(val) {
this.multipleSelection = val
},
// 检查选择情况
checkSelection(status) {
console.log(this.multipleSelection)
if (this.multipleSelection.length === 0) {
this.$message.error('至少选中一项')
return false
} else if (status === 'del') {
console.log(this.multipleSelection)
for (var item of this.multipleSelection) {
if (item.status !== '已完成') {
this.$message.warning('只能删除已完成工单')
return false
}
}
return true
} else if (status === 'distribute') {
console.log(this.multipleSelection)
for (var item2 of this.multipleSelection) {
if (item2.status !== '待派发') {
this.$message.warning('只能派发待派发工单')
return false
}
}
return true
} else {
return true
}
},
couldDistribute(row) {
if (row.status === '待派发') {
return true
} else {
return false
}
},
showDetail(row) {
this.detailShow = true
this.$refs.inspectionDetail.initDialog(true, row)
},
distribute() {
if (!this.checkSelection('distribute')) {
return
}
this.$refs.distribute.initDialog(true, this.multipleSelection)
},
del() {
if (!this.checkSelection('del')) {
return
}
const jobIds = []
this.multipleSelection.forEach(function(value, index) {
jobIds.push(value.id)
})
this.$confirm('确定要删除所选工单吗?', '确认操作', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
inspectionDelete(jobIds).then(response => {
if (response.code === 200) {
this.$message.success('删除成功')
this.fetchData()
}
})
})
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
$tableTitleHeight:46px;
.table-container{
margin: 20px;
// margin-top: 50px;
}
.table{
margin-bottom: 20px;
}
.pagination-container{
margin-bottom: 50px;
}
.table-title{
background-color:rgba(243, 243, 243, 1);
height: $tableTitleHeight;
.title-header{
line-height:$tableTitleHeight;
color: #606266;
font-size: 15px;
i{
margin-left: 5px;
margin-right: 5px;
}
}
}
.edit_btns{
.edit_btn{
float:right;
margin:7px 10px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2
}
}
</style>