relateStoreDialog.vue
5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!-- 关联门店弹窗 -->
<template>
<d2-dialog
title="关联门店"
:isVisible.sync="relateStoreVisible"
width="70%"
btnOkLabel="关联"
@confirmDialog="handleRelateStoreConfirm"
@closeDialog="handleRelateStoreClose"
class="relateStore"
>
<slot></slot>
<el-row>
<el-col :span="12">
<el-table
ref="seletingTable"
:data="selectingData"
height="500px"
class="table"
border
@select="handleChange"
@select-all="handleAll"
>
<el-table-column
type="selection"
width="55"
align="center"
:selectable="selectable"
></el-table-column>
<!-- <el-table-column>
<template slot-scope="scope">{{scope.row.beServed}}</template>
</el-table-column> -->
<el-table-column
prop="merchantName"
label="门店名称"
align="center"
></el-table-column>
</el-table>
<el-pagination
small
background
@current-change="handleCurrentChange"
:current-page.sync="currentPage"
:page-size="pageSize"
layout="total, prev, pager, next"
:total="total"
></el-pagination>
</el-col>
<el-col :span="12">
<el-table
:data="selectedData"
class="table"
border
height="500px"
>
<el-table-column
prop="merchantName"
align="center"
label="门店名称"
></el-table-column>
</el-table>
</el-col>
</el-row>
</d2-dialog>
</template>
<script>
export default {
name: 'relateStoreDialog',
data() {
return {
selectedData: [],
selectingData: [],
// 分页
total: 0,
currentPage: 1,
pageSize: 10
}
},
props: {
relateStoreVisible: {
type: Boolean,
default: false
},
storeApi: {
type: Function,
default: () => { }
},
storeSelected: {
type: Array,
default: () => []
},
storeSearchForm: {
type: Object,
default: () => { }
}
// 限制个数
// maxLength: {
// type: String,
// default: '-1'
// }
},
mounted() {
this.selectedData = this.storeSelected
this.getSelectingList()
},
methods: {
selectable(row, index) {
return row.hasOwnProperty('beServed') ? !row.beServed : true
},
recoverySelection() {
var exitIds = this.selectedData.map(item => item.merchantId)
this.selectingData.forEach(item => {
exitIds.includes(item.merchantId) && this.$refs.seletingTable.toggleRowSelection(item, true)
})
},
getSelectingList() {
this.storeApi({
...this.storeSearchForm,
currentPage: this.currentPage,
pageSize: this.pageSize
}).then(res => {
console.log(res)
this.selectingData = res.list
this.total = res.total
this.$nextTick(() => {
this.recoverySelection()
})
})
},
handleChange(selection, row) {
var addOrDelete = !!selection.find(item => item.merchantId === row.merchantId)
// var item = selection.find(item => item.merchantId === row.merchantId)
// if (addOrDelete) {
// if (this.maxLength !== '-1' && this.selectedData.length > this.maxLength - 1) {
// this.$message.error(`只能选择${this.maxLength}个门店`)
// this.$refs.seletingTable.toggleRowSelection(item, false)
// return true
// }
// this.selectedData.push(row)
// return true
// }
// this.selectedData = this.selectedData.filter(item => item.merchantId !== row.merchantId)
addOrDelete
? this.selectedData.push(row)
: (this.selectedData = this.selectedData.filter(item => item.merchantId !== row.merchantId))
},
handleAll(selection) {
// if (this.selectingData[0].hasOwnProperty('beServed') && ((selection.map(i => i.beServed === true).length + this.selectedData.length) > (this.maxLength - 1)) && selection.length) {
// this.$message.error(`只能选择${this.maxLength}个门店`)
// this.selectingData.forEach(item => {
// this.$refs.seletingTable.toggleRowSelection(item, false)
// })
// console.log(this.selectedData)
// return true
// }
// this.selectingData.forEach(item => {
// var isExit = this.selectedData.findIndex(subItem => subItem.merchantId === item.merchantId)
// var isServed = item.hasOwnProperty('beServed') ? item.beServed : false
// if (selection.length && (isExit === -1) && !isServed) {
// this.selectedData.push(item)
// } else if (!selection.length && (isExit !== -1) && !isServed) {
// this.selectedData.splice(isExit, 1)
// }
// })
this.selectingData.forEach(item => {
var isExit = this.selectedData.findIndex(subItem => subItem.merchantId === item.merchantId)
var isServed = item.hasOwnProperty('beServed') ? item.beServed : false
if (selection.length && (isExit === -1) && !isServed) {
this.selectedData.push(item)
} else if (!selection.length && (isExit !== -1)) {
this.selectedData.splice(isExit, 1)
}
})
},
handleCurrentChange(val) {
this.currentPage = val
this.getSelectingList()
},
handleRelateStoreConfirm() {
this.$emit('handleRelateStoreConfirm', this.selectedData)
},
handleRelateStoreClose() {
this.$emit('handleRelateStoreClose')
}
}
}
</script>
<style>
.relateStore .table {
margin: 0 auto 20px !important;
width: 98%;
}
.relateStore .el-table .cell {
line-height: 26px !important;
}
.relateStore .el-table .cell {
padding: 0 8px !important;
}
</style>