<template>
	<view class="content">
		<navseat :opacity='false' :title='"开票记录"' :titleshow='true' :iconshow='iconshow' :namecolor='"#fff"'
			iconcolor='#fff'></navseat>
		<view class="content_item" v-for="(item,index) in list" :key="index" @click="clickoange(item)">
			<view class="content_item_top flex-between">
				<view class="content_item_topone flex-start">
					<image src="https://czg-invoicing.oss-cn-beijing.aliyuncs.com/static/sz.png" mode="aspectFill">
					</image>
					<text>{{item.createtime}}</text>
				</view>
				<view class="content_item_toptow flex-start">
					<text class="content_item_toptowtext">¥{{item.price}}</text>
					<u-icon name="arrow-right" color="#9d9d9d" size="10"></u-icon>
				</view>
			</view>
			<view class="content_item_bottom" style="background: #318AFE;" v-if="item.status == 0">
				未提交开票信息
			</view>
			<view class="content_item_bottom" style="background:#8B8B8B;" v-if="item.status == 1 || item.status == 3">
				开票中
			</view>
			<view class="content_item_bottom" v-if="item.status == 2">
				已开票
			</view>
			<view class="content_item_bottom" style="background:#e4b9c0;" v-if="item.status == -1">
				待商家审核
			</view>
			<view class="content_item_bottom" style="background: #ffbb76;" v-if="item.status == 4">
				已作废
			</view>
			<view class="content_item_bottom" style="background: #fdc539;" v-if="item.status == 6">
				商家拒绝
			</view>
		</view>
		<view class="empty-wrap">
			<u-loadmore :status="form.status" fontSize="16" color="#999" iconSize="16" />
		</view>
	</view>
</template>

<script>
	import navseat from '@/components/navseat.vue'
	export default {
		components: {
			navseat
		},
		data() {
			return {
				list: [],
				form: {
					page: 1,
					status: 'loadmore',
				},
				iconshow: true,
				off_openid: '',
				type: '1',
			};
		},
		async onLoad(e) {
			await this.$onLaunched;
			if (e.off_openid) {
				this.off_openid = e.off_openid
				this.iconshow = false
			} else {
				this.iconshow = true
			}
			// 内链跳转进来  返回按钮判断
			try {
				if (e.typeshow == 1) {
					this.iconshow = true
				}
			} catch (e) {
				//TODO handle the exception
			}
			//判断微信扫码进来
			if (this.type == 1) {
				this.initial()
			}
		},
		onShow() {
			if (this.type == 2) {
				this.initial()
			}
		},
		onReachBottom() {
			if (this.form.status != 'nomore') {
				this.form.page = ++this.form.page;
				this.storeinvoicelist()
			}

		},
		methods: {
			initial() {
				this.form = {
						page: 1,
						status: 'loadmore',
					},
					this.storeinvoicelist()
			},
			clickoange(e) {
				if (e.status == -1) {
					return false;
				}
				uni.navigateTo({
					url: e.t_url
				})
			},
			async storeinvoicelist() {
				this.form.status = 'loading';
				this.type = 2
				let res = await this.api.useroauthcallback({
					open_id: uni.cache.get('open_id'),
					page: this.form.page,
					off_openid: this.off_openid

				})
				if (this.form.page == 1 && res.data.invo.length == 0) {
					this.form.status = 'nomore'
					this.list = []
					return false;
				} else {

					setTimeout(() => {
						if (this.form.page == 1) {
							this.list = res.data.invo
						} else {
							this.list = [...this.list, ...res.data.invo];
						}
						if (res.data.invo.length < 10) {
							this.form.status = 'nomore';
						} else {
							this.form.status = 'loadmore';
						}
					}, 500)
				}
				console.log(this.list)
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #F9F9F9;
	}

	.content {
		padding: 6px 28rpx;

		.content_item {
			margin-top: 32rpx;
			width: 100%;
			background: #FFFFFF;
			border-radius: 30rpx 30rpx 30rpx 30rpx;

			.content_item_top {
				padding: 34rpx 16rpx 30rpx 42rpx;

				.content_item_topone {
					image {
						width: 37.11rpx;
						height: 37.11rpx;
					}

					text {
						margin-left: 28rpx;
						font-family: Source Han Sans CN, Source Han Sans CN;
						font-weight: 400;
						font-size: 28rpx;
						color: #666666;
						text-align: center;
						font-style: normal;
						text-transform: none;
					}
				}

				.content_item_toptow {
					.content_item_toptowtext {
						font-family: Source Han Sans CN, Source Han Sans CN;
						font-weight: 500;
						font-size: 32rpx;
						color: #666666;
						text-align: center;
						font-style: normal;
						text-transform: none;
					}
				}
			}

			.content_item_bottom {
				padding: 16rpx 0 16rpx 108rpx;
				background: rgba(85, 159, 255, 0.74);
				box-shadow: 0px 3rpx 6rpx 1px rgba(0, 0, 0, 0.16);
				border-radius: 0rpx 0rpx 30rpx 30rpx;
				font-family: Source Han Sans CN, Source Han Sans CN;
				font-weight: 500;
				font-size: 32rpx;
				color: #FFFFFF;
				font-style: normal;
				text-transform: none;
			}
		}
	}
</style>