/* * Copyright (c) Baidu, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @file location-list 组件 */ import {Component} from 'san'; import type {LocationCardData, LocationListData, LocationListEvents} from './interface'; import Swiper from '@cosui/cosmic/swiper'; import SwiperItem from '@cosui/cosmic/swiper-item'; import LocationCard from '@cosui/cosmic-dqa/location-card'; export default class LocationList extends Component { static trimWhitespace = 'all'; static template = `
`; static components = { 'cos-swiper': Swiper, 'cos-swiper-item': SwiperItem, 'location-card': LocationCard }; static computed = { pages(this: LocationList) { const items = this.data.get('items'); let pages: LocationCardData[][] = []; let curr: LocationCardData[] = []; items.forEach((item: LocationCardData, index: number) => { curr.push(item); if ((index + 1) % 3 === 0 || index === items.length - 1) { pages.push(curr); curr = []; } }); return pages; } }; initData(): LocationListData { return { items: [] }; } handleClick(event: Event, index: number, item: LocationCardData) { this.fire('click', {event, index, item}); } }