<template>
	<view class="processWrapper ">

		<view style="height:196rpx"></view>
		<view class="ding">
			<scroll-view scroll-x class="bg-white nav text-center">
				<view class="cu-item" :class="index==TabCur?'text-blue cur':''" v-for="(item,index) in tabNav"
					:key="index" @tap="tabSelect" :data-id="index" :data-status="index+1">
					<!-- <view v-if="TabCur==index" class="cu-tag badge">
						<block class="cu-tag badge">{{TabCur? unporcessList.length:porcessedList.length}} </block>
					</view> -->
					{{item}}
				</view>
			</scroll-view>

			<!-- 筛选框start -->
			<view class="cu-bar search bg-gray filter-section">
				<view class="search-form round bg-white">
					<text class="cuIcon-search"></text>
					<input class="" type="text" placeholder="请输入站点名称" v-model="site_name"></input>
				</view>
				<view class="action">
					<button class="cu-btn bg-blue round" @click="searchSiteList">查询</button>
				</view>
			</view>
			<!-- 筛选框end -->


		</view>

		<!-- 未执行 -->
		<block v-if="TabCur==0">
			<view style=" height: calc(100vh - 400rpx);">
				<view class="cu-list menu-avatar">
					<view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''"
						@touchstart="ListTouchStart" @touchmove="ListTouchMove" @touchend="ListTouchEnd"
						:data-target="'move-box-' + index" v-for="(item,index) in planListData" :key="index"
						 @tap="goDetail(item.id)">
						<view class="cu-avatar lg" style="background-image:url(../../../static/unprocessIcon.png);">
						</view>
						<view class="content"  style="width:460rpx">
							<view class="pro-title">
								<view class="cut inOneLine">{{item.site_name}}</view>
							</view>
							<view class="pro-date ">{{item.start_time}}</view>
						</view>
						<view class="action" style="z-index:99">
							<view class="unProcess" @tap="goUnprocessDetail(item.id)">未执行</view>
						</view>
						<view class="move">
							<view class="bg-grey" @click.stop="editItem(item)">编辑</view>
							<view class="bg-red" @click.stop="deleteItem(item)">删除</view>
						</view>
					</view>
					<view class=" text-center margin-top" v-if="planListData.length === 0">暂无数据...</view>
				</view>
			</view>
		</block>
		<!-- 执行中 -->
		<block v-if="TabCur==1">
			<view style=" height: calc(100vh - 400rpx);">
				<view class="cu-list menu-avatar eleDoing">
					<view class="cu-item " :class="modalName=='move-box-'+ index?'move-cur':''"
						@touchstart="ListTouchStart" @touchmove="ListTouchMove" @touchend="ListTouchEnd"
						:data-target="'move-box-' + index" v-for="(item,index) in planListData" :key="index"
						 @tap="goDetail(item.id)">
						<view class="cu-avatar lg" style="background-image:url(../../../static/processingIcon.png);">
						</view>
						<view class="content" style="width:460rpx">
							<view class="pro-title">
								<view class="cut inOneLine">{{item.site_name}}</view>
							</view>
							<view class="pro-date ">{{item.start_time}}</view>
						</view>
						<view class="action" style="z-index:99">
							<view class="processing" @tap="goProcessedDetail(item.id)">执行中</view>
						</view>
						<view class="move"  style="width: 66px;"  >
							<view class="bg-grey"@click.stop="editItem(item)">编辑</view>
							<!-- <view class="bg-red" @click.stop="deleteItem(item)">删除</view> -->
						</view>
					</view>
					<view class="text-center margin-top" v-if="planListData.length === 0">暂无数据...</view>
					<view v-show="isLoadMore&&planListData.length!= 0">
						<uni-load-more :status="loadStatus"></uni-load-more>
					</view>
				</view>
			</view>
		</block>
		<!-- 已执行 -->
		<block v-if="TabCur==2">
			<view style="    height: calc(100vh - 400rpx);">
				<view class="cu-list menu-avatar ">
					<view class="cu-item" v-for="(item,index) in planListData" :key="index" @tap="goDetail(item.id)">
						<view class="cu-avatar lg" style="background-image:url(../../../static/processedIcon.png);">
						</view>
						<view class="content"  style="width:460rpx">
							<view class="pro-title">
								<view class="cut inOneLine">{{item.site_name}}</view>
							</view>
							<view class="pro-date ">{{item.start_time}}</view>
						</view>
						<view class="action" style="z-index:99">
							<view class="processed" @tap="goProcessedDetail(item.id)">已执行</view>
						</view>
					</view>
					<view class="text-center margin-top" v-if="planListData.length === 0">暂无数据...</view>
					<view v-show="isLoadMore&&planListData.length != 0&&this.currentPage>1">
						<uni-load-more :status="loadStatus"></uni-load-more>
					</view>
				</view>
			</view>
		</block>


		<!-- 新增按钮start -->
		<view class="plus">
			<image src="../../../static/plus.png" style="width:100rpx;height:100rpx" @tap="goAddPage()"></image>
		</view>
		<!-- 新增按钮end -->

	</view>
