团队功能里面分为一级、二级,每级包含交易额、会员数、等级,交易额又包含为本月累计,会员数包含会员的数量,等级包含会员、VIP、合伙人。
这是样式给大家展示出来:
CSS:
<style> * { margin: 0; padding: 0; } #dengji { display: flex; justify-content: space-around; width: 100%; height: 30px; font-size: 20px; margin-top: 20px; } #jiaoyi { font-size: 20px; display: flex; justify-content: space-around; margin-top: 20px; } #mingcheng { margin-top: 20px; font-size: 20px; display: flex; justify-content: space-around; } #benyue { font-size: 20px; margin-left: 40px; } #huiyuan { font-size: 20px; margin-left: 45.5%; } #san { font-size: 20px; margin-left: 80%; } </style>
HTML:
<div id="dengji"> <div id="dengji_d" onclick="yiji_y()">一级</div> <div id="dengji_e" onclick="erji_e()">二级</div> </div> <!-- 交易 --> <div id="jiaoyi"> <div onclick="jiaoyi_j()">交易额</div> <div onclick="huiyuan_u()">会员数</div> <div onclick="dengji()">等级</div> </div> <div id="benyue" style="display: none;" onclick="benyue_b()">本月累计</div> <div id="huiyuan" style="display: none;" onclick="huiyuan_h()">会员数</div> <div id="san"> <div id="hui" style="display: none;" onclick="hui_h()">会员</div> <div id="vip" style="display: none;" onclick="vip_v()">VIP</div> <div id="hehuoren" style="display: none;" onclick="hehuoren_h()">合伙人</div> </div> <!-- 一级 --> <div id="yiji"> </div>
JS:
<script> let data = [{ id: 1, name: "孙悟空", partner: "合伙人", volume: 333, inviter: 4 }, { id: 1, name: "猪八戒", partner: "VIP", volume: 427, inviter: 5 }, { id: 1, name: "沙僧", partner: "会员", volume: 123, inviter: 9 }, { id: 1, name: "白龙马", partner: "会员", volume: 73, inviter: 10 }, { id: 2, name: "菩提老祖", partner: "合伙人", volume: 333, inviter: 44 }, { id: 2, name: "如来佛祖", partner: "VIP", volume: 427, inviter: 43 }, { id: 2, name: "观音菩萨", partner: "会员", volume: 123, inviter: 22 }, { id: 2, name: "六耳猕猴", partner: "会员", volume: 73, inviter: 11 }] // 执行渲染 let t = 1; // 创建渲染函数 function xuanran() { let arr = ""; for (let i = 0; i < data.length; i++) { if (t == 1 && data[i].id == 1) { arr += `<div id="mingcheng"> <div id="mingcheng_m"> <span>${data[i].name}</span> <p>${data[i].partner}</p> </div> <div id="mingcheng_i"> <span>交易量:${data[i].volume}</span> <p>邀请人:${data[i].inviter}</p> </div> </div>`; } else if (t == 2 && data[i].id == 2) { arr += `<div id="mingcheng"> <div id="mingcheng_m"> <span>${data[i].name}</span> <p>${data[i].partner}</p> </div> <div id="mingcheng_i"> <span>交易量:${data[i].volume}</span> <p>邀请人:${data[i].inviter}</p> </div> </div>`; } document.getElementById("yiji").innerHTML = arr; } } xuanran() function yiji_y() { t = 1; xuanran(); } function erji_e() { t = 2; xuanran(); } // 点击交易额显示本月累计 function jiaoyi_j() { document.getElementById("benyue").style.display = "block"; } // 点击本月累计消失本月累计 function benyue_b() { document.getElementById("benyue").style.display = "none"; for (let i = 0; i < data.length - 1; i++) { for (let j = 0; j < data.length - 1 - i; j++) { if (data[j].volume < data[j + 1].volume) { let num = data[j]; data[j] = data[j + 1]; data[j + 1] = num; } } } xuanran(); } // 点击会员数显示会员并且排序 function huiyuan_u() { document.getElementById("huiyuan").style.display = "block"; } // 点击会员数消失会员数并且排序 function huiyuan_h() { document.getElementById("huiyuan").style.display = "none"; for (let i = 0; i < data.length - 1; i++) { for (let j = 0; j < data.length - 1 - i; j++) { if (data[j].inviter < data[j + 1].inviter) { let num = data[j]; data[j] = data[j + 1]; data[j + 1] = num; } } } xuanran(); } // 点击等级显示:会员,VIP,合伙人 function dengji() { document.getElementById("hui").style.display = "block"; document.getElementById("vip").style.display = "block"; document.getElementById("hehuoren").style.display = "block"; } // 筛选会员 function hui_h() { document.getElementById("hui").style.display = "none"; document.getElementById("hehuoren").style.display = "none"; document.getElementById("vip").style.display = "none"; let arr = ""; for (let i = 0; i < data.length; i++) { if (t == 1 && data[i].partner == "会员" && data[i].id == 1) { arr += `<div id="mingcheng"> <div id="mingcheng_m"> <span>${data[i].name}</span> <p>${data[i].partner}</p> </div> <div id="mingcheng_i"> <span>交易量:${data[i].volume}</span> <p>邀请人:${data[i].inviter}</p> </div> </div>`; } else if (t == 2 && data[i].partner == "会员" && data[i].id == 2) { arr += `<div id="mingcheng"> <div id="mingcheng_m"> <span>${data[i].name}</span> <p>${data[i].partner}</p> </div> <div id="mingcheng_i"> <span>交易量:${data[i].volume}</span> <p>邀请人:${data[i].inviter}</p> </div> </div>`; } document.getElementById("yiji").innerHTML = arr; } } // 筛选VIP function vip_v() { document.getElementById("vip").style.display = "none"; document.getElementById("hui").style.display = "none"; document.getElementById("hehuoren").style.display = "none"; let arr = ""; for (let i = 0; i < data.length; i++) { if (t == 1 && data[i].partner == "VIP" && data[i].id == 1) { arr += `<div id="mingcheng"> <div id="mingcheng_m"> <span>${data[i].name}</span> <p>${data[i].partner}</p> </div> <div id="mingcheng_i"> <span>交易量:${data[i].volume}</span> <p>邀请人:${data[i].inviter}</p> </div> </div>`; } else if (t == 2 && data[i].partner == "VIP" && data[i].id == 2) { arr += `<div id="mingcheng"> <div id="mingcheng_m"> <span>${data[i].name}</span> <p>${data[i].partner}</p> </div> <div id="mingcheng_i"> <span>交易量:${data[i].volume}</span> <p>邀请人:${data[i].inviter}</p> </div> </div>`; } document.getElementById("yiji").innerHTML = arr; } } // 筛选合伙人 function hehuoren_h() { document.getElementById("vip").style.display = "none"; document.getElementById("hui").style.display = "none"; document.getElementById("hehuoren").style.display = "none"; let arr = ""; for (let i = 0; i < data.length; i++) { if (t == 1 && data[i].partner == "合伙人" && data[i].id == 1) { arr += `<div id="mingcheng"> <div id="mingcheng_m"> <span>${data[i].name}</span> <p>${data[i].partner}</p> </div> <div id="mingcheng_i"> <span>交易量:${data[i].volume}</span> <p>邀请人:${data[i].inviter}</p> </div> </div>`; } else if (t == 2 && data[i].partner == "合伙人" && data[i].id == 2) { arr += `<div id="mingcheng"> <div id="mingcheng_m"> <span>${data[i].name}</span> <p>${data[i].partner}</p> </div> <div id="mingcheng_i"> <span>交易量:${data[i].volume}</span> <p>邀请人:${data[i].inviter}</p> </div> </div>`; } document.getElementById("yiji").innerHTML = arr; } } </script>