<template>
	<view>
		<view
			style="box-shadow: 0px 0px 8px 0px rgba(165, 189, 251, 0.4);width: 96%;border-top-right-radius: 10rpx;margin: 10rpx auto;padding-top: 10rpx;">
			<span
				style="width: 10rpx;height: 40rpx;background-color: #2979ff;display: block;float: left;margin-top: 20rpx;"></span>
			<!-- <h4 style="width: 140rpx;border-radius: 200rpx;text-align: center;color: #2979ff;border: 2rpx solid #1785FF;float: right;margin-right: 10rpx;margin-top: 10rpx;">2222222</h4> -->
			<view style="width: 92%;margin: 0 auto;margin: 0 auto;">
				<view
					style="display: flex;justify-content: space-between;height: 80rpx;line-height: 80rpx;border-bottom: 1rpx solid #eff4ff;">
					<h3>基本信息</h3>
				</view>
				<view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">仓库</view>
						<view style="float: right;">{{form.fWarehouseName}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">计划日期</view>
						<view style="float: right;">{{form.fInspectionDatetime}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">最新巡查日期</view>
						<view style="float: right;">{{form.fUpdateTime}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">巡检员</view>
						<view style="float: right;">{{form.fInspectorName}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">备注</view>
						<view style="float: right;">{{form.fRemark}}</view>
					</view>
				</view>
				<!-- <view style="width: 100%;margin: 0 auto;height: 80rpx;margin: 0 auto;line-height: 80rpx;border-top: 1rpx solid #eff4ff;" @click="expenseDetails(item)">
					<view style="float: left;"><h3>立即巡检</h3></view>
					<view style="float: right;"><u-icon name="arrow-right"></u-icon></view>
				</view> -->
			</view>
		</view>
		<view
			style="box-shadow: 0px 0px 8px 0px rgba(165, 189, 251, 0.4);width: 96%;border-top-right-radius: 10rpx;margin: 10rpx auto;padding-top: 10rpx;">
			<span
				style="width: 10rpx;height: 40rpx;background-color: #2979ff;display: block;float: left;margin-top: 20rpx;"></span>
			<!-- <h4 style="width: 140rpx;border-radius: 200rpx;text-align: center;color: #2979ff;border: 2rpx solid #1785FF;float: right;margin-right: 10rpx;margin-top: 10rpx;">2222222</h4> -->
			<view style="width: 92%;margin: 0 auto;margin: 0 auto;">
				<view
					style="display: flex;justify-content: space-between;height: 80rpx;line-height: 80rpx;border-bottom: 1rpx solid #eff4ff;">
					<h3>上传附件</h3>
				</view>
				<view>
					<u-upload style="width: 100%;" :action="action" @on-success="success" @on-remove="remove" :file-list="fileList" :header="headers"></u-upload>
				</view>
			</view>
		</view>
		<view
			style="width: 100%;position:fixed; bottom:0;background-color: #FFFFFF;padding-left: 20px;padding-right: 20px;padding-bottom: 30rpx;">
			<u-button type="primary" @click="submit">确认保存</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				action: this.$u.http.config.baseUrl + '/common/upload',
				headers: {
					Authorization: 'Bearer ' + this.$store.state.vuex_token
				},
				form: {},
				fileList: [],
				pictureEist: [],
				twarehousecheckdetailList: {}
			}
		},
		onLoad(option) {
			this.form = JSON.parse(option.form)
			let scope = {
				row:JSON.parse(option.form)
			}
			this.$u.get('/warehouse/checkitemsdetails/list', {
				fItemFid: this.form.fId
			}).then(res => {
				console.log(res)
				let data = res.rows
				if (data.length === 0) {
					this.twarehousecheckdetailList = {
						fCheckFid: scope.row.fCheckFid,
						fItemFid: scope.row.fId,
						fWarehouseid: scope.row.fWarehouseFid, //仓库名称
						fCreateTime: '',
						fInspectorid: '',
						fRemark: '',
						fPhotoUrl: []
					}
				} else {
					this.twarehousecheckdetailList = res.rows[0]
					this.twarehousecheckdetailList.fWarehouseid = scope.row.fWarehouseFid
					this.fileList = []
					for (let item in JSON.parse(res.rows[0].fPhotoUrl)) {
						this.fileList.push(JSON.parse(res.rows[0].fPhotoUrl)[item])
					}
					this.pictureEist = this.fileList
				}
			})
		},
		created() {},
		methods: {
			submit() {
				// console.log(this.twarehousecheckdetailList)
				// console.log(this.fileList)
				// console.log(this.pictureEist)
				this.twarehousecheckdetailList.fPhotoUrl = []
				for (let item in this.pictureEist) {
					if (this.pictureEist[item].response) {
						this.twarehousecheckdetailList.fPhotoUrl.push({
							url: this.pictureEist[item].response.url
						})
					} else {
						this.twarehousecheckdetailList.fPhotoUrl.push({
							url: this.pictureEist[item].url
						})
					}
				}
				this.twarehousecheckdetailList.fPhotoUrl = JSON.stringify(this.twarehousecheckdetailList.fPhotoUrl)
				if (!this.twarehousecheckdetailList.fId) {
					this.$u.post('warehouse/checkitemsdetails', this.twarehousecheckdetailList).then(res => {
						uni.showToast({
							icon: 'none',
							title: '保存成功',
							position: "bottom"
						})
					})
				} else {
					this.$u.put('warehouse/checkitemsdetails', this.twarehousecheckdetailList).then(res => {
						uni.showToast({
							icon: 'none',
							title: '保存成功',
							position: "bottom"
						})
					})
				}
			},
			success(data, index, lists, name) {
				// console.log(lists)
				this.pictureEist = lists
			},
			remove(index, lists, name) {
				// console.log(index,lists)
				this.pictureEist = lists
			}
		}
	}
</script>

<style>

</style>
