<template>
	<!-- 我的维修工单 -->
	<view class="container">
		<u-navbar back-icon-color='#fff' :background="{ background: '#409eff'}" back-text="" title-color='#fff'
			title="我的报修">
		</u-navbar>
		<Search @search='search' @screen='screen'/>
		<view class="list">
			<view class="item" v-for="(item,index) in list" :key="index" @click="itemClick(item,index)">
				<view class="title">
					<view class="title-txt">
						{{item.describes}}
					</view>
					<view class="time">
						2023-12-12 08:00:00
					</view>
				</view>
				<view class="dec">
					报修单号:<span>{{item.number}}</span>
				</view>
				<view class="dec">
					设备编号:<span>{{item.deviceNumber}}</span>
				</view>
				<view class="dec">
					设备名称:<span>{{item.name}}</span>
				</view>
				<view class="dec">
					所属厂区:<span>{{item.factoryAreaName}}</span>
				</view>
				<view class="bottom">
					<view class="status">
						<u-tag text="已报修" v-if="item.result=='已报修'" bg-color='rgba(255,255,255,0)' color='#2ba471'
							border-color='#2ba471' type="primary" shape='circle' />
					</view>
					<view class="button">
						<u-button shape="circle" type="primary" size="mini" style="min-width: 120rpx;"
							v-if="item.isCancel == 0" @click="cancle(item)">撤销</u-button>
					</view>
					
				</view>
			</view>
		<view style="height: 94rpx;padding-top: 30rpx;">
			<u-loadmore :status="status" v-if="status != 'loadmore'" />
		</view>
		</view>
		<view style="height: constant(safe-area-inset-bottom); height: env(safe-area-inset-bottom);"></view>
	</view>
</template>

<script>
	import workOrderList from '@/components/workOrderList/index.vue'
	import * as deviceApi from "@/api/device.js"
	export default {
		components: {
			workOrderList
		},
		data() {
			return {
				params: {
					pageNo: 1,
					pageSize: 10,
					type: 'DEVICE',
					flag:1
				},
				status: 'loadmore', //是否显示没有更多了
				list: [],

			}
		},
		methods: {
			// 筛选
			screen() {
				this.$tab.navigateTo(`/pages/deviceReport/screen?type=${this.type}`)
			},
			itemClick(item, index) {
				this.$tab.navigateTo(`/pages/workOrderList/detail?type=${this.type}`)
			},
			addForm() {
				this.$tab.navigateTo(`/pages/deviceReport/addForm?type=${this.params.type}`)
			},
			// 获取设备保修列表
			getList() {
				if (this.status == 'nomore') return;
				this.status = 'loading';
				deviceApi.deviceRepairPage(this.params).then((res) => {
					if (res.data.list.length > 0) {
						this.list = this.list.concat(res.data.list);
						this.params.pageNo++;
						this.status = 'loadmore'
					} else {
						this.status = 'nomore'
					}
				})
			},
			// 撤销
			cancle(item){
				this.$modal.confirm('确定撤销报修吗？').then(()=>{
					deviceApi.rejected(item.id).then((res) => {
						this.params.pageNo = 1
						this.list = []
						this.status = 'loadmore'
						this.getList()
					})
				})
				
			}
		},
		onShow() {
			this.params.pageNo = 1
			this.list = []
			this.status = 'loadmore'
			this.getList()
		},
		onReachBottom() {
			this.getList()
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		margin-top: 20rpx;

		.item {
			padding: 30rpx 30rpx 0px 30rpx;
			margin-top: 20rpx;
			background: white;

			.title {
				display: flex;
				align-items: center;
				padding-bottom: 20rpx;

				.title-txt {
					color: #409eff;
					font-weight: bold;
					font-size: 36rpx;
					width: 0px;
					flex: 1;
				}

				.time {
					color: #919191;

				}
			}

			.dec {
				padding-bottom: 20rpx;

				span {
					color: #999999;
				}
			}

			.last {
				padding-bottom: 30rpx;
			}

			.bottom {
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-top: 1px solid #E4E4E4;
				padding: 20rpx 0px;

			}
		}
	}

	.list {
		background: #f5f5f5;
		margin-top: 20rpx;

		.item {
			padding: 30rpx 30rpx 0px 30rpx;
			margin-top: 20rpx;
			background: white;

			.title {
				display: flex;
				align-items: center;
				padding-bottom: 20rpx;

				.title-txt {
					color: #409eff;
					font-weight: bold;
					font-size: 36rpx;
					width: 0px;
					flex: 1;
				}

				.time {
					color: #919191;

				}
			}

			.dec {
				padding-bottom: 20rpx;

				span {
					color: #999999;
				}
			}

			.last {
				padding-bottom: 30rpx;
			}

			.bottom {
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-top: 1px solid #E4E4E4;
				padding: 20rpx 0px;
				position: relative;

				.status {
					flex: 1;
				}
				.button{
					position: absolute;
					right: 0rpx;
				}

			}
		}
	}
</style>