<template>
	<view class="page">
		<view class="tabs-box">
			<u-tabs-swiper ref="tabs" :current="current" :list="tabList" @change="tabsChange" :is-scroll="false" :font-size="24" active-color="#0FBB59" :height="70">
			</u-tabs-swiper>
		</view>
		<!-- 搜索 -->
		<view class="head-search">
			<u-search bg-color="#fff" placeholder="请输入关键词" v-model="query.keyword" :show-action="false" @search="search"></u-search>
			<u-button type="success" @click="search">搜索</u-button>
		</view>
		<view class="goods-data">
			<view class="goods-list">
				<view class="good-item" v-for="(v, i) in datalist" :key="i">
					<view class="body">
						<image :src="v.coverImage" ></image>
						<view class="info">
							<view class="title">{{v.activityName}}</view>
							<view class="info-items">
								<view class="info-item">
									<view class="label">活动时间：</view>
									<text>{{v.startTime}}</text>
								</view>
								<view class="info-item">
									<view class="label">参与商家：</view>
									<text>{{v.maxParticipants}}人</text>
								</view>
								<view class="info-item">
									<view class="label">活动状态：</view>
									<text>{{v.auditStatus =='1'?'待提交':v.auditStatus =='2'?'待审核':v.auditStatus =='3'?'审核通过':v.auditStatus =='4'?'审核驳回':''}}</text>
								</view>
							</view>
						</view>
					</view>
					<view class="footer">
						<!-- <u-button type="primary" size="mini"  v-if="v.auditStatus == '1'">编辑</u-button> -->
						<u-button type="success" size="mini" @click="tijiao('2',v.id)"  v-if="v.auditStatus == '1'"  style="margin-right: 22rpx;">提交审核</u-button>
						<u-button type="success" size="mini" @click="toDetail(v.id, '/pages/activityDetail/activityDetail')" style="margin-right: 22rpx;">查看详情</u-button>
						<u-button type="info" size="mini" @click="tijiao('1',v.id)" v-if="v.auditStatus == '2'" style="margin-right: 22rpx;">撤回</u-button>
						<u-button type="info" size="mini" @click="delact(v.id)" v-if="v.auditStatus == '1'" style="margin-right: 22rpx;">删除</u-button>
					</view>
				</view>
				<!-- <u-loadmore :status="statuslist" @loadmore='loading' style="width: 100%; text-align: center;"/> -->
			</view>
		</view>
		<view style="height: 120rpx;"></view>
		<view class="page-footer">
			<u-button type="success" @click="toAdd">活动申请</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabList:[
					{ name: '全部' },
					{ name: '待提交' },
					{ name: '待审核' },
					{ name: '通过' },
					{ name: '驳回' },
					{ name: '进行中' },
					{ name: '已结束' },
				],
				current: 0,
				datalist: [],
				total: 2,
				statuslist: 'loadmore',
				query: {
					keyword: '',
					pageSize: 10,
					pageNum: 0,
				},
				listIn:0,
				num:0,
				pageIndex :{
					pageNumber: 1,
					pageSize: 10,
					createUser:uni.getStorageSync('shopId')
				}
			};
		},
		onLoad(option) {
			this.num = option.id;
			this.statuslist = 'nomore';
		},
	
		// onPullDownRefresh(e) {
		// 	let that = this
		// 	that.statuslist = 'loading';
		// 	this.page = 0;
		// 	setTimeout(() => {
		// 		that.datalist = [{}];
		// 		that.statuslist = that.datalist.length >= that.total ? 'nomore' : 'loadmore';
		// 		uni.stopPullDownRefresh();
		// 	}, 1000);
		// },
		onReachBottom(e) {
			// this.loading();
		},
		mounted() {
			this.getAll()
		},
		methods: {
			toDetail(item, path) {
				uni.navigateTo({
					url: `${path}?item=${item}`
				})
				
			},
			tabsChange(val) {
				this.current = val
				
				if(val == 0){
					this.getAll()
				}else{
					this.getAll(val )
				}
			},
			getAll(val){
				if(val !=0){
					this.pageIndex.auditStatus = val
				}
				this.$http.sendRequest('/cereActivityApplication/queryByPage', 'POST',this.pageIndex,1).then(res => {
				   this.datalist = res.data.data.content
				}).catch(err => {
					console.log(err)
					//请求失败
				})
			},
			search() {},
			// loading() {
			// 	let that = this
			// 	if(that.statuslist == 'nomore') return;
			// 	that.statuslist = 'loading';
			// 	that.query.pageNum = ++that.query.pageNum;
			// 	setTimeout(() => {
			// 		let data = [{}, {}];
			// 		that.datalist = [...that.datalist, ...data];
			// 		console.log(that.datalist);
			// 		that.statuslist = that.datalist.length >= that.total ? 'nomore' : 'loadmore';
			// 	}, 300)
			// },
			sel(val){
				this.listIn = val
			},
			reconciliationdetail() {
	
			},
			toAdd() {
				uni.navigateTo({
					url: '/pages/activityAdd/activityAdd'
				})
			},
			tijiao(val,ids){
			let pageIndex = {
				id:ids,
				auditStatus:val
			}
				this.$http.sendRequest('/cereActivityApplication/edit', 'POST',pageIndex,1).then(res => {
					this.current = 0
				    this.getAll()
				}).catch(err => {
					console.log(err)
					//请求失败
				})
			},
			delact(ids){
			 let padge = {
					id:ids	
				}
				this.$http.sendRequest('/cereActivityApplication/deleteById', 'POST',padge,1).then(res => {
					this.current = 0
				    this.getAll()
				}).catch(err => {
					console.log(err)
					//请求失败
				})
			},
		}
	}
</script>

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