<template>
	<view class="content">
		<view class="top-content" v-if="couponType==5||couponType==6">
			<!-- 搜索框 -->
			<view class="search-cont">
				<view class="inner">
					<image class="icon-search" src="https://cqtyt-2025.oss-cn-beijing.aliyuncs.com/huyi/images/icon_search.png" mode=""></image>
					<input type="text" v-model="keyword" placeholder="输入名称搜索" confirm-type="search" @confirm="doSearch" placeholder-style="font-size:28rpx;color:#BBBBBB;font-family: PingFang SC;" />
				</view>
			</view>
			<view class="cate-list">
				<!-- 关键字列表 -->
				<scroll-view   scroll-x="true" >
					<view class="inner">
						<view v-for="(item,index) in cateOptions" :key="index" :class="cateId == item.dictValue?'item active':'item'" @click="choseCate(item)">
							{{ item.dictLabel }}
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<mescroll-body :top="couponType==5||couponType==6?'192rpx':'0rpx'" bottom="0" ref="mescrollRef" @init="mescrollInit"    :down="downOption" :up="upOption" @down="downCallback" @up="upCallback">
		<view class="tui-coupon-list">
		  <view class="tui-coupon-item tui-top20" v-for="(item, index) in dataList" :key="index">
		     <image :src="baseUrl + '/images/bg_coupon_3x.png'" class="tui-coupon-bg" mode="widthFix"></image>
			<view class="tui-coupon-item-left">
		      <view class="tui-coupon-price-box" >
		        <view class="tui-coupon-price-sign">￥</view>
		        <view class="tui-coupon-price" :class="{ 'tui-price-small': false }">{{ item.price.toFixed(2) }}</view>
		      </view>
		      <view class="tui-coupon-intro">满{{ item.minPrice.toFixed(2) }}元可用</view>
		    </view>
		    <view class="tui-coupon-item-right">
		      <view class="tui-coupon-content">
		        <view class="tui-coupon-title-box">
		          <view class="tui-coupon-title">{{ item.title }}</view>
		        </view>
		        <view class="tui-coupon-rule">
		          <view class="tui-rule-box tui-padding-btm">
		            <view class="tui-coupon-circle"></view>
		            <view class="tui-coupon-text">不可叠加使用</view>
		          </view>
		          <view class="tui-rule-box">
		            <view class="tui-coupon-circle"></view>
		            <view class="tui-coupon-text">{{ item.limitTime }} 到期</view>
		          </view>
		        </view>
		      </view>
		    </view>
		    <view class="tui-btn-box">
				<view class="btn receive"   @click="navTo('/pages_company/couponDetails?isShare='+isShare+'&couponId='+item.couponId)">查看</view>
		    </view>
		  </view>
		</view>
		</mescroll-body>
  </view>
