提交 | 用户 | 时间
|
dea0a3
|
1 |
<template> |
A |
2 |
<el-dialog :title="title" :visible.sync="visible" @close="handleClose"> |
|
3 |
<el-table :data="gridData" selection="single" ref="multipleTable" @selection-change="productSelectionChange"> |
|
4 |
<el-table-column type="selection" width="55"></el-table-column> |
|
5 |
<el-table-column property="date" label="日期" width="150"></el-table-column> |
|
6 |
<el-table-column property="name" label="姓名" width="200"></el-table-column> |
|
7 |
<el-table-column property="address" label="地址"></el-table-column> |
|
8 |
</el-table> |
|
9 |
<div slot="footer" class="dialog-footer"> |
|
10 |
<el-button @click="handleClose">取 消</el-button> |
|
11 |
<el-button type="primary" @click="confirmSelection">确 定</el-button> |
|
12 |
</div> |
|
13 |
</el-dialog> |
|
14 |
</template> |
|
15 |
|
|
16 |
<script> |
|
17 |
export default { |
|
18 |
name: "ProductSelector", |
|
19 |
props: { |
|
20 |
visible: Boolean, |
|
21 |
title: { |
|
22 |
type: String, |
|
23 |
default: "物料信息" |
|
24 |
}, |
|
25 |
gridData: Array |
|
26 |
}, |
|
27 |
data() { |
|
28 |
return { |
|
29 |
multipleSelection: [] |
|
30 |
}; |
|
31 |
}, |
|
32 |
methods: { |
|
33 |
handleClose() { |
|
34 |
this.$emit('update:visible', false); |
|
35 |
}, |
|
36 |
productSelectionChange(selection) { |
|
37 |
if (selection.length > 1) { |
|
38 |
this.$refs.multipleTable.clearSelection(); |
|
39 |
this.$refs.multipleTable.toggleRowSelection(selection[selection.length - 1], true); |
|
40 |
this.multipleSelection = [selection[selection.length - 1]]; |
|
41 |
} else { |
|
42 |
this.multipleSelection = selection; |
|
43 |
} |
|
44 |
}, |
|
45 |
confirmSelection() { |
|
46 |
if (this.multipleSelection.length > 0) { |
|
47 |
this.$emit('select-product', this.multipleSelection[0]); |
|
48 |
this.handleClose(); |
|
49 |
} else { |
|
50 |
this.$message({ |
|
51 |
message: '警告哦,未选择任何行', |
|
52 |
type: 'warning' |
|
53 |
}); |
|
54 |
} |
|
55 |
} |
|
56 |
} |
|
57 |
}; |
|
58 |
</script> |