mer-tradescreen/src/components/areaList.vue

121 lines
2.3 KiB
Vue
Raw Normal View History

2023-11-28 15:26:40 +08:00
<template>
<Transition>
<div class="address" v-if="props.choseArea">
2023-12-11 18:35:55 +08:00
<div class="address-li" @click="choseAreaFn">龙马谭区 </div>
2023-12-07 19:05:27 +08:00
<div class="address-li" @click="choseTownFn(item.code, item.name)" v-for="( item, index ) in areaList ">{{
item.name }}
</div>
2023-11-28 15:26:40 +08:00
</div>
</Transition>
</template>
<script setup>
2023-12-07 19:05:27 +08:00
import { defineProps, defineEmits, onMounted, reactive } from "vue"
2023-11-28 15:26:40 +08:00
import { useRouter } from 'vue-router'
2023-12-11 18:35:55 +08:00
import { areaObj } from '@/store/index.js'
2023-12-07 19:05:27 +08:00
import axios from "axios"
2023-12-11 18:35:55 +08:00
let areaStore = areaObj()
2023-11-28 15:26:40 +08:00
const router = useRouter()
const emit = defineEmits(['offAreaList'])
const props = defineProps({
choseArea: Boolean,
})
2023-12-07 19:05:27 +08:00
let areaList = reactive([])
2023-11-28 15:26:40 +08:00
// 选额镇
2023-12-07 19:05:27 +08:00
const choseTownFn = (id, name) => {
2023-12-11 18:35:55 +08:00
areaStore.changeArea({
areaCode: areaStore.area.areaCode,
streetCode: id
})
2023-11-28 15:26:40 +08:00
props.choseArea = false
2023-12-07 19:05:27 +08:00
emit('offAreaList', name)
2023-12-08 00:06:02 +08:00
// router.go(0)
2023-12-07 19:05:27 +08:00
2023-12-08 00:06:02 +08:00
router.replace('/townDetail?code=' + id)
2023-12-07 19:05:27 +08:00
2023-12-11 18:35:55 +08:00
}
// x选择区县
const choseAreaFn = () => {
areaStore.changeArea({
areaCode: areaStore.area.areaCode,
streetCode: null
})
props.choseArea = false
emit('offAreaList', "龙马潭区")
router.replace('/')
2023-11-28 15:26:40 +08:00
}
2023-12-07 19:05:27 +08:00
onMounted(() => {
2023-12-11 18:35:55 +08:00
axios.get(`https://crmeb-test.shop.lihaink.cn/api/city/get_street?area_code=${areaStore.area.areaCode}`)
2023-12-07 19:05:27 +08:00
.then(function (response) {
response.data.data.forEach(item => {
areaList.push(item)
})
})
.catch(function (error) {
// 处理错误情况
})
.finally(function () {
// 总是会执行
});
})
2023-11-28 15:26:40 +08:00
</script>
<style lang="scss" scoped>
.address {
left: 1vw;
top: 18px;
position: absolute;
width: 8vw;
height: 18vh;
background-color: #001E32;
color: #C7DBE3;
z-index: 9999;
overflow-y: auto;
box-sizing: border-box;
padding: 5px;
.address-li {
padding: 2px 5px;
cursor: pointer;
border-bottom: 0.1px solid #0E293C;
}
}
.address::-webkit-scrollbar {
width: 10px;
background-color: #153041;
}
.address::-webkit-scrollbar-track {
background-color: #153041;
}
::-webkit-scrollbar-thumb {
background-color: #4AB9D0;
border-radius: 5px;
}
</style>