<template name="task">
	<view class="content">
		<view class="cu-bar search bg-white">
			<view class="search-form round" >
				<u-search placeholder="请输入合同编号、车牌号或派车编号" v-model="keyword"
				@search="searchKeyWord()"
				@custom="searchKeyWord()"
				></u-search>
			</view>
		</view>
		<view style='background:#fff;padding:0 15px;'>
			<view @click='tabcarchange(1)' class='line' :class='statusFlag==1?"active":""'>未完成</view>
			<view  @click='tabcarchange(3)' class='line'  :class='statusFlag==3?"active":""'>已完成</view>
		</view>
		<view class="introduce-section">
			<view v-for="(item, index) in taskInfo" :key="index" class="guess-item" @click="navToDetailPage(item)">
				<view class="title flex">
					<text>
						{{item.carNo}}({{item.tranCarNo}})
					</text>
					<view  class="title-tip-a" v-if="item.statusFlag==3">已完成</view>
					<view  class="title-tip" v-if="item.statusFlag==1">未完成</view>
				</view>
				<view class="flex title_b">
					<view class="title-tip">
						{{item.contractNo}}
					</view>
					<view class="title-tip-b">{{item.inOutDate}}</view>
				</view>
				<u-tag :text="item.taskType" type="success" v-if="item.taskType == '出库任务'"/>
				<u-tag :text="item.taskType" type="primary" v-if="item.taskType == '入库任务'"/>
			</view>
			<view v-show="isLoadMore">
				<uni-load-more :status="loadStatus"></uni-load-more>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "task",
		data() {
			return {
				PageCur: "task",
				taskInfo: [],
				pages: 1, //页数
				limit: 10, //每次取条目数
				loadStatus: 'loading', //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				isLoadMore: false, //是否加载中
				showTran: true,
				scrollTop: 0,
				statusFlag: 1,
				current: 1,
				warehouseInOutInfo: {
					pageSize: 10,
					currentPage: 1
				},
				keyword:""
			};
		},
		onShow() {
			this.getIndexBuyData()
		},
		// onLoad(options) {
		// 	this.getIndexBuyData()
		// },
		filters: {
			formatDate (date) {
				var date=new Date(date)
				var time=new Date()
				var newdate=''
				if(time.getMonth() + 1>=10){
					newdate=time.getFullYear()+'-'+(time.getMonth()+1)+'-'+time.getDate()
				}else{
					newdate=time.getFullYear()+'-0'+(time.getMonth()+1)+'-'+time.getDate()
				}
			     //把时间戳改为yyyy-MM-dd格式
			     //判断是否今天
				 var datatime=''
				 if(date.getMonth() + 1>=10){
				 	datatime=date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()
				 }else{
				 	datatime=date.getFullYear()+'-0'+(date.getMonth()+1)+'-'+date.getDate()
				 }
			     if(datatime == newdate){
			          var h = date.getHours();
			             h = h < 10 ? '0' + h : h;
			             var m = date.getMinutes();
			             m = m < 10 ? '0' + m : m;
			             var s = date.getSeconds();
			             s = s < 10 ? '0' + s : s;
			             return h + ':' + m + ':' + s;
			     }else{
					 if(date.getMonth() + 1>=10){
						 return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()
					 }else{
						  return date.getFullYear()+'-0'+(date.getMonth()+1)+'-'+date.getDate()
					 } 
				 }
			 let o = {
			  'Y': date.getFullYear(),
			  'M+': date.getMonth() + 1,
			  'd+': date.getDate(),
			 }
			},
		},
		methods: {
			searchKeyWord(){
				if(!this.keyword){
					this.$api.msg('关键字不能为空')
				}
				this.warehouseInOutInfo.statusFlag = this.statusFlag
				this.warehouseInOutInfo.keyWord = this.keyword
				uni.showLoading({
					title:"正在加载"
				})
				this.$api.doRequest('get', '/warehouseInOutInfo/selectInfoByKeyWord', this.warehouseInOutInfo).then(res => {
					if (res.data.code == 200) {
						this.taskInfo = res.data.data
						uni.hideLoading()
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 2000
						})
						uni.hideLoading()
					}
				}).catch(res => {
					uni.showToast({
						title: res.data.message,
						icon: 'none',
						duration: 2000
					})
					uni.hideLoading()
				})
			},
			getIndexBuyData() {
				const that = this
				var pages = that.pages
				var limit = that.limit
				uni.showLoading({
					title:"正在加载"
				})
				this.warehouseInOutInfo.statusFlag = this.statusFlag
				//this.warehouseInOutInfo.status = this.status
				this.$api.doRequest('get', '/warehouseInOutInfo/selectInfo', this.warehouseInOutInfo).then(res => {
					if (res.data.code == 200) {
						let data = res.data.data.records
						//采购信息
						if (data.length > 0) {
							that.taskInfo = that.taskInfo.concat(data)
							that.isLoadMore = false
						} else {
							if (that.pages > 1) {
								that.pages -= 1
							}
							that.isLoadMore = true
							that.loadStatus = 'nomore'
						}
						uni.hideLoading()
						this.taskInfo = res.data.data.records
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none',
							duration: 2000
						})
					}
				}).catch(res => {
					uni.showToast({
						title: res.data.message,
						icon: 'none',
						duration: 2000
					})
				})
			},
			tabcarchange(statusFlag) {
				this.statusFlag = statusFlag
				this.pageSize = 1
				this.getIndexBuyData()
			},
			navToDetailPage(item) {
				if(item.taskType == "入库任务"){
					
				if(item.statusFlag == 3){
				uni.navigateTo({
					url: `/pageD/warehousings/warehousingDetails?id=${item.id}`
				})
				}else{
					uni.navigateTo({
						url: `/pageD/warehousings/warehousings?id=${item.id}&goodsName=${item.goodsName}&contractNo=${item.contractNo}&startWeight=${item.startWeight}&carNo=${item.carNo}&tranCarNo=${item.tranCarNo}&warehouseName=${item.warehouseName}`
					})
				}
			}else if(item.taskType == "出库任务"){
				if(item.statusFlag == 3){
				uni.navigateTo({
					url: `/pageD/warehousings/ex_warehouse_detail?id=${item.id}`
				})
				}else{
					uni.navigateTo({
						url: `/pageD/warehousings/ex_warehouse?id=${item.id}&goodsName=${item.goodsName}&contractNo=${item.contractNo}&consignee=${item.consignee}&carNo=${item.carNo}&tranCarNo=${item.tranCarNo}&boxNo=${item.boxNo}&titleNo=${item.titleNo}`
					})
				}
			}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tag {
		background:#F5F6F9;
		padding: 5px;
		color:#333333;
		display: inline-flex;
		font-size: 22rpx;
		border-radius: 3px;
		margin: 3px;
	}
	.introduce-section .title_b .title-tip{
		font-size: 13px;
		height:40px;
		line-height: 40px;
		flex: 2.5;
	}
	.introduce-section .title_b .title-tip-b{
		flex: 1;
		font-size: 13px;
		color: #878C9C;
		height:40px;
		line-height: 40px;
	}
	.introduce-section .title text{
		font-size: 17px;
		font-weight: bold;
		height:50px;
		line-height: 50px;
		flex: 2.5;
		border-bottom:1px solid #EEEEEE;
	}
	.introduce-section .title .title-tip{
		flex: 1;
		font-size: 15px;
		color: #FE6430;
		font-weight: 500;
		height:50px;
		line-height: 50px;
		border-bottom:1px solid #EEEEEE;
	}
	.introduce-section .title .title-tip-a{
		flex: 1;
		font-size: 15px;
		color: #AFB3BF;
		font-weight: 500;
		height:50px;
		line-height: 50px;
		border-bottom:1px solid #EEEEEE;
	}
	.introduce-section .guess-item{
		border-radius:4px;
		background: #fff;
		padding: 0upx 30upx 20upx;
		margin:10px;
		padding-bottom: 20upx;
		border-bottom: 1px solid #ccc;
	}
	.line{
		display:inline-block;
		padding:5px;
		position:relative;
		font-size:17px;
	}
	.line.active{
		font-size:19px;
		font-weight: 900;
	}
	.line.active:after{
		content:'';
		display:block;
		position:absolute;
		width:18px;
		left:50%;
		transform: translateX(-50%);
		bottom:0;
		border-bottom:1px solid #22C572;
	}
</style>
