<template>
	<view>
		<view class=" mart10 marb20 alijus">
			<view class="font16 fcor333 paddtop5 paddbotm5  margle20  marRight40" v-for="(item,index) in orderStatus"
				@click="switchid(item)" :class="[statusid == item.id ? 'fcor089 borbtom fontwig6' : '']" :key="index">
				{{item.title}}
			</view>
		</view>

		<view class="input-box">
			<view class="icon search"></view>
			<input placeholder="请输入搜索的内容" v-model="searchName" placeholder-style="color:#c0c0c0;" @input="toSearch()" />
		</view>

		<view v-if="activityList == ''" class="mart60 fotct font14 fcor666">
			<image mode="widthFix" style="width: 70vw;" src="../../../static/img/noorder.png"></image>
		</view>
		<view class="width94 backcorfff border-r mart15" v-for="(item,index) in activityList" :key="index"
			@click="jumpdetails(item.activityNo,item.status,1)">
			<view class="notes" style="border-bottom: 0px;">
				<view class="width80p margle">
					<view class="font14 fcor333">{{item.merAbbreviate}}</view>
					<view class="font12 fcor999">{{item.createTime | timeFormat('yyyy-mm-dd')}}
						{{item.createTime | timeFormat('hh:mm')}}
					</view>
				</view>
				<view class="storestus" v-if="item.status == 1">
					编辑中
				</view>
				<view class="storestus" v-if="item.status == 2">
					进行中
				</view>
				<view class="otstatucs" v-if="item.status == 3">
					已结束
				</view>


			</view>
			<view class="conts" style="border-bottom: 0px;">
				<view class="font14 fcor999">活动类型 :
					<text class="font13" v-if="item.activityType == 1"> 优惠活动</text>
					<text class="font13" v-if="item.activityType == 2"> 优惠券</text>
				</view>
			</view>
			<view class="conts" style="border-bottom: 0px;">
				<view class="font14 fcor999">优惠类型 :
					<text class="font13" v-if="item.preferentialType == 1"> 满减</text>
					<text class="font13" v-if="item.preferentialType == 2"> 立减</text>
					<text class="font13" v-if="item.preferentialType == 3"> 折扣</text>
				</view>
			</view>
			<view class="conts" style="border-bottom: 0px;">
				<view class="font14 fcor999">使用规则 :
					<text class="font13" v-if="item.preferentialType == 1"> 满{{item.condition}}减{{item.price}}</text>
					<text class="font13" v-if="item.preferentialType == 2"> 立减{{item.price}}</text>
					<text class="font13" v-if="item.preferentialType == 3"> {{item.price}}折</text>
				</view>
			</view>

			<view class="height45 width94">
				<button class="btns mart10" @click.stop="openActivity(item.activityNo)"
					v-if="item.status == 1">开启活动</button>
				<button class="btns mart10" @click.stop="closeActivity(item.activityNo)"
					v-if="item.status == 2">关闭活动</button>
				<button class="btns mart10" @click.stop="jumpRechange(item.activityNo)"
					v-if="item.status != 3">充值金额</button>
				<button class="btns mart10" @click.stop="jumpdetails(item.activityNo,item.status,2)"
					v-if="item.status != 3">修改时间</button>
				<button class="btns mart10" @click.stop="recover(item.activityNo)">回收余额</button>
			</view>
			<view class="width100 height10"></view>
		</view>
		<image src="../../../static/img/addser.png" mode="widthFix" class="xfimg" @click="jumpaddactivity"></image>
	</view>
</template>

