<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-input
						class="inputCompatible"
						clearable
						v-model="formInline.tyshxydm"
						placeholder="请输入"
					></el-input>
				</el-form-item>
				<el-form-item label="收购资格：">
					<el-select
						class="inputCompatible"
						clearable
						v-model="formInline.sfjysgzg"
						placeholder="全部"
					>
						<el-option
							v-for="item in sgzgOptions"
							:key="item.value"
							:label="item.label"
							:value="item.value"
						></el-option>
					</el-select>
				</el-form-item>

				<el-form-item>
					<div class="search-button">
						<span class="search-line"></span>
						<div
							class="search-select"
							@click="searchShowMoreBool = !searchShowMoreBool"
						>
							更多条件
							<i
								class="el-icon-arrow-up"
								v-show="searchShowMoreBool"
							></i
							><i
								class="el-icon-arrow-down"
								v-show="!searchShowMoreBool"
							></i>
						</div>
						<el-button
							type="primary"
							size="small"
							class="iconfont iconchaxun"
							@click="doSearch"
							>查询</el-button
						>
						<el-button
							type="primary"
							@click="resetInfo('formInline')"
							size="small"
							class="iconfont iconzhongzhi"
						>
							重置</el-button
						>
					</div>
				</el-form-item>
				<el-row v-show="searchShowMoreBool">
					<el-form-item label="所属粮食行政管理部门：">
						<el-select
							class="inputCompatible"
							clearable
							v-model="formInline.sslsxzglbm"
							placeholder="请选择"
						>
							<el-option
								v-for="item in glbmOptions"
								:key="item.value"
								:label="item.value"
								:value="item.code"
							></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="状态：">
						<el-select
							class="inputCompatible"
							clearable
							v-model="formInline.qyzt"
							placeholder="全部"
						>
							<el-option
								v-for="item in options"
								:key="item.value"
								:label="item.label"
								:value="item.value"
							></el-option>
						</el-select>
					</el-form-item>
				</el-row>
			</el-form>
		</el-row>
		<el-row></el-row>
		<el-row class="addBtnBg">
			<el-button
				type="primary"
				class="iconfont iconxinzeng11"
				size="small"
				@click="addSubmit()"
				>新增</el-button
			>
			<el-button
				type="primary"
				class="iconfont icondaochu11"
				size="small"
				@click="exportSubmit()"
				>导出</el-button
			>
			<el-upload
				style="display: inline-block"
				:action="actionUrl"
				:headers="uploadHeader"
				class="daoru"
				:on-success="handleSuccess"
				:on-change="changeFj"
				accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel"
			>
				<el-button
					type="primary"
					class="iconfont icondaoru1"
					size="small"
					>导入</el-button
				>
			</el-upload>
		</el-row>
		<el-row>
			<el-table
				:data="tableData"
				stripe
				v-loading="listLoading"
				border
				fit
				highlight-current-row
				style="width: 100%"
				@selection-change="handleSelectionChange"
			>
				<el-table-column
					align="center"
					type="selection"
					width="50"
					disabled="true"
				></el-table-column>
				<el-table-column align="center" label="序号" width="70">
					<template slot-scope="scope">
						<span>{{ scope.$index + 1 }}</span>
					</template>
				</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="统一社会信用代码"
					min-width="130"
					show-overflow-tooltip
				>
				</el-table-column>
				<el-table-column
					align="center"
					prop="fddbr"
					label="法定代表人"
					show-overflow-tooltip
				>
				</el-table-column>
				<el-table-column
					align="center"
					prop="qylxr"
					label="联系人"
					show-overflow-tooltip
				>
				</el-table-column>
				<el-table-column
					align="center"
					prop="bgdh"
					label="联系电话"
					show-overflow-tooltip
				>
				</el-table-column>
				<el-table-column
					align="center"
					label="所属粮食行政管理部门"
					min-width="130"
					show-overflow-tooltip
				>
					<template slot-scope="scope"
						>{{ getGlbm(scope.row.sslsxzglbm) }}
					</template>
				</el-table-column>
				<el-table-column align="center" prop="qyzt" label="状态">
					<!--                    <template slot-scope="scope">-->
					<!--                        <span v-if="scope.row.sfba == '1'">正常</span>-->
					<!--                        <span v-if="scope.row.sfba == '2'">注销</span>-->
					<!--                    </template>-->
				</el-table-column>
				<el-table-column align="center" label="操作" width="130">
					<template slot-scope="scope">
						<el-button
							@click="detailSubmit(scope.row.tyshxydm)"
							title="查看"
							type="primary"
							size="small"
							class="operate_show_btn iconfont iconchakan2"
						></el-button>
						<el-button
							@click="editSubmit(scope.row.tyshxydm)"
							title="编辑"
							type="primary"
							size="small"
							v-if="scope.row.dataSourceType === 2"
							class="operate_edit_btn iconfont iconxiugai1"
						></el-button>
						<!-- v-if="orgCode == scope.row.sslsxzglbm" -->
						<el-button
							@click="auditSubmit(scope.row.tyshxydm)"
							title="审核"
							type="primary"
							size="small"
							v-if="
								orgCode == scope.row.sslsxzglbm &&
								scope.row.qybgsqVO &&
								scope.row.qybgsqVO.sfty !== '0' &&
								scope.row.qybgsqVO.sfty !== '1'
							"
							class="operate_edit_btn iconfont iconshenhe"
						></el-button>
					</template>
				</el-table-column>
			</el-table>
			<div style="height: 0px; overflow: hidden">
				<el-table
					id="outTablexm"
					:data="tabDataAll"
					border
					stripe
					highlight-current-row
					background
					class="tab-scoll"
				>
					<el-table-column
						align="center"
						type="selection"
						width="50"
						disabled="true"
					></el-table-column>
					<el-table-column align="center" label="序号" width="70">
						<template slot-scope="scope">
							<span>{{ scope.$index + 1 }}</span>
						</template>
					</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="统一社会信用代码"
						min-width="130"
						show-overflow-tooltip
					>
					</el-table-column>
					<el-table-column
						align="center"
						prop="fddbr"
						label="法定代表人"
						show-overflow-tooltip
					>
					</el-table-column>
					<el-table-column
						align="center"
						prop="qylxr"
						label="联系人"
						show-overflow-tooltip
					>
					</el-table-column>
					<el-table-column
						align="center"
						prop="bgdh"
						label="联系电话"
						show-overflow-tooltip
					>
					</el-table-column>
					<el-table-column
						align="center"
						label="所属粮食行政管理部门"
						min-width="130"
						show-overflow-tooltip
					>
						<template slot-scope="scope"
							>{{ getGlbm(scope.row.sslsxzglbm) }}
						</template>
					</el-table-column>
					<el-table-column align="center" prop="qyzt" label="状态">
					</el-table-column>
				</el-table>
			</div>
		</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>

		<el-dialog
			title="新增企业"
			:visible.sync="addDialogVisible"
			width="600px"
		>
			<el-form
				label-width="200px"
				ref="addDialogData"
				:model="addDialogData"
				:rules="addDialogRules"
			>
				<el-row :gutter="10">
					<el-col :span="24">
						<el-form-item label="企业名称：" prop="qymc">
							<el-input
								v-model="addDialogData.qymc"
								clearable
							></el-input>
							<!-- <el-autocomplete
								v-model="addDialogData.qymc"
								style="width: 360px"
								:label="addDialogData.qymc"
								@select="changeQy"
								:fetch-suggestions="querySearch"
								placeholder="企业名称"
								:trigger-on-focus="false"
								clearable
							></el-autocomplete> -->
						</el-form-item>
					</el-col>
				</el-row>
				<el-row :gutter="10">
					<el-col :span="24">
						<el-form-item
							label="企业统一社会信用代码："
							prop="tyshxydm"
						>
							<el-input
								v-model="addDialogData.tyshxydm"
								clearable
							></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<div style="margin-top: 10px; text-align: center">
					<el-button
						type="primary"
						class="iconfont icontijiao"
						size="small"
						@click="addDialogSubmit('addDialogData', 1)"
					>
						提交</el-button
					>
					<el-button
						type="primary"
						class="iconfont iconquxiao"
						size="small"
						@click="addDialogSubmit('addDialogData', 0)"
					>
						取消</el-button
					>
				</div>
			</el-form>
		</el-dialog>
		<el-dialog title="系统提示" :visible.sync="xgssqyVisible" width="600px">
			<el-form
				label-width="100px"
				ref="ssqyData"
				:model="ssqyData"
				:rules="ssqyRules"
			>
				<el-row :gutter="10">
					<el-col :span="24">
						<p>
							该企业目前属于{{
								ssqyData.sslsxzglbmmc
							}}管辖，是否申请变更属地？
						</p>
					</el-col>
				</el-row>
				<el-row :gutter="10">
					<el-col :span="24">
						<el-form-item label="申请原因：" prop="sqyy">
							<el-input
								v-model="ssqyData.sqyy"
								type="textarea"
								:rows="2"
								clearable
							></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<div style="margin-top: 10px; text-align: center">
					<el-button
						type="primary"
						class="iconfont icontijiao"
						size="small"
						@click="xgssqySubmit('ssqyData', 1)"
					>
						申请</el-button
					>
					<el-button
						type="primary"
						class="iconfont iconquxiao"
						size="small"
						@click="xgssqySubmit('ssqyData', 0)"
					>
						取消</el-button
					>
				</div>
			</el-form>
		</el-dialog>
		<auditDialog
			v-if="auditData.dialogVisible"
			:auditData="auditData"
			@getList="getList"
		/>
	</div>
