<template>
	<view class="mould-page">
		<navigation title="工单管理"></navigation>
		<!-- 搜索框 -->
		<view class="white-card">
			<!-- 搜索框 -->
			<!-- <uni-search-bar :focus="true" ></uni-search-bar> -->
			<u-search placeholder="请输入工单名称,工单编号" v-model="form.taskName"
				@search="searchforfun" @custom="searchforfun" @clear="clearforfun">
			</u-search>
		</view>
		
		<view class="list-box" v-if="dataList.length>0">
			<view class="list-item" v-for="(item, index) in dataList" :key="index" @click="Jumpfun(item)">
				<view class="item-text flex-box">
					<view class="item-text-left">订单名称：</view>
					<view class="item-text-right">{{item.taskName}}</view>
				</view>
				<view class="item-text flex-box">
					<view class="item-text-left">订单编号：</view>
					<view class="item-text-right">{{item.taskNum}}</view>
				</view>
				<view class="item-text flex-box">
					<view class="item-text-left">工单编号：</view>
					<view class="item-text-right">{{item.orderNum}}</view>
				</view>
				<view class="item-text flex-box">
					<view class="item-text-left">工单数量：</view>
					<view class="item-text-right">{{item.orderAmounts || 0}}</view>
				</view>
				<view class="item-text flex-box">
					<view class="item-text-left">已完成数量：</view>
					<view class="item-text-right">{{item.orderFinishNum || 0}}</view>
				</view>
				<view class="item-text flex-box">
					<view class="item-text-left">工单状态：</view>
					<view class="item-text-right" v-if="item.orderStatus == 0">创建</view>
					<view class="item-text-right" v-if="item.orderStatus == 1">执行</view>
					<view class="item-text-right" v-if="item.orderStatus == 2">完成</view>
				</view>
			</view>
		</view>
		
		<empty v-else text="暂无数据"></empty>
		
		<view v-if="total !== 0 && dataList.length != 0" style="height: 60rpx;">
			<u-loadmore :status="status" />
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 请求传递的参数
				form:{
					current:1,
					size:10,
					orderStatus:1
				},
				// 列表数据
				dataList:[],
				total:0,
				status: 'loadmore',
			}
		},
		onShow() {
			this.dataList = []
			this.productOrderlistfun()
		},
		onReachBottom() {
			this.status = 'loading'
			if (this.dataList.length < this.total) {
				this.page.current++
				this.productOrderlistfun()
			} else {
				this.status = 'nomore'
			}
		},
		methods: {
			// 跳转方法
			Jumpfun(item){
				uni.navigateTo({
					url: '/subPackages/workorder/details?orderId=' + item.id
				});
			},
			// 搜索事件
			searchforfun(){
				this.form.current = 1
				this.dataList = []
				this.productOrderlistfun()
			},
			// 搜索清空
			clearforfun(){
				delete this.form.taskName
				this.form.current = 1
				this.dataList = []
				this.productOrderlistfun()
			},
			// 获取列表接口
			productOrderlistfun(){
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				this.$api.productOrderlist(this.form).then(res=>{
					this.dataList = this.dataList.concat(res.rows)
					this.total = res.total
					if (this.dataList.length == res.total) {
						this.status = 'nomore'
					}
					uni.hideLoading();
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.mould-page {
		.white-card {
			background-color: $uni-bg-color;
			padding: 20rpx;
		}
		.list-box {
			padding: 0 20rpx;
			color: $uni-text-color-list; 	// #666
			.list-item {
				background-color: $uni-bg-color; // #ffffff
				padding: 20rpx;
				border-radius: 20rpx;
				margin-top: 28rpx;
	
				.item-text {
					margin-top: 10rpx;
					font-size: 30rpx;
					padding: 10rpx 0;
					border-bottom: 1rpx solid rgba(0, 0, 0, .1);
					&:last-child {
						border: 0;
					}
					.item-text-left {
						// width: 180rpx;
						text-align: right;
					}
					.item-text-right {
						// font-size: 30rpx;
					}
				}
			}
	
		}
		.flex-box {
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
	}
</style>
