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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
| <template> <table class="user-table"> <!--表头--> <tbody> <tr class="tb-title"> <th class="tb-checkbox"> <el-checkbox @change="allUserSelectHandle" v-model="alluserselect" :indeterminate="allindeterminate"></el-checkbox> </th> <th>用户信息</th> <th>部门</th> <th>职位</th> <th>手机号</th> </tr> </tbody>
<!--内容--> <div class="tb-content"> <tbody v-for="group in showUserTable" :key="group.id">
<!--公司栏--> <tr :class="['tb-context','open','company-row','company-'+group.id]" @click="userPackUp(group)"> <td class="tb-checkbox"> <el-checkbox @change="groupSelectHandle" v-model="group.checked" :indeterminate="group.indeterminate"></el-checkbox> </td> <td colspan="4" class="company-col"> <div class="company"> <div class="company-name">{{group.name}}</div> <div class="tb-select" @click="e=>userPackUp(group,e)"> <i class="el-icon-caret-bottom"></i> </div> </div> </td> </tr>
<!--用户栏--> <tr class="tb-context user-row" v-for="user,index in group.children" :key="user.WxOpenid">
<td class="tb-checkbox" :rowspan="group.children.length" v-if="index==0&&group.show"></td>
<td class="name-merge" v-if="group.show"> <div class="tb-checkbox"> <el-checkbox @change="userSelectHandle" v-model="user.checked"></el-checkbox> </div> <div class="tb-name"> {{user.UserRealName}} </div> </td>
<td v-if="group.show">{{user.UserCompanyBranch}}</td> <td v-if="group.show">{{user.UserJob}}</td> <td v-if="group.show">{{user.UserPhone}}</td> </tr> </tbody> </div> </table> </template>
<script> import _find from "lodash/find";
import {getDatabaseUser} from "@api/billing.js"
export default { name:"test", data() { return { stepActive:0, // 激活步骤
alluserselect:false, // 全部用户是否选中 allindeterminate:false, // 半选状态 showUserTable:[], // 用户显示信息表格 } }, mounted(){ this.init(); }, methods:{ init(){ this.getUserList(); }, // 获取用户列表 getUserList(){ this.showUserTable=[{ id:1, name:"组名1", checked:false, indeterminate:false, // 半选状态 show:true, // 是否打开分组 children:[ { "WxOpenid":"1", "UserCompanyBranch":"部门", "UserJob":"职位", "UserPhone":"手机号", checked:false, }, { "WxOpenid":"2", "UserCompanyBranch":"部门", "UserJob":"职位", "UserPhone":"手机号", checked:false, } ] },{ id:2, name:"组名2", checked:false, indeterminate:false, // 半选状态 show:true, // 是否打开分组 children:[ { "WxOpenid":"12", "UserRealName":"用户名", "UserCompanyBranch":"部门", "UserJob":"职位", "UserPhone":"手机号", checked:false, }, { "WxOpenid":"22", "UserRealName":"用户名", "UserCompanyBranch":"部门", "UserJob":"职位", "UserPhone":"手机号", checked:false, } ] }] }, // 用户收起 userPackUp(group,e){ let id=group.id; let companyDiv=document.querySelector('.tb-content .company-'+id); console.log(group);
if(companyDiv.classList.contains("open")){ this.$set(group,"show",false); // 关闭 companyDiv.classList.remove("open"); }else{ this.$set(group,"show",true); // 打开 companyDiv.classList.add("open"); } // 取消引用 companyDiv=null;
// 阻止冒泡 if(e){ e.stopPropagation(); } }, // 用户选中处理事件 userSelectHandle(){ // 全部用户选中 let users=this.showUserTable; let userNumber=0; let userAllSelectNumber=0; // 遍历是否选中用户 for(let group of users){ let userSelectNumber=0; for(let user of group.children){ if(user.checked){ userSelectNumber++; userAllSelectNumber++; } userNumber++; } // 全选 if(userSelectNumber==group.children.length){ group.checked=true; group.indeterminate=false; }else if(userSelectNumber==0){ // 全不选 group.checked=false; group.indeterminate=false; }else{ // 选择一部分 group.checked=false; group.indeterminate=true; } } this.showUserTable=users;
// 判断全部用户是否需要选中 if(userAllSelectNumber==userNumber){ this.alluserselect=true; this.allindeterminate=false; }else if(userAllSelectNumber==0){ // 全不选 this.alluserselect=false; this.allindeterminate=false; }else{ // 选择一部分 this.alluserselect=false; this.allindeterminate=true; }
}, // 用户分组处理事件 groupSelectHandle(){ // 全部用户选中 let users=this.showUserTable; let userGroupSelectNumber=0; // 遍历是否选中用户 for(let group of users){ if(group.checked){ userGroupSelectNumber++; for(let user of group.children){ user.checked=true; } }else{ for(let user of group.children){ user.checked=false; } } }
// 全选 if(userGroupSelectNumber==users.length){ this.alluserselect=true; this.allindeterminate=false; }else if(userGroupSelectNumber==0){ // 全不选 this.alluserselect=false; this.allindeterminate=false; }else{ // 选择一部分 this.alluserselect=false; this.allindeterminate=true; }
this.showUserTable=users; }, // 全部用户选中 allUserSelectHandle(value){ // 全部用户选中 let users=this.showUserTable; this.allindeterminate=false; // 全部用户半选状态 if(value){ for(let group of users){ group.checked=true; for(let user of group.children){ user.checked=true; } } }else{ // 全部用户不选 for(let group of users){ group.checked=false; for(let user of group.children){ user.checked=false; } } } this.showUserTable=users; } } } </script>
<style lang="scss"> .user-table{ width: 100%; border-collapse: collapse; text-align: left; cursor: default; border: none; table,tbody{ display:table; width:100%; table-layout:fixed; border-collapse: collapse; border-spacing:0; empty-cells:hide; }
tbody tr th:first-child,tbody tr td:first-child{ width:50px; border-bottom: none; }
.tb-content{ height: 330px; overflow-x: hidden; } tbody tr:first-child{ border-top: none; }
.tb-title>th { font-weight: 300; text-align: center; padding: 10px 0 10px 0; background-color: rgb(78, 132, 255); color: #efefef; } th, td,tr { border: 1px solid #eee; border-collapse:collapse; }
tbody tr:last-child{ border-bottom: none; td{ border-bottom: none; } }
tbody:last-child tr:last-child{ border-bottom: 1px solid #eee; }
td{ text-align: center; padding: 6px 0 6px 0; }
.tb-checkbox{ text-align: center; }
.tb-context{
.company-col{ padding: 0;
.company{ text-align: left;
display: flex;
.company-name{ flex: 1; padding: 6px; }
.tb-select{ width: 50px; position: relative; text-align: center; cursor: pointer;
i{ top: 50%; position: relative; transform: translateY(-50%); } } }
}
.name-merge{ display: flex; padding: 0; width: auto!important; border: none;
.tb-checkbox{ width: 50px; border-right: 1px solid #eee; padding:6px 0; }
.tb-name{ flex: 1; padding:6px 0; } } }
.company-row{ cursor: pointer; }
}
.user-table:first-child{ margin-top: 20px; } </style>
|