<template>
	<view class="shelf-analyse-content">
		<view class="checkbox-price">
			<u-checkbox-group  placement="row" :size="24">
				<u-checkbox v-model="item.checked" activeColor="rgb(4, 133, 246)" v-for="(item,index) in tabList" :key="index" :name="item.val">{{item.name}}</u-checkbox>
			</u-checkbox-group>
			<view class="search" @click="showModal=true">
				筛选 <u-icon name="arrow-down"></u-icon>
			</view>
		</view>
		<scroll-view class="product-list" scroll-y @scrolltolower="onreachBottom">
			<view class="st-detailList-main">
				<view class="st-detailList-main-item" v-for="(item, index) in listData" :key="item.id" @click="toViewDetail(item)">
					<view class="st-detailList-item-con flex align_center">
						<view class="pimgs">
							<u-image :src="item.productMainPic&&item.productMainPic.imageUrl?item.productMainPic.imageUrl:`../../static/${theme}/def_img@2x.png`" width="100" height="100" border-radius="10"></u-image>
						</view>
						<view class="flex_1">
							<view class="flex align_center justify_between">
								<view>
									LJJLDS234DD323453
								</view>
								<view class="font_13">
									2022-05-06 12:25:36
								</view>
							</view>
							<view class="padding_3">{{item.name || '--'}} </view>
						</view>
					</view>
					<view class="price-all flex" v-if="selPriceShow">
						<view class="price-item" v-if="priceList[0].checked">
							<view>空调滤清器</view>
							<text class="green">有适配</text>
						</view>
						<view class="price-item" v-if="priceList[1].checked">
							<view>空气滤清器</view>
							<text class="red">无适配</text>
						</view>
						<view class="price-item" v-if="priceList[2].checked">
							<view>机油滤清器</view>
							<text>--</text>
						</view>
					</view>
				</view>
				<u-empty v-if="listData.length == 0 &&status!='loading'" :text="noDataText" mode="list" ></u-empty>
				<view style="padding-bottom: 20upx;">
					<u-loadmore v-if="totalNum>listData.length || status=='loading'" :status="status" />
				</view>
			</view>
		</scroll-view>
		<!-- 搜索弹窗 -->
		<search :showModal="showModal" @refresh="refreshList" @close="showModal=false"/>
	</view>
</template>

<script>
	import { toThousands } from '@/libs/tools'
	import { dealerProductList } from '@/api/sales'
	import search from './search.vue'
	import copyText from '@/pages/common/copyText.vue'
	export default{
		components:{search,copyText},
		data(){
			return{
				toThousands,
				listData:[],
				totalNum:0,
				priceList:[
					{ name: '空调滤清器', checked: true, val: 'kt' },
					{ name: '空气滤清器', checked: true, val: 'kq' },
					{ name: '机油滤清器', checked: true, val: 'jy' },
				],
				pageNo:1,
				pageSize:15,
				noDataText: '暂无数据',
				theme: '',
				status: 'loadmore',
				showModal:false,
				params:{},
				detail: null
			}
		},
		onNavigationBarButtonTap(e){
		},
		computed: {
			selPriceShow() {
				const a = this.priceList.filter(item => item.checked)
				return a.length > 0
			},
			tabList(){
				return this.priceList
			}
		},
		onLoad(option) {
			this.detail = JSON.parse(option.data)
			this.theme = getApp().globalData.theme
			uni.setNavigationBarTitle({
				title: this.detail.shelfName
			})
			this.getList()
		},
		methods:{
			toPage(url){
				uni.switchTab({
					url:url
				})
			},
			// 刷新列表
			refreshList(val){
				this.params =val ? val : {},
				this.listData = []
				this.totalNum = 0
				this.getList(1)
			},
			// 列表
			getList(pageNo){
				const _this = this
				if (pageNo) {
					this.pageNo = pageNo
				}
				let params = Object.assign(this.params, { pageNo: this.pageNo, pageSize: this.pageSize })
				this.status = "loading"
				console.log(params)
				dealerProductList(params).then(res => {
					if (res.status == 200) {
						if(this.pageNo>1){
							this.listData = this.listData.concat(res.data.list || [])
						}else{
							this.listData = res.data.list || []
						}
						this.totalNum = res.data.count || 0
					} else {
						this.listData = []
						this.totalNum = 0
						this.noDataText = res.message
					}
					this.status = "loadmore"
				})
			},
			// scroll-view到底部加载更多
			onreachBottom() {
				if(this.listData.length < this.totalNum){
					this.pageNo += 1
					this.getList()
				}
			},
			// 查看销售记录
			toViewDetail(row){
				uni.navigateTo({
					url: "/pages/sales/salesRecord?productSn="+row.productSn + "&productName="+row.name+ "&productCode="+row.code
				})
			}
		}
	}
</script>

<style lang="scss">
	.shelf-analyse-content{
		width:100%;
		height: 100vh;
		.checkbox-price{
			background-color: #fff;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 25rpx;
			color: #191919;
			.search{
				color:#00aaff;
			}
		}
		.product-list{
			height: calc(100vh - 94upx);
				.st-detailList-main{
					padding: 20upx;
					.st-detailList-main-item{
						background: #ffffff;
						padding: 20upx;
						margin-bottom: 25upx;
						border-radius: 25upx;
						box-shadow: 1px 1px 3px #EEEEEE;
						.st-detailList-item-con{
							padding: 20upx 0;
							font-size: 26upx;
							.red{
								color: red;
							}
							.pimgs{
								margin-right: 16upx;
							}
							.font_13{
								font-size: 24upx;
								color: #999;
							}
							.padding_3{
								padding: 6upx 0;
								word-break: break-all;
							}
						}
						.price-all{
							border-top: 1px solid #e4e7ed;
							padding: 10upx 20upx 0;
							.price-item{
								width: 33.3%;
								border-right:  1px solid #e4e7ed;
								text-align: center;
								>view{
									color:#999;
									margin-bottom: 10rpx;
									font-size: 24rpx;
								}
								>text{
									border:1rpx solid #eee;
									font-size: 20rpx;
									padding:5rpx 10rpx;
									border-radius: 10rpx;
									min-width: 100rpx;
									display: inline-block;
								}
								.red{
									color:#ff5500;
									border-color: #ff5500;
								}
								.green{
									color:#00cb00;
									border-color: #00cb00;
								}
							}
							.price-item:last-child{
								border-right:  none;
							}
						}
					}
				}
				
				
		}
	}
</style>
