<template>
	<view>
		<headerSerch :dataConfig="headItem"></headerSerch>
		<view class="header-group">
			<view class="tabs">
				<u-tabs :list="navigationList" @click="clickNav" lineColor="#FFD373" :inactiveStyle="{ color: '#FFF' }"
					:activeStyle="{ color: '#FFD373', fontWeight: 'bold' }" keyName="title"></u-tabs>
			</view>
		</view>
		<!-- 内容切换 -->
		<view class="tab-content" v-if="current == 0">
			<!-- 轮播 -->
			<view class="swiper-group">
				<u-swiper :list="swiperList" indicator indicatorMode="line" circular></u-swiper>
			</view>
			<!-- 宫格 -->
			<view class="grid-box">
				<view class="grid-group">
					<view class="grid-item">
						<image src="../../../static/menus/秒杀专区.png" mode="aspectFit" @click="menusTap('秒杀专区')"></image>
						<text>秒杀专区</text>
					</view>
					<view class="grid-item">
						<image src="../../../static/menus/红包商城.png" mode="aspectFit" @click="menusTap('红包商城')"></image>
						<text>红包商城</text>
					</view>
					<view class="grid-item">
						<image src="../../../static/menus/积分专区.png" mode="aspectFit" @click="menusTap('积分专区')"></image>
						<text>积分专区</text>
					</view>
					<view class="grid-item">
						<image src="../../../static/menus/创客专区.png" mode="aspectFit" @click="menusTap('创客专区')"></image>
						<text>创客专区</text>
					</view>
					<view class="grid-item">
						<image src="../../../static/menus/城市合伙人.png" mode="aspectFit" @click="menusTap('城市合伙人')">
						</image>
						<text>城市合伙人</text>
					</view>
					<view class="grid-item">
						<image src="../../../static/menus/积分抵扣专区.png" mode="aspectFit" @click="menusTap('积分抵扣专区')">
						</image>
						<text>抵扣专区</text>
					</view>
				</view>
			</view>

			<!-- 通知 -->
			<view class="notice">
				<u-notice-bar :text="notice" direction="column" duration="3000" @click="goNoticeDetail($event)">
				</u-notice-bar>
			</view>
			<!-- 通知弹框 -->
			<view>
				<u-modal :show="noticeShow" title="通告" confirmText="我已知晓" confirmColor="#FABA59" @confirm="noticeClose">
					<view class="slot-content">
						<rich-text :nodes="noticeContent"></rich-text>
					</view>
				</u-modal>
			</view>

			<!-- 爆款专区 -->
			<view class="sale-group">
				<view class="sale-content">
					<view class="title">爆款专区 <view class="more">
						</view>
					</view>
					<view class="goods-scroll">
						<scroll-view scroll-x="true">
							<view class="goods-item" v-for="(item, index) in tempArrBao" :key="index"
								@click="goDetail(item)">
								<image :src="item.image" mode="aspectFit"></image>
								<view class="goods-name">
									<u-text prefixIcon="bookmark" iconStyle="font-size: 16px; color:red" :lines="2" bold
										block size="12" :text="item.store_name"></u-text>
									<view class="tags">赠送20.54红积分</view>
									<view class="price">¥{{ item.ot_price }}</view>
								</view>
							</view>
						</scroll-view>
					</view>
				</view>
			</view>
			<!-- 商品列表 -->
			<view class="goods-list">
				<view class="title">
					<view class="line"></view>
					商品推荐
					<view class="line"></view>
				</view>
				<goodListMall @changeTab="changeTab" :tempArr="tempArr" :iSshowH="false" @detail="goDetail"
					:isSortType="isSortType"></goodListMall>
			</view>
		</view>

		<view class="tab-content" v-show="current >= 1">
			<!-- 轮播 -->
			<view class="swiper-group">
				<u-swiper :list="swiperList" indicator indicatorMode="line" circular></u-swiper>
			</view>
			<!-- 商品列表 -->
			<goodListMall @changeTab="changeTab" :iSshowH="true" @detail="goDetail" :currentId="currentId"
				:isSortType="isSortType"></goodListMall>
		</view>
	</view>
</template>