</template>


<script>
import {
	getList,
	xzqyFun,
	insertEntitySelective,
	queryEnterpriseInformation,
	selectByEntity,
	exportFun,
} from '@/api/enterpriseInformationBase/index'
import { getParameter } from '@/utils/index'
import auditDialog from './auditDialog'
import { getCompanyInfo, tree } from '@/api/jcxxwh/qyjcxx'
import FileSaver from 'file-saver'
import XLSX2 from 'xlsx'
import XLSX from 'xlsx-style'
import { baseServer } from '@/api'
function formatData(list) {
	return list.map((item) => {
		let newItem = {}
		newItem.label = item.orgName
		newItem.value = item.orgName
		newItem.code = item.orgCode
		if (item.orgCode.length == 8) {
			return newItem
		}
		if (item.hasOwnProperty('children') && item.children.length > 0) {
			newItem.children = formatData(item.children)
			newItem.children.length = 18
		}

		return newItem
	})
}
export default {
	components: {
		auditDialog,
	},
	data() {
		return {
			auditData: {
				dialogVisible: false,
				code: null,
			},
			searchShowMoreBool: false,
			multipleSelection: [],
			formInline: {
				qymc: '',
				tyshxydm: '',
				sslsxzglbm: '',
				sfjysgzg: '',
				qyzt: '',
			},
			sgzgOptions: [
				{
					value: 1,
					label: '是',
				},
				{
					value: 0,
					label: '否',
				},
			],
			glbmOptions: [],
			glbmOptionsTxt: [],
			options: [
				{
					value: 1,
					label: '启用',
				},
				{
					value: 0,
					label: '禁用',
				},
			],
			listLoading: false,
			tableData: [],
			tabDataAll: [],
			pageForm: {
				pageNum: 1,
				pageSize: 10,
				total: 0,
			},
			xgssqyVisible: false,
			ssqyData: {
				ssqy: '',
				sqyy: '',
			},
			ssqyRules: {
				sqyy: [
					{
						required: true,
						message: '请输入申请原因',
						trigger: 'blur',
					},
					{
						min: 1,
						max: 50,
						message: '长度在 1 到 50 个字符',
						trigger: 'blur',
					},
				],
			},
			addDialogVisible: false,
			addDialogData: {
				qyName: '',
				qymc: '',
				tyshxydm: '',
			},
			addDialogRules: {
				qymc: [
					{
						required: true,
						message: '请输入企业名称',
						trigger: 'blur',
					},
					{
						min: 1,
						max: 50,
						message: '长度在 1 到 50 个字符',
						trigger: 'change',
					},
				],
				tyshxydm: [
					{
						required: true,
						message: '请输入企业统一社会信用代码',
						trigger: 'blur',
					},
					{
						min: 1,
						max: 18,
						message: '长度在 1 到 18 个字符',
						trigger: 'change',
					},
				],
			},
			orgName: null,
			orgCode: null,
			actionUrl: baseServer + '/company/importByEntity',
			uploadHeader: {
				token: sessionStorage.getItem('TOKENL'),
			},
			fileListUpload: [],
		}
	},
	created() {
		this.orgName = sessionStorage.getItem('orgName')
		this.orgCode = sessionStorage.getItem('orgCode')
		this.getTree()
	},
	methods: {
		getGlbm(sslsxzglbm) {
			let bm = ''
			if (sslsxzglbm.length > 5) {
				bm = sslsxzglbm.substring(0, 8)
			} else {
				bm = sslsxzglbm
			}
			let value = null
			this.glbmOptionsTxt.forEach((item) => {
				if (item.code == bm) {
					value = item.value
				}
			})
			return value
		},
		getTree() {
			tree().then((res) => {
				if (!res) {
					this.tree = []
					return
				}
				var arr = []
				arr.push(res.data)
				let tree = formatData(arr)
				arr[0].children.forEach((item) => {
					if (item.orgCode == 'LS001060') {
						console.log(item)
						tree.push({
							label: item.orgName,
							value: item.orgName,
							code: item.orgCode,
						})
					}
				})
				let glbm = []
				let glbmTxt = []
				tree.forEach((item) => {
					glbm.push({
						label: '全部',
						value: '全部',
						code: item.code,
					})
					item.children.forEach((val) => {
						glbm.push({
							label: val.label,
							value: val.value,
							code: val.code,
						})
					})
					glbmTxt.push({
						label: item.label,
						value: item.value,
						code: item.code,
					})
					item.children.forEach((val) => {
						glbmTxt.push({
							label: val.label,
							value: val.value,
							code: val.code,
						})
					})
				})
				this.glbmOptions = glbm
				this.glbmOptionsTxt = glbmTxt
				this.formInline.sslsxzglbm = this.orgCode
				this.getList('start')
			})
		},
		handleSelectionChange(val) {
			this.multipleSelection = val
		},
		changeQy(val) {
			if (val && val.tyshxydm) {
				this.addDialogData.tyshxydm = val.tyshxydm
			}
		},
		querySearch(queryString, cb) {
			let data = {
				qymc: queryString,
				tyshxydm: '',
			}
			xzqyFun(data).then((res) => {
				if (res.data) {
					for (let i of res.data.companyInfo) {
						i.value = i.qymc
						i.label = i.tyshxydm
					}
					let restaurants = res.data.companyInfo
					if (restaurants.length === 0) {
						restaurants = []
					}
					cb(restaurants)
				} else {
					cb([])
				}
			})
		},
		//新增企业-提交
		addDialogSubmit(formName, type) {
			//提交 1 取消 0
			if (type) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						let params = this.addDialogData
						let data = {
							entname: this.addDialogData.qymc,
							orgno: this.addDialogData.tyshxydm,
							// entname: '中粮利金（天津）粮油股份有限公司',
							// orgno: '120000000005499',
						}
						queryEnterpriseInformation(data)
							.then((res) => {
								//该新增企业所属管辖区与当前登录人所属管辖区不同时-提示'该企业目前属于XX区管辖，是否申请变更属地'
								if (res.infoCode == '200') {
									if (res.data.length > 0) {
										this.$router.push({
											path: '/grainCoManage/enterpriseInformationBase/add',
											query: {
												name: this.addDialogData.qymc,
												code: this.addDialogData
													.tyshxydm,
												data: JSON.stringify(
													res.data[0]
												),
											},
										})
									} else {
										this.$message.error('请核对信息！')
									}

									//if (
									//	res.data.companyInfo[0].sslsxzglbm !=
									//	sessionStorage.getItem('orgCode')
									//) {
									// if (res.data.companyInfo[0].apply) {
									// true代表有已经提交还未审核的申请-需提示
									// 		this.$message.error(
									// 			'您已经提交过变更区域申请,请耐心等待审核结果'
									// 		)
									// 	} else {
									// 		//需变更属地
									// 		this.addDialogVisible = false
									// 		this.ssqyData.sslsxzglbmmc =
									// 			res.data.companyInfo[0].sslsxzglbmmc
									// 		this.ssqyData.sslsxzglbm =
									// 			res.data.companyInfo[0].sslsxzglbm
									// 		this.xgssqyVisible = true
									// 	}
									// } else {
									//可进行填写企业基础信息
									//this.$router.push({
									// 	path: '/grainCoManage/enterpriseInformationBase/edit',
									// 	query: {
									// 		code: this.addDialogData.tyshxydm,
									// 	},
									// })
									// }
								} else {
									this.$message.error(res.msg)
									//查询不到该企业 - 进行新增企业
									// this.$router.push({
									// 	path: '/grainCoManage/enterpriseInformationBase/add',
									// 	query: {
									// 		name: this.addDialogData.qymc,
									// 		code: this.addDialogData.tyshxydm,
									// 	},
									// })
								}
							})
							.catch((res) => {
								this.$message.error(res.msg)
							})
					} else {
						return false
					}
				})
			} else {
				this.addDialogVisible = false
			}
		},
		//变更所属粮食行政管理部门
		xgssqySubmit(formName, type) {
			//提交 1 取消 0
			if (type) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						let params = {
							sqqy: this.ssqyData.sqyy, //申请原因
							sqqybm: sessionStorage.getItem('orgCode'), //"申请区域编码#<检索>"
							sqqybmmc: sessionStorage.getItem('orgName'), //"申请区域编码名称"
							sqrid: sessionStorage.getItem('userCode'), //"申请人id#<检索>"
							sqridmc: sessionStorage.getItem('userName'), //"申请人名称"
							tyshxydm: this.addDialogData.tyshxydm,
							qymc: this.addDialogData.qymc,
							bgqqybmmc: this.ssqyData.sslsxzglbmmc,
							bgqqybm: this.ssqyData.sslsxzglbm,
						}
						insertEntitySelective(params)
							.then((res) => {
								if (res.infoCode == 200) {
									//申请成功
									this.$message.success('申请成功')
									this.xgssqyVisible = false
								} else {
									//申请失败
									this.$message.error('申请失败')
									this.xgssqyVisible = false
								}
							})
							.catch((res) => {
								this.$message.error(res.msg)
							})
					} else {
						return false
					}
				})
			} else {
				this.xgssqyVisible = false
				this.addDialogVisible = true
			}
		},
		//重置
		resetInfo() {
			this.pageForm.pageNum = 1
			this.pageForm.pageSize = 10
			this.formInline.qymc = null
			this.formInline.tyshxydm = null
			this.formInline.sfjysgzg = null
			this.formInline.qyzt = null
			this.formInline.sslsxzglbm = this.orgCode
			this.getList()
		},
		//查询
		doSearch() {
			this.pageForm.pageNum = 1
			this.getList()
		},
		//获取列表
		getList(type) {
			let data = {
				pageNum: this.pageForm.pageNum,
				pageSize: this.pageForm.pageSize,
				qymc: this.formInline.qymc,
				tyshxydm: this.formInline.tyshxydm,
				qyzt: this.formInline.qyzt, //企业状态
				sfjysgzg: this.formInline.sfjysgzg, //收购资格
				sslsxzglbm: this.formInline.sslsxzglbm, //所属粮食行政管理部门
			}
			if (type != 'start') {
				//非初始化调用：查询、分页
				sessionStorage.setItem('searchData', JSON.stringify(data))
			} else {
				//初始化分两种情况，详情页等返回后的初始化，以及第一次进入此菜单的初始化
				if (
					JSON.parse(sessionStorage.getItem('searchData')) &&
					sessionStorage.getItem('searchData') != '{}'
				) {
					//详情页返回后，将对应查询条件和分页的字段赋值，页面回显参数
					let searchData = JSON.parse(
						sessionStorage.getItem('searchData')
					)
					this.formInline = getParameter(searchData, [
						'qymc',
						'zzjgdm',
						'qyzt',
						'sfjysgzg',
					])
					this.pageForm = getParameter(searchData, [
						'pageNum',
						'pageSize',
					])
				} else {
					//第一次进去此菜单时，保存上方默认的data
					sessionStorage.setItem('searchData', JSON.stringify(data))
				}
			}
			getList(JSON.parse(sessionStorage.getItem('searchData'))).then(
				(res) => {
					console.log('========res=========', res)
					if (res.infoCode == 200) {
						this.tableData = res.data.list
						this.tableData.forEach((val, index, arr) => {
							// 状态值中文显示处理
							this.tableData[index].qyzt == 1
								? (this.tableData[index].qyzt = '启用')
								: (this.tableData[index].qyzt = '禁用')
						})
						this.$set(
							this.pageForm,
							'total',
							Number(res.data.total)
						)
					} else {
						this.$message({
							type: 'error',
							message: res.msg,
						})
					}
				}
			)
		},

		//新增
		addSubmit() {
			this.addDialogVisible = true
			this.addDialogData = {
				qyName: '',
				qymc: '',
				tyshxydm: '',
			}
		},
		//导出
		exportSubmit() {
			let data = {
				pageNum: 1,
				pageSize: 100,
				qymc: this.formInline.qymc,
				tyshxydm: this.formInline.tyshxydm,
				qyzt: this.formInline.qyzt,
				sfjysgzg: this.formInline.sfjysgzg,
				fields: 'qymc-企业名称,tyshxydm-统一社会信用代码,fddbr-法定代表人,qylxr-联系人,bgdh-联系电话,sslsxzglbm-所属粮食行政管理部门,qyzt-状态',
			}
			const formData = new FormData()
			formData.set(
				'fields',
				'qymc-企业名称,tyshxydm-统一社会信用代码,fddbr-法定代表人,qylxr-联系人,bgdh-联系电话,sslsxzglbm-所属粮食行政管理部门,qyzt-状态'
			)
			formData.set('pageNum', 1)
			formData.set('pageSize', 1000)
			formData.set('qymc', this.formInline.qymc)
			formData.set(
				'tyshxydm',
				this.formInline.tyshxydm ? this.formInline.tyshxydm : ''
			)
			formData.set(
				'qyzt',
				this.formInline.qyzt ? this.formInline.qyzt : ''
			)
			formData.set(
				'sfjysgzg',
				this.formInline.sfjysgzg ? this.formInline.sfjysgzg : ''
			)
			exportFun(formData)
				.then((response) => {
					let blob = new Blob([response], {
						type: 'application/vnd.ms-excel',
					})

					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()
			// getList(data)
			//     .then(res => {
			//         if (res.infoCode == 200) {
			//             this.tabDataAll = res.data.list;
			//             this.tabDataAll.forEach((val, index, arr) => {
			//                 // 状态值中文显示处理
			//                 this.tabDataAll[index].qyzt == 1 ? this.tabDataAll[index].qyzt = '启用' : this.tabDataAll[index].qyzt = '禁用';
			//             });
			//             this.detailStr = '企业信息库'
			//             let self = this
			//             this.$nextTick(function(){
			//                 self.setExport2Excel()
			//             })
			//         } else {
			//             this.$message({
			//                 type: 'error',
			//                 message: res.msg
			//             });
			//         }
			//     });
		},
		setExport2Excel() {
			/* generate workbook object from table */
			console.log(document.querySelector('#outTablexm'))
			var wb = XLSX2.utils.table_to_sheet(
				document.querySelector('#outTablexm'),
				{ raw: true }
			) //outTablexm为表格的id名,//{ raw: true }可解决数字变为E的情况

			if (!wb['!merges']) {
				this.$message.warning('无法导出：报表无数据')
				return
			}
			wb['!cols'] = []
			//设置表格宽度
			for (var i = 0; i < 9; i++) {
				let width = 50
				if (i > 1) {
					width = 150
				}
				if (i == 2 || i == 7) {
					width = 300
				} else if (i == 3) {
					width = 180
				}
				wb['!cols'][i] = { wpx: width }
			}
			// 样式的文档地址
			// https://www.npmjs.com/package/xlsx-style
			for (const key in wb) {
				if (key.indexOf('!') === -1 && wb[key].v) {
					wb[key].s = {
						font: {
							//字体设置
							sz: 13,
							bold: false,
							color: {
								rgb: '000000', //十六进制，不带#
							},
						},
						alignment: {
							//文字居中
							horizontal: 'center',
							vertical: 'center',
							wrap_text: true,
						},
						border: {
							// 设置边框
							top: { style: 'thin' },
							bottom: { style: 'thin' },
							left: { style: 'thin' },
							right: { style: 'thin' },
						},
					}
				}
			}
			var data = this.addRangeBorder(wb['!merges'], wb) //合并项添加边框
			var filedata = this.sheet2blob(data)
			this.openDownloadDialog(filedata, '企业信息库.xlsx')
		},
		//为合并项添加边框
		addRangeBorder(range, ws) {
			let arr = [
				'A',
				'B',
				'C',
				'D',
				'E',
				'F',
				'G',
				'H',
				'I',
				'J',
				'K',
				'L',
				'M',
				'N',
				'O',
				'P',
				'Q',
				'R',
				'S',
				'T',
				'U',
				'V',
				'W',
				'X',
				'Y',
				'Z',
			]

			range.forEach((item) => {
				let startColNumber = Number(item.s.r),
					endColNumber = Number(item.e.r)
				let startRowNumber = Number(item.s.c),
					endRowNumber = Number(item.e.c)
				const test = ws[arr[startRowNumber] + (startColNumber + 1)]
				for (let col = startColNumber; col <= endColNumber; col++) {
					for (let row = startRowNumber; row <= endRowNumber; row++) {
						ws[arr[row] + (col + 1)] = test
					}
				}
			})
			return ws
		},
		//将一个sheet转成最终的excel文件的blob对象，然后利用URL.createObjectURL下载
		sheet2blob(sheet, sheetName) {
			sheetName = sheetName || 'sheet1'
			var workbook = {
				SheetNames: [sheetName],
				Sheets: {},
			}
			workbook.Sheets[sheetName] = sheet // 生成excel的配置项

			var wopts = {
				bookType: 'xlsx', // 要生成的文件类型
				bookSST: false, // 是否生成Shared String Table，官方解释是，如果开启生成速度会下降，但在低版本IOS设备上有更好的兼容性
				type: 'binary',
			}
			var wbout = XLSX.write(workbook, wopts)
			var blob = new Blob([s2ab(wbout)], {
				type: 'application/octet-stream',
			}) // 字符串转ArrayBuffer
			function s2ab(s) {
				var buf = new ArrayBuffer(s.length)
				var view = new Uint8Array(buf)
				for (var i = 0; i != s.length; ++i)
					view[i] = s.charCodeAt(i) & 0xff
				return buf
			}
			return blob
		},
		openDownloadDialog(url, saveName) {
			if (typeof url == 'object' && url instanceof Blob) {
				url = URL.createObjectURL(url) // 创建blob地址
			}
			var aLink = document.createElement('a')
			aLink.href = url
			aLink.download = saveName || '' // HTML5新增的属性，指定保存文件名，可以不要后缀，注意，file:///模式下不会生效
			var event
			if (window.MouseEvent) event = new MouseEvent('click')
			else {
				event = document.createEvent('MouseEvents')
				event.initMouseEvent(
					'click',
					true,
					false,
					window,
					0,
					0,
					0,
					0,
					0,
					false,
					false,
					false,
					false,
					0,
					null
				)
			}
			aLink.dispatchEvent(event)
		},
		//导入
		handleSuccess(response) {
			console.log('handleSuccess=', response)
			if (response && response.infoCode === 200) {
				this.$message.success('导入成功')
				this.getList()
			} else {
				this.$message.error(response.msg)
			}
		},
		//附件上传
		changeFj(file, fileList) {
			console.log('changeFj=', file)
		},
		//查看
		detailSubmit(id) {
			this.$router.push({
				path: '/grainCoManage/enterpriseInformationBase/details',
				query: {
					code: id,
				},
			})
		},
		//编辑
		editSubmit(id) {
			this.$router.push({
				path: '/grainCoManage/enterpriseInformationBase/edit',
				query: {
					code: id,
				},
			})
		},
		//审核
		auditSubmit(id) {
			this.auditData.dialogVisible = true
			this.auditData.code = 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>
