<template>
	<div class="content-main">
		<el-row>
			<el-form
				:inline="true"
				:model="formInline"
				class="search-bm-boder"
				ref="formInline"
				label-width="6em"
			>
				<el-form-item label="仓房编码:" prop="cfbh">
					<el-input clearable class="inputCompatible" v-model="formInline.cfbh" placeholder="请输入"></el-input>
				</el-form-item>
				<el-form-item label="仓房名称:" prop="cfmc">
					<el-input clearable class="inputCompatible" v-model="formInline.cfmc" placeholder="请输入"></el-input>
				</el-form-item>
				<el-form-item label="建设时间:" prop="jssj">
					<el-date-picker
						clearable
						class="inputCompatible"
						v-model="formInline.jssj"
						type="date"
						value-format="yyyy-MM-dd HH:mm:ss"
						placeholder="选择日期"
					></el-date-picker>
				</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="状态:" prop="sfba">
						<!-- <el-input clearable v-model="formInline.sfba" placeholder="请输入"></el-input> -->
						<el-select clearable class="inputCompatible" 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-row>
			</el-form>
		</el-row>
		<el-row></el-row>
		<!-- <el-row class="addBtnBg">
			<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="cfmc" label="仓房名称">
					<template slot-scope="scope">{{ scope.row.cfmc }}</template>
				</el-table-column>
				<el-table-column show-overflow-tooltip align="center" prop="cfbh" label="仓房编码">
					<template slot-scope="scope">{{ scope.row.cfbh }}</template>
				</el-table-column>
				<el-table-column align="center" prop="ajxh" label="廒间序号">
					<template slot-scope="scope">{{ scope.row.ajxh }}</template>
				</el-table-column>
				<el-table-column align="center" prop="hwxh" label="货位号">
					<template slot-scope="scope">{{ scope.row.hwxh }}</template>
				</el-table-column>
				<el-table-column align="center" prop="jssj" label="建设时间">
					<template slot-scope="scope">{{ scope.row.jssj }}</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" width="180" label="操作">
					<template slot-scope="scope">
						<el-tooltip class="item" effect="light" content="查看" placement="top">
							<el-button
								@click="detailSubmit(scope.row)"
								type="primary"
								size="small"
								class="operate_show_btn iconfont iconchakan2"
							></el-button>
						</el-tooltip>
						<!-- <el-tooltip
              class="item"
              effect="light"
              content="编辑"
              placement="top"
              v-show="scope.row.sfba == 1 || scope.row.sfba == 3 || scope.row.sfba == 5"
            >
              <el-button
                @click="editSubmit(scope.row.cfbh)"
                type="primary"
                size="small"
                class="operate_edit_btn iconfont iconxiugai"
              ></el-button>
						</el-tooltip>-->
						<!-- <el-tooltip
							class="item"
							effect="light"
							content="提交"
							placement="top"
							v-show="scope.row.sfba ==1"
						>
						<el-button
							@click="sendSubmit(scope.row.cfbh)"
							type="primary"
							class="operate_show_btn iconfont icontijiao"
						></el-button>
						</el-tooltip>-->
						<!-- <el-tooltip
              class="item"
              effect="light"
              content="删除"
              placement="top"
              v-show="scope.row.sfba == 1 || scope.row.sfba == 3"
            >
              <el-button
                @click="deleteSubmit(scope.row.cfbh)"
                type="primary"
                size="small"
                class="operate_delete_btn iconfont iconshanchu"
              ></el-button>
						</el-tooltip>-->
					</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>
import { getPageList, deleteFn, detailsFn, editFn } from '@/api/jcxxwh/cfxx'
import { dateFormat } from '@/utils'
export default {
	data() {
		return {
			searchShowMoreBool: false,
			formInline: {
				cfbh: '',
				cfmc: '',
				jssj: '',
				sfba: ''
			},
			listLoading: false,
			tableData: [],
			pageForm: {
				page: 1,
				size: 10,
				total: 0
			},
			options: [
				{
					value: 1,
					label: '待提交'
				},
				{
					value: 2,
					label: '审核中'
				},
				{
					value: 3,
					label: '已驳回'
				},
				{
					value: 5,
					label: '审核通过'
				}
			],
			kd: ''
		}
	},
	created() {
		this.getList()
	},
	methods: {
		doSearch() {
			this.pageForm.page = 1
			this.getList()
		},
		resetInfo(formName) {
			this.$refs[formName].resetFields()
			this.doSearch()
		},
		//获取列表
		getList() {
			// this.formInline.tyshxydm = sessionStorage.getItem('tyshxydm')
			// this.formInline.kddm = `${sessionStorage.getItem('tyshxydm')}001`
			this.formInline.zts = this.formInline.sfba
				? [this.formInline.sfba]
				: [1, 2, 3, 5]
			this.formInline.cklx="1"
			getPageList(this.pageForm, this.formInline).then((res) => {
				this.tableData = res.data.list
				this.pageForm.total = res.data.total
				this.tableData.map((item) => {
					item.jssj = dateFormat(item.jssj)
					if (item.ajxh.slice(1) == '-0') {
						item.ajxh = '无'
					}
				})

				
				// alert(this.pageForm.total)
			})
		},
		//新增
		addSubmit() {
			this.$router.push({
				path:
					'/grainCoManage/warehousingLogistics/facilitiesSituation/coRegAudit/details'
			})
		},
		sendSubmit(sbbh) {
			detailsFn(sbbh).then((res) => {
				let form = {}
				form = res.data
				form.sfba = 2
				editFn(form).then((response) => {
					if (response.infoCode == 200) {
						this.$message({
							message: '提交成功',
							type: 'success'
						})
					} else {
						this.$message({
							message: '提交失败',
							type: 'error'
						})
					}

					this.getList()
				})
			})
		},
		//详情
		detailSubmit(row) {
			this.$router.push({
				path:
					'/grainCoManage/warehousingLogistics/facilitiesSituation/coRegAudit/details',
				query: {
					status: 'detail',
					cfbhNum: row.cfbh,
					sfba: row.sfba
				}
			})
		},
		editSubmit(cfbh) {
			this.$router.push({
				path:
					'/grainCoManage/warehousingLogistics/facilitiesSituation/coRegAudit/details',
				query: {
					status: 'edit',
					cfbhNum: cfbh
				}
			})
		},
		//删除
		deleteSubmit(rowId) {
			this.$confirm('此操作将永久删除, 是否继续?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			})
				.then(() => {
					deleteFn(rowId).then((res) => {
						if (res.infoCode == 200) {
							this.$message({
								message: '删除成功',
								type: 'success'
							})
							this.getList()
						} else {
							this.$message({
								message: '删除失败',
								type: 'error'
							})
							this.getList()
						}
					})
				})
				.catch(() => {
					this.$message({
						message: '已取消删除',
						type: 'warning'
					})
				})
		},

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