<template>

	<view style="margin-left: 20px; margin-right: 20px;padding-bottom: 50px">

		<view style="display: flex;width: 100%;">
			<view style="flex: 1;"></view>
			<text style="size: 25px;font-family: sans-serif;font-weight: 600;color: white;
					margin-top: 10px;margin-right: 5px;border: none; padding: 5px 15px;
		border-radius: 5px 5px;
		background: #0498FD;" @click="download">
				下载
			</text>
		</view>


		<view
			style="display: flex; width: 100%;justify-content: center; size: 25px;font-family: sans-serif;font-weight: 600;margin: 10px;">
			{{date}}
		</view>

		<view style="margin-top: 20px; display: flex; flex-direction: column;">
			<text style="size: 25px;font-family: sans-serif;font-weight: 600;padding-bottom: 10px;">库存日报汇总表</text>
			<text>编号:{{logInfo.serialNumber}}</text>
			<text>上报时间:{{logInfo.reportTime}}</text>
			<text style="margin-bottom: 10px;">货值合计:{{logInfo.countAmount}}</text>

			<uni-table ref="table1" border stripe emptyText="暂无更多数据">
				<uni-tr>
					<!-- <uni-th align="center">序号</uni-th> -->
					<uni-th align="center" width="180">仓库类型</uni-th>
					<uni-th align="center" width="80">仓库数量</uni-th>
					<uni-th align="center" width="80">品种数量</uni-th>
					<uni-th align="center" width="100">品种货值</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData1" :key="index">
					<!-- <uni-td align="center">{{ index+1}}</uni-td> -->
					<uni-td align="center">{{ item.storeType }}</uni-td>
					<uni-td align="center">{{ item.storeNumber }}</uni-td>
					<uni-td align="center">{{ item.productCountNumber }}</uni-td>
					<uni-td align="center">{{ item.productAmount }}</uni-td>
				</uni-tr>

			</uni-table>

		</view>

		<view style="margin-top: 50px; display: flex; flex-direction: column;">
			<text style="size: 25px;font-family: sans-serif;font-weight: 600;padding-bottom: 10px;">仓库库存明细表</text>
			<text>商品数量合计:{{logInfo2.countProductNumber}}</text>
			<text style="margin-bottom: 10px;">商品货值合计:{{logInfo2.countAmount}}</text>
			<uni-table ref="table1" border stripe emptyText="暂无更多数据">
				<uni-tr>
					<!-- <uni-th align="center" width="50">序号</uni-th> -->
					<uni-th align="center" width="180">仓库名称</uni-th>
					<uni-th align="center" width="80">商品数量</uni-th>
					<uni-th align="center" width="100">商品货值</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData2" :key="index">
					<!-- <uni-td align="center">{{ index+1 }}</uni-td> -->
					<uni-td align="center">{{ item.storeCodeName }}</uni-td>
					<uni-td align="center">{{ item.productCountNumber }}</uni-td>
					<uni-td align="center">{{ item.productAmount }}</uni-td>
				</uni-tr>

			</uni-table>

		</view>

		<view style="margin-top: 50px; display: flex; flex-direction: column;">
			<text style="size: 25px;font-family: sans-serif;font-weight: 600;padding-bottom: 10px;">烟草库存明细表</text>
			<text>商品数量合计:{{logInfo3.countProductNumber}}</text>
			<text style="margin-bottom: 10px;">商品货值合计:{{logInfo3.countAmount}}</text>
			<uni-table ref="table1" border stripe emptyText="暂无更多数据">
				<uni-tr>
					<!-- <uni-th align="center">序号</uni-th> -->
					<uni-th align="center" width="180">仓库名称</uni-th>
					<uni-th align="center" width="80">品种数量</uni-th>
					<uni-th align="center" width="100">品种货值</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData3" :key="index">
					<!-- <uni-td align="center">{{ index+1 }}</uni-td> -->
					<uni-td align="center">{{ item.storeCodeName }}</uni-td>
					<uni-td align="center">{{ item.productCountNumber }}</uni-td>
					<uni-td align="center">{{ item.productAmount }}</uni-td>
				</uni-tr>

			</uni-table>

		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				date: "2023-07-26",
				logInfo: {
					serialNumber: "",
					reportTime: "",
					countAmount: "",
				},
				logInfo2: {
					countProductNumber: "",
					countAmount: "",
				},
				logInfo3: {
					countProductNumber: "",
					countAmount: "",
				},
				tableData1: [],
				tableData2: [],
				tableData3: [],
				tempFilePath: "",
				// fileUrl:"https://desk-fd.zol-img.com.cn/t_s960x600c5/g5/M00/01/0F/ChMkJlbKwtmINC3iAAx4ozyK5jAAALGuAMGw3cADHi7853.jpg"
				fileUrl: ""
			};
		},
		onLoad(option) {

			// this.date = option.orderDate

			// console.log('1111', this.queryParams)
			this.getData()



		},
		onShow() {
			wx.hideHomeButton()
		},
		methods: {
			download() {
				if (this.fileUrl == '') {
					uni.showToast({
						title: "下载地址错误，请重新进入页面。",
						duration: 5000
					})
					return
				}


				uni.downloadFile({
					url: this.fileUrl, // 网络文档地址
					success: (data) => {
						if (data.statusCode === 200) {
							uni.saveFile({
								tempFilePath: data.tempFilePath, //临时路径
								success: function(res) {
									// 保存路径
									uni.showToast({
										title: "文件已保存：" + res.savedFilePath,
										duration: 5000
									})
									setTimeout(() => {
										//打开文档查看
										uni.openDocument({
											filePath: res.savedFilePath,
											showMenu: true, //右上角是否有可以转发分享的功能
											success: function(res) {
												console.log('打开文档成功')
											}
										})
									}, 3000);
								}
							});
						}
					},
					fail: (err) => {
						uni.showToast({
							title: '失败请重新下载'
						});
					},
				});


			},
			getData() {
				console.log('getData', this.date)
				this.$api.getReportInventoryDayGather(this.date).then((resp) => {
					console.log('1111>>>>>>', resp)
					this.fileUrl = resp.downloadUrl
					this.tableData1 = resp.list
					this.logInfo = {
						serialNumber: resp.serialNumber,
						reportTime: resp.reportTime,
						countAmount: resp.countAmount,
					}

				}).catch(e => {
					console.log('eeeee', e)
				})

				this.$api.getReportInventoryDayStore(this.date).then((resp) => {
					console.log('2222>>>>>>', resp)
					this.tableData2 = resp.list
					this.logInfo2 = {
						countProductNumber: resp.countProductNumber,
						countAmount: resp.countAmount,
					}
				}).catch(e => {
					console.log('eeeee', e)
				})

				this.$api.getReportInventoryDayToStore(this.date).then((resp) => {
					console.log('3333>>>>>>', resp)
					this.tableData3 = resp.list
					this.logInfo3 = {
						countProductNumber: resp.countProductNumber,
						countAmount: resp.countAmount,
					}
				}).catch(e => {
					console.log('eeeee', e)
				})
			},
		}
	}
</script>

<style lang="scss">
	.title {
		width: 100%;
		height: 100rpx;
		background: white;
		display: flex;
		align-items: center;
		justify-content: space-around;
	}

	.titleSel {
		color: #5f6fee;
		font-size: 32rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}


	.headerLineSel {
		background: #5f6fee;
		height: 6rpx;
		width: 220rpx;
		margin-top: 10rpx;
	}

	.headerLineUnsel {
		background: #fff;
		height: 6rpx;
		width: 40rpx;
		position: relative;
		margin-top: 10rpx;
	}

	.swiper {
		width: 100%;
		flex: 1;
		height: 100vh;
		overflow: scroll;
	}

	.recordItem {
		margin-top: 10rpx;
		background-color: white;
		padding-bottom: 20rpx;
		padding-top: 20rpx;
	}
</style>