<template>
	<view class="container">
		<VNavigationBar leftTitle="true" backgroundColor="transparent" title="车辆检测维修"></VNavigationBar>
		<view class="body">
			<view class="body-top-banner">
<!--				<image class="banner" src="@/static/images/banner.jpg" mode="aspectFit" />-->
<!--				<image class="banner" v-for="banner in bannerList" :key="banner.id" :src="banner.url" @click="toContent(banner.id)" mode="scaleToFill" />-->
        <swiper class="swiper" circular indicator-dots="true" autoplay="true" interval="2000"
                duration="500">
          <swiper-item v-for="banner in bannerList" :key="banner.id" @click="toContent(banner.id)">
            <image class="banner" :src="banner.url" mode="scaleToFill" />
          </swiper-item>
          <!--          <swiper-item>-->
          <!--            <view class="swiper-item uni-bg-green">B</view>-->
          <!--          </swiper-item>-->
          <!--          <swiper-item>-->
          <!--            <view class="swiper-item uni-bg-blue">C</view>-->
          <!--          </swiper-item>-->
        </swiper>
			</view>
			<view class="menus">
				<view @click="gotoPage(menu)" v-for="(menu, index) in menus" :key="index" class="menu-item">
					<image class="menu-icon" :src="menu.icon" mode="aspectFit"></image>
					<text class="menu-title">{{menu.title}}</text>
				</view>
			</view>
			<view class="info">
				<image class="info-icon" src="@/static/icons/homeInfo.png" mode="aspectFit"></image>
				<view class="infoList">
					<view v-for="(item, index) in infoList" :key="item.id" class="infoItem">
						<view class="infoIndex"></view>
						<view class="infoText">{{item.title}}</view>
					</view>
				</view>
				<image class="more-icon" src="../../static/icons/homeInfoMore.png" mode="aspectFit"></image>
			</view>
			<view class="repairShop">
				<view class="title">推荐修理厂</view>
				<view class="shopList">
					<view v-for="(item, index) in shopList" :key="index" class="shopItem" @click="gotoShopDetail(item)">
						<image class="shopImg" :src="item.image" mode="aspectFill"></image>
						<view class="shopInfo">
							<view class="shopTitle">{{item.corpName}}</view>
							<view class="shopDetail">
								<view class="shopAddress">{{item.address}}</view>
								<view class="line"></view>
								<view class="shopDistance">{{item.distance}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<tabBarVue msg="1"></tabBarVue>
	</view>
</template>

<script>
	import tabBarVue from '@/components/tabBar/tabBar.vue'
	import VNavigationBar from '@/components/VNavigationBar.vue'
  import request from "../../utils/request";
  import config from "@/config";
	export default {
		components: {
			tabBarVue,
			VNavigationBar
		},
		data() {
			return {
				menus: [{
						title: '预约记录',
						icon: require('@/static/icons/homeMenuIcon/menu1.png'),
						path: '/pages/myReservation/myReservation'
					},
					{
						title: '我的车辆',
						icon: require('@/static/icons/homeMenuIcon/menu2.png'),
						path: '/pages/myCar/myCar'
					},
					{
						title: '活动礼包',
						icon: require('@/static/icons/homeMenuIcon/menu3.png'),
						path: '/pages/home/active'
					},
					{
						title: '操作指南',
						icon: require('@/static/icons/homeMenuIcon/menu4.png'),
						path: '/pages/guideList/guideList'
					},
				],
				infoList: [{
						id: 1,
						title: '暖心！深夜汽车高速路上爆胎 彝良交警化身“修理工”帮忙换胎'
					},
					{
						id: 2,
						title: '车辆机件“焕新上岗”，武汉公交修旧创效出实招'
					},
				],
				// shopList: [{
				// 		id: 1,
				// 		title: '顺捷汽车维修搭电救援补胎中心',
				// 		address: '济南市历下区福瑞达历下护理院东南门旁',
				// 		distance: '1.9km',
				// 		image: ''
				// 	},
				// 	{
				// 		id: 2,
				// 		title: '顺捷汽车维修搭电救援补胎中心',
				// 		address: '济南市历下区福瑞达历下护理院东南门旁',
				// 		distance: '1.9km',
				// 		image: ''
				// 	},
				// 	{
				// 		id: 3,
				// 		title: '顺捷汽车维修搭电救援补胎中心',
				// 		address: '济南市历下区福瑞达历下护理院东南门旁',
				// 		distance: '1.9km',
				// 		image: ''
				// 	},
				// ]
        shopList: [],
        bannerList: [],
        richTextHtml: null
      }
		},
    onShow(){
      this.getCompanyPage()
      this.getBannerList()
    },
		methods: {
      toContent(id){
        uni.navigateTo({
          url: "/pages/home/content?id=" + id,
        })
      },
      async getBannerList(){
        const res = await request({
          url: '/userClient/banner/list?type=weixiu',
          method: "get",
        })
        this.bannerList = res.data
        this.bannerList.forEach(item => {
          item.url = config.baseImageUrl + item.url
        })
      },
			gotoShopDetail(row) {
        // 直接把那一行的数据转发过去
				uni.navigateTo({
					url: '/pages/shopDetail/shopDetail?info=' + encodeURIComponent(JSON.stringify(row))
				})
			},
			gotoPage(menu) {
				uni.navigateTo({
					url: menu.path
				})
			},
      // 附近修理厂
      async getCompanyPage(){
        const res = await request({
          url: "/userClient/base/company/page",
          method: "get",
          params:{
            serviceCodes: "weixiu"
          }
        })
        this.shopList = res.data.records
        this.shopList.forEach(item => {
          item['image'] = require("@/static/images/outImage.jpg")
        })
      }
		}
	}
</script>

<style scoped lang="less">
	.container {
		height: 100%;
		background-color: #fff;
		background: linear-gradient(180deg, #0174F6 0%, rgba(1, 116, 246, 0) 100%);
		background-size: 100% 600rpx;
		background-repeat: no-repeat;
		color: #333333;
		display: flex;
		flex-direction: column;

		.body {
			flex: 1;
			height: 0;
			overflow: auto;
			padding-bottom: 30rpx;
		}


		.body-top-banner {
			text-align: center;
		}

		.banner {
			margin: 24rpx 0 0;
			width: 686rpx;
			height: 290rpx;
			border-radius: 12rpx 12rpx 12rpx 12rpx;
			background-color: #0174F6;
		}

		.menus {
			margin: 30rpx auto 0;
			box-sizing: border-box;
			width: 686rpx;
			padding: 40rpx 38rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 16rpx 0rpx rgba(10, 54, 104, 0.1);
			border-radius: 12rpx 12rpx 12rpx 12rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.menu-item {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			row-gap: 22rpx;
			font-size: 24rpx;

			.menu-icon {
				width: 48rpx;
				height: 48rpx;
			}
		}

		.info {
			width: 686rpx;
			margin: 38rpx auto 0;
			display: flex;
			align-items: center;
			column-gap: 20rpx;

			.info-icon {
				width: 80rpx;
				height: 80rpx;
			}

			.infoList {
				flex: 1;
				width: 0;

				.infoItem {
					display: flex;
					align-items: center;
					justify-content: space-between;
					column-gap: 10rpx;
				}

				.infoIndex {
					width: 12rpx;
					height: 12rpx;
					border-radius: 50%;
					background-color: #333;
				}

				.infoText {
					flex: 1;
					width: 0;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					font-size: 24rpx;
				}
			}

			.more-icon {
				width: 24rpx;
				height: 24rpx;
			}
		}

		.repairShop {
			width: 686rpx;
			margin: 38rpx auto 0;

			.title {
				font-weight: bold;
				font-size: 32rpx;
				color: #333333;
			}

			.shopList {
				.shopItem {
					padding: 30rpx 0;
					border-bottom: 1rpx solid #DDDDDD;
					display: flex;
					align-items: center;
					column-gap: 20rpx;
				}

				.shopImg {
					width: 160rpx;
					height: 100rpx;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					background-color: #999;
				}

				.shopInfo {
					flex: 1;
					width: 0;
				}

				.shopTitle {
					font-weight: 500;
					font-size: 28rpx;
					color: #333333;
					margin-bottom: 20rpx;
				}

				.shopDetail {
					display: flex;
					align-items: center;
					font-size: 24rpx;
					color: #666666;
					column-gap: 10rpx;
				}

				.shopAddress {
					flex: 1;
					width: 0;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				.line {
					width: 2rpx;
					height: 24rpx;
					background-color: #858BA0;
				}

				.shopDistance {
					flex-shrink: 0;
				}
			}
		}
	}
</style>
