首先,桌位上如果已點(diǎn)餐,會有點(diǎn)餐時間tableInterval,作為是否為空位的標(biāo)識
1.單桌
只能選擇空桌(空桌即沒有tableInterval的),只能選擇一個
2.拼桌
選擇有tableInterval的,可以選擇無限個,進(jìn)行拼桌
3.并桌
選擇空桌進(jìn)行并桌,不限個數(shù)
4.同時選擇到的桌位高亮
5.麻煩大神幫忙實(shí)現(xiàn)一下,,真的布吉島怎么寫┭┮﹏┭┮
直接復(fù)制粘貼便可看到效果: 注重理解
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>注意細(xì)節(jié)</title>
<style>
* {
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
li {
display: inline-block;
padding: 5px 10px;
border: 1px solid gray;
cursor: pointer;
margin-left: 5px;
border-radius: 5px;
}
ul.types li.active {
border: 1px solid #0078d7;
background-color: #0078d7;
color: #fff;
}
ul.selects li.active {
border: 1px solid #0078d7;
background-color: #0078d7;
color: #fff;
}
ul.selects li.disabled {
border: 1px solid #999;
background-color: #999;
opacity: 0.6;
}
</style>
</head>
<body>
<div id="app">
<p>選擇桌子:</p>
<ul class="types">
<li v-for="(item, index) in typesList" :class="{ active: index == result.types_value }" @click="typesEvent(index)">{{item.types}}</li>
</ul>
<p>可供選擇的桌子:</p>
<ul class="selects">
<!-- 注意綁定的class的寫法 -->
<li v-for="(item, index) in selectList" :class="{ disabled: result.types_value != 1 && item.time > 0 , active: result.select.indexOf(item.id) >= 0 }" @click="selectEvent(item)">
<p>{{item.title}}</p>
<p>
<span v-if="item.time > 0">{{item.time}}分鐘</span>
<span v-else>無客</span>
<span>{{item.price}}元</span>
</p>
</li>
</ul>
<p>結(jié)果數(shù)組:(數(shù)組內(nèi)的數(shù)字對應(yīng)已選中的桌子的id)</p>
{{result.select}}
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
new Vue({
el: '#app',
data: {
typesList: [ //選桌類型數(shù)組
{
types: "單桌",
value: 0
},
{
types: "拼桌",
value: 1
},
{
types: "并桌",
value: 2
}
],
selectList: [ //可供選擇桌子數(shù)組
{
title: "1號桌",
id: 1,
time: 55,
price: 12
},
{
title: "2號桌",
id: 2,
time: 0,
price: 22
},
{
title: "3號桌",
id: 3,
time: 5,
price: 102
},
{
title: "4號桌",
id: 4,
time: 0,
price: 120
}
],
result: { //選擇結(jié)果數(shù)組
types_value: 0,
select: []
}
},
methods: {
typesEvent(index) { //選類型觸發(fā)事件
if(index == this.result.types_value) {
return false; //防止重復(fù)點(diǎn)擊已選中類型時清空數(shù)據(jù)
}
this.result.select = []; //清空之前選擇的數(shù)據(jù)
this.result.types_value = index; //給當(dāng)前點(diǎn)擊的類型添加active
},
selectEvent(item) {
let _this = this;
if(_this.result.types_value != 1 && item.time > 0) { //對單桌和并合桌中已經(jīng)有時間的桌進(jìn)行禁止點(diǎn)擊操作
return false;
}
if(_this.result.types_value == 0) { //單獨(dú)處理單桌的情況,單桌僅允許結(jié)果數(shù)組中只有一條數(shù)據(jù),且再次點(diǎn)擊同一個時取消選中
_this.result.select = _this.result.select.indexOf(item.id) >= 0 ? [] : [item.id];
return true;
}
let buff_id = _this.result.select.indexOf(item.id); //獲取當(dāng)前點(diǎn)擊的是否已被選取,若已選取,則是取消選擇操作
if(buff_id >= 0) {
_this.result.select.splice(buff_id,1);
return true;
}
_this.result.select.push(item.id); //能執(zhí)行到這里表示該條未被選中,現(xiàn)在添加到結(jié)果數(shù)組中去
return true;
}
}
});
</script>
</body>
</html>
Vuex版本
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>注意細(xì)節(jié)</title>
<style>
* {
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
li {
display: inline-block;
padding: 5px 10px;
border: 1px solid gray;
cursor: pointer;
margin-left: 5px;
border-radius: 5px;
}
ul.types li.active {
border: 1px solid #0078d7;
background-color: #0078d7;
color: #fff;
}
ul.selects li.active {
border: 1px solid #0078d7;
background-color: #0078d7;
color: #fff;
}
ul.selects li.disabled {
border: 1px solid #999;
background-color: #999;
opacity: 0.6;
}
</style>
</head>
<body>
<div id="app">
<p>選擇桌子:</p>
<ul class="types">
<li v-for="(item, index) in typesList" :class="{ active: index == types_value }" @click="typesEvent(index)">{{item.types}}</li>
</ul>
<p>可供選擇的桌子:</p>
<ul class="selects">
<!-- 注意綁定的class的寫法 -->
<li v-for="(item, index) in selectList" :class="{ disabled: types_value != 1 && item.time > 0 || types_value == 1 && item.time <= 0, active: store.getters.getSelectId(item.id) }" @click="selectEvent(item)">
<p>{{item.title}}</p>
<p>
<span v-if="item.time > 0">{{item.time}}分鐘</span>
<span v-else>無客</span>
<span>{{item.price}}元</span>
</p>
</li>
</ul>
<p>結(jié)果數(shù)組:(數(shù)組內(nèi)的數(shù)字對應(yīng)已選中的桌子的id)</p>
{{store.state.result}}
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://cdn.bootcss.com/vuex/3.0.1/vuex.min.js"></script>
<script>
const store = new Vuex.Store({
state: {
types_value: 0,
result: []
},
mutations: {
saveResult(state, payload) {
state.result = payload.data;
},
saveTypesValue(state, payload) {
state.types_value = payload.index;
},
deleteResult(state, payload) {
for(let i = 0; i < state.result.length; i++) {
if(state.result[i].id === payload.id) {
state.result.splice(i,1);
break;
}
}
},
pushResult(state, payload) {
state.result.push(payload.data);
}
},
getters: {
getSelectId: (state) => (id) => {
return state.result.find(item => item.id === id);
}
}
});
new Vue({
el: '#app',
data: {
typesList: [ //選桌類型數(shù)組
{
types: "單桌",
value: 0
},
{
types: "拼桌",
value: 1
},
{
types: "并桌",
value: 2
}
],
selectList: [ //可供選擇桌子數(shù)組
{
title: "1號桌",
id: 0,
time: 55,
price: 12
},
{
title: "2號桌",
id: 1,
time: 0,
price: 22
},
{
title: "3號桌",
id: 2,
time: 5,
price: 102
},
{
title: "4號桌",
id: 3,
time: 0,
price: 120
}
]
},
computed: {
types_value() {
return store.state.types_value;
}
},
methods: {
typesEvent(index) { //選類型觸發(fā)事件
if(index == this.types_value) {
return false; //防止重復(fù)點(diǎn)擊已選中類型時清空數(shù)據(jù)
}
store.commit({
type: "saveResult",
data: []
}) //清空之前選擇的數(shù)據(jù)
store.commit({
type: "saveTypesValue",
index: index
}) //給當(dāng)前點(diǎn)擊的類型添加active
},
selectEvent(item) {
let _this = this;
if(_this.types_value != 1 && item.time > 0 || _this.types_value == 1 && item.time <= 0) { //對單桌和并合桌中已經(jīng)有時間的桌進(jìn)行禁止點(diǎn)擊操作
return false;
}
if(_this.types_value == 0) { //單獨(dú)處理單桌的情況,單桌僅允許結(jié)果數(shù)組中只有一條數(shù)據(jù),且再次點(diǎn)擊同一個時取消選中
store.commit({
type: "saveResult",
data: store.getters.getSelectId(item.id) ? [] : [_this.selectList[item.id]]
});
return true;
}
if(store.getters.getSelectId(item.id)) {
store.commit({
type: "deleteResult",
id: item.id
});
return true;
}
store.commit({
type: "pushResult",
data: _this.selectList[item.id]
}); //能執(zhí)行到這里表示該條未被選中,現(xiàn)在添加到結(jié)果數(shù)組中去
return true;
}
}
});
</script>
</body>
</html>
希望我的回答對你有所幫助!
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。