<script>
import headerSerch from './components/headerSerch';
import goodListMall from './components/goodListMall';
import { getAdsList, getNoticeList, getCategoryOne, getGoodsPage, getIndexData, getGoodsInfo } from '../../../api/home.js'
import {
	goShopDetail
} from '@/libs/order.js';
export default {
	components: {
		headerSerch,
		goodListMall
	},
	data() {
		return {
			currentId: '',
			noticeShow: false,
			noticeContent: '',
			tempArr: [],
			tempArrBao: [
				{
					"id": 72,
					"image": "https://demo26.crmeb.net/uploads/attach/2021/11/20211112/mid_1608a6e46f559f11328c544fa05ea10b.png",
					"store_name": "COACH/蔻驰女士swinger腋下包单肩包麻将包豌豆包",
					"store_info": "COACH/蔻驰女士swinger腋下包单肩包麻将包豌豆包",
					"cate_id": "79",
					"price": "3000.00",
					"ot_price": "2900.00",
					"sales": "226",
					"unit_name": "件",
					"sort": 446,
					"activity": [],
					"stock": 258,
					"vip_price": 0,
					"is_vip": 0,
					"couponId": [],
					"star": [
						{
							"product_score": 5,
							"product_id": 72
						}
					],
					"checkCoupon": false
				},
				{
					"id": 119,
					"image": "https://demo26.crmeb.net/uploads/attach/2021/12/10/mid_738c68638ab29effeff2e98365ec6dd6.jpg",
					"store_name": "微星(MSI)GK50Z 机械键盘 红轴 RGB光效 有线 游戏电竞办公键盘 104键 吃鸡键盘 黑色",
					"store_info": "ceshi123",
					"cate_id": "38",
					"price": "0.01",
					"ot_price": "199.00",
					"sales": "135",
					"unit_name": "件",
					"sort": 999,
					"activity": [],
					"stock": 24855,
					"vip_price": 0,
					"is_vip": 0,
					"couponId": [
						{
							"id": 23,
							"product_id": 119,
							"issue_coupon_id": 218,
							"title": "",
							"add_time": 1664522680
						}
					],
					"star": [
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 4,
							"product_id": 119
						},
						{
							"product_score": 4,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 4,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 2,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 3,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 4,
							"product_id": 119
						},
						{
							"product_score": 4,
							"product_id": 119
						},
						{
							"product_score": 3,
							"product_id": 119
						},
						{
							"product_score": 4,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 4,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 4,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 4,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 4,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 4,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 2,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						},
						{
							"product_score": 5,
							"product_id": 119
						}
					],
					"checkCoupon": false
				},
				{
					"id": 41,
					"image": "http://demo26.crmeb.net/uploads/attach/2020/10/13/a23b5bc300cc6a965082368f8c657b3d.jpg",
					"store_name": "华为智选摄像头智能家居监控器无线高清网络摄像头家用全景智能摄像机1080P夜间清晰人像AI智能看护",
					"store_info": "华为智选摄像头智能家居监控器无线高清网络摄像头家用全景智能摄像机1080P夜间清晰人像AI智能看护",
					"cate_id": "11,21",
					"price": "500.00",
					"ot_price": "1000.00",
					"sales": "94",
					"unit_name": "件",
					"sort": 0,
					"activity": [],
					"stock": 1981,
					"vip_price": 0,
					"is_vip": 0,
					"couponId": [],
					"star": [],
					"checkCoupon": false
				},
				{
					"id": 51,
					"image": "http://demo26.crmeb.net/uploads/attach/2020/10/20201014/118bccc3d5499881dd7178c43ebb9346.jpg",
					"store_name": "极度空间 中秋贺卡 生日卡片 创意3D明信片感恩卡*10",
					"store_info": "极度空间 中秋贺卡 生日卡片 创意3D明信片感恩卡*10",
					"cate_id": "40,34",
					"price": "100.00",
					"ot_price": "1000.00",
					"sales": "39",
					"unit_name": "件",
					"sort": 0,
					"activity": [],
					"stock": 761,
					"vip_price": 0,
					"is_vip": 0,
					"couponId": [],
					"star": [
						{
							"product_score": 5,
							"product_id": 51
						}
					],
					"checkCoupon": true
				},
				{
					"id": 89,
					"image": "https://demo26.crmeb.net/uploads/attach/2021/11/20211113/mid_2fbe723632427b0768df24c4f23c6cad.png",
					"store_name": "家居梵高系列联名款饭盒袋大容量手拎保温实用方便 星月夜饭盒袋",
					"store_info": "",
					"cate_id": "35",
					"price": "350.00",
					"ot_price": "300.00",
					"sales": "19",
					"unit_name": "件",
					"sort": 553,
					"activity": [],
					"stock": 185,
					"vip_price": 0,
					"is_vip": 0,
					"couponId": [],
					"star": [
						{
							"product_score": 5,
							"product_id": 89
						}
					],
					"checkCoupon": false
				},
				{
					"id": 45,
					"image": "http://demo26.crmeb.net/uploads/attach/2020/10/20201014/1bfcaad092adb917739ec681f55fb255.jpg",
					"store_name": "Adidas阿迪达斯男装 2020秋季新款运动服户外跑步训练健身透气舒适时尚休闲夹克外套GD5462 GD5462 L",
					"store_info": "Adidas阿迪达斯男装 2020秋季新款运动服户外跑步训练健身透气舒适时尚休闲夹克外套GD5462 GD5462 L",
					"cate_id": "26,27,50,54",
					"price": "200.00",
					"ot_price": "500.00",
					"sales": "11",
					"unit_name": "件",
					"sort": 0,
					"activity": [],
					"stock": 4984,
					"vip_price": "120.00",
					"is_vip": 1,
					"couponId": [],
					"star": [
						{
							"product_score": 5,
							"product_id": 45
						},
						{
							"product_score": 5,
							"product_id": 45
						},
						{
							"product_score": 2,
							"product_id": 45
						}
					],
					"checkCoupon": false
				},
				{
					"id": 71,
					"image": "https://demo26.crmeb.net/uploads/attach/2021/09/03/mid_0b209a475fe7a7118dc964407c98542c.jpg",
					"store_name": "Casio卡西欧女表时尚优雅简约指针防水复古石英手表LTP-1094E-1A",
					"store_info": "品质保障 全场包邮",
					"cate_id": "38",
					"price": "265.00",
					"ot_price": "265.00",
					"sales": "6",
					"unit_name": "件",
					"sort": 300,
					"activity": [],
					"stock": 94,
					"vip_price": 0,
					"is_vip": 0,
					"couponId": [],
					"star": [
						{
							"product_score": 5,
							"product_id": 71
						},
						{
							"product_score": 5,
							"product_id": 71
						},
						{
							"product_score": 5,
							"product_id": 71
						}
					],
					"checkCoupon": false
				}
			],
			isSortType: 0,
			headItem: {
				"name": "headerSerch",
				"timestamp": "1666235374470000",
				"setUp": {
					"tabVal": 0
				},
				"bgColor": {
					"title": "背景颜色(渐变)",
					"name": "bgColor",
					"default": [
						{
							"item": "#F62C2C"
						},
						{
							"item": "#F96E29"
						}
					],
					"color": [
						{
							"item": "rgba(242,16,78,1)"
						},
						{
							"item": "rgba(210,41,87,1)"
						}
					]
				},
				"boxStyle": {
					"title": "边框样式",
					"name": "boxStyle",
					"type": 0,
					"list": [
						{
							"val": "圆角",
							"icon": "iconPic_fillet"
						},
						{
							"val": "直角",
							"icon": "iconPic_square"
						}
					]
				},
				"txtStyle": {
					"title": "文本位置",
					"name": "txtStyle",
					"type": 1,
					"list": [
						{
							"val": "居左",
							"icon": "icondoc_left"
						},
						{
							"val": "居中",
							"icon": "icondoc_center"
						}
					]
				},
				"prConfig": {
					"title": "背景边距",
					"val": 8,
					"min": 0
				},
				"mbConfig": {
					"title": "页面间距",
					"val": 0,
					"min": 0
				},
				"hotWords": {
					"list": [
						{
							"val": ""
						}
					]
				},
				"logoConfig": {
					"type": 1,
					"header": "设置logo",
					"title": "",
					"url": "https://demo26.crmeb.net/uploads/attach/2022/10/20221009/7436ee5680bc5d67c46a6017939475e5.png"
				},
				"id": "id1665385357481000"
			},
			current: 0,
			noticeList: [],
			notice: [
				'寒雨连江夜入吴',
				'平明送客楚山孤',
				'洛阳亲友如相问',
				'一片冰心在玉壶'
			],
			swiperList: [
				'https://cdn.uviewui.com/uview/swiper/swiper3.png',
				'https://cdn.uviewui.com/uview/swiper/swiper2.png',
				'https://cdn.uviewui.com/uview/swiper/swiper1.png',
			],
			navigationList: [{
				title: '推荐',
				id: '0'
			}]
		}
	},
	created() {
		this.getCategoryOne()
		this.getAdsList()
		this.getNoticeList()
		this.getIndexData()
		this.getGoodsInfo()
	},
	onLoad() {
	},
	methods: {
		getGoodsInfo() {
			getGoodsInfo({
				current: 1,
				size: 50,
				isRecom: 1
			}).then(res => {
				this.tempArr = res.data
			})
		},
		getCategoryOne() {
			getCategoryOne().then(res => {
				this.navigationList = []
				let tuiJian = {
					title: '推荐',
					id: '0'
				}
				this.navigationList = res.data
				this.navigationList.unshift(tuiJian)
			})
		},
		menusTap(url) {
			// #ifdef H5
			location.href = url
			// #endif
			// #ifdef MP || APP-PLUS
			uni.navigateTo({
				url: "/pages/goods/goods_list_mall/index?sid=" + 1 + "&title=" + url
			});
			// #endif
		},
		noticeClose() {
			this.noticeShow = false
		},
		goNoticeDetail(value) {
			this.noticeContent = this.noticeList[value].content
			this.noticeShow = true
		},
		getNoticeList() {
			getNoticeList().then(res => {
				this.notice = []
				this.noticeList = res.data
				res.data.forEach(element => {
					this.notice.push(element.title)
				});
			})
		},
		getAdsList() {
			getAdsList({
				type: 2
			}).then(res => {
				if (res.data.length > 0) {
					this.swiperList = []
					res.data.forEach(element => {
						this.swiperList.push(element.imageUrl)
					});
				}
			});
		},
		// 促销列表的点击事件;
		changeTab(type) {
			this.goodType = type;
			this.tempArr = [];
			this.page = 1;
			this.loadend = false;
			let onloadH = true;
			this.getGroomList(onloadH);
		},
		// 精品推荐
		getGroomList(onloadH) {
			let that = this;
			let type = that.goodType;
			if (that.loadend) return false;
			if (that.loading) return false;
			if (onloadH) {
				that.$set(that, 'iSshowH', true);
			}
			uni.request({
				url: 'api/groom/list',
				success: res => {
					that.$set(that, 'iSshowH', false);
					let maxPage = Math.ceil(this.numConfig / this.limit);
					let list = res.data.list,
						loadend = list.length < that.limit || that.page >= maxPage;
					let tempArr = that.$util.SplitArray(list, that.tempArr);
					that.$set(that, 'tempArr', tempArr.slice(0, this.numConfig));
					that.loadend = loadend;
					that.loadTitle = loadend ? that.$t(`没有更多内容啦~`) : that.$t(`加载更多`);
					that.page = that.page + 1;
					that.loading = false;
				}
			})
			// getGroomList(type, {
			// 	page: that.page,
			// 	limit: this.numConfig
			// })
			// 	.then(({
			// 		data
			// 	}) => {
			// 		that.$set(that, 'iSshowH', false);
			// 		let maxPage = Math.ceil(this.numConfig / this.limit);
			// 		let list = data.list,
			// 			loadend = list.length < that.limit || that.page >= maxPage;
			// 		let tempArr = that.$util.SplitArray(list, that.tempArr);
			// 		that.$set(that, 'tempArr', tempArr.slice(0, this.numConfig));
			// 		that.loadend = loadend;
			// 		that.loadTitle = loadend ? that.$t(`没有更多内容啦~`) : that.$t(`加载更多`);
			// 		that.page = that.page + 1;
			// 		that.loading = false;
			// 	})
			// 	.catch(res => {
			// 		that.loading = false;
			// 		that.loadTitle = that.$t(`加载更多`);
			// 	});
		},
		goDetail(item) {
			goShopDetail(item, this.$store.state.app.uid).then(res => {
				uni.navigateTo({
					url: `/pages/goods_details/index?id=${item.id}`
				});
			});
		},
		// 去商品详情
		goGoodsDetail(item) {
			goShopDetail(item, this.uid).then(res => {
				uni.navigateTo({
					url: `/pages/goods_details/index?id=${item.id}`
				});
			});
		},
		clickNav(e) {
			this.current = e.index
			if (e.index > 0) {
				this.currentId = e.id
			}
		}
	}
}
</script>

