<template>
	<div class="content-main">
		<el-row>
			<el-form
				:inline="true"
				:model="formInline"
				class="search-bm-boder"
				ref="formInline"
			>
				<el-form-item label="企业名称:">
					<el-input
						class="inputCompatible"
						clearable
						v-model="formInline.qymc"
						placeholder="请输入"
					></el-input>
				</el-form-item>
				<el-form-item label="备案日期:">
					<el-date-picker
						v-model="formInline.barq"
						style="width: 180px"
						type="date"
						value-format="yyyy-MM-dd"
						placeholder="选择日期"
					></el-date-picker>
				</el-form-item>
				<el-form-item label="所在行政区:" v-show="!authDisable">
					<el-select
						class="inputCompatible"
						clearable
						v-model="formInline.szxzqy"
						placeholder="请选择"
					>
						<el-option
							v-for="item in dicOptions"
							:key="item.dictCode"
							:label="item.dictName"
							:value="item.dictCode"
						></el-option>
					</el-select>
				</el-form-item>

				<el-form-item>
					<div class="search-button">
						<el-button
							type="primary"
							size="small"
							class="iconfont iconchaxun"
							@click="getList"
							>查询
						</el-button>
						<el-button
							type="primary"
							class="iconfont icondaochu11"
							size="small"
							@click="exportSubmit()"
						>
							导出
						</el-button>
						<el-button
							type="primary"
							@click="resetInfo('formInline')"
							size="small"
							class="iconfont iconzhongzhi"
							>重置
						</el-button>
					</div>
				</el-form-item>
			</el-form>
		</el-row>
		<el-row></el-row>
		<el-row class="addBtnBg" v-show="authDisable">
			<el-button
				type="primary"
				class="iconfont iconxinzeng11"
				size="small"
				@click="editSubmit()"
				>新增</el-button
			>
		</el-row>
		<el-row>
			<el-table
				:data="tableData"
				v-loading="listLoading"
				border
				style="width: 100%"
			>
				<el-table-column align="center" label="序号" width="50">
					<template slot-scope="scope">
						<span>{{ scope.$index + 1 }}</span>
					</template>
				</el-table-column>
				<el-table-column
					align="center"
					prop="dictname"
					label="所在行政区域"
					show-overflow-tooltip
				></el-table-column>
				<el-table-column
					align="center"
					prop="qymc"
					label="企业名称"
					show-overflow-tooltip
				></el-table-column>
				<el-table-column
					align="center"
					prop="tyshxydm"
					label="统一社会信用代码"
					width="120"
					show-overflow-tooltip
				></el-table-column>
				<el-table-column
					align="center"
					prop="xxdz"
					label="地址"
					show-overflow-tooltip
				></el-table-column>
				<el-table-column
					align="center"
					prop="lxr"
					label="联系人"
					show-overflow-tooltip
				></el-table-column>
				<el-table-column
					align="center"
					prop="dh"
					label="电话"
					show-overflow-tooltip
				></el-table-column>
				<el-table-column
					align="center"
					prop="barq"
					label="备案日期"
					show-overflow-tooltip
				></el-table-column>
				<el-table-column
					align="center"
					prop="bajg"
					label="备案机关"
					show-overflow-tooltip
				></el-table-column>
				<!-- 1:待提交 2:已提交 -->
				<el-table-column
					align="center"
					prop="sjztname"
					label="状态"
					show-overflow-tooltip
					v-if="authDisable"
				></el-table-column>
				<el-table-column
					align="center"
					label="操作"
					width="120"
					v-if="authDisable"
				>
					<template slot-scope="scope">
						<el-button
							@click="editSubmit(scope.row.id)"
							title="编辑"
							type="primary"
							size="small"
							class="operate_edit_btn iconfont iconxiugai1"
						></el-button>
						<el-button
							@click="deleteSubmit(scope.row.id)"
							title="删除"
							type="primary"
							size="small"
							class="operate_delete_btn iconfont iconshanchu"
						></el-button>
						<el-button
							v-if="scope.row.sjzt === 1"
							@click="toSubmit(scope.row)"
							title="提交"
							type="primary"
							size="small"
							class="operate_edit_btn iconfont icontijiao"
						></el-button>
					</template>
				</el-table-column>
			</el-table>
		</el-row>
		<el-row>
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				:current-page.sync="pageForm.pageNum"
				:page-sizes="[10, 20, 30, 40]"
				:page-size="pageForm.pageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="pageForm.total"
			></el-pagination>
		</el-row>
		<editDialog
			v-if="addData.dialogEditVisible"
			:addData="addData"
			@getList="getList"
		/>
	</div>
