169 lines
3.9 KiB
Vue
Raw Normal View History

2024-02-22 23:01:05 +08:00
<template>
2024-02-23 11:51:14 +08:00
<div class="areacontent">
2024-02-22 23:01:05 +08:00
<div class="area-list">
2024-02-23 17:18:22 +08:00
<div v-for="(item, index) in options" :key="index" :class="{ act: actIndex == index }"
@click="handChose(index)"> {{
item.label }} </div>
2024-02-22 23:01:05 +08:00
</div>
<div class="town-list">
2024-02-23 17:18:22 +08:00
<div class="town-list-li" v-for="(item, index) in townLists" :key="index" @click="handTown(index)">{{ item.name
}}</div>
2024-02-22 23:01:05 +08:00
</div>
</div>
</template>
<script setup>
import { ref, reactive } from "vue"
import { apigetTownLists } from "@/api.js"
2024-02-23 11:32:33 +08:00
import { sendMsg } from "@/api.js"
2024-02-22 23:01:05 +08:00
// 镇列表
const options = reactive([
2024-02-23 17:18:22 +08:00
{
value: '510521',
label: '泸县',
},
2024-02-22 23:01:05 +08:00
{
value: '510502',
label: '江阳区',
},
{
value: '510503',
label: '纳溪区',
},
{
value: '510504',
label: '龙马潭区',
},
{
value: '510522',
label: '合江县 ',
},
{
value: '510524',
label: '叙永县 ',
}, {
value: '510525',
label: '古蔺县 ',
},
])
const actIndex = ref(0)
const townLists = ref([])
2024-02-23 15:51:41 +08:00
const emit = defineEmits(['handTown', 'handArea'])
2024-02-22 23:01:05 +08:00
// 选择区/县
const handChose = (index) => {
2024-02-23 11:32:33 +08:00
actIndex.value = index;
getTownListsFn(options[index].value);
2024-02-23 17:18:22 +08:00
sendFn('choserArea', { name: options[index].label, code: options[index].value })
emit('handArea', options[actIndex.value].value,)
2024-02-23 11:32:33 +08:00
}
2024-02-23 17:18:22 +08:00
const handTown = (index) => {
2024-02-23 11:32:33 +08:00
console.log(townLists.value[index]);
// townLists.value.forEach(item => {
// if (item.value == townLists[index].value) {
// sendFn('choseTown', { name: item.label, code: item.value })
// }
// })
townLists.value.forEach(item => {
2024-02-23 17:18:22 +08:00
if (item.code == townLists.value[index].code) {
sendFn('choseTown', { name: item.name, code: item.code })
emit('handTown', options[actIndex.value].value, item.code)
}
2024-02-23 11:32:33 +08:00
})
2024-02-22 23:01:05 +08:00
}
const getTownListsFn = async (area_code = 510502) => {
let res = await apigetTownLists({ area_code })
2024-02-23 11:32:33 +08:00
townLists.value = res.data;
2024-02-22 23:01:05 +08:00
}
getTownListsFn()
2024-02-23 11:32:33 +08:00
const props = defineProps({
channel: {
type: String,
2024-02-23 17:18:22 +08:00
default: () => 'user-3'
2024-02-23 11:32:33 +08:00
}
})
// 发送消息
const page = ref(1)
const sendFn = (event, data = '') => {
2024-02-23 17:18:22 +08:00
if (data.page) page.value = data.page;
sendMsg({ channel: props.channel, event, data })
2024-02-23 11:32:33 +08:00
}
2024-02-22 23:01:05 +08:00
</script>
<style lang="scss" scoped>
2024-02-23 11:51:14 +08:00
.areacontent {
2024-02-22 23:01:05 +08:00
width: 998.3px;
height: 445.74px;
background-image: url('/static/img/area/bg.png');
background-size: 100% 100%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-sizing: border-box;
padding: 17px 20px;
.area-list {
font-size: 24px;
display: flex;
justify-content: space-around;
margin-top: 20px;
color: #9AADC4;
font-family: FZCYJ;
cursor: pointer;
2024-02-23 17:18:22 +08:00
padding: 0 80px;
2024-02-22 23:01:05 +08:00
}
.act {
font-size: 28px;
color: white;
transition: 0.4s;
}
.town-list {
height: 290px;
overflow-y: auto;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin-top: 40px;
padding: 0 50px;
2024-02-23 17:18:22 +08:00
.town-list-li {
2024-02-22 23:01:05 +08:00
font-size: 18px;
color: #E4EFF5;
background-image: url('/static/img/area/townbg.png');
height: 46.52px;
background-size: 100% 100%;
width: 270px;
text-align: center;
line-height: 46.52px;
margin-bottom: 20px;
cursor: pointer;
}
}
2024-02-23 17:18:22 +08:00
.town-list::-webkit-scrollbar {
width: 10px;
background-color: #153041;
}
.town-list::-webkit-scrollbar-track {
background-color: #153041;
}
2024-02-22 23:01:05 +08:00
2024-02-23 17:18:22 +08:00
::-webkit-scrollbar-thumb {
background-color: #084D89;
border-radius: 5px;
}
2024-02-22 23:01:05 +08:00
}
2024-02-23 17:18:22 +08:00
</style>