<template>
	<div class="content-main">
		<el-row>
			<el-form :inline="true" :model="formInline" class="search-bm-boder" ref="formInline" label-width="70px">
				<el-form-item label="仓房编码" prop="cfbh">
					<el-input class="inputCompatible" clearable v-model="formInline.cfbh" placeholder="请输入"></el-input>
				</el-form-item>
				<el-form-item label="仓房名称" prop="cfmc">
					<el-input class="inputCompatible" clearable 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 class="inputCompatible" 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-row>
			</el-form>
		</el-row>
		<el-row></el-row>
		<el-row class="addBtnBg">
			<el-button type="primary" class="iconfont iconshenhe" 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%"
				@selection-change="handleSelectionChange"
			>
				<el-table-column
					align="center"
					:selectable="checkboxT"
					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="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 show-overflow-tooltip 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-button
							@click="detailSubmit(scope.row.cfbh)"
							title="查看"
							type="primary"
							size="small"
							class="operate_show_btn iconfont iconchakan2"
						></el-button>
						<el-button
							@click="editSubmit(scope.row.cfbh)"
							title="审批"
							type="primary"
							v-show="scope.row.sfba ==2"
							size="small"
							class="operate_edit_btn iconfont iconshenpi"
						></el-button>
						<!-- <el-button  @click="deleteSubmit(scope.row.cfbh)" title="删除" type="primary" v-show="scope.row.sfba ==1" size="small"  class="operate_delete_btn iconfont iconshanchu"></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>
		<el-dialog title="仓房信息审核" :visible.sync="dialogVisible">
			<div>
				<el-form :model="shForm" label-width="80px" style="height:270px;">
					<el-col :span="24">
						<el-form-item label="审批:">
							<el-radio v-model="shForm.sfba" :label="5">通过</el-radio>
							<el-radio v-model="shForm.sfba" :label="3">驳回</el-radio>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="审核意见:">
							<el-input style="width:90%" v-model="shForm.shyj"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="审核人:">
							<el-input disabled style="width:80%" v-model="shForm.shrmc"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="审核时间:">
							<el-input disabled style="width:80%" v-model="shForm.shsj"></el-input>
						</el-form-item>
					</el-col>
				</el-form>
				<div slot="footer"  style="text-align: center;">
					<el-button type="primary" class="iconfont iconzancun" @click="save">保存</el-button>
					<el-button type="primary" class="iconfont iconfanhui" @click="dialogVisible = false"> 返回</el-button>
				</div>
			</div>
		</el-dialog>
	</div>
</template>


<script>
import {
	getPageList,
	deleteFn,
	detailsFn,
	editFn,
	warehouseBatch
} from '@/api/jcxxwh/cfxx'
import { dateFormat,getNowDate } 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: 2,
					label: '审核中'
				},
				{
					value: 3,
					label: '已驳回'
				},
				{
					value: 5,
					label: '审核通过'
				}
			],
			dialogVisible: false,
			shForm: {
				sfba: 5,
				shrmc: '',
				shsj: '',
				shyj: ''
			},
			multipleSelection: []
		}
	},
	created() {
		this.getList()
	},
	methods: {
		doSearch(){
			this.pageForm.page = 1
			this.getList()
		},
		//获取列表
		resetInfo(formName) {
			this.$refs[formName].resetFields();
			this.doSearch();
		},
		getList() {
			// this.formInline.kddm = `${sessionStorage.getItem('tyshxydm')}001`
			this.formInline.zts = this.formInline.sfba
				? [this.formInline.sfba]
				: [2, 3, 5]
			// this.formInline.tyshxydm = sessionStorage.getItem('tyshxydm')
			getPageList(this.pageForm, this.formInline).then((res) => {
				this.tableData = res.data.list
				this.tableData.map((item) => {
					item.jssj = dateFormat(item.jssj);
					if(item.ajxh.slice(1) == '-0'){
						item.ajxh = '无'
					}
				})
				this.pageForm.total = res.data.total
			})
		},
		checkboxT(row, index) {
			if (row.sfba == 2) {
				return 1
			} else {
				return 0
			}
		},
		handleSelectionChange(val) {
			this.multipleSelection = val
		},
		save() {
			this.shForm.cfbhs = []
			console.log(this.multipleSelection)
			this.multipleSelection.map((item) => {
				this.shForm.cfbhs.push(item.cfbh)
			})
			this.shForm.tyshxydm = sessionStorage.getItem('tyshxydm')
			warehouseBatch(this.shForm).then((res) => {
				if (res.infoCode == 200) {
					this.$message({
						message: '审核成功',
						type: 'success'
					})
					this.dialogVisible = false;
					this.getList();
				} else {
					this.$message.error('审核失败')
				}
			})
		},
		//批量审核
		addSubmit() {
			if (this.multipleSelection.length) {
				this.dialogVisible = true
				this.shForm.shrmc = sessionStorage.getItem('userName')
				this.shForm.shsj = getNowDate(new Date())
			} else {
				this.$message({
					message: '请先勾选',
					type: 'warning'
				})
			}
		},
		sendSubmit(sbbh) {
			detailsFn(sbbh).then((res) => {
				let form = {}
				form = res.data
				form.sfba = 2
				editFn(form).then((response) => {
					this.$message({
						message: '提交成功',
						type: 'success'
					});
					this.getList()
				})
			})
		},
		//详情
		detailSubmit(cfbh) {
			this.$router.push({
				path: 'cfxxAdd',
				query: {
					status: 'detail',
					cfbhNum: cfbh
				}
			})
		},
		editSubmit(cfbh) {
			this.$router.push({
				path: 'cfxxAdd',
				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.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>
