<template>
	<view class="query-wrap">
		<view class="inner-item">
			<view class="item-stats">
				{{acceptDetaData.stas=='C'?'已验收':"待验收"}}
			</view>
			<view class="inventory-item" v-if="acceptDetaData.stas=='C'">
				<view class="shuo-item-name">
					<view class="shuo-label">
						验收单号:
					</view>
					<view class="shuo-unit">
						{{acceptDetaData.id}}
					</view>
				</view>
			</view>
			<view class="inventory-item" v-if="acceptDetaData.stas=='C'">
				<view class="shuo-item-name">
					<view class="shuo-label">
						本次验收量:
					</view>
					<view class="shuo-unit">
						{{acceptDetaData.mcsCnt}}
					</view>
				</view>
			</view>
			<view class="inventory-item" v-if="acceptDetaData.stas=='B'">
				<view class="shuo-item-name">
					<view class="shuo-label">
						配送单号:
					</view>
					<view class="shuo-unit">
						{{acceptDetaData.stooutId}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						配送品种数:
					</view>
					<view class="shuo-cont">
						{{acceptDetaData.stoCnt}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						配送总数量:
					</view>
					<view class="shuo-cont">
						{{acceptDetaData.devCnt}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						采购品种数:
					</view>
					<view class="shuo-cont">
						{{acceptDetaData.catCnt}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						采购总数量:
					</view>
					<view class="shuo-cont">
						{{acceptDetaData.sumCnt}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item-name">
					<view class="shuo-label">
						未配送数量:
					</view>
					<view class="shuo-cont">
						{{acceptDetaData.lstCnt}}
					</view>
				</view>
			</view>
			<view class="inventory-item" v-if="acceptDetaData.stas=='C'">
				<view class="shuo-item-name">
					<view class="shuo-label">
						配送单号:
					</view>
					<view class="shuo-cont">
						{{acceptDetaData.stooutId}}
					</view>
				</view>
			</view>
			<view class="inventory-item" v-if="acceptDetaData.stas=='B'">
				<view class="shuo-item">
					<view class="shuo-label">
						采购员:
					</view>
					<view class="shuo-cont">
						{{acceptDetaData.crteUsrName}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						采购时间:
					</view>
					<view class="shuo-cont" style="font-size: 18rpx;">
						{{ forMatTimehs(acceptDetaData.crteTime) }}
					</view>
				</view>
			</view>
			<view class="inventory-item" v-if="acceptDetaData.stas=='C'">
				<view class="shuo-item">
					<view class="shuo-label">
						验收员:
					</view>
					<view class="shuo-cont">
						{{acceptDetaData.crteUsrName}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						验收时间:
					</view>
					<view class="shuo-cont">
						{{ forMatTime(acceptDetaData.crteTime) }}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						采购类型:
					</view>
					<view class="shuo-cont">
						<span v-if="acceptDetaData.purcType == 'A'">普通采购</span>
						<span v-if="acceptDetaData.purcType == 'B'">手术备货</span>
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						采购订单号:
					</view>
					<view class="shuo-it-ut">
						{{acceptDetaData.soucId}}
					</view>
				</view>
			</view>
		</view>
		<view class="inner-item" v-if="acceptDetaData.purcType=='B'">
			<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">
						{{acceptDetaData.oprnName}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						手术间:
					</view>
					<view class="shuo-cont">
						{{acceptDetaData.oprtRoom}}
					</view>
				</view>
			</view>
			<view class="inventory-item">
				<view class="shuo-item">
					<view class="shuo-label">
						主治医生:
					</view>
					<view class="shuo-cont">
						{{acceptDetaData.atddr}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						手术日期:
					</view>
					<view class="shuo-cont">
						{{forMatTime(acceptDetaData.oprtTime)}}
					</view>
				</view>
			</view>
		</view>
		<view class="inner-item" v-for="(item,idex) in acceptDetail" :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">
					<view class="shuo-label">
						验收数量:
					</view>
					<view class="shuo-label-green">
						{{item.shppCnt}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						拒收数量:
					</view>
					<view class="shuo-label-red">
						{{item.retCnt||0}}
					</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">
					<view class="shuo-label">
						集采批次:
					</view>
					<view class="shuo-cont">
						{{item.fasBtch}}
					</view>
				</view>
				<view class="shuo-item">
					<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">
						{{item.manuDate?forMatTime(item.manuDate):""}}
					</view>
				</view>
				<view class="shuo-item">
					<view class="shuo-label">
						有效日期:
					</view>
					<view class="shuo-cont">
						{{item.prodExpy?forMatTime(item.prodExpy):""}}
					</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="acceptDetaData.stas=='B'">
			<button type="default" plain="true" style="width:200rpx;line-height: 70rpx;background: #01A992;color:#fff"
				@click.stop="orderAcept()">验收</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: [],
				acceptDetaData: {}
			}
		},
		computed: {
			...mapState(['acceptDetail'])
		},
		onShow() {
			let that = this;
			that.$forceUpdate();
			uni.getStorage({
				key: 'accept-storage-details',
				success: function(res) {
					that.acceptDetaData = res.data;
				}
			});
		},
		mounted() {
			this.$nextTick(() => {
				this.touData(this.acceptDetaData);
			})
		},
		methods: {
			...mapActions(['getAwaitDetail', 'getAreadyDetail', 'submitAceptData']),
			...mapMutations(['setMentItemData', 'setRefusaData']),
			async touData(data) {
				if (data && data.stas == "C") {
					await this.getAreadyDetail({
						...paging,
						stoinId: data.id || 0
					})
				} else {
					await this.getAwaitDetail({
						...paging,
						stooutId: data.stooutId || 0
					})
				}
			},
			//确定验收
			async dialogConfirm() {
				await this.submitAceptData({
					stooutId: this.acceptDetaData.stooutId || 0,
					soucId: this.acceptDetaData.soucId || 0,
					mcsStooutDetlDReqDTOS: this.acceptDetail
				}).then((res) => {
					this.$refs.popup.close();
					uni.redirectTo({
						url: '/pages/acceptance/index',
						success: function(res) {

						}
					});
				})
			},
			//验收按钮触发
			orderAcept() {
				this.$refs.popup.open();
			},
			dialogClose() {
				this.$refs.popup.close();
			},
			//日期格式化
			forMatTime(time) {
				return moment(time).format("YYYY-MM-DD");
			},
			//加时分秒
			forMatTimehs(time) {
				return moment(time).format("YYYY-MM-DD HH:mm");
			},
			//跳转耗材清单详情	 
			itemDetails(item, index) {
				this.setRefusaData({
					index: index,
					data: {
						...item,
						purcType: this.acceptDetaData.purcType
					}
				})
				uni.navigateTo({
					url: '/pages/acceptrefusal/index',
					success: function(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;
			}
		}

	}

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