<template>
	<view class="invoice-detail" v-if="detail.id">
		<view class="detail">
			<view class="detail-box">
				<view class="title-box">
					<view class="title">{{detail.name}}</view>
					<view class="date">{{$field.findTypeName('invoiceType',detail.type)}}</view>
					<view class="title-icon">
						<uni-icons type="icon-hetongwendang" custom-prefix="iconfont" color="#fff" size="18">
						</uni-icons>
					</view>
				</view>
				<view class="other">
					<view class="item">
						<view class="label">发票代码</view>
						<view class="value">{{detail.code || '-'}}</view>
					</view>
					<view class="item">
						<view class="label">发票号码</view>
						<view class="value">{{detail.number || '-'}}</view>
					</view>
					<view class="item">
						<view class="label">货物名称</view>
						<view class="value">{{detail.cargoName || '-'}}</view>
					</view>
				</view>
				<view class="state">
					<view></view>
					<view class="tag">
						<div class="status-tag success" v-if="!detail.status">正常</div>
						<div class="status-tag error" v-else-if="detail.status === 1">作废</div>
					</view>
				</view>
			</view>
			<view class="detail-box file-box" v-if="detail.attachment && detail.attachment !='[]'">
				<view class="sub-title">
					<uni-icons type="images-filled" class="inherit-icons" size="26" color="#08979c"></uni-icons>
					<text class="sub-label">发票附件</text>
				</view>
				<view class="other">
					<upload ref="upload" accept="all" :list="detail.attachment ? JSON.parse(detail.attachment) : []" type="preview">
					</upload>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getInvoiceDetailById
	} from '@/request/api/invouce.js'
	import upload from '@/components/common/upload.vue'
	export default {
		data() {
			return {
				invoiceId: '',
				type: '',
				detail: {}
			}
		},
		onLoad(body) {
			this.invoiceId = body.invoiceId;
			this.type = body.type;
			this.init();
		},
		methods: {
			init() {
				if (!this.invoiceId) return;
				getInvoiceDetailById(this.invoiceId).then(this.invoiceSuccess);
			},
			invoiceSuccess(res) {
				if (res.code === 200) {
					this.detail = res.data;
				}
			}
		},
		components: {
			upload
		}
	}
</script>

<style>

</style>