</template>

<script>
	export default {
		data() {
			return {

				modalName: null,
				listTouchStart: 0,
				listTouchDirection: null,

				type: '0',

				CustomBar: this.CustomBar,
				TabCur: 0,
				tabNav: ['未执行', '执行中', '已执行', ],
				
				planListData:[],
				site_name:'',
				status_value:1,
				
				currentPage: 1,
				size: 10,
				loadStatus: 'loading', //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				isLoadMore: false, //是否加载中
			};
		},
		onReachBottom() { //上拉触底函数
			if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
				this.isLoadMore = true
				this.currentPage += 1;
				
				this.loadData()
		
			}
		},
	
		onLoad: function(option) {
			// this.getDataList({"status_value":1})
			this.loadData()
		},
		
		methods: {
			
			//编辑
			editItem(item) {
				uni.navigateTo({
					url: '/pages/eleControl/powerCut/powerCutAdd/powerCutAdd?id=' + item.id + '&status_value=' + this.status_value + '',
				});
			},
			
			
			//筛选
			searchSiteList() {
				this.currentPage=1,
				this.planListData=[]
				this.loadData()
				
			},
			loadData(){
				this.getDataList({
					"site_name": this.site_name,
					"status_value":this.status_value,
					"currentPage": this.currentPage,
					"size": this.size,
				})
				
			},
			
			//删除
			deleteItem(item) {
				uni.showModal({
					title: '确认删除吗？',
					content: '',
					success: function(result) {
						if (result.confirm) {
							this.setDelSite({
								"id": item.id
							})
						} else if (result.cancel) {
							// console.log('用户点击取消');
						}
					}.bind(this)
				});
			},
			async setDelSite(ming = {}) {
				const res = await this.$myRequest({
					url: 'BlackoutPlan/delBlackoutPlan',
					data: ming
				})
				if (!res.data.flag) {
					uni.showToast({
						title: "删除失败",
						icon: "none"
					});
				}else{
					uni.showToast({
						title: "删除成功",
					});
					setTimeout(() => {
						this.loadData()
					}, 1000);
				}
				
			},
			
			
			
			//数据请求
			async getDataList(params = {}) {
				const res = await this.$myRequest({
					url: 'BlackoutPlan/getBlackoutPlanList',
					showLoading: true,
					data: params
				})
				// console.log('res.data.data')
				// console.log(res.data.data)
				// this.planListData = res.data.data
				if (res.data.data.length) {
					this.planListData = this.planListData.concat(res.data.data)
									
					if (res.data.data.length < this.size) { //判断接口返回数据量小于请求数据量，则表示此为最后一页
						this.isLoadMore = true
						this.loadStatus = 'nomore'
					} else {
						this.isLoadMore = false
					}
				} else {
					this.isLoadMore = true
					this.loadStatus = 'nomore'
				}
			},
			
			
			tabSelect(e) {
				console.log(e.currentTarget);
				this.currentPage=1,
				this.planListData=[],
				this.site_name='',
				this.TabCur = e.currentTarget.dataset.id;
				// this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60;
				this.status_value=e.currentTarget.dataset.status;
				this.modalName=null;
				this.loadData()
			},
			goAddPage(id) {
				uni.navigateTo({
					url: '/pages/eleControl/powerCut/powerCutAdd/powerCutAdd',
				});
			},
			goDetail(id) {
				uni.navigateTo({
					url: '/pages/eleControl/powerCut/powerCutDetail/powerCutDetail?id='+id+'&&status_value='+this.status_value,
				});
			},

			// ListTouch触摸开始
			ListTouchStart(e) {
				this.listTouchStart = e.touches[0].pageX;
			},
			// ListTouch计算方向
			ListTouchMove(e) {
				this.listTouchDirection = e.touches[0].pageX - this.listTouchStart < -80 ? 'left' : 'right'
			},
			// ListTouch计算滚动
			ListTouchEnd(e) {
				if (this.listTouchDirection == 'left') {
					this.modalName = e.currentTarget.dataset.target
				} else {
					this.modalName = null
				}
				this.listTouchDirection = null
			}
		}
	}
</script>

<style lang="scss">
	//已处理未处理消息个数样式

	.cu-list.menu-avatar .cu-item {
		height: 89px;
	}

	.nav .cu-item.cur {
		position: relative;
		border-bottom: 8rpx solid;
	}

	.cu-tag.badge {
		top: 14rpx;
		right: 42rpx;
	}

	.nav .cu-item {
		width: 33.333%;
		margin: 0;

		.text-blue,
		.line-blue,
		.lines-blue {
			color: #4274E7
		}
	}
	
	.cu-list.eleDoing>.cu-item.move-cur {
		-webkit-transform: translateX(-66px);
	}
</style>
