<template> 
 | 
  <PageLayout title="选择城市" class="citySelect-page-wrapper" :need-auth="false"> 
 | 
    <ContentView class="citySelect-content-wrapper"> 
 | 
      <div class="current-city">当前城市:{{ locationCity }}</div> 
 | 
      <Elevator :index-list="elevatorData" :height="'100%'" @click-item="clickItem" /> 
 | 
    </ContentView> 
 | 
  </PageLayout> 
 | 
</template> 
 | 
  
 | 
<script setup lang="ts"> 
 | 
import { PageLayout, LoadingLayout, ContentScrollView, ContentView } from '@/components'; 
 | 
import { useUser } from '@/hooks'; 
 | 
import { useArea } from '@12333/hooks'; 
 | 
import { AreaType } from '@12333/constants'; 
 | 
import { groupBy, sortBy } from 'lodash'; 
 | 
import { useUserStore } from '@/stores/modules/user'; 
 | 
import { Elevator } from '@12333/components'; 
 | 
  
 | 
defineOptions({ 
 | 
  name: 'citySelect', 
 | 
}); 
 | 
  
 | 
const { completeAreaList, getAreaByAreaCode } = useArea(); 
 | 
const { locationCity } = useUser(); 
 | 
const userStore = useUserStore(); 
 | 
  
 | 
const cityList = computed(() => { 
 | 
  if (completeAreaList.value?.length > 0) { 
 | 
    return [...completeAreaList.value].filter((x) => x.layer === AreaType.City); 
 | 
  } 
 | 
  return []; 
 | 
}); 
 | 
  
 | 
const elevatorData = computed(() => { 
 | 
  let cityGroups = groupBy( 
 | 
    sortBy(cityList.value, (c) => c.quickQuery.charAt(0)), 
 | 
    (city) => city.quickQuery.charAt(0) 
 | 
  ); 
 | 
  const _elevatorData = []; 
 | 
  for (let key in cityGroups) { 
 | 
    _elevatorData.push({ 
 | 
      title: key, 
 | 
      list: cityGroups[key].map((x) => ({ 
 | 
        name: x.areaName, 
 | 
        id: x.areaCode, 
 | 
        parentId: x.parentCode, 
 | 
      })), 
 | 
    }); 
 | 
  } 
 | 
  return _elevatorData; 
 | 
}); 
 | 
  
 | 
console.log('elevatorData: ', elevatorData); 
 | 
  
 | 
const clickItem = (key: string, item: any) => { 
 | 
  console.log('item: ', item, getAreaByAreaCode(item.parentId).areaName); 
 | 
  userStore.setLocationCity(item.name, getAreaByAreaCode(item.parentId).areaName); 
 | 
}; 
 | 
</script> 
 | 
  
 | 
<style lang="scss"> 
 | 
@import '@/styles/common.scss'; 
 | 
  
 | 
.citySelect-page-wrapper { 
 | 
  .current-city { 
 | 
    padding: 20px 0; 
 | 
    color: boleGetCssVar('text-color', 'primary'); 
 | 
    font-size: 28px; 
 | 
  } 
 | 
  
 | 
  .citySelect-content-wrapper { 
 | 
    display: flex; 
 | 
    flex-direction: column; 
 | 
    height: 100%; 
 | 
  } 
 | 
  
 | 
  .nut-elevator { 
 | 
    flex: 1; 
 | 
    min-height: 0; 
 | 
  
 | 
    .nut-elevator__list__item__name, 
 | 
    .nut-elevator__list__item__code { 
 | 
      padding: 0; 
 | 
    } 
 | 
  } 
 | 
} 
 | 
</style> 
 |