<template>
    <view class="page">
        <view class="red-top">
            <view class="building-title">
                <view class="title-right">
                    建材
                </view>
                <view class="title-left">
                    寻找你想要的建材材料
                </view>
            </view>
            <view class="building-search">
                <!-- <view class="address">
                    <image src="../../static/image/home/1.png" mode=""></image>
                    <view class="eare">
                        <text>{{ selectCity.name }}</text>
                    </view>
                    <view class="down-arrow"></view>
                </view> -->
				
				<selectCityPopup @cityChange="getData"/>
				
                <view class="search">
                    <uv-search bgColor="#ffffff" 
					placeholder="搜索材料" 
					disabled
					@click="$utils.navigateTo(`/pages_order/product/productList?search=true`)"
                    showAction="false"></uv-search>
                </view>
            </view>
        </view>

        <view class="image-home"
		@click="$utils.navigateTo('/pages_order/order/fastCreateOrder')">
            <uv-swiper class="uv-swaip" 
			keyName="image"
			height="350rpx" 
			:list="bannerList" 
			circular 
			bgColor="#ffffff">
            </uv-swiper>
        </view>

        <view class="building-class">
            <view style="width: 710rpx;">
                <uv-grid :col="4" :border="false">
                    <uv-grid-item v-for="(item, index) in menuList" :key="index"
					@click="menuClick(item)">
                        <image class="image" :src="item.image" mode=""></image>
                        <text class="grid-text">{{item.title}}</text>
                    </uv-grid-item>
                </uv-grid>
            </view>
        </view>
        
        <view class="hot-building">
            <text>热卖建材</text>
        </view>


        <view class="productList">
			<productItem 
			@click="$utils.navigateTo(`/pages_order/product/productDetail?id=${item.id}`)"
			:item="item" v-for="(item, index) in list" :key="index"/>
        </view>
		
        <PrivacyAgreementPoup />
		
		<quick-order-entry 
            ref="quickOrderEntry"
        />
		
		<kefu/>

        <tabber select="home" />
    </view>
</template>

<script>
import PrivacyAgreementPoup from '@/components/config/PrivacyAgreementPoup.vue'
import tabber from '@/components/base/tabbar.vue'
import productItem from '@/components/productItem.vue'
import mixinsList from '@/mixins/list.js'
import selectCityPopup from '@/components/selectCityPopup.vue'
export default {
	mixins: [mixinsList],
    components: {
        tabber,
        PrivacyAgreementPoup,
		productItem,
		selectCityPopup,
    },
    data() {
        return {
            keyword: '',
			bannerList : [],
			menuList: [],
			mixinsListApi: '',
            hasNewOrderMessage: false,
            orderMessageCount: 0
        }
    },
    computed: {
    },
	onLoad(query) {
		if (query.shareId) {
			uni.setStorageSync('shareId', query.shareId)
		}
    	if(this.selectCity.id){
			this.mixinsListApi = 'getProductList'
		}
		uni.$on('initCity', () => {
			this.mixinsListApi = 'getProductList'
			this.getData()
		})
    },
	onShow() {
		this.getBanner()
		this.getMenu()
		if(uni.getStorageSync('token')){
            this.$store.commit('getUserInfo')
			this.$refs.quickOrderEntry.refresh()
		}
	},
    methods: {
		// 获取轮播图
		getBanner() {
			this.$api('getBanner', res => {
				if (res.code == 200) {
					this.bannerList = res.result
				}
			})
		},
		beforeGetData(){
			return {
				cityId : this.selectCity.id
			}
		},
		// 获取菜单
		getMenu() {
			this.$api('getIcon', res => {
				if (res.code == 200) {
					this.menuList = res.result
				}
			})
		},
        toUrl() {
            uni.navigateTo({
                url: '/pages_order/order/fastCreateOrder'
            })
        },
        toGoodInfo(item, index) {
            uni.navigateTo({
                url: `/pages_order/product/productDetail?id=${item.id}`
            })
        },
		menuClick(item){
			uni.navigateTo({
				url: `/pages_order/product/productList?title=${item.title}&iconId=${item.id}`
			})
			// if(!item.url){
			// 	return
			// }
   //          uni.navigateTo({
   //              url: item.url,
   //          })
		},
    }
}
</script>

