<!-- 详情 -->
<template>
	<nav-bar id="nav-bar" ref="navBar" :navbar-data="navbarData"></nav-bar>
	<view :style="{paddingTop: height +'px'}" class="content">
		<view class="doc">
			<view class="doc-intro">
				<view class="doc-intro-left">
					<view>
						<image style="width:100rpx;height:100rpx;border-radius: 50%;" :src="detailObj.admDocImage" />
					</view>
					<view class="desc">
						<view style="margin-bottom:10rpx">
							<text style="font-size:32rpx">{{detailObj.admDocDesc}}</text>
							<text style="margin-left:20rpx;color:#999999">{{detailObj.admLocDesc}}</text>
						</view>
						<view style="color:#999999">就诊时间：{{detailObj.admDateTime}}</view>
					</view>
				</view>
				<view style="color:#999999">{{detailObj.payStatus}}</view>
			</view>
			<view>诊断：{{detailObj.diagDesc}}</view>
		</view>

		<view v-if="detailObj.admTypeDesc==='住院'">
			<view style="border-bottom: 2rpx solid #dddddd;">
				<view class="fee-desc">
					<view class="fee-desc-text">
						<view>
							<view class="num">¥:{{detailObj.totalAmt}}</view>
							<view>当前总费用</view>
						</view>
					</view>
					<view class="fee-desc-text">
						<view>
							<view class="num">¥:{{detailObj.subBalanc==="" ?"0":detailObj.subBalanc}}</view>
							<view class="fee">余额</view>
						</view>
						<view class="btn" @tap="turnPay">缴费</view>
					</view>
				</view>
				<!-- <view class="fee-desc">
					<view class="fee-desc-text">
					  <view>
						<view class="num">¥:{{detailObj.personAmt}}</view>
						<view>自费金额</view>
					  </view>
					</view> 
				</view> -->
			</view>
		</view>

		<view style="border-bottom: 2rpx solid #dddddd;" v-if="detailObj.admTypeDesc!=='住院'">
			<view>
				<view class="fee-desc-text-btw">
					<view>当前总费用</view>
					<view class="num">¥:{{detailObj.ordReasonPatAmt}}</view>
				</view>
				<!-- <view class="fee-desc-text">
			    <view>
			      <view class="num">¥:{{detailObj.personAmt}}</view>
			      <view>自费金额</view>
			    </view>
			  </view> -->
			</view>
			<view class="title">费用清单</view>
			<view>
				<uni-collapse :value="activeNames" @change="onChange">
					<uni-collapse-item title="费用详细" :open="false">
						<view class="drug-list" v-for="(item,index) in detailObj.detail" :key="index">
							<view class="drug-desc">
								<view class="drug-desc-tip">
									<view class="tip"></view>
									<view style="margin-left:20rpx">{{item.medItemDesc}} {{item.spec}} </view>
								</view>
								<view class="left">
									单价:￥{{item.medPrice+" "}}数量:{{item.qty}}{{item.unitDesc+" "}}总金额:￥{{item.medPatPrice}}
								</view>
								<!-- <view class="left">数量：{{item.qty}}</view>
									<view class="left">总金额：￥{{item.medPatPrice}}</view> -->
							</view>
						</view>
					</uni-collapse-item>
				</uni-collapse>
			</view>
		</view>

		<view v-if="detailObj.admTypeDesc==='住院'">
			<van-tabs :tabs="['汇总清单','每日清单']" :value="active" height="88rpx" @change="onChange3"></van-tabs>
			<view style="background-color:#dddddd;height:4rpx"></view>
			<view v-if="active===0">
				<uni-collapse :value="activeNames1" @change="onChange1">
					<uni-collapse-item title="费用详细" :open="true">
						<view class="drug-list" v-for="(item,index) in detailObj.detail" :key="index">
							<view class="drug-desc">
								<view class="drug-desc-tip">
									<view class="tip"></view>
									<view style="margin-left:20rpx">{{item.medItemDesc}} {{item.spec}} </view>
								</view>
								<view class="left">
									单价:￥{{item.medPrice+" "}}数量:{{item.qty}}{{item.unitDesc+" "}}总金额:￥{{item.medPatPrice}}
								</view>
							</view>
						</view>
					</uni-collapse-item>
				</uni-collapse>
			</view>
			<view v-if="active===1">
				<view class="data-choose">
					<view>范围</view>
					<view class="date-range">
						<view class="border" style="margin-left:20rpx">
							<picker mode="date" :value="startDate" :start="minDate" :end="maxDate" @change="onInputStart">
								<text>{{startDate}}</text>
							</picker>
						</view>
						<view class="border">至</view>
						<view class="border">
							<picker mode="date" :value="endDate" :start="minDate" :end="maxDate" @change="onInputEnd">
								<text>{{endDate}}</text>
							</picker>
						</view>
					</view>
					<view class="btn-search" @tap="getInDayList">搜索</view>
				</view>
				<view v-for="(item1,index) in dayList" :key="index">
					<view class="title">{{item1.admDate}} 总金额￥{{item1.allAmt}}</view>
					<uni-collapse :value="activeNames2" @change="onChange2">
						<uni-collapse-item title="费用详细" :open="false">
							<view class="drug-list" v-for="(item,idx) in item1.doctorArr" :key="idx">
								<view class="drug-desc">
									<view class="drug-desc-tip">
										<view class="tip"></view>
										<view style="margin-left:20rpx">{{item.descripts}} {{item.icDesc}} </view>
									</view>
									<view class="left">
										单价:￥{{item.medPrice+" "}}数量:{{item.qty}}{{item.unitDesc+" "}}总金额:￥{{item.medPatPrice}}
									</view>
								</view>
							</view>
						</uni-collapse-item>
					</uni-collapse>
				</view>
			</view>
		</view>

		<!-- <van-popup :show="showStart" @close="onCloseStart" position="bottom">
			<van-datetime-picker type="date" value="{{ startTime }}" min-date="{{ minDateStart }}" max-date="{{ maxDateStart }}" bind:confirm="onInputStart" bind:cancel="onCloseStart" />
		</van-popup> -->

		<!-- <van-popup :show="showEnd" @close="onCloseEnd" position="bottom">
			<van-datetime-picker type="date" value="{{ endTime }}" min-date="{{ minDateEnd }}"
				max-date="{{ maxDateEnd }}" bind:confirm="onInputEnd" bind:cancel="onCloseEnd" />
		</van-popup> -->
	</view>