<style lang="scss" scoped>
page {
	background-color: #ee4040;
}

.header-group {
	background-color: #EB4C63;

	.search-group {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx 30rpx 10rpx 30rpx;


		.logo {
			width: 138rpx;
			height: 46rpx;
		}

		.message {
			line-height: 1;

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

		.search {
			flex: 1;
			padding: 0 30rpx;

			.searchBox {
				padding: 0 30rpx;
				display: flex;
				align-items: center;
				background-color: #FFF;
				border-radius: 100rpx;
				height: 60rpx;

				image {
					width: 28rpx;
					height: 28rpx;
					padding-right: 20rpx;
				}

				text {
					font-size: 24rpx;
					color: #999;
				}

			}
		}
	}

	.tabs {
		padding: 0 20rpx;
	}
}

.tab-content {
	.swiper-group {
		padding: 20rpx 30rpx 10rpx 30rpx;
		background-image: linear-gradient(to bottom, #EB4C63, #F9F9F9);
	}

	.grid-box {
		padding: 10rpx 30rpx 20rpx 30rpx;

		.grid-group {
			padding: 20rpx 0;
			border-radius: 20rpx;
			background-color: #FFF;
			display: flex;
			align-items: center;
			flex-wrap: wrap;

			.grid-item {
				width: 33.333%;
				display: flex;
				flex-direction: column;
				align-items: center;
				margin: 10rpx 0;

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

				text {
					font-size: 24rpx;
					color: #666;
					margin-top: 10rpx;
				}
			}

		}
	}

	.notice {
		padding: 0 30rpx;
	}

	.sale-group {
		padding: 20rpx 30rpx;

		.sale-content {
			border-radius: 20rpx;
			background-image: linear-gradient(45deg, #EB4C63, #FFA470);
			padding: 20rpx 0;

			.title {
				display: flex;
				align-items: center;
				justify-content: space-between;
				color: #FFF;
				font-weight: bold;
				padding: 0 30rpx;

				.more {
					display: flex;
					align-items: center;
					font-size: 24rpx;
					font-weight: normal;

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

			.goods-scroll {
				white-space: nowrap;
				padding: 20rpx 15rpx 0 15rpx;

				.goods-item {
					display: inline-block;
					width: 240rpx;
					padding: 15rpx;
					margin: 0 10rpx;
					background-color: #FFF;
					border-radius: 10rpx;

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

					.goods-name {
						font-size: 26rpx;
						color: #333;
						width: 240rpx;
						margin: 6rpx 0;
						word-break: break-all;
						white-space: pre-wrap;
						text-overflow: ellipsis;
						display: -webkit-box;
						line-height: 1.2;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
					}

					.tags {
						display: inline-block;
						font-size: 20rpx;
						padding: 6rpx;
						background-color: #FCE9EC;
						color: #EB4C63;
						margin: 6rpx 0;
					}

					.price {
						font-size: 32rpx;
						font-weight: bold;
						color: #EB4C63;
					}
				}


			}
		}
	}

	.goods-list {
		.title {
			text-align: center;
			color: #333;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 32rpx;
			font-weight: bold;

			.line {
				display: inline-block;
				width: 200rpx;
				height: 2rpx;
				margin: 0 30rpx;
				background-color: #FFA470;
			}
		}

		.list-group {
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			padding: 15rpx;
			box-sizing: border-box;

			.list-item-content {
				width: 50%;
				padding: 15rpx;
				box-sizing: border-box;

				.list-item {
					padding: 15rpx;
					background-color: #FFF;
					border-radius: 10rpx;

					image {
						width: 100%;
					}

					.goods-name {
						font-size: 28rpx;
						color: #333;
						margin: 6rpx 0;
						word-break: break-all;
						white-space: pre-wrap;
						text-overflow: ellipsis;
						display: -webkit-box;
						line-height: 1.4;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
						overflow: hidden;
					}

					.tags {
						display: inline-block;
						font-size: 20rpx;
						padding: 6rpx;
						background-color: #FCE9EC;
						color: #EB4C63;
						margin: 6rpx 0;
					}

					.price {
						font-size: 32rpx;
						font-weight: bold;
						color: #EB4C63;
					}
				}
			}
		}
	}

}
</style>