</template>


<script>
import {
	getPageList,
	findByPDictCode,
	editData,
	removeData,
	exportByObject,
} from '@/api/grainCoManage/acquisitionQualification/index'
import editDialog from './editDialog'

export default {
	components: {
		editDialog,
	},
	data() {
		return {
			addData: {
				// 编辑
				dialogEditVisible: false,
				id: null,
				// 所在行政区(字典)
				dicOptions: [],
			},
			formInline: { qymc: '', barq: '', szxzqy: '', sjzt: '' },
			// 所在行政区
			dicOptions: [],
			listLoading: false,
			tableData: [],
			pageForm: {
				pageNum: 1,
				pageSize: 10,
				total: 0,
			},
			// 默认查看权限
			authDisable: false,
		}
	},
	created() {
		// console.log("deptId-->", sessionStorage.getItem('deptId'));
		let deptId = sessionStorage.getItem('deptId')
		let orgCode = sessionStorage.getItem('orgCode')
		// 组织数据权限参数
		this.formInline.cjdw = orgCode
		// 区级提交,市级查看(depotcode是DP001015查看)综合调控处
		if (deptId !== 'DP001015') {
			// 操作权限
			this.authDisable = true
		}
		// 市局领导权限
		if (orgCode === 'LS001') {
			// 查看权限
			this.authDisable = false
			// 查询状态条件
			this.formInline.sjzt = 2
		}
		this.getDic()
		this.getList()
	},
	methods: {
		// 获取字典所在行政区
		getDic() {
			findByPDictCode('120000').then((res) => {
				if (res.infoCode === 200) {
					this.dicOptions = res.data
					this.addData.dicOptions = res.data
				}
			})
		},
		//重置
		resetInfo() {
			this.pageForm.pageNum = 1
			this.pageForm.pageSize = 10
			this.formInline.qymc = null
			this.formInline.barq = null
			this.formInline.szxzqy = null
			this.getList()
		},
		//获取列表
		getList() {
			// console.log("条件:", this.formInline);
			getPageList(this.pageForm, this.formInline).then((res) => {
				this.tableData = res.list
				this.$set(this.pageForm, 'total', Number(res.total))
			})
		},
		//导出
		exportSubmit() {
			console.log(this.formInline, 'this.formInline')
			exportByObject(this.formInline)
				.then((res) => {
					let blob = new Blob([res], {
						type: 'application/vnd.ms-excel;charset=utf-8',
					})
					if (!!window.ActiveXObject || 'ActiveXObject' in window) {
						window.navigator.msSaveOrOpenBlob(
							blob,
							'收购企业备案.xls'
						)
					} else {
						const link = document.createElement('a')
						link.style.display = 'none'
						link.href = URL.createObjectURL(blob)
						link.setAttribute('download', '收购企业备案.xls')
						document.body.appendChild(link)
						link.click()
						document.body.removeChild(link)
					}
				})
				.catch((err) => {
					this.$message.error(err)
				})
		},
		// 删除
		deleteSubmit(id) {
			this.$confirm('此操作将永久删除数据,是否继续?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning',
			}).then(() => {
				removeData(id)
					.then((res) => {
						if (res.status === 'success') {
							this.$message.success('删除成功')
							this.getList()
						} else {
							this.$message.success(res.msg)
						}
					})
					.catch((err) => {
						this.$message.error('删除失败')
					})
			})
		},
		// 提交
		toSubmit(data) {
			// 已提交
			data.sjzt = 2
			editData(data)
				.then((res) => {
					this.$message.success('提交成功')
					this.getList()
				})
				.catch((err) => {
					this.$message.error('操作失败')
				})
		},
		//编辑
		editSubmit(id) {
			this.addData.dialogEditVisible = true
			if (id === undefined) this.addData.id = ''
			else this.addData.id = id
		},
		// 分页函数
		handleSizeChange(val) {
			this.pageForm.pageSize = val
			this.getList()
		},
		handleCurrentChange(val) {
			this.pageForm.pageNum = val
			this.getList()
		},
	},
}
</script>
<style scoped>
.daoru {
	margin: 0 10px;
}

.daoru /deep/ .el-upload-list {
	display: none;
}
</style>
