<template>
	<view class="pages">
		<u-navbar title="使用记录" :border-bottom="false" :background="bgc" title-color='#000' back-icon-color="#000"
			title-size='36' height='50'></u-navbar>
         <view class="serch">
         	<view class="lt">
         		<image src="https://api.ccttiot.com/smartmeter/img/static/uaG7R4JLfYOzBhWfDN0j" mode=""></image><input type="text" v-model="keyword" placeholder="搜索"/> <view class="sousuo" @click="searchs">搜索</view>
         	</view>
         </view>
         <view class="orderlist" @scrolltolower="onReachBottom">
         	<view class="otderlist_item" v-for="(item,index) in wateringList" :key="index" @click="btnxq(item.billId)">
         		<view class="order_top">
         			<view class="">
         				订单编号:{{item.billNo == null ? '--' : item.billNo}}
         			</view>
					<view class="">
						<text style="color: #ccc;" v-if="item.status == 1"><text style="width: 10rpx;height: 10rpx;background-color: #ccc;border-radius: 50%;display: inline-block;vertical-align: middle;margin-right: 5rpx;"></text> 未支付</text>
						<text style="color: #27da77;" v-if="item.status == 2"><text style="width: 10rpx;height: 10rpx;background-color: #27da77;border-radius: 50%;display: inline-block;vertical-align: middle;margin-right: 5rpx;"></text> 支付成功</text>
						<text style="color: #ccc;" v-if="item.status == 3"><text style="width: 10rpx;height: 10rpx;background-color: #ccc;border-radius: 50%;display: inline-block;vertical-align: middle;margin-right: 5rpx;"></text> 已退款</text>
						<text style="color: red;" v-if="item.status == 4"><text style="width: 10rpx;height: 10rpx;background-color: red;border-radius: 50%;display: inline-block;vertical-align: middle;margin-right: 5rpx;"></text> 用户取消</text>
						<text style="color: red;" v-if="item.status == 5"><text style="width: 10rpx;height: 10rpx;background-color: red;border-radius: 50%;display: inline-block;vertical-align: middle;margin-right: 5rpx;"></text> 系统超时取消</text>
						<text style="color: #8892F1;" v-if="item.status == 6"><text style="width: 10rpx;height: 10rpx;background-color: #8892F1;border-radius: 50%;display: inline-block;vertical-align: middle;margin-right: 5rpx;"></text> 未支付</text>
						<text style="color: #ccc;" v-if="item.status == 7"><text style="width: 10rpx;height: 10rpx;background-color: #000;border-radius: 50%;display: inline-block;vertical-align: middle;margin-right: 5rpx;"></text> 退款中</text>
					</view>
         		</view>
				<view class="order_bd">
					<view class="order_fu">
						<view class="name">
							用户:{{item.userName == null ? '--' : item.userName}}
						</view>
						<view class="">
							订单费用:{{item.money == null ? '--' : item.money}}元
						</view>
					</view>
					<view class="order_fu">
						<view class="name">
							设备编码:{{item.deviceNo == null ? '--' : item.deviceNo}}
						</view>
						<view class="">
							设备名称:{{item.deviceName == null ? '--' : item.deviceName}}
						</view>
					</view>
					<view class="order_fu">
						<view class="name">
							开始时间:{{item.suitStartTime == null ? '--' : item.suitStartTime}}
						</view>
						<view class="">
							有无售后	:{{item.status == 3 || item.status == 7 ? '有' : '无'}}
						</view>
					</view>
				</view>
         	</view>
			<view v-if="jlflag" class="" style="font-size: 28rpx;color: #ccc;margin-top: 30rpx;width: 100%;text-align: center;">-没有更多订单记录-</view>
         </view>
          
		  <u-picker mode="time" v-model="show" :params="params" @confirm="confirm"></u-picker>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgc: {
					backgroundColor: "#fff",
				},
				list: [{
					name: '全部'
				}, {
					name: '未支付'
				}, {
					name: '已支付',
				}, {
					name: '已完成',
				}, {
					name: '有售后',
				}],
				current: 0,
				pagenum: 1,
				wateringList: [],
				pagesize: 10, // 一页多少数据
				isLoading: false, // 是否正在加载数据  
				noMoreData: false, // 是否没有更多数据  
				total: 0,
				showflag: false,
				jlflag:false,
				statusList:'',
				type:'',
				endtime:'',
				lasttime:'',
				params: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				show: false,
				num:'',
				types:'',
				storeId:'',
				vipld:''
			}
		},
		onLoad(option) {
            if(option.type == '11'){
				this.types = option.type
			}
			if(option.storeId){
				this.storeId = option.storeId
			}
			if(option.vipid){
				this.vipld = option.vipid
			}
		},
		onShow() {
			this.wateringList = []
			this.pagenum = 1
			this.getList()
		},
		// 分享到好友(会话)
		onShareAppMessage: function() {
			return {
				title: '创想物联',
				path: '/pages/shouye/index'
			}
		},

		// 分享到朋友圈  
		onShareTimeline: function() {
			return {
				title: '创想物联',
				query: '',
				path: '/pages/shouye/index'
			}
		},
		methods: {
			btnks(num) {
				this.show = true
				if (num == 1) {
					this.num = 1
				} else {
					this.num = 2
				}
			},
			btnqc(){
				this.endtime = ''
				this.lasttime = ''
				this.wateringList = []
				this.pagenum = 1
				this.statusList = ''
				this.getList()
			},
			confirm(e) {
				if (this.num == 1) {
					this.endtime = e.year + '-' + e.month + '-' + e.day
					if(this.lasttime != ''){
						this.wateringList = []
						this.pagenum = 1
						this.statusList = ''
						this.getList()
					}
				} else {
					this.lasttime = e.year + '-' + e.month + '-' + e.day
					if(this.endtime != ''){
						this.wateringList = []
						this.pagenum = 1
						this.statusList = ''
						this.getList()
					}
				}
			},
			btnxq(billId){
				uni.navigateTo({
					url:'/page_user/mapditu/orderxq?billId=' + billId
				})
			},
			
			change(index) {
				 this.jlflag = false
				this.current = index;
				if(index == 0){
					this.wateringList = []
					this.pagenum = 1
					this.statusList = ''
					this.getList()
				}else if(index == 1){
					this.wateringList = []
					this.pagenum = 1
					this.statusList = 1
					this.getList()
				}else if(index == 2){
					this.wateringList = []
					this.pagenum = 1
					this.statusList = 2
					this.getList()
				}else if(index == 3){
					this.wateringList = []
					this.pagenum = 1
					this.statusList = '2,3,7'
					this.getList()
				}else if(index == 4){
					this.wateringList = []
					this.pagenum = 1
					this.statusList = '3,7'
					this.getList()
				}
			},
			btnsear(){
				this.wateringList = []
				this.pagenum = 1
				this.statusList = ''
				this.getList()
			},
			
			getList(){
				if(this.types == '11'){
					this.$u.get(`/staff/bill/list?pageNum=${this.pagenum}&pageSize=${this.pagesize}&statusList=${this.statusList}&keyword=${this.type}&startDate=${this.endtime}&endDate=${this.lasttime}&vipId=${this.vipld}`).then((res) => {
						if (res.code == 200) {
						   this.total = res.total
						   if (res.rows.length > 0) {
						   	// 有数据,追加到列表  
						   	 this.wateringList =  this.wateringList.concat(res.rows)
						   	 this.pagenum++
						   } else {
						   	// 没有更多数据  
						   	this.noMoreData = true
					         setTimeout(()=>{
								 this.jlflag = true
							 })
							}
						   this.isLoading = false
						}
					})
				}else{
					this.$u.get(`/app/bill/incomeList?pageNum=${this.pagenum}&pageSize=${this.pagesize}&statusList=${this.statusList}&keyword=${this.type}&startDate=${this.endtime}&endDate=${this.lasttime}&vipId=${this.vipld}`).then((res) => {
						if (res.code == 200) {
						   this.total = res.total
						   if (res.rows.length > 0) {
						   	// 有数据,追加到列表  
						   	 this.wateringList =  this.wateringList.concat(res.rows)
						   	 this.pagenum++
						   } else {
						   	// 没有更多数据  
						   	this.noMoreData = true
					         setTimeout(()=>{
								 this.jlflag = true
							 })
							}
						   this.isLoading = false
						}
					})
				}
			},
			
			onReachBottom() {
				let sum = this.total / this.pagesize
				if (this.pagenum-1 < sum) {
					this.getList() // 上拉加载更多  
				} else {
					this.jlflag = true
					// uni.showToast({
					// 	title: '没有更多记录了',
					// 	icon: 'none',
					// 	duration: 1000
					// })
				}
			},
			// 点击查询详情
			btndetail(id){
				uni.navigateTo({
					url:'/page_user/order_detail?id=' + id
				})
			}
			
		},
		// 分享到好友(会话)
		  onShareAppMessage: function () {  
		    return {  
		      title: '创想物联',  
		      path: '/pages/shouye/index'  
		    }  
		  },  
		  
		  // 分享到朋友圈  
		  onShareTimeline: function () {  
		    return {  
		      title: '创想物联',  
		      query: '',  
		      path: '/pages/shouye/index'  
		    }  
		  },
	}
