<template>
	<div class="content-main">
		<el-row>
			<el-form :inline="true" :model="formInline" class="search-bm-boder">
				<el-form-item label="审核状态">
					<el-select clearable v-model="formInline.sfba" 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-form-item label="是否有效">
					<el-select clearable v-model="formInline.sfyx" placeholder="请选择">
						<el-option
							v-for="(item,index) in [{val:0,key:'否'},{val:1,key:'是'}]"
							:key="index"
							:label="item.key"
							:value="item.val"
						></el-option>
					</el-select>
				</el-form-item>-->
				<el-form-item>
					<div class="search-button">
						<span class="search-line"></span>
						<el-button type="primary" size="small" class="iconfont iconchaxun" @click="doSearch">查询</el-button>
						<el-button type="primary" @click="formInline={};doSearch()" size="small" class="iconfont iconzhongzhi">重置</el-button>
					</div>
				</el-form-item>
			</el-form>
		</el-row>
		<el-row></el-row>
		<!-- <el-row style="background: rgb(237, 245, 253); line-height: 50px;margin-bottom: 10px;">
			<el-button type="primary" class="iconfont iconxinzeng" size="small" @click="addSubmit()">更新信息</el-button>
		</el-row>-->
		<el-row>
			<el-table
				:data="tableData"
				stripe
				v-loading="listLoading"
				border
				fit
				highlight-current-row
				style="width: 100%"
			>
				<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>
					<template slot-scope="scope">{{scope.row.qymc}}</template>
				</el-table-column>
				<el-table-column
					align="center"
					prop="tyshxydm"
					label="统一社会信用代码"
					min-width="130"
					show-overflow-tooltip
				>
					<template slot-scope="scope">{{scope.row.tyshxydm}}</template>
				</el-table-column>
				<el-table-column align="center" prop="qyxz" label="单位性质" show-overflow-tooltip>
					<template slot-scope="scope">{{scope.row.qyxz}}</template>
				</el-table-column>
				<el-table-column align="center" prop="dwlxmc" label="单位类型" show-overflow-tooltip></el-table-column>
				<el-table-column align="center" prop="qytxdz" label="所在地" show-overflow-tooltip>
				</el-table-column>
				<el-table-column align="center" prop="qylxr" label="联系人" show-overflow-tooltip>
					<template slot-scope="scope">{{scope.row.qylxr}}</template>
				</el-table-column>
				<el-table-column align="center" prop="bgdh" label="电话" show-overflow-tooltip>
					<template slot-scope="scope">{{scope.row.bgdh}}</template>
				</el-table-column>
				<el-table-column align="center" prop="sfba" label="审核状态">
					<template slot-scope="scope">
						<!-- <span v-if="scope.row.sfba == '0'">未备案</span> -->
						<span v-if="scope.row.sfba == '1'">待提交</span>
						<span v-if="scope.row.sfba == '2'">审核中</span>
						<span v-if="scope.row.sfba == '3'">已驳回</span>
						<!-- <span v-if="scope.row.sfba == '4'">已备案</span> -->
						<span v-if="scope.row.sfba == 5">审核通过</span>
					</template>
				</el-table-column>
				<el-table-column align="center" label="是否有效">
					<template slot-scope="scope">
						<span v-if="scope.row">是</span>
					</template>
				</el-table-column>
				<!-- <el-table-column align="center" prop="cc" label="是否有效">
          <template slot-scope="scope">{{scope.row.qylsgx}}</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
							v-if="scope.row.sfba==2"
							@click="$router.push({path:'qyxxAdd',query:{code:scope.row.tyshxydm}})"
							title="审核"
							type="primary"
							size="small"
							class="operate_edit_btn iconfont iconshenhe"
						></el-button>
					</template>
				</el-table-column>
			</el-table>
		</el-row>
		<el-row>
			<el-pagination
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				:current-page.sync="pageForm.page"
				:page-sizes="[10,20,30,40]"
				:page-size="pageForm.size"
				layout="total, sizes, prev, pager, next, jumper"
				:total="pageForm.total"
			></el-pagination>
		</el-row>
	</div>
</template>


<script>
const coType = { 1: '应急', 2: '仓储', 3: '加工', 4: '物流', 5: '配送' }
import { getPageList, getInfoById } from '@/api/jcxxwh/qyjcxx.js'
export default {
	data() {
		return {
			formInline: {
				qyjgdm:sessionStorage.qyjgdm
				// tyshxydm: `${sessionStorage.getItem('tyshxydm')}`
			},
			options: [
				// {
				// 	value: 0,
				// 	label: '未备案'
				// },
				// {
				// 	value: 1,
				// 	label: '待提交'
				// },
				{
					value: 2,
					label: '审核中'
				},
				{
					value: 3,
					label: '已驳回'
				},
				// {
				// 	value: 4,
				// 	label: '已备案'
				// },
				{
					value: 5,
					label: '审核通过'
				}
			],
			listLoading: false,
			tableData: [],
			pageForm: {
				page: 1,
				size: 10,
				total: 0
			}
		}
	},
	created() {
		this.getList()
	},
	methods: {
		doSearch(){
			this.pageForm.page = 1
			this.getList()
		},
		//获取列表
		getList() {
			this.listLoading = true
			// this.formInline.tyshxydm = sessionStorage.getItem('tyshxydm')
			this.formInline.qyjgdm = sessionStorage.orgCode
			getPageList(this.pageForm, this.formInline)
				.then((res) => {
					this.listLoading = false
					// if (!res) return
					this.tableData = res.data.list
					this.tableData.forEach((d) => {
						if(d.dwlx){
							d.dwlxmc = []
							d.dwlx.split(',').forEach(dw=>{
								let dwmc = coType[dw]
								if(dwmc){
									d.dwlxmc.push(dwmc)
								}
							})
							d.dwlxmc = d.dwlxmc.join(',')
						}
					})
					this.pageForm.total = res.data.total
					if(this.tableData[0].sfba == 1){
						this.tableData = []
						this.pageForm.total = 0
					}
				})
				.catch((err) => {
					this.listLoading = false
					this.pageForm.total = 0
					this.tableData = []
				})
		},

		//新增
		addSubmit() {
			this.$router.push({ path: '/jcxxwh/qyjcxxAdd' })
		},
		//详情
		detailSubmit(id) {
			this.$router.push({
				path: 'qyxxAdd',
				query: {
					status: 'detail',
					code:id
				}
			})
		},
		//删除
		deleteSubmit() {},

		handleSizeChange(val) {
			this.pageForm.size = val
			this.getList()
		},
		handleCurrentChange(val) {
			this.pageForm.page = val
			this.getList()
		}
	}
}
</script>
