<template>
	<view class="pagesCons">
		<view class="tab-body flex_column ">
			<view class="flex_column">
				<view>
					<u-tabs-swiper ref="uTabs" bar-width='100' :active-color="$config('primaryColors')" :list="tabList" name="dispName" :current="current" @change="tabsChange" :is-scroll="false"
					 swiperWidth="750"></u-tabs-swiper>
				</view>
				<view class="stock-con">
					<view class="stock-tit">
						<view class="u-line"></view>库存查询
					</view>
					<view class="flex align_center align_center" style="margin-top: 10px;">
						<u-image width="60px" height="60px"/>
						<view style="padding-left: 10px;height: 80px;" class="flex_column align_center">
							<view>产品编码：<text>{{'0123456'}}</text></view>
							<view>原厂编码：<text>{{'0123456'}}</text></view>
							<view>
								<text>可用数量：122</text>
								<text>库存成本：1230000</text>
							</view>
						</view>
					</view>
				</view>
			</view>
				<swiper class="check-list" :current="swiperCurrent" @transition="transition" @change="swiperChange" @animationfinish="animationfinish">
					<swiper-item class="swiper-item" style="height: 100%;width: 100%;overflow: hidden;" v-for="(tabs, index) in tabList" :key="index">
						<scroll-view scroll-y style="width: 100%;overflow: scroll;" @scrolltolower="onreachBottom">
							<view  
							class="check-order-list" 
							v-for="item in 7"
							>
								 <view class="check-row" @click="viewRow(item)">
									 <view class="flex justify_between"> 
										 <text>2021-12-31 12:12:12</text>
										 <text>销售退货</text>
									 </view>
									 <view class="flex justify_between">
									 <text>2021-12-31 12:12:12</text>
									 <text>销售退货</text>
									 </view>
								 </view>
							 </view>
							 <u-empty text="暂无套餐" :src="`/static/${$config('themePath')}/def_no_meal@3x.png`" icon-size="240" img-width="120" v-if="list.length==0 && status!='loading'" mode="list"></u-empty>
							 <view style="padding: 20upx;">
								 <u-loadmore :load-text="$config('loadText')" v-if="total>pageSize || status=='loading'" :status="status" />
							 </view>
						</scroll-view>
					</swiper-item>
				</swiper>
		</view>
		
	</view>
</template>

