<template>
	<div class="hui-flex hui-content">
		<div class="hui-flex">
			<div class="hui-content-title">
				<div class="hui-title-item active">收款发票列表</div>
			</div>
			<div class="hui-flex-box hui-flex hui-table">
				<list-filter ref="invoice" type="invoice" @filter="filterInit"></list-filter>
				<!-- <div class="hui-content-insert">
					<el-button type="primary" size="medium" @click="insertItem">开具发票</el-button>
				</div> -->
				<div class="hui-flex-box">
					<el-table :data="tableData" row-key="id" border height="100%">
						<el-table-column label="序号" width="50">
							<template slot-scope="scope">
								<div style="text-align: center;">{{scope.$index + 1}}</div>
							</template>
						</el-table-column>
						<el-table-column label="发票名称" prop="name"></el-table-column>
						<el-table-column label="发票类型" prop="code" width="200">
							<template slot-scope="scope">
								<span>{{$field.findTypeName('invoiceType',scope.row.type)}}</span>
							</template>
						</el-table-column>
						<el-table-column label="发票代码" prop="code"></el-table-column>
						<el-table-column label="发票号码" prop="number"></el-table-column>
						<el-table-column label="货物名称" prop="cargoName"></el-table-column>
						<el-table-column label="状态" width="80">
							<template slot-scope="scope">
								<div class="hui-table-tag">
									<div class="hui-tag hui-tag-success" v-if="!scope.row.status">正常</div>
									<div class="hui-tag hui-tag-warning" v-else-if="scope.row.status === 1">作废</div>
								</div>
							</template>
						</el-table-column>
						<el-table-column label="操作" width="80">
							<template slot-scope="scope">
								<div class="hui-table-operation">
									<span class="table-operation" @click="detailItem(scope.row)">
										详情
									</span>
								</div>
							</template>
						</el-table-column>
						<template slot="empty">
							<empty description="暂无数据"></empty>
						</template>
					</el-table>
				</div>
				<div class="hui-content-pagination">
					<el-pagination :page-size="pageSize" :pager-count="9" layout="prev, pager, next" :total="totalCount"
						@current-change="currentChange">
					</el-pagination>
				</div>
			</div>
		</div>
		<el-dialog :close-on-click-modal="false" :title="isUpdate?'编辑':'新增'" :visible.sync="visible" width="900px"
			:append-to-body="true">
			<edit v-if="visible" @callback="callback" :isUpdate="isUpdate" :detailId="detailId"></edit>
		</el-dialog>
		<el-drawer title="发票详情" :visible.sync="drawer" :size="400" :append-to-body="true">
			<detail v-if="drawer" :detailId="detailId" @reload="init"></detail>
		</el-drawer>
	</div>
</template>

<script>
	import detail from '@/components/work/invoice/detail'
	import edit from '@/components/work/invoice/edit'
	import listFilter from '@/components/common/listFilter'
	import {
		getInvoiceListByPage
	} from '@/httpApi/invoice'
	export default {
		data() {
			return {
				tableData: [],
				currPage: 1,
				pageSize: 10,
				totalCount: 0,
				detailId: '',
				isUpdate: false,
				filterOption: {},
				drawer: false,
				visible: false
			}
		},
		created() {
			this.init();
		},
		methods: {
			init() {
				let postData = {
					currPage: this.currPage,
					pageSize: this.pageSize,
					projectId: this.$store.getters.project.id,
					organizationId: this.$store.getters.organization.id,
					type: 2
				}
				postData = Object.assign(postData, this.filterOption);
				getInvoiceListByPage(postData).then(res => {
					if (res.state) {
						this.tableData = res.data.dataList;
						this.totalCount = res.data.totalCount;
					}
				})
			},
			filterInit(option) {
				this.filterOption = option;
				this.currPage = 1;
				this.init();
			},
			currentChange(currPage) {
				this.currPage = currPage;
				this.init();
			},
			insertItem() {
				this.isUpdate = false;
				this.visible = true;
			},
			updateItem(item) {
				this.detailId = item.id;
				this.isUpdate = true;
				this.visible = true;
			},
			detailItem(item) {
				this.detailId = item.id;
				this.drawer = true;
			},
			callback(type) {
				if (type === 'init') this.init();
				this.visible = false;
			}
		},
		components: {
			detail,
			listFilter,
			edit
		},
	}
</script>

<style>
</style>