<template>
	<view class="page">

		<view class="swiper padding bg-white">
			<u-swiper height="306rpx" :list="swiperList" keyName="swiperPicture" showTitle :autoplay="true" circular
				radius="20"></u-swiper>
		</view>

		<view class="bg-white">
			<u-tabs :list="categoryList" @click="clickTab" keyName="categoryName" :scrollable="false" :lineWidth="30"
				:activeStyle="{
            color: '#303133',
            fontWeight: 'bold',
            transform: 'scale(1.05)'
        }" :lineHeight="6">
			</u-tabs>
			<view class="image-text_4 flex-col bg-white margin-top margin-left w700" style="height: 60rpx;">
				<view class="flex-row align-center justify-between">
					<view class="flex-row align-center" @click="showPriceDownList">
						<text class=" margin-right-xs">排序</text>
						<image class="thumbnail_3" :src="imagesUrl+'downarr.png'" />
					</view>
					<view @click="this.$tab.navigateTo('/subMallPages/registerPartner/registerPartner')">
						<text>申请成为合作商</text>
					</view>
				</view>
				<view class="downList flex-row flex-wrap justify-start" v-show="priceDownListShow">
					<view class="btn" :style="{ 'background': orderBy == 'priceAsc' ? '#feebb2' :''}"
						@click="orderBySelect('priceAsc')">
						<text>价格最低</text>
					</view>
					<view class="btn" :style="{ 'background': orderBy == 'priceDesc' ? '#feebb2' :''}"
						@click="orderBySelect('priceDesc')">
						<text>价格最高</text>
					</view>
					<view class="btn margin-left-xl" @click="orderBySelect('')">
						<text>重置排序</text>
					</view>
				</view>
			</view>
		</view>

		<view class="goodList radius">
			<view class="goods radius" style="position: relative;" v-for="item,index in mallGoodsList" :key="index"
				@click="this.$tab.navigateTo('/subMallPages/goodInfo/goodInfo?id='+item.id)">
				<u--image class="goodImg" radius="10rpx" width="300rpx" height="220rpx" :showLoading="true"
					:src="item.image"></u--image>
				<view style="position: absolute; top: 20rpx; right: 20rpx;">
					<u-tag text="不参与会员折扣" type="warning" plain plainFill size="mini"
						v-if="item.isAttend !== '1'"></u-tag>
					<u-tag text="此商品参与会员折扣" type="warning" plain plainFill size="mini" v-else></u-tag>
				</view>
				<view class="carTitle">
					<text class="u-line-2">
						{{ item.title }}
					</text>
				</view>
				<view class="flex-row justify-between">
					<view class="">
						<text class="priceIcon">￥</text>
						<text class="priceNum">{{ item.lowPrice }}</text>
					</view>
					<view class="butBtn">查看</view>
				</view>
			</view>
			<view class="flex-col align-center justify-center margin" style="margin: 0 auto; min-height: 300rpx;"
				v-if="mallGoodsList.length == 0">
				<u-empty mode="list" textSize="32rpx" iconSize="160rpx">
				</u-empty>
			</view>
		</view>
		<!-- 分页 -->
		<view class="margin-top">
			<page-pagination :total="total" :currentPage="queryParams.pageNum" :showBorder="false" mode="simple"
				layout="prev,page,next" @change="changePageNum"></page-pagination>
		</view>
		<view class="partTitle">
			<u--image :showLoading="true" :lazyLoad="true" :src="imagesUrl+'partner.png'" width="140rpx" mode="widthFix"
				height="48rpx"></u--image>
		</view>
		<view class="w700 bg-white flex-row flex-wrap justify-between padding radius" style="margin: auto;">
			<view class="text-center margin-bottom" v-for="(item,index) in mallPartnerList" :key="index"
				@click="goPartner(item.partnerId)">
				<u--image radius="10rpx" width="200rpx" height="200rpx" :showLoading="true"
					:src="item.partnerLogo"></u--image>
				<text class="margin-top-xs" style="display: block;">{{ item.partnerName }}</text>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				imagesUrl: getApp().globalData.config.imagesUrl,
				swiperList: [],
				categoryList: [],
				priceDownListShow: false,
				mallGoodsList: [],
				total: '', //总页数
				queryParams: {
					goodsCategory: '品牌酒水',
					pageNum: 1,
					pageSize: 10,
					orderBy: ''
				},
				mallPlatinum: 0, // 铂金会员级别
				mallPartnerList: []
			};
		},
		onLoad() {
			this.getSwpier()
			this.getConfig()
			this.getCategoryList()
			this.getGoodsList()
			this.getMallPartnerList()
		},
		methods: {
			// 获取轮播图
			async getSwpier() {
				const res = await this.$request({
					url: '/system/swiper/listWx',
					data: {
						moudleName: '商城'
					}
				})
				for (let i = 0; i < res.rows.length; i++) {
					res.rows[i].swiperPicture = getApp().globalData.config.baseUrl + res.rows[i].swiperPicture;
					res.rows[i].title = res.rows[i].swiperName
				}
				this.swiperList = res.rows
				// console.log(this.swiperList);
			},
			// 获取分类
			async getCategoryList() {
				const res = await this.$request({
					url: '/system/mallGoodsCategory/listWx',
				})
				this.categoryList = res.rows
			},
			// 获取配置:铂金会员折扣
			async getConfig() {
				const res = await this.$request({
					url: '/system/shopconfig/listWx'
				})
				this.mallPlatinum = res.rows[0].mallPlatinum
				console.log('this.mallPlatinum', this.mallPlatinum);
			},
			// 获取商品列表
			async getGoodsList() {
				const res = await this.$request({
					url: '/system/mallGoods/listWx',
					data: this.queryParams

				})
				for (let i = 0; i < res.rows.length; i++) {
					res.rows[i].image = getApp().globalData.config.baseUrl + res.rows[i].image; // 处理图片拼接
					// if (res.rows[i].isAttend == '1') { // 参与会员折扣 显示最高铂金会员折扣价格
					// 	res.rows[i].price = (res.rows[i].price * (this.mallPlatinum / 10)).toFixed(2)
					// } else {
					// 	res.rows[i].price = res.rows[i].price.toFixed(2)
					// }
				}
				this.total = res.total
				this.mallGoodsList = res.rows
				console.log(this.mallGoodsList);
			},
			// 分页切换
			changePageNum(pageNum, type) {
				this.queryParams.pageNum = pageNum;
				// console.log("点击了" + type + "，当前页：" + pageNum);
				this.getGoodsList()

			},
			goPartner(partnerId) {
				this.$tab.navigateTo('/subMallPages/partner/partner?partnerId=' + partnerId)
			},
			// 排序按钮
			showPriceDownList() {
				this.priceDownListShow = !this.priceDownListShow
			},
			// 排序实现
			orderBySelect(orderBy) {
				this.queryParams.orderBy = orderBy
				this.mallGoodsList = []
				this.queryParams.pageNum = 1
				this.getGoodsList()
				this.priceDownListShow = false
			},
			// 切换tab
			clickTab(e) {
				this.queryParams.goodsCategory = e.categoryName
				this.getGoodsList()
			},
			// 获取合作商列表
			async getMallPartnerList() {
				const res = await this.$request({
					url: '/system/mallPartners/listWx',
				})
				this.mallPartnerList = res.rows
				for (let i = 0; i < res.rows.length; i++) {
					res.rows[i].partnerLogo = getApp().globalData.config.baseUrl + res.rows[i].partnerLogo; // 处理图片拼接
				}

				console.log(res);
			}

		},
	};
