<template>
	<view>
		<uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="巡点检工单" @clickLeft="back"></uni-nav-bar>
		<template>
			<view class="tab-title">
				<view v-for="(item, index) in tabList" :key="index" class="tab-item" :class="index === pickTabIndex ? 'active' : ''" @click="changeChartsTab(index)">
					{{ item.label }}
					<text v-if="item.number > 0" class="title-red">{{ item.number }}</text>
				</view>
			</view>
			<view class="tab-title__placeholder"></view>
		</template>

		<OrderTask v-for="(item, index) in tabList" :key="index" v-show="index === pickTabIndex" :list="item.list" :type="tabList.value"></OrderTask>
	</view>
</template>

<script>
	import { getWorkOrderList } from '@/api/myTicket'
	import OrderTask from './OrderTask.vue'
	import { post, postJ } from '@/utils/api.js'
	let [page, size, isEnd] = [1, 10, true]
	export default {
		components: {
			OrderTask
		},
		data() {
			return {
				tabList: [
					{
						value: 0,
						label: '待接收',
						list: [],
						number: 0
					},
					{
						value: 2,
						label: '执行中',
						list: [],
						number: 0
					},
					{
						value: 3,
						label: '已完成',
						list: [],
						number: 0
					}
				],
				pickTabIndex: 0,
				qrContent: null,
				barType: 0
			}
		},
		onShow() {
			this.getFirstList()
			this.getStatus()
		},
		onReachBottom: function () {
			if (isEnd) {
				return
			}
			// 显示加载图标
			uni.showLoading({
				title: '数据加载中'
			})
			this.getMoreLists()
		},
		methods: {
			getStatus() {
				getWorkOrderList({ orderStatus: [0], type: 1, pageNum: 1, size: 1 }).then(res => {
					this.tabList[0].number = res.count
				})
				getWorkOrderList({ orderStatus: [2], type: 1, pageNum: 1, size: 1 }).then(res => {
					this.tabList[1].number = res.count
				})
				getWorkOrderList({ orderStatus: [3], type: 1, pageNum: 1, size: 1 }).then(res => {
					this.tabList[2].number = res.count
				})
				getWorkOrderList({ orderStatus: [4], type: 1, pageNum: 1, size: 1 }).then(res => {
					this.tabList[3].number = res.count
				})
			},
			getCount() {
				statistics().then(data => {
					console.log('onsole.log(data)-----------')
					console.log(data)
					this.tabList = this.tabList.map(item => {
						switch (item.value) {
							case '0':
								return { ...item, badge: { value: data.maintenanceNum } }
							case '2':
								return { ...item, badge: { value: data.patrolInspection } }
							case '3':
								return { ...item, badge: { value: data.quantityNum } }
							case '4':
								return { ...item, badge: { value: data.repairsNum } }
						}
					})
				})
			},
			getFirstList: function () {
				page = 1
				isEnd = true
				this.getList()
			},
			getMoreLists: function () {
				//获取更多数据
				page++
				this.getList()
			},
			getList() {
				uni.showLoading({
					title: '数据加载中'
				})
				let params = {
					orderStatus: [this.tabList[this.pickTabIndex].value],
					type: 1,
					pageNum: page,
					size
				}
				getWorkOrderList(params)
					.then(res => {
						this.tabList[this.pickTabIndex].list = res.list
						isEnd = this.tabList[this.pickTabIndex].list >= res.count
						uni.hideLoading()
					})
					.catch(() => {
						uni.hideLoading()
					})
			},
			changeChartsTab(index) {
				this.pickTabIndex = index
				this.getFirstList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tab-title {
		position: fixed;
		z-index: 99;
		width: 100%;
		padding: 10rpx;
		// display: flex;
		// justify-content: space-between;
		height: $tab-height;
		line-height: $tab-height;
		background-color: #ffffff;
		border-bottom: 1px solid #f2f2f2;
		// box-sizing: border-box;
		white-space: nowrap;
		overflow: auto hidden;
		display: flex;

		&::-webkit-scrollbar {
			/*滚动条整体样式*/
			width: 10px;
			/*高宽分别对应横竖滚动条的尺寸*/
			height: 1px;
		}

		&::-webkit-scrollbar-thumb {
			/*滚动条里面小方块*/
			border-radius: 10px;
			-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
			background: #535353;
		}

		&::-webkit-scrollbar-track {
			/*滚动条里面轨道*/
			-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
			border-radius: 10px;
			background: #ededed;
		}

		.tab-item {
			flex: 1;
			text-align: center;
			display: inline-block;
			font-size: 32rpx;
			color: $uni-text-color-grey;
		}

		.tab-item.active {
			color: $j-primary-border-green;
			border-bottom: 1px solid $j-primary-border-green;
		}
		.title-num {
			font-size: 26rpx;
		}
		.title-red {
			display: inline-block;
			font-size: 22rpx;
			padding: 0 10rpx;
			border-radius: 50rpx;
			color: #ffffff;
			background: red;
			line-height: 38rpx;
			position: absolute;
			top: 10rpx;
			min-width: 18rpx;
		}
	}
</style>
