<template>
	<view class="query-wrap">
		<view class="inner-item" v-for="(item,index) in listData" :key="index">
			<view class="item-stats">
				<span v-if="item.stas == 'A'">已确认待拣货</span>
				<span v-if="item.stas == 'B'">已出库待配送</span>
				<span v-if="item.stas == 'C'">配送中</span>
				<span v-if="item.stas == 'D'">已配送</span>
			</view>
			<view class="inventory-item">
				<view class="shuo-item-name">
					<view class="shuo-label">
						出库订单号:
					</view>
					<view class="shuo-unit">
						{{item.stooutId}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item-name">
					<view class="shuo-label">
						来源订单号:
					</view>
					<view class="shuo-unit">
						{{item.soucId}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						出库品种数:
					</view>
					<view class="shuo-cont">
						{{item.stoCnt}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						出库总数量:
					</view>
					<view class="shuo-cont">
						{{item.devCnt}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item-name">
					<view class="shuo-label">
						出库总金额:
					</view>
					<view class="shuo-unit">
						{{item.devAmt}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item-name">
					<view class="shuo-label">
						出库类型:
					</view>
					<view class="shuo-cont">
						{{item.stoType}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item-name">
					<view class="shuo-label">
						目标位置:
					</view>
					<view class="shuo-cont">
						{{item.deptName}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						出库人:
					</view>
					<view class="shuo-cont">
						{{item.crteUsrName}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						出库时间:
					</view>
					<view class="shuo-cont">
						{{forMatTime(item.crteTime)}}
					</view>
				</view>
			</view>
			<view class="upload-file-wrap" v-if="listData[0].stas=='C'">
				<view class="tit-label">
					接收文件:
				</view>
				<view class="file-wrap">
					<jade-image-upload :list="media" :control="control" :maxCount="maxCount"
						:compressSize="compressSize" :compressQuality="compressQuality" :compressWidth='compressWidth'
						:imageSize="imageSize" :sourceType="sourceType" @chooseFile="chooseFile"
						@imgDelete="mediaDelete">
					</jade-image-upload>
				</view>
			</view>
		</view>
		<view class="inner-item">
			<view class="text-title">
				<view class="title-circ">

				</view>
				<span>手术信息</span>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						手术名称:
					</view>
					<view class="shuo-cont">
						{{listData[0].oprnName}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						手术间:
					</view>
					<view class="shuo-cont">
						{{listData[0].oprtRoom}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						主治医生:
					</view>
					<view class="shuo-cont">
						{{listData[0].atddr}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						手术日期:
					</view>
					<view class="shuo-cont">
						{{listData[0].oprtTime?forMatTime(listData[0].oprtTime):""}}
					</view>
				</view>
			</view>
		</view>
		<view class="inner-item" v-for="(item,idex) in detailsData" :key="idex" @click.stop="itemDetails(item,idex)">
			<view class="text-title" v-if="idex=='0'">
				<view class="title-circ">

				</view>
				<span>商品清单</span>
			</view>
			<view class="inventory-item">
				<view class="shuo-item-name">
					<view class="shuo-label-podnme">
						{{item.prodName}}
					</view>
					<view class="shuo-unit">
						<span>{{ item.purcUnt }} ({{ item.convrat
			  			}}{{item.prcUnt}}/{{ item.purcUnt }})</span>
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item-name">
					<view class="shuo-label">
						出库数量:
					</view>
					<view class="shuo-unit">
						{{item.stooutCnt}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						规格:
					</view>
					<view class="shuo-cont">
						{{item.spec}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						型号:
					</view>
					<view class="shuo-cont">
						{{item.mol}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item-name">
					<view class="shuo-label">
						注册证号:
					</view>
					<view class="shuo-cont">
						{{item.regcertno}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						耗材类别:
					</view>
					<view class="shuo-cont-blue">
						<span v-if="item.mcsType == '0'"> 普通耗材 </span>
						<span v-if="item.mcsType == '1'"> 高值耗材 </span>
						<span v-if="item.mcsType == '2'"> 试剂 </span>
						<span v-if="item.mcsType == '3'"> 总务耗材 </span>
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						生产来源:
					</view>
					<view class="shuo-cont-blue">
						<span v-if="item.prodSouc == '1'" type="success"> 国产 </span>
						<span v-if="item.prodSouc == '2'" type="danger"> 进口 </span>
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item-name">
					<view class="shuo-label">
						生产企业:
					</view>
					<view class="shuo-cont">
						{{item.prodEntp}}
					</view>
				</view>
			</view>
		</view>
		<uni-popup ref="popup">
			<uni-popup-dialog type="warn" :before-close="true" cancelText="取消" confirmText="确定" content="你确定配送当前订单吗？"
				@confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
		</uni-popup>
		<view class="botm-btn" v-if="listData[0].stas=='B'||listData[0].stas=='C'">
			<button type="default" plain="true" style="width:240rpx;line-height: 70rpx;background: #01A992;color:#fff"
				@click.stop="orderAcept('dev')" v-if="listData[0].stas=='B'">开始配送</button>
			<button type="default" plain="true" style="width:240rpx;line-height: 70rpx;background: #01A992;color:#fff"
				@click.stop="orderAcept('suc')" v-if="listData[0].stas=='C'">配送完成</button>
		</view>
	</view>
</template>
<script>
	import {
		mapState,
		mapMutations,
		mapActions
	} from 'vuex';
	import moment from "moment";
	const paging = {
		current: 1,
		size: 10000
	};
	export default {
		data() {
			return {
				listData: [],
				detailsData: [],
				type: "",
				control: true,
				maxCount: 1,
				compressSize: 3,
				imageSize: 2,
				compressQuality: 0.8,
				compressWidth: 375,
				sourceType: [],
				uploadTask: null,
				media: [], //数据源
				fileID: ""
			}
		},
		computed: {
			...mapState(['acceptDetaData', 'acceptDetail'])
		},
		onShow() {
			let that = this;
			this.$forceUpdate();
			uni.getStorage({
				key: 'deliveredDetail',
				success: function(res) {
					that.listData = [
						res.data
					];
				}
			});
		},
		mounted() {
			this.$nextTick(() => {
				this.getData();
			})
		},
		methods: {
			...mapActions([]),
			...mapMutations(['setMentItemData', 'setRefusaData']),
			chooseFile(data) {
				let fileCName = data[0].file.path.split('/');
				let fileuop = fileCName[fileCName.length - 1];
				this.$http('delivery.uploadFile', {
					fileName: `接收文件.${fileuop.split('.')[1]}`,
					itemcode: 'spd',
					fileContent: data[0].src
				}).then((res) => {
					if (res.success == true) {
						this.fileID = res.data.id;
						data[0].status = 'success'
						data[0].progress = '上传成功'
					}
				})
			},
			// 删除图片
			mediaDelete(val) {
				this.fileID = "";
			},
			getData() {
				this.$http('delivery.getListDetalData', {
					stooutId: this.listData[0].stooutId,
					soucStroomId: this.listData[0].soucStroomId,
				}, '加载中', true).then((res) => {
					if (res.success == true) {
						this.detailsData = res.data.records;
					}
				})
			},
			//确定验收
			dialogConfirm() {
				this.$http('delivery.subMitData', {
					stooutId: this.listData[0].stooutId,
					type: this.type,
					fileId: this.fileID
				}, '加载中', true).then((res) => {
					if (res.success == true) {
						this.$refs.popup.close();
						uni.redirectTo({
							url: '/pages/delivery/index',
							success: function(res) {
								console.log(res, "res")
							}
						});
					}
				})
			},
			//验收按钮触发
			orderAcept(type) {
				if (this.fileID == "" && type == 'suc') {
					uni.showToast({
						title: '请上传接收文件',
						icon: 'none',
					}, );
					return;
				}
				this.$refs.popup.open();
				this.type = type;
			},
			dialogClose() {
				this.$refs.popup.close();
			},
			//日期格式化
			forMatTime(time) {
				return moment(time).format("YYYY-MM-DD");
			},
			//跳转拣货明细详情	 
			itemDetails(item, index) {
				uni.setStorage({
					key: 'pickIngData',
					data: {
						...item,
						stooutId: this.listData[0].stooutId
					}
				});
				uni.navigateTo({
					url: '/pages/pickingview/index',
					success: function(res) {
						console.log(res, "res")
					}
				});
			},
		},
		watch: {

		}

	}
</script>

<style lang="scss" scoped>
	.query-wrap {
		width: 100%;
		height: 100%;
		padding: 20rpx;
		box-sizing: border-box;
		background-color: #F1F1F1;
		overflow-y: scroll;
		overflow-x: hidden;
		position: relative;
		padding-bottom: 200rpx;

		.botm-btn {
			width: 100%;
			height: 120rpx;
			background-color: #fff;
			position: fixed;
			left: 0;
			bottom: 0;
			padding-top: 40rpx;
		}

		.time-view {
			height: 350rpx;
			background-color: #fff;
			padding: 50rpx 50rpx 0 50rpx;
			box-sizing: border-box;

			.btn-view {
				width: 100%;
				height: 100rpx;
				margin-top: 100rpx;
				display: flex;
				justify-content: space-around;
			}
		}
	}

	.upload-file-wrap {
		margin-top: 20rpx;
		width: 100%;
		height: 280rpx;

		.tit-label {
			color: rgba(16, 16, 16, 1);
			font-size: 28rpx;
			text-align: left;
			font-family: PingFangSC-regular;
			font-weight: bold;
		}

		.file-wrap {
			width: 100%;
			height: 217rpx;
			margin-top: 20rpx;
		}
	}

	uni-page-body {
		width: 100%;
		height: 100%;
	}
</style>