</script>

<style lang="scss">
	/deep/ .u-title {
		padding-bottom: 22rpx;
	}

	/deep/ .u-icon__icon {
		padding-bottom: 22rpx;
	}
	.serch{
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 36rpx;
		box-sizing: border-box;
		padding-top: 22rpx;
		padding-bottom: 22rpx;
		background-color: #fff;
		.lt{
			display: flex;
			align-items: center;
			width: 100%;
			height: 68rpx;
			border: 2rpx solid #8883F0;
			border-radius: 24rpx;
			padding-left: 30rpx;
			box-sizing: border-box;
			.sousuo{
				width: 140rpx;
				height: 66rpx;
				text-align: center;
				line-height: 66rpx;
				font-size: 32rpx;
				color: #FFFFFF;
				background: #8883F0;
				border: 2rpx solid #8883F0;
				border-radius: 0 20rpx 20rpx 0;
			}
			image{
				width: 46rpx;
				height: 46rpx;
			}
			input{
				width: 460rpx;
				margin-left: 30rpx;
				height: 68rpx;
				line-height: 68rpx;
			}
		}
	}
     .orderlist{
		 width: 100%;
		 height: 100%;
		 overflow: scroll;
		 .otderlist_item{
			 margin-top: 30rpx;
			 background-color: #fff;
			 height: 230rpx;
			 .order_top{
				 color: #000;
				 font-size: 28rpx;
				 display: flex;
				 justify-content: space-between;
				 border-bottom: 1px solid #ccc;
				 padding: 0 30rpx;
				 box-sizing: border-box;
				 height: 80rpx;
				 line-height: 80rpx;
			 }
			 .order_fu{
				 display: flex;
				 color: #ccc;
				 font-size: 26rpx;
				 padding: 20rpx 30rpx;
				 box-sizing: border-box;
				 height: 40rpx;
				 line-height: 40rpx;
				 .name{
					 width: 440rpx;
				 }
			 }
		 }
	 }

	page {
		background-color: #F7FAFE !important;
	}
    
	
</style>