<style scoped lang="scss">
.page{
	width: 100vw;
	overflow: hidden;
}
.red-top {
    position: relative;
    height: 420rpx;
    background: linear-gradient(to bottom, $uni-color, #f05a45);
    border-bottom-left-radius: 100rpx;
    border-bottom-right-radius: 100rpx;

    .building-title {
        position: absolute;
        height: 100rpx;
        width: 100%;
        margin-top: 100rpx;

        .title-right {
            color: $uni-bg-color;
            height: 100rpx;
            line-height: 100rpx;
            font-size: 45rpx;
            font-weight: 900;
            margin-left: 30rpx;
            display: inline-block;
        }

        .title-left {
            display: inline-block;
            margin-left: 30rpx;
            font-size: 22rpx;
            color: $uni-bg-color;
        }
    }

    .building-search {
        position: absolute;
        height: 100rpx;
        width: 100%;
        margin-top: 200rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		gap: 20rpx;
		
        .address {
            height: 100rpx;
            width: 150rpx;
            position: relative;
            display: flex;
            align-items: center;
			justify-content: center;
			gap: 10rpx;

            image {
                height: 20rpx;
                width: 20rpx;
            }

            .eare {
                color: $uni-bg-color;
            }

            .down-arrow {
                content: "";
                display: block;
                width: 0;
                height: 0;
                border-left: 10rpx solid transparent;
                border-right: 10rpx solid transparent;
                border-top: 15rpx solid $uni-bg-color;
            }
        }

        .search {
			background-color: #fff;
			border-radius: 40rpx;
			display: flex;
			padding: 20rpx;
            :deep(.uv-search__content) {
                box-shadow: 0 5rpx 15rpx rgba(0, 0, 0, 0.1);
            }
        }

    }
}

.image-home {
    z-index: 1;
    margin: 0 20rpx;
    margin-top: -90rpx;
    border-radius: 20rpx;
    overflow: hidden;
    box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.1);
}

.building-class {
	padding: 20rpx 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    /* 垂直居中 */
    background-color: $uni-bg-color;
    margin: 20rpx 0;
    border-radius: 20rpx;
    box-shadow: 0 5rpx 15rpx rgba(0, 0, 0, 0.05);

    image {
        margin-left: 20rpx;
        margin-right: 20rpx;
        margin-bottom: 10rpx;
        width: 90rpx;
        height: 90rpx;
        display: inline-block;
        transition: transform 0.3s;

        &:hover {
            transform: scale(1.05);
        }
    }

    .grid-text {
		margin-top: 4rpx;
        font-size: 26rpx;
        font-weight: 500;
        color: #333;
    }
}

.text-building {
    display: flex;
    justify-content: space-around;
    align-items: center;
    /* 垂直居中 */
    background-color: $uni-bg-color;
    text-align: center;
    font-weight: 500;
    margin-bottom: -30rpx;
    padding-bottom: 40rpx;
    // overflow: hidden;
}

.hot-building {
    margin-top: 25rpx;
    height: 80rpx;
    background-color: $uni-bg-color;
    display: flex;
    align-items: center;
    padding-left: 40rpx;
    font-size: 35rpx;
    font-weight: 600;
    color: #333;
    position: relative;

    &::after {
        content: '';
        position: absolute;
        left: 40rpx;
        bottom: 15rpx;
        width: 60rpx;
        height: 6rpx;
        background-color: $uni-color;
        border-radius: 3rpx;
    }
}
.productList{
	
}
</style>