<script>
	// import { listCustomerBundle } from '@/api/customerBundle'
	// import vSelect from '@/components/select/v-select.vue'
	// import { searchCustomerList } from '@/api/car.js'
	export default {
		// components: {
		// 	vSelect
		// },
		data() {
			return {
				showSearch: false,
				showCustomeList: false,
				customList: [],
				tips: {
					text: '请选择客户信息',
					color: '#666',
					fontSize: 34
				},
				status: 'loadmore',
				background: {
					// 渐变色
					backgroundImage: this.$config('topBarBackground')
				},
				tabList: [
					{
						dispName: '出库详情',
						code:''
					},
					{
						dispName: '出入库明细',
						code:'1'
					},
					
				],
				current: 0,
				swiperCurrent: 0,
				orderStatus: '', // 订单状态
				currentId: '',
				payTypeList: [],
				pageNo: 1,
				pageSize: 10,
				list: [],
				total: 0,
				// 查询条件
				beginDate: null,
				endDate: null,
				queryWord: '',
				bundleName: '',
				number: '',
				payTypes: '',
				sellChannel: '',
				refundStatus: '',
				carNumber: '',
				createChannels: [],
				createChanneList: [] // 创建渠道列表
			}
		},
		onLoad() {
			let _this = this
			this.getpayType()
			this.pageInit()
			//创建渠道列表
			this.createChanneList = this.$store.state.vuex_createChannelList
			uni.$on('refreshBundle',function(data){
				 console.log(data.msg,'refreshOrder')
			     _this.pageInit()
			})
			uni.setNavigationBarColor({
				backgroundColor: this.$config('topBarBackground'),
				frontColor: this.$config('topBarTitleColors')
			})
		},
		onBackPress() {
			if(this.showSearch){
				this.showSearch = false
				return true
			}
		},
		onNavigationBarButtonTap(e){
			if(e.index == 0){
				this.openSearch()
			}
		},
		methods:{ 
			message(title){
				uni.showToast({
					icon:'none',
					title: title
				})
			},
			// 获取所有收费方式
			getpayType () {
				this.payTypeList = this.$store.state.vuex_paymentTypeList
			},
			filterpayType (val,dataList) {
			  var _value = ''
			    for (let i = 0; i < dataList.length; i++) {
			      if (val == dataList[i].code) {
			        _value = dataList[i].dispName
			        break
			      }
			    }
			  return _value
			},
			getpayTypeText(v) {
				this.payTypes = v
			},
			// 选择创建渠道
			selCreatChannel(items,index){
				let hasIndex = this.createChannels.findIndex(item=> item == items.code)
				if(hasIndex>=0){
					this.createChannels.splice(hasIndex,1)
					this.createChanneList[index].checked = false
				}else{
					this.createChannels.push(items.code)
					this.createChanneList[index].checked = true
				}
				this.createChanneList.splice()
			},
			pageInit(showSearch){
				if(showSearch){
					if(this.endDate&&!this.beginDate){
					  this.message('请选择开始日期')
					  return false
					}
					if(this.beginDate&&!this.endDate){
					  this.message('请选择结束日期')
					  return false
					}
				}
				this.total = 0
				this.pageNo = 1
				this.getRow()
				this.showSearch = showSearch
			},
			// tabs通知swiper切换
			tabsChange(index) {
				this.swiperCurrent = index;
			},
			swiperChange(event){
				console.log(event.detail)
				this.list = []
				this.status = "loading"
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			transition(e) {
				console.log(e,'eeeeeeeee')
				let dx = e.detail.dx;
				this.$refs.uTabs.setDx(dx);
			},
			// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
			// swiper滑动结束，分别设置tabs和swiper的状态
			animationfinish(e) {
				console.log('---------')
				let current = e.detail.current;
				if(current != this.current){
					this.$refs.uTabs.setFinishCurrent(current);
					this.swiperCurrent = current;
					this.current = current;
					this.refundStatus = this.tabList.length ? this.tabList[this.current].code : ''
					this.resetForm(false)
				}
			},
			// scroll-view到底部加载更多
			onreachBottom() {
				console.log(this.list.length, this.total)
				if(this.list.length < this.total){
					this.pageNo += 1
					this.getRow()
				}else{
					this.status = "nomore"
				}
			},
			checkNums (states, i){
			  if(states){
				  let arr = states.split(',')
				  return arr[i]
			  }
				return 0
			},
			// 查询列表
			getRow (pageNo) {
			  let _this = this
			  if (pageNo) {
			    this.pageNo = pageNo
			  }
			  
			  let sdata = {
			    pageNo: this.pageNo,
			    pageSize: this.pageSize,
			    queryWord: this.queryWord,
				beginDate: this.beginDate||'',
				endDate: this.endDate||'',
				createChannels: this.createChannels
			  }
			  if (this.number) {
			    sdata.number = this.number
			  }
			  if (this.bundleName) {
			    sdata.bundleName = this.bundleName
			  }
			  if (this.payTypes) {
				  let arr = []
				  arr.push(this.payTypes)
			    sdata.payTypes = arr
			  }
			  if (this.sellChannel) {
			    sdata.sellChannelCode = this.sellChannel
			  }
			  if (this.refundStatus) {
			    sdata.refundStatus = this.refundStatus
			  }
			 
			  _this.status = "loading"
			  listCustomerBundle(sdata).then(res => {
				if (res.code == 200 || res.status == 204 || res.status == 200) {
				  if(_this.pageNo>1){
					  _this.list = _this.list.concat(res.data.list || [])
				  }else{
					  _this.list = res.data.list || []
				  }
				  _this.total = res.data.count || 0
				} else {
				  _this.list = []
				  _this.total = 0
				}
				_this.status = "loadmore"
			  })
			},
			// 查询条件
			openSearch(){
				let _this = this
				this.showSearch = true
				if (this.payTypes) {
					setTimeout(function(){
						_this.$refs.payType.setVal(_this.payTypes)
					},300)
				}
				if(this.createChanneList.length==0){
					//创建渠道列表
					this.createChanneList = this.$store.state.vuex_createChannelList
					this.createChanneList.map(item=>{item.checked = false})
				}
			},
			bindBeginDateChange(e){
				this.beginDate = e.target.value
			},
			bindEndDateChange(e){
				this.endDate = e.target.value
			},
			// 重置
			resetForm(flag){
				this.queryWord = ''
				this.beginDate = ''
				this.endDate = ''
				this.bundleName = ''
				this.number = ''
				this.payTypes = ''
				this.sellChannel = ''
				this.carNumber = ''
				this.createChannels= []
				//创建渠道列表
				if(flag){
					this.createChanneList = this.$store.state.vuex_createChannelList
					this.createChanneList.map(item=>{item.checked = false})
					this.$refs.payType.resetVal()
				}
				this.pageInit(flag)
			},
			// 详细页
			viewRow(item){
				uni.navigateTo({
					url: "/pages/workOrder/sellOrder/customBundleDetail?id="+item.id
				})
			},
		   // 付款
		   payRow (params) {
		     let _this = this
		     let id = params.row.id
		     this.currentId = id
		     this.$Modal.confirm({
		       title: '确认付款操作吗',
		       onOk: () => {
		         // 打开购买套餐页面
		         _this.openPackagePay = true
		       },
		       onCancel: () => {
		       }
		     })
		   },
			collectMoney (data){
                 // 进入收款页面
				 uni.redirectTo({
					 url: '/pages/workOrder/sellOrder/bundlePay?id='+data.id
				 })
		    },
			// 车牌号查询客户信息
			queryCustomByCar (event) {
				console.log(event.detail.value, '==搜索关键词')
			   let queryWord = event.detail.value
			   if (queryWord.length > 0){
				 let params = {vehicleNumber: ''}
				 if (queryWord.length == 5 || queryWord.length == 6){
				   params.vehicle5Number = queryWord.toUpperCase()
				   this.queryCustomInfo(params)
				 } else if (queryWord.length == 7 || queryWord.length == 8){
				   params.vehicleNumber = queryWord.toUpperCase()
				   this.queryCustomInfo(params)
				 }
			   }else{
				   this.queryWord = ''
			   }
			},
			// 获取客户车辆信息
			queryCustomInfo (params) {
			    let _this = this
				searchCustomerList(params).then(res => {
				  if (res.status - 0 === 200) {
					_this.customList = res.data || []
					if(_this.customList.length){
						_this.customList.map(item=>{
							item.text = item.customer.mobile + '-' + item.vehicle.number
						})
						if(_this.customList.length > 1){
							this.showCustomeList = true
							uni.hideKeyboard()
						}else{
							this.selectCustomCar(0)
						}
					}else{
						uni.showToast({
							icon:'none',
							title:'此车牌不存在'
						})
						this.carNumber = ''
					}
				  } 
				})
			},
			// 选择下拉选项
			selectCustomCar (index){
				let row = this.customList[index]
				if (row){
					this.queryWord = row.customer.mobile
					this.carNumber = row.vehicle.number
				}
			},
			// 取消选择已存在的客户信息
			closeSelCust(){
				this.customList = []
				this.queryWord = ''
				this.carNumber = ''
			},
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
	}
	.pagesCons{
		width: 100%;
		height: 100%;
		background-color: #fff;
		display: flex;
		flex-direction: column;
		.tab-body{
			height: 100%;
			display: flex;
			flex-direction: column;
			.stock-con{
				background-color: #ffffff;
				border-radius: 20upx;
				box-shadow: 3upx 2upx 6upx #eee;
				padding: 20upx;
				// position: fixed;
				// top:40px;
				.stock-tit{
					.u-line{
						display: inline-block;
						width: 6upx;
						height: 40upx;
						background-color: red;
						vertical-align: bottom;
						margin: 0 20upx 0 10upx;
					}
				}
			}
			.check-list{
				flex-grow: 1;
				
				// height: calc(100vh - 44px);
			}
			.check-order-list{
				background: #ffffff;
				padding: 10upx 20upx;
				margin-top: 25upx;
				border-radius: 30upx;
				box-shadow: 1px 1px 3px #EEEEEE;
				.check-row{
					>view{
						padding: 5px;
					}
					// display: flex;
					// align-items: center;
					// padding: 20upx 10upx;
					// font-size: 28upx;
					// &:first-child{
					// 	color: #222222;
					// 	font-size: 34upx;
					// 	padding-bottom: 0;
					// }
					// &:last-child{
					// 	color: #666E75;
					// }
					// > view{
					// 	&:first-child{
					// 		flex-grow: 1;
					// 	}
					// }
					// .state{
					// 	font-size: 30upx;
					// 	width: 30%;
					// 	text-align: right;
					// }
					// .customeInfo{
					// 	color: #999;
					// 	.uname{
					// 		margin-right: 20upx;
					// 	}
					// }
					// .action{
					// 	margin: 0 6rpx;
					// 	padding: 0 20rpx;
					// 	color: #fff;
					// 	border-radius: 100rpx;
					// 	&:after{
					// 		border: 0;
					// 	}
					// }
					// .pay{
					// 	background-color: #ffaa00;
					// }
				}
			}
		}
	}
   .slot-wrap {
		display: flex;
		align-items: center;
		/* 如果您想让slot内容占满整个导航栏的宽度 */
		flex: 1;
		/* 如果您想让slot内容与导航栏左右有空隙 */
		padding: 0 30rpx 0 0;
		color: #fff;
		font-size: 28upx;
		.left-icon{
			flex-grow: 1;
			font-size: 32upx;
		}
		.right-icon{
			padding-left:50upx;
		}
		.uni-icons{
			margin-right: 10upx;
		}
	}
	.search-popup{
		.search-title{
			text-align: center;
			padding: 20upx;
			color: #333; 
			border-bottom: 1px solid #eee;
		}
		uni-picker{
			width: 100%;
		}
		.uni-list{
			padding:10upx 30upx;
			margin: 0;
			border-bottom: 1px solid #EEEEEE;
			.uni-list-cell{
				border: 0;
				.uni-list-cell-db{
					flex: 1;
					width: 100%;
				}
				.p30{
					padding-right: 30upx;
				}
				.uni-input{
					height: 2.5em;
					line-height: 2.5em;
					font-size: 28upx;
					display: flex;
					align-items: center;
					text-align: right;
					> view{
						&:first-child{
							flex-grow: 1;
						}
						&:last-child{
							color: #999;
						}
						.form-input-placeholder{
							color: #999;
						}
					}
				}
				.item-icon{
					margin-left: 10upx;
				}
				.checkbox-items{
					display: flex;
					flex-wrap: wrap;
					justify-content: space-between;
					.checkbox{
						width: 24%;
						background: #F8F8F8;
						text-align: center;
						margin: 20upx 0;
						padding: 10upx 0;
						border-radius: 50upx;
						font-size: 24upx;
						border:1upx solid #eee;
					}
					.checked{
						background: rgba(4, 133, 246, 0.15);
						border-color: rgba(4, 133, 246, 0.5);
						color: rgba(4, 133, 246, 1);
					}
				}
			}
		}
		.uni-list-btns{
			display: flex;
			padding: 20upx;
			uni-button{
				font-size: 28upx;
				margin: 25upx 20upx 0;
				flex:1;
				border-radius: 100upx;
				&:after{
					border: 0;
				}
			}
		}
		
	}
</style>
