<template>
	<view class="content">
		<view class="topbar" v-show="isIphone">
		</view>
		<view class="status_bar">
			<view class="left" @click="goBack"><u-icon name="arrow-left"></u-icon>返回</view>
			<span style="font-size: 36rpx;">详情</span>
			<view class="right"></view>
		</view>
		<view class="mainCont">
			<view class="title">
				{{ info.packCode }}
				<span style="float: right; color: #bcbcbc" v-show="info.packState == '4'">已完成</span>
				<span style="float: right; color: #2D8CF0" v-show="info.packState == '3'">待验收</span>
			</view>
			<u-cell-group style="margin-bottom: 10px">
				<u-cell-item :arrow="false" :value-style="{textAlign: 'left',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>科&emsp;&emsp;室：</view>
					{{ info.positionName }}
				</u-cell-item>
			</u-cell-group>
			<u-cell-group style="margin-bottom: 10px">
				<u-cell-item :arrow="false" :value-style="{textAlign: 'left',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>分&emsp;&emsp;类：</view>
					{{ info.rubbishCategoryStr }}
				</u-cell-item>
				<u-cell-item :arrow="false" :value-style="{textAlign: 'left',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>重&emsp;&emsp;量：</view>
					{{ info.packWeight }}kg
				</u-cell-item>
				<u-cell-item :arrow="false" :value-style="{textAlign: 'left',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>打&ensp;包&ensp;人：</view>
					{{ info.createUserName }}
				</u-cell-item>
				<u-cell-item :arrow="false" :value-style="{textAlign: 'left',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>打包时间：</view>
					{{ info.createTime }}
				</u-cell-item>
				<u-cell-item :arrow="false" :value-style="{textAlign: 'left',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>暂&ensp;存&ensp;点：</view>
					{{ info.provisionalName }}
				</u-cell-item>
			</u-cell-group>
			<view class="imgupload">
				<view>{{ info.packRemake }}</view>
				<view class="imgbox">
					<img v-for="(item,index) in fileList" :src="item.filePath" alt="">
				</view>
				<!-- <u-upload :action="action" :file-list="fileList"></u-upload> -->
			</view>
			<u-cell-group style="margin-bottom: 10px">
				<u-cell-item :arrow="false" :value-style="{textAlign: 'left',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>收&ensp;集&ensp;人：</view>
					{{ info.collectUserName }}
				</u-cell-item>
				<u-cell-item :arrow="false" :value-style="{textAlign: 'left',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>收集时间：</view>
					{{ info.updateTime }}
				</u-cell-item>
			</u-cell-group>
			<u-cell-group style="margin-bottom: 10px" v-show="info.checkUserName">
				<u-cell-item :arrow="false" :value-style="{textAlign: 'left',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>验&ensp;收&ensp;人：</view>
					{{ info.checkUserName }}
				</u-cell-item>
				<u-cell-item :arrow="false" :value-style="{textAlign: 'left',paddingLeft: '10px'}">
					<view slot="title"><span class="red"></span>验收时间：</view>
					{{ info.checkTime }}
				</u-cell-item>
			</u-cell-group>
			<view class="imgupload" v-show="info.abnormalRemake">
				<view>异常内容：{{ info.abnormalRemake }}</view>
				<view class="imgbox">
					<img v-for="(item,index) in imgList2" :src="item.filePath" alt="">
				</view>
				<!-- <u-upload :action="action" :file-list="fileList"></u-upload> -->
			</view>
			<!-- <view class="imgupload" v-show="info.packState != '2'">
				<u-input v-model="remark" auto-height type="textarea" />
				<u-upload ref="upload" @on-remove="uploadRemove" @on-success="uploadSuccess" :header="uploadHeader"
					max-count="3" width="80px" height="80px" :custom-btn="true" :action="action" :file-list="fileList">
					<view slot="addBtn" class="slot-btn">
						<u-icon name="photo" size="60" :color="$u.color['lightColor']"></u-icon>
					</view>
				</u-upload>
			</view>
			<view class="bottomButton" @click="collectDo" v-show="info.packState != '2'">
				<view>收集</view>
			</view> -->
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	const NET = require('@/utils/request')
	const API = require('@/config/api')
	export default {
		data() {
			return {
				remark: "",
				action: API.uploadFile,
				fileList: [],
				imgList: [],
				imgList2: [],
				id: "",
				isIphone: false,
				uploadHeader: {
					Authorization: 'Bearer ' + uni.getStorageSync('token')
				},
				info: {},
			}
		},
		onLoad(options) {
			uni.getSystemInfo({
				success: (res) => {
					console.log(res)
					if (res.model == 'iPhone') {
						this.isIphone = true;
					}
				},
				fail: (err) => {
					console.log(err)
				}
			})
			this.id = options.id
			NET.request(API.getPackageInfo + '/' + options.id, {}).then(res => {
				this.info = res.data
				this.fileList = res.data.packFiles.filter(a => a.fileCategory == 1)
				this.imgList2 = res.data.packFiles.filter(a => a.fileCategory == 3)
			}).catch(error => {
				this.$refs.uToast.show({
					title: error.msg,
					type: 'warning',
				})
			})
		},
		onReady() {
			if (this.isIphone) {
				document.getElementsByClassName('mainCont')[0].style.height = document.getElementsByClassName('mainCont')[
					0].clientHeight - 25 + 'px'
			}
		},
		methods: {
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			uploadSuccess(data, index) {
				console.log(data, index)
				if (data.code == 200) {
					data.data[0].fileType = 2
					data.data[0].fileCategory = 2
					this.imgList.push(data.data[0])
				} else {
					this.$refs.upload.remove(index)
				}
			},
			uploadRemove(index) {
				console.log(index);
				this.imgList.splice(index, 1)
			},
			collectDo() {
				let postData = {
					collectRemake: this.remark,
					collectFileList: this.imgList
				}
				NET.request(API.collectRubbishPackage + '/' + this.id, postData, 'POST').then(res => {
					this.$refs.uToast.show({
						title: '收集成功',
						type: 'success',
					})
					uni.navigateBack({
						delta: 1
					});
				}).catch(error => {
					this.$refs.uToast.show({
						title: error.msg,
						type: 'warning',
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	.mainCont {
		height: calc(100% - 80rpx);
		padding-bottom: 60px;
		overflow-y: scroll;
	}

	.title {
		height: 40px;
		line-height: 20px;
		padding: 10px;
	}

	.red {
		display: inline-block;
		width: 10px;
		height: 10px;
		color: red;
	}

	.imgupload {
		margin-bottom: 10px;
		padding: 10px 25px;
		background: #fff;

		.imgbox {
			img {
				width: 80px;
				height: 80px;
				margin: 10px 10px 10px 0;
			}
		}
	}

	.slot-btn {
		width: 80px;
		height: 80px;
		display: flex;
		justify-content: center;
		align-items: center;
		border: 1px solid #c0c4cc;
		border-radius: 5px;
	}

	/deep/ .u-cell__value {
		color: #1c1c1c;
	}
</style>
