<template>
	<!-- 营销推广活动 -->
	<view class="page">
		<!-- 搜索 -->
		<view class="head-search">
			<u-search bg-color="#fff" placeholder="请输入关键词" v-model="query.title" :show-action="false" @search="search"></u-search>
			<u-button type="success" @click="search">搜索</u-button>
		</view>
		<!-- <view class="screen-list">
			<view class="list" @click="sortshow = true">
				<text>默认排序</text>
				<image  :src="$imgUrl('/down.png')"></image>
				<u-select v-model="sortshow" :list="sortTypeOptions" @confirm="(v) => {queryChange('sortType', v)}"></u-select>
			</view>
			<view class="list" @click="statusshow = true">
				<text>进行中</text>
				<image  :src="$imgUrl('/down.png')"></image>
				<u-select v-model="statusshow" :list="statusOptions" @confirm="(v) => {queryChange('status', v)}"></u-select>
			</view>
		</view> -->
		<!-- 订单列表 -->
		<view class="goods-data">
			<u-row :gutter="16" class="goods-list">
				<u-col span="6" v-for="(item,index) in list" :key="index" @click="toDetail(item.id)">
					<view class="demo-layout good-item">
						<image :src="item.coverImage" style="width: 315rpx; height: 315rpx; border-radius: 10rpx;"></image>
						<view class="info">
							<view class="title">{{item.title}}</view>
							<view class="name">活动时间：{{item.startTime}}至{{item.endTime}}</view>
							<u-tag text="进行中" type="success" mode="dark" />
						</view>
					</view>
				</u-col>
				<u-loadmore :status="status" @loadmore='loading' style="width: 100%; text-align: center;"/>
			</u-row>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 'loadmore',
				list: [],
				total: 1,
				query: {
					title: '', // 搜索项
					sortType: '', // 排序方式
					status: '', // 活动状态
					pageNumber:1,
					pageSize: 10,
				},
				sortshow: false,
				sortTypeOptions: [
					{ label: '默认排序', value: 1 },
					{ label: '正序', value: 2 },
					{ label: '倒序', value: 3 },
				],
				statusshow: false,
				statusOptions: [
					{ label: '进行中', value: 1 },
					{ label: '已结束', value: 2 },
					{ label: '未开始', value: 3 },
				],
			};
		},
		onLoad() {
			this.status = 'nomore';
		},
		onPullDownRefresh(e) {
			let that = this
			that.status = 'loading';
			this.page = 0;
			setTimeout(() => {
				that.list = 1;
				that.status = that.list >= that.total ? 'nomore' : 'loadmore';
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom(e) {
			this.loading();
		},
		mounted() {
			this.getALL()
		},
		methods: {
			getALL(){
					let pagesize = {
						pageNumber: 1,
						pageSize: 2
					}
			
			this.$http.sendRequest('/cereMarketingActivity/queryByPage', 'POST', pagesize,1).then(res => {
				this.list =res.data.data.content 
			})
				},
			toMyAdd() {
				// 跳转我的活动申请
				uni.navigateTo({
					url: '/pages/mycreated/mycreated'
				})
			},
			search() {
			this.$http.sendRequest('/cereMarketingActivity/queryByPage', 'POST', this.query,1).then(res => {
				this.list =res.data.data.content 
				this.query  ={
						title: '', // 搜索项
						sortType: '', // 排序方式
						status: '', // 活动状态
						pageNumber: 1,
						pageSize: 10,
					
				}
			})
			},
			queryChange(key, val) {
				this.query[`${key}`] = val[0].value;
				this.search();
			},
			loading() {
				let that = this
				if(that.status == 'nomore') return;
				that.status = 'loading';
				that.page = ++that.page;
				setTimeout(() => {
					that.list += 10;
					that.status = that.list >= that.total ? 'nomore' : 'loadmore';
				}, 300)
			},
			toDetail(items) {
				  let msg = JSON.stringify(items)
				uni.navigateTo({
					url: `/pages/marketing/marketingDetail/marketingDetail?item=${msg}`
				})
			},
			join(){
				uni.navigateTo({
					url: '/pages/mycreated/mycreated?id=1'
				})
			},
			toAdd() {
				uni.navigateTo({
					url: '/pages/activityAdd/activityAdd'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'marketingList.scss';
</style>