</template>

<script>
	import $http from "@/utils/https";
	import Util from "@/utils/utils";
	import httpConfig from '@/utils/httpConfig';
	import NavBar from '@/components/navBar/index.vue'
	import VanPopup from '@/components/popup/index.vue'
	// import VanCollapse from '@/components/collapse/index.vue'
	// import VanCollapseItem from '@/components/collapse-item/index.vue'
	import VanTabs from '@/components/tabs/tabs.vue'
	import VanCell from '@/components/cell/index.vue'
	const app = getApp();
	export default {
		components: {
			'nav-bar': NavBar,
			"van-popup": VanPopup,
			// "van-collapse": VanCollapse,
			// "van-collapse-item": VanCollapseItem,
			"van-tabs": VanTabs,
			'van-cell': VanCell,
		},
		data() {
			return {
				height: app.globalData.height,
				windowHost: httpConfig && httpConfig.ipDeault,
				navbarData: {
					isGoHome: true,
					isGoBack: true,
					title: "费用清单"
				},
				active: 0,
				activeNames: [],
				activeNames1: [],
				activeNames2: [],
				minDate: '2020-01-01',
				maxDate: Util.timestampToDateFormat(new Date().getTime(),"YYYY-MM-DD"),
				startDate: Util.timestampToDateFormat(new Date().getTime(),"YYYY-MM-DD"),
				endDate: Util.timestampToDateFormat(new Date().getTime(),"YYYY-MM-DD"),
				detailObj: {},
				dayList: {},
				admID: ""
			}
		},
		onLoad: function(options) {
			const eventChannel = this.getOpenerEventChannel()
			eventChannel.on("detailObj", (data) => {
				this.setData({
					detailObj: data.detailObj,
				}, () => {
					if (this.detailObj && this.detailObj.admTypeCode === "I") {
						this.getInDayList()
					}
				});
			})
			// #ifdef MP-ALIPAY
			 my.setNavigationBar({
				 title: ''
			 }) 
			// #endif
		},
		methods: {
			//打开折叠面板
			onChange(event) {
				this.setData({
					activeNames: event.detail,
				});
			},
			//打开折叠面板
			onChange1(event) {
				this.setData({
					activeNames1: event.detail,
				});
			},
			//打开折叠面板
			onChange2(event) {
				this.setData({
					activeNames2: event.detail,
				});
			},
			onChange3(event) {
				this.setData({
					active: event.detail.name
				})
			},
			onInputStart(event) {
				this.setData({
					startDate: event.detail.value,
					endDate: event.detail.value,
					showStart: false
				})
			},
			onInputEnd(event) {
				this.setData({
					endDate: event.detail.value,
					startDate: event.detail.value,
					showEnd: false,
				})
			},
			turnPay() {
				uni.navigateTo({
					url: '../advancePayment/advancePayment',
				})
			},
			//住院一日清单
			getInDayList: function() {
				let userData = this.$cache.get('userData');
				let {
					startDate,
					endDate
				} = this
				let data = {
					params: [{
						recordPatNum: userData.hisPatNo || '',
						hospCode: userData.hisHospID || '', //医院ID
						hospID: '', //医院ID
						startDate: startDate ? startDate : Util.timestampToDateFormat(new Date().getTime()), //就诊开始日期
						endDate: endDate ? endDate : Util.timestampToDateFormat(new Date().getTime()), //就诊结束日期
					}]
				}
				$http.post("urlS", this, {
					code: "03100203",
					data: data,
					namespace: "Y",
					success: function(res) {
						if (+res.errorCode === 0) {
							for (var i = 0; i < res.result.length; i++) {
								if (res.result[i].admID === this.detailObj.admID) {
									this.setData({
										dayList: res.result[i]
									})
								} else {
									this.setData({
										dayList: {}
									})
								}
							}
						} else {
							this.setData({
								dayList: {}
							})
						}
					}
				});
			}
		}
	}