<script>
	import {
		getActivityList,
		openActivity,
		closeActivity,
		recover,
		getActivityAccount
	} from '../../../Utils/Api.js';
	let app = getApp();
	export default {
		data() {
			return {
				accountNumber: '', // 商户号
				orderStatus: [{
						id: 1,
						title: '编辑中'
					},
					{
						id: 2,
						title: '进行中'
					},
					{
						id: 3,
						title: '已结束'
					}
				], //状态
				statusid: 1, //当前状态
				activityList: [],
				searchName: '', //搜索内容
				pageNum: 1,
				pageSize: 10,
				isNoMoreData: false, //是否加载中
			}
		},
		onLoad(options) {
			this.accountNumber = options.merNo;
		},
		onShow() {
			this.activityList = [];
			this.getActivityList();
		},
		methods: {
			//切换id
			switchid(item) {
				this.statusid = item.id;
				this.pageNum = 1;
				this.activityList = [];
				this.getActivityList();
			},
			//修改资料详情
			jumpdetails(item, item1, item2) {
				if (item1 == 1 && item2 == 1) {
					uni.navigateTo({
						url: '/pages/index/activity_add/activity_add?merNo=' + this.accountNumber + '&type=2' +
							'&activityno=' + item
					})
				}
				if (item2 == 2) {
					uni.navigateTo({
						url: '/pages/index/activity_add/activity_add?merNo=' + this.accountNumber + '&type=3' +
							'&activityno=' + item
					})
				}

				if (item1 != 1 && item2 == 1) {
					uni.navigateTo({
						url: '/pages/index/activity_details/activity_details?activityno=' + item
					})
				}

			},
			//查询门店列表
			getActivityList() {
				uni.showLoading({
					title: '加载中...'
				})
				if (this.isNoMoreData) {
					uni.hideLoading();
					return false;
				}
				let pagenum = this.pageNum;
				let datas = {
					status: this.statusid,
					pageNum: pagenum,
					pageSize: this.pageSize,
					merNo:app.globalData.userInfo.mer.merNo,
				}
				getActivityList(datas).then(res => {
					uni.hideLoading();
					if (res.return_code == '000000' && res.return_data.list != '') {
						this.activityList = res.return_data.list;
					} else {
						this.activityList = [];
					}
				})
			},
			//添加活动
			jumpaddactivity() {
				uni.navigateTo({
					url: '/pages/index/activity_add/activity_add?merNo=' + this.accountNumber + '&type=1'
				})
			},
			//开启活动
			openActivity(item) {
				let that = this;
				uni.showModal({
					title: '开启活动',
					content: '是否开启活动。',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '提交中...'
							})
							let data = {
								activityNo: item
							}
							openActivity(data).then(res => {
								if (res.return_code == '000000') {
									uni.showToast({
										title: '开启成功',
										icon: 'none',
										duration: 2000
									})
									that.pageNum = 1;
									that.activityList = [];
									that.getActivityList();
								} else {
									uni.showToast({
										title: res.return_msg,
										icon: 'none',
										duration: 2000
									})
								}
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			//结束活动
			closeActivity(item) {
				let that = this;
				uni.showModal({
					title: '关闭活动',
					content: '是否关闭活动。',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '提交中...'
							})
							let data = {
								activityNo: item
							}
							closeActivity(data).then(res => {
								if (res.return_code == '000000') {
									uni.showToast({
										title: '关闭成功',
										icon: 'none',
										duration: 2000
									})
									that.pageNum = 1;
									that.activityList = [];
									that.getActivityList();
								} else {
									uni.showToast({
										title: res.return_msg,
										icon: 'none',
										duration: 2000
									})
								}
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			//回收活动余额
			recover(item) {
				let that = this;
				uni.showModal({
					title: '回收活动余额',
					content: '确认是否回收活动余额。',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '提交中...'
							})
							let data = {
								activityNo: item
							}
							recover(data).then(res => {
								if (res.return_code == '000000') {
									uni.showToast({
										title: '回收成功',
										icon: 'none',
										duration: 2000
									})
									that.pageNum = 1;
									that.activityList = [];
									that.getActivityList();
								} else {
									uni.showToast({
										title: res.return_msg,
										icon: 'none',
										duration: 2000
									})
								}
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			//跳转充值活动
			jumpRechange(item) {
				let data = {
					activityNo: item
				}
				getActivityAccount(data).then(res => {
					if (res.return_code == '000000') {
						uni.navigateTo({
							url: '/pages/index/recharge_balance/recharge_balance?merNo=' + this
								.accountNumber + '&price=' +
								res.return_data.amount + '&type=2' + '&activityNo=' + item
						})
					} else {
						uni.showToast({
							title: res.return_msg,
							icon: 'none',
							duration: 2000
						})
					}
				});

			}
		}
	}
</script>

<style lang="scss">
	.input-box {
		width: 90%;
		margin-left: 5%;
		margin-top: 15px;
		margin-bottom: 15px;
		height: 70rpx;
		background-color: #fff;
		border-radius: 10rpx;
		position: relative;
		display: flex;
		align-items: center;

		.icon {
			display: flex;
			align-items: center;
			position: absolute;
			top: 2px;
			left: 5px;
			width: 60upx;
			height: 60upx;
			font-size: 34upx;
			color: #c0c0c0;
		}

		input {
			padding-left: 50upx;
			height: 28upx;
			font-size: 28upx;
			width: 100%;
		}
	}

	.borbtom {
		border-bottom: 3px solid #089bf5;
	}

	page {
		background-color: #f6f6f6;
	}

	.notes {
		width: calc(100% - 40rpx);
		display: flex;
		align-items: center;
		padding: 30rpx 0 10rpx 20rpx;
		border-bottom: 1px solid #f6f6f6;
	}

	.storestus {
		padding: 1px 5px;
		color: #91bb88;
		font-size: 14px;
		background-color: #e8fbe6;
	}

	.otstatucs {
		background-color: #fbeee4;
		color: #db8c73;
		font-size: 14px;
		padding: 1px 5px;
	}

	.conts {
		width: calc(100% - 60rpx);
		display: flex;
		align-items: center;
		padding: 0 30rpx 0 30rpx;
	}

	.xfimg {
		width: 100rpx;
		bottom: 60rpx;
		position: fixed;
		right: 40rpx;
	}

	.btns {
		width: 21%;
		margin-left: 2%;
		float: left;
		height: 35px;
		line-height: 35px;
		background-color: #0083f5;
		color: #FFFFFF;
		font-weight: bold;
		font-size: 12px;
		padding: 0px;
	}
</style>