<template>
	<!-- 设备报修 -->
	<view class="container">
		<u-navbar back-icon-color='#fff' :background="{ background: '#409eff'}" back-text="" title-color='#fff'
			title="设备报修">
			<template v-slot:right>
				<u-icon name="plus" color="#fff" size="36" style="padding-right: 30rpx;" @click="addForm"></u-icon>
			</template>
		</u-navbar>
		<!-- <Search @search='search' @screen='screen' :isShowScreen='false'/> -->
		<view class="list">
			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="title">
					<view class="title-txt">
						{{item.describes}}
					</view>
					<view class="time">
						{{`${$time.formatDate(item.createTime)}`}}
					</view>
				</view>
				<view class="dec">
					报修单号:<span>{{item.number}}</span>
				</view>
				<view class="dec">
					类型:<span>{{item.type=='DEVICE'?'设备':item.type=='TECH'?'工艺':'模具'}}</span>
				</view>
				<view class="dec">
					{{`${params.type=='DEVICE'?'设备' : '模具'}`}}编号:<span>{{item.deviceNumber}}</span>
				</view>
				<view class="dec">
					{{`${params.type=='DEVICE'?'设备' : '模具'}`}}名称:<span>{{item.name}}</span>
				</view>
				<view class="dec">
					所属厂区:<span>{{item.factoryAreaName}}</span>
				</view>

				<view class="images">
					<image :src="cur" mode="" v-for="(cur,key) in item.filePathList" :key='key'
						@click="previewImage(key,item.filePathList)"></image>
				</view>
				<view class="bottom">
					<view class="status">
						<u-tag :text="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>
		<view style="height: 94rpx;padding-top: 30rpx;">
			<u-loadmore :status="status" v-if="status != 'loadmore'" />
		</view>
		<view style="height: constant(safe-area-inset-bottom); height: env(safe-area-inset-bottom);"></view>
	</view>
</template>

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

			}
		},
		methods: {
			// 筛选
			screen() {
				this.$tab.navigateTo(`/pages/deviceReport/screen?type=${this.type}`)
			},
			addForm() {
				console.log(this.params)
				this.$tab.navigateTo(`/pages/deviceReport/addForm?type=${this.params.type}`)
			},
			// 获取设备保修列表
			async getList() {
				if (this.status == 'nomore') return;
				this.status = 'loading';
				this.$modal.loading('加载中')
				await deviceApi.deviceRepairPage(this.params).then((res) => {
					this.$modal.closeLoading()
					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(() => {
					this.$modal.loading('加载中')
					deviceApi.rejected(item.id).then(async (res) => {
						this.$modal.closeLoading()
						this.params.pageNo = 1
						this.list = []
						this.status = 'loadmore'
						await this.getList()
						this.$modal.showToast('撤销成功')
					})
				})

			},
			previewImage(current, array) {
				uni.previewImage({
					urls: array,
					current: current,
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			}
		},
		onLoad(option) {
			if (option.type) this.params.type = option.type;
			if (this.type == 'DEVICE') {
				uni.setNavigationBarTitle({
					title: '设备报修'
				})
			} else {
				uni.setNavigationBarTitle({
					title: '模具报修'
				})
			}
		},
		onShow() {
			this.params.pageNo = 1
			this.list = []
			this.status = 'loadmore'
			this.getList()
		},
		onReachBottom() {
			this.getList()
		}
	}
</script>

<style lang="scss" scoped>
	.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;
				height: 90rpx;

			}
		}
	}

	.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;
				}

			}
		}
	}

	.images {
		display: flex;
		width: 100%;

		image {
			width: 30%;
			margin-right: 20rpx;
			height: 200rpx;
			border-radius: 10rpx;
		}
	}
</style>