</script>

<style>
	/* pages/order//pages/feeInquiryDetail/feeInquiryDetail.wxss */
	.content {
		background-color: #FFFFFF;
	}

	.doc-intro {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-bottom: 10rpx;
	}

	.doc-intro-left {
		display: flex;
		align-items: center;
	}

	.doc {
		padding: 30rpx 30rpx 15rpx 30rpx;
	}

	.doc-intro-left .desc {
		padding-left: 20rpx;
	}

	.fee-desc {
		display: flex;
		align-items: center;
		padding: 30rpx 0 0 0;

	}

	.fee-desc-text {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 50%;
		padding: 20rpx 0;
		border-top: 2rpx solid #dddddd;
		border-right: 2rpx solid #dddddd;
	}

	.btn {
		min-width: 100rpx;
		min-height: 56rpx;
		background: #007AFF;
		border-radius: 25rpx;
		border: 2rpx solid #007AFF;
		font-size: 26rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 36rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-left: 30rpx;
	}

	.fee-desc-text .fee {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.num {
		color: #007AFF;
	}

	.title {
		background-color: #eeeeee;
		height: 100rpx;
		font-size: 32rpx;
		display: flex;
		align-items: center;
		padding-left: 30rpx;
	}

	.tip {
		width: 20rpx;
		height: 20rpx;
		background-color: #007AFF;
		border-radius: 50%;
	}

	.drug-desc {
		border-bottom: 1rpx solid #dddddd;
		padding: 20rpx;
	}

	.drug-desc-tip {
		display: flex;
		align-items: center;
	}

	.drug-desc .left {
		margin-left: 36rpx;
	}

	.drug-desc>view {
		padding-bottom: 16rpx;
	}

	.drug-list .drug-desc:last-child {
		border-bottom: 0;
		padding-bottom: 0rpx;
	}

	.drug-list .drug-desc:first-child {
		padding-top: 0rpx;
	}

	.data-choose {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 88rpx;
		padding: 0 30rpx;
		margin-top: 20rpx;
	}
	
	.date-range {
		display: flex;
	}
	
	.border {
		border: 1rpx solid #dddddd;
		padding: 15rpx 25rpx;
		font-size: 24rpx;
	}

	.btn-search {
		border: 2rpx solid #007AFF;
		color: #007AFF;
		padding: 10rpx 15rpx;
		margin-left: 30rpx;
		border-radius: 30rpx;
	}

	.fee-desc-text-btw {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx;
	}
</style>