<template>
	<view>
		<view v-if="!invoiced_list[0].id" class="no_content">
			<image class="img" src="/static/images/ui/none.png" />
			<view class="warn">没有查询到您的开票历史</view>
		</view>
		<view v-else class="_container" v-for="(item, index) in invoiced_list" :key="index">
			<view class="invoice_info">
				<view class="_left">
					<view class="_t">开票时间：{{ item.add_time }}</view>
					<view class="_b">{{ item.invoice_type }}</view>
				</view>
				<view class="_right">¥{{ item.total_price }}</view>
			</view>

			<view class="invoice_status" @tap="get_download" data-url="item.invoice_url" v-if="item.invoice_url">立即下载
			</view>
			<view v-else class="invoice_status">{{item.invoice_status}}</view>
		</view>
	</view>
</template>

<script>
	// pages/user/invoice/invoice_history/invoice_history.js
	import {
		http
	} from '../../../../utils/util';
	export default {
		data() {
			return {
				invoiced_list: {
					id: ''
				}
			};
		}
		/**
		 * 生命周期函数--监听页面加载
		 */
		,
		onLoad: function(options) {
			http('/api/v1/invoiced-list', 'post').then((res) => {
				this.setData({
					invoiced_list: res
				});
			});
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		methods: {
			get_download(e) {
				// console.log(e);
				uni.showLoading({
					title: '正在加载',
					mask: true
				});
				let url = e.currentTarget.dataset.url;
				uni.downloadFile({
					url,
					header: {
						'content-type': 'application/json'
					},
					success: function(res) {
						let filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							fileType: 'pdf',
							showMenu: true,
							success: function(res) {
								console.log('打开文档成功');
							}
						});
					}
				});
				setTimeout(() => {
					uni.hideLoading();
				}, 1000);
			}
		}
	};
</script>
<style>
	._container {
		margin: 20rpx;
		background-color: #fff;
		padding: 10rpx;
		border-radius: 10rpx;
	}

	.invoice_info {
		border-bottom: 1rpx dashed #dddddd;
		display: flex;
		align-items: center;
		margin: 0 20rpx;
		padding: 20rpx 0;
		justify-content: space-between;
	}

	._t {
		margin-bottom: 10rpx;
		font-size: 28rpx;
		color: #181818;
	}

	._b {
		width: 100rpx;
		height: 32rpx;
		line-height: 32rpx;
		background: #e2f3ff;
		border-radius: 6rpx;
		border: 2rpx solid #22c0ff;
		font-size: 22rpx;
		color: #22c0ff;
		text-align: center;
	}

	.invoice_status {
		padding: 20rpx;
		font-size: 26rpx;
		color: #22C0FF;
	}

	._right {
		font-size: 40rpx;
		color: #181818;
	}
</style>
