<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 type="order" @filter="filterInit"></list-filter>
				<div class="hui-content-insert">
					<el-button type="primary" size="medium" @click="insert">新增工单</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="code"></el-table-column>
						<el-table-column label="租客" prop="name">
							<template slot-scope="scope">
								{{scope.row.tenantType === 1 ? scope.row.merchantName: scope.row.clientName}}
							</template>
						</el-table-column>
						<el-table-column label="房号" prop="projectItemTargetRoomIds">
							<template slot-scope="scope">
								<div class="hui-ellipsis">
									<span v-for="(item,index) in scope.row.roomMap">
										{{item}}、
									</span>
								</div>
							</template>
						</el-table-column>
						<el-table-column label="开始日" prop="startDate"></el-table-column>
						<el-table-column label="结束日" prop="endDate"></el-table-column>
						<el-table-column label="运营跟进人" prop="operatorName"></el-table-column>
						<el-table-column label="操作" width="150">
							<template slot-scope="scope">
								<div class="hui-table-operation">
									<span class="table-operation" @click="detailItem(scope.row)">
										详情
									</span>
									<span class="table-operation" @click="updateItem(scope.row)">
										编辑
									</span>
									<span class="table-operation" @click="deleteItem(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>
	</div>
</template>

<script>
	import edit from '@/components/work/contract/list/edit'
	import detail from '@/components/work/contract/list/detail'
	import listFilter from '@/components/common/listFilter'

	import {
		getContractListByPage,
		deleteContractById
	} from '@/httpApi/contract'
	export default {
		data() {
			return {
				tableData: [],
				currPage: 1,
				pageSize: 10,
				totalCount: 0,
				detailId: '',
				filterOption: {}
			}
		},
		created() {
			this.init();
		},
		methods: {
			init() {
				let postData = {
					currPage: this.currPage,
					pageSize: this.pageSize,
					organizationId: this.$store.getters.organization.id,
					projectId: this.$store.getters.project.id
				}
				postData = Object.assign(postData, this.filterOption);
			},
			filterInit(option) {
				this.filterOption = option;
				this.currPage = 1;
				this.init();
			},
			insert() {
				this.$message.warning('功能开发中')
			},
			currentChange(currPage) {
				this.currPage = currPage;
				this.init();
			},
			detailItem(item) {
				this.detailId = item.id;
			},
			updateItem(item) {
				this.detailId = item.id;
			},
			deleteItem(item) {
				this.$confirm('确定要删除该合同文件?', () => {
					deleteContractById(item.id).then(res => {
						if (res.state) {
							this.$message({
								type: 'success',
								message: '操作成功'
							})
							this.init();
						}
					})
				});
			},
			callback(type) {
				if (type === 'init') this.init();
				this.type = 'list';
			}
		},
		components: {
			edit,
			detail,
			listFilter
		},
	}
</script>

<style>
</style>