<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-top: 10px;">
			每日回款审核报告
		</view>

		<view style="margin-top: 20px;font-family: sans-serif;font-weight: 600;">石家庄汇融农村合作银行振头支行：</view>

		<view style=" line-height: 30px; margin-top: 10px;text-indent:2em;">
			<text style="font-family: sans-serif;font-weight: 600;">{{info.companyName}}</text>
			<text>昨日销售及今日回款情况如下：昨日销售总计：</text>
			<text style="font-family: sans-serif;font-weight: 600;">{{info.totalSales}}</text>
			<text> 元，今日应回款：</text>
			<text style="font-family: sans-serif;font-weight: 600;">{{info.collection}}</text>
			<text> 元，今日实际回款：</text>
			<text style="font-family: sans-serif;font-weight: 600;">{{info.actualCollection}}</text>
			<text> 元，回款差额：</text>
			<text style="font-family: sans-serif;font-weight: 600;">{{info.difference}}</text>
			<text> 元，未回款原因平台扣除手续费、服务费等。具体原因详见附件今日回款明细。</text>

			<view>
				<text>截至</text>
				<text style="font-family: sans-serif;font-weight: 600;">{{info.endTime}}</text>
				<text>，今日支付完毕款项后，账户余额为：</text>
				<text style="font-family: sans-serif;font-weight: 600;">{{info.balance}}</text>
				<text> 元。</text>
			</view>

		</view>

		<view style="display: flex;flex-direction: column;margin-top: 15px; line-height: 30px;">
			<text style="size: 25px;font-family: sans-serif;font-weight: 600;">审核结果：</text>
			<text style="text-indent:2em;">{{info.auditResult}}</text>
			<!-- <view>
				<text
					style="margin-top: 10px;text-indent:2em;">实际回款资金已按要求回到{{info.companyName}}{{info.account}}（账号为</text>
				<text style="font-family: sans-serif;font-weight: 600;">{{info.accountNumber}}</text>
				<text>）。</text>
			</view> -->

		</view>


		<view style="display: flex;flex-direction: column;width: 100%;align-items: flex-end; margin-top: 30px;">

			<text style="font-family: sans-serif;font-weight: 600;">{{info.reviewedBy}}</text>
			<text style="margin-top:10px ; font-family: sans-serif;font-weight: 600;">{{info.date}}</text>

		</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>
			<uni-table ref="table1" border stripe emptyText="暂无更多数据">
				<uni-tr>
					<uni-th align="center">销售日期</uni-th>
					<uni-th align="center">支付渠道</uni-th>
					<uni-th align="center">金额（元）</uni-th>
					<uni-th align="center">对应公司主体</uni-th>
					<uni-th align="center">回款金额</uni-th>
					<uni-th align="center">回款差额</uni-th>
					<uni-th align="center">备注</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData1" :key="index">
					<uni-td align="center">{{ item.salesDate }}</uni-td>
					<uni-td align="center">{{ item.payChannels }}</uni-td>
					<uni-td align="center">{{ item.money }}</uni-td>
					<uni-td align="center">{{ item.mainBody }}</uni-td>
					<uni-td align="center">{{ item.collection }}</uni-td>
					<uni-td align="center">{{ item.different }}</uni-td>
					<uni-td align="center">{{ item.notes }}</uni-td>
				</uni-tr>

			</uni-table>

		</view>

		<view style="margin-top: 30px; display: flex; flex-direction: column;">
			<text style="size: 25px;font-family: sans-serif;font-weight: 600;padding-bottom: 10px;">附件：昨日销售报表</text>

			<uni-table ref="table2" border stripe emptyText="暂无更多数据">

				<uni-tr>
					<uni-th align="center">支付渠道</uni-th>
					<uni-th align="center">金额（元）</uni-th>
					<uni-th align="center">对应公司主体</uni-th>
					<uni-th align="center">到账周期</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData2" :key="index">
					<uni-td align="center">{{ item.payChannels }}</uni-td>
					<uni-td align="center">{{ item.money }}</uni-td>
					<uni-td align="center">{{ item.mainBody }}</uni-td>
					<uni-td align="center">{{ item.cycle }}</uni-td>
				</uni-tr>

			</uni-table>
		</view>



	</view>

</template>

<script>
	export default {
		data() {
			return {
				queryParams: {
					dataDate: "2023-06-14",
					companyName: "河北源蜂惠民科技集团有限公司"
				},
				loading1: false,
				loading2: false,
				info: {
					companyName: "",
					totalSales: "",
					collection: "",
					actualCollection: "",
					different: "",
					endTime: "",
					balance: "",
					account: "",
					accountNumber: "",
					reviewedBy: "",
					date: "",
				},

				tableData1: [
					// 	{
					// 	"salesDate": "2023年6月7日",
					// 	"payChannels": "批发-京东",
					// 	"money": "397.09",
					// 	"mainBody": "源蜂-汇融",
					// 	"collection": "357.87",
					// 	"different": "39.22",
					// 	"notes": "6.7回小时购150.12"
					// },
				],
				tableData2: [
					// 	{
					// 	"payChannels": "现金",
					// 	"money": "63094.88",
					// 	"mainBody": "-",
					// 	"cycle": "每月19号归集"
					// },
				],

				fileUrl: ""
			};
		},
		onLoad(option) {

			// this.queryParams = {
			// 	dataDate: option.dataDate,
			// 	companyName: option.companyName
			// }

			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.queryParams)
				this.$api.getReportInfo(this.queryParams).then((resp) => {
					console.log('1111>>>>>>', resp)
					this.fileUrl = resp.downloadUrl
					this.info = resp

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

				this.$api.getCsmReportTodayByComSid(this.queryParams).then((resp) => {
					console.log('2222>>>>>>', resp)
					this.loading1 = true
					this.tableData1 = resp

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

				this.$api.getCsmReportYesterdayByComSid(this.queryParams).then((resp) => {
					console.log('3333>>>>>>', resp)
					this.loading2 = true
					this.tableData2 = resp

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

<style>
</style>