</template>
<script>
import {getDictByKey} from '@/api/common.js'
import { getCouponList } from '@/api/coupon.js'
import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
export default {
	name: 'UserCoupon',
	props: {},
	mixins: [MescrollMixin], // 使用mixin
	data: function() {
		return {
			baseUrl:uni.getStorageSync('requestPath'),
			keyword: '',
			cateOptions:[],
			cateId:null,
			couponType:null,
			mescroll:null,
			downOption: {   //下拉刷新
				use:true,
				auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
			},
			upOption: {
				onScroll:false,
				use: true, // 是否启用上拉加载; 默认true
				page: {
					pae: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					size: 10 // 每页数据的数量,默认10
				},
				noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
				textNoMore:"已经到底了",
				empty: {
					icon:'https://cqtyt-2025.oss-cn-beijing.aliyuncs.com/huyi/imagesNew/cf4a86b913a04341bb44e34bb4d37aa2.png',
					tip: '暂无数据'
				}
			},
			dataList: [],
			isShare:null,
		}
	},
	watch: {
    
	},
	onLoad(options) {
		this.couponType=options.couponType;
		this.isShare=options.isShare;
	},
	onShow() {
		if(this.couponType==5){
			this.getDictByKey("sys_package_private_type");
		}
		else if(this.couponType==6){
			this.getDictByKey("sys_package_disease_type");
		}
	},
	methods: {
		choseCate(item) {
			this.cateId = item.dictValue;
			this.mescroll.resetUpScroll()
		},
		getDictByKey(key){
			var data={key:key}
			getDictByKey(data).then(
				res => {
					if(res.code==200){
						this.cateOptions=res.data;
					}
				},
				err => {
				}
			);
			
		},
		doSearch(){
			this.mescroll.resetUpScroll()
		},
		navTo(url){
			uni.navigateTo({
				url: url
			})
		},
		mescrollInit(mescroll) {
			this.mescroll = mescroll;
		},
		/*下拉刷新的回调 */
		downCallback() {
			this.mescroll.resetUpScroll()
		},
		/*上拉加载的回调*/
		upCallback(page) {   
			//联网加载数据
			var that = this;
			var data = {
				keyword:this.keyword,
				couponType:this.couponType,
				pageNum: page.num,
				pageSize: page.size
			};
			if(this.cateId!=null){
				data.cateId=this.cateId;
			}
			getCouponList(data).then(res => {
				if(res.code==200){
					if (page.num == 1) {
						that.dataList = res.data.list; 
						
					} else {
						that.dataList = that.dataList.concat(res.data.list);
						 
					}
					that.mescroll.endBySize(res.data.list.length, res.data.total);
					
				}else{
					uni.showToast({
						icon:'none',
						title: "请求失败",
					});
					that.dataList = null;
					that.mescroll.endErr();
				}
			});
		},
	},
}
</script>
<style lang="less" scoped>
	.content{
		height: 100%;
		.top-content{
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 10;
		}
		.search-cont{
			padding: 16upx 30upx;
			background-color: #FFFFFF;
			.inner{
				box-sizing: border-box;
				width: 100%;
				height: 72upx;
				background: #F7F7F7;
				border-radius: 36upx;
				display: flex;
				align-items: center;
				padding: 0 30upx;
				.icon-search{
					width: 28upx;
					height: 28upx;
					margin-right: 20upx;
				}
				input{
					height: 60upx;
					line-height: 60upx;
					flex: 1;
				}
			}
		}
		.cate-list{
			box-sizing: border-box;
			background: #fff;
			padding: 10upx 27upx;
			height: 100upx;
			.inner{
				display: flex;
			}
			.item{
				flex-shrink: 0;
				padding: 0 24upx;
				height: 64upx;
				line-height: 64upx;
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #078C9D;
				background: #ffffff;
				border: 1px solid #E2C99E;
				border-radius: 32upx;
				margin: 0 20upx 20upx 0;
				&.active{
					color: #FFFFFF;
					background: #078C9D;
					border: 1px solid #078C9D;
				}
			}
		}
		 
		 
	}
	.tui-coupon-list {
		margin-top: 0upx;
		width: 100%;
		padding: 0 25rpx;
		box-sizing: border-box;
	}
	
	.tui-coupon-banner {
	  width: 100%;
	}
	
	.tui-coupon-item {
	  width: 100%;
	  height: 210rpx;
	  position: relative;
	  display: flex;
	  align-items: center;
	  padding-right: 30rpx;
	  box-sizing: border-box;
	  overflow: hidden;
	 
	}
	
	.tui-coupon-bg {
	  width: 100%;
	  height: 210rpx;
	  position: absolute;
	  left: 0;
	  top: 0;
	  z-index: 1;
	}
	
	.tui-coupon-sign {
	  height: 110rpx;
	  width: 110rpx;
	  position: absolute;
	  z-index: 9;
	  top: -30rpx;
	  right: 40rpx;
	}
	
	.tui-coupon-item-left {
	  width: 218rpx;
	  height: 210rpx;
	  position: relative;
	  z-index: 2;
	  display: flex;
	  align-items: center;
	  justify-content: center;
	  flex-direction: column;
	  flex-shrink: 0;
	}
	
	.tui-coupon-price-box {
	  display: flex;
	  color: #e41f19;
	  align-items: flex-end;
	}
	
	.tui-coupon-price-sign {
	  font-size: 30rpx;
	}
	
	.tui-coupon-price {
	  font-size: 32rpx;
	  line-height: 68rpx;
	  font-weight: bold;
	}
	
	.tui-price-small {
	  font-size: 58rpx !important;
	  line-height: 56rpx !important;
	}
	
	.tui-coupon-intro {
	  background: #f7f7f7;
	  padding: 8rpx 10rpx;
	  font-size: 26rpx;
	  line-height: 26rpx;
	  font-weight: 400;
	  color: #666;
	  margin-top: 18rpx;
	}
	
	.tui-coupon-item-right {
	  flex: 1;
	  height: 210rpx;
	  position: relative;
	  z-index: 2;
	  display: flex;
	  align-items: center;
	  justify-content: space-between;
	  padding-left: 24rpx;
	  box-sizing: border-box;
	  overflow: hidden;
	}
	
	.tui-coupon-content {
	  width: 82%;
	  display: flex;
	  flex-direction: column;
	  justify-content: center;
	}
	
	.tui-coupon-title-box {
	  display: flex;
	  align-items: center;
	}
	
	.tui-coupon-btn {
	  padding: 6rpx;
	  background: #ffebeb;
	  color: #078C9D;
	  font-size: 25rpx;
	  line-height: 25rpx;
	  display: flex;
	  align-items: center;
	  justify-content: center;
	  transform: scale(0.9);
	  transform-origin: 0 center;
	  border-radius: 4rpx;
	  flex-shrink: 0;
	}
	
	.tui-color-grey {
	  color: #888 !important;
	}
	
	.tui-bg-grey {
	  background: #f0f0f0 !important;
	  color: #888 !important;
	}
	
	.tui-coupon-title {
	  width: 100%;
	  font-size: 26rpx;
	  color: #333;
	  white-space: nowrap;
	  overflow: hidden;
	  text-overflow: ellipsis;
	}
	
	.tui-coupon-rule {
	  padding-top: 52rpx;
	}
	
	.tui-rule-box {
	  display: flex;
	  align-items: center;
	  transform: scale(0.8);
	  transform-origin: 0 100%;
	}
	
	.tui-padding-btm {
	  padding-bottom: 6rpx;
	}
	
	.tui-coupon-circle {
	  width: 8rpx;
	  height: 8rpx;
	  background: rgb(160, 160, 160);
	  border-radius: 50%;
	}
	
	.tui-coupon-text {
	  font-size: 28rpx;
	  line-height: 28rpx;
	  font-weight: 400;
	  color: #666;
	  padding-left: 8rpx;
	  white-space: nowrap;
	}
	
	.tui-top20 {
	  margin-top: 20rpx;
	}
	
	.tui-coupon-title {
	  font-size: 28rpx;
	  line-height: 28rpx;
	}
	
	.tui-coupon-radio {
	  transform: scale(0.7);
	  transform-origin: 100% center;
	}
	
	.tui-btn-box {
	  position: absolute;
	  right: 20rpx;
	  bottom: 40rpx;
	  z-index: 10;
	  .btn{
	  	width: 155upx;
	  	height: 64upx;
	  	line-height: 64upx;
	  	font-size: 26upx;
	  	font-family: PingFang SC;
	  	font-weight: 500;
	  	text-align: center;
	  	border-radius: 32upx;
	  	margin-left: 15upx;
	  	&.cancel{
	  		border: 1px solid red;
	  		color: red;
	  	}
	  	&.receive{
	  		background: #078C9D;
	  		color: #FFFFFF;
	  	}
	  }
	}
	
	
</style>