</script>
<style scoped lang="scss">
	.partTitle {
		margin: 20rpx;
	}

	.downList {
		width: 750rpx;
		position: relative;
		top: 20rpx;
		padding: 20rpx;
		background-color: #fff;
		z-index: 9999;
		border-radius: 5rpx;

		.btn {
			width: 160rpx;
			height: 50rpx;
			padding: 10rpx;
			font-size: 24rpx;
			text-align: center;
			margin-bottom: 10rpx;
			margin-right: 10rpx;
			background-color: #e5e5e5;
		}
	}

	.text-group_4 {
		width: 50rpx;
		height: 24rpx;
		overflow-wrap: break-word;
		color: rgba(69, 69, 69, 1);
		font-size: 24rpx;
		font-family: MicrosoftYaHei;
		font-weight: NaN;
		text-align: left;
		white-space: nowrap;
		line-height: 24rpx;
	}

	.thumbnail_3 {
		width: 13rpx;
		height: 10rpx;
	}

	.goodList {
		margin: 0 auto;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		width: 700rpx;

		border-radius: 10rpx;

		.goods {
			width: 340rpx;
			padding: 20rpx;
			box-sizing: border-box;
			margin-top: 20rpx;
			background-color: #ffffff;


			.carTitle {
				width: 320rpx;
				margin: 20rpx 0;
			}

			.carAge {
				font-size: 12px;
				color: #b5b5b5;
				margin: 10rpx 0;
			}

			.goodImg {
				border-radius: 25rpx;
			}

			.butBtn {
				background: #FF7019;
				color: #fff;
				font-size: 24rpx;
				padding: 10rpx 20rpx;
				border-radius: 10rpx;
			}

			.priceIcon {
				font-size: 28rpx;
				color: #FF7019;
			}

			.priceNum {
				font-size: 40rpx;
				color: #FF7019;
			}

			.delPrice {
				margin-left: 10rpx;
				color: #B5B5B5;
				text-decoration: line-through;
			}
		}
	}
</style>