// 货主授权审核
<template>
	<div class="center">
		<div class="center_css">
			<div class="top_css">
				<el-row>
					<el-col :span="14" style="height: 45px;">
						<!-- <el-button type="primary">添加</el-button> -->
					</el-col>
					<el-col :span="10">
						<div class="screen">
							<el-input class='find' placeholder="可按货主姓名、账号和企业名称查找" @keyup.enter.native="find" v-model="searchkeyWord" clearable @change="find"></el-input>
							<el-button class="search" @click="find"><img width="16" height="16"
									style="margin-left: -8px" src="../../../public/img/sousuo.png" /></el-button><span
								class="count_css">共{{ deptBudgetTotal }}条</span>
						</div>
					</el-col>
				</el-row>
				<el-row>
					<el-col>
						<div class="search_btn">
							<div :class="search == '' ? 'search' : 'searchNo'" class="search_item search_block"
								@click="searchBtn('')">
								全部
							</div>
							<div :class="search == 1 ? 'search' : 'searchNo'" class="search_item" @click="searchBtn(1)">
								待审核
							</div>
							<div :class="search == 3 ? 'search' : 'searchNo'" class="search_item" @click="searchBtn(3)">
								已通过
							</div>
							<div :class="search == 2 ? 'search' : 'searchNo'" class="search_item" @click="searchBtn(2)">
								已驳回
							</div>
						</div>
					</el-col>
				</el-row>
			</div>
			<el-table :data="tableData" style="width: 98%; margin: 0 auto; border-radius: 10px" height="68vh" border highlight-current-row>
				<el-table-column type="index" width="60"  label="序号" align="center">
					<template scope="scope">
						<span>{{scope.$index + 1}}</span>
						<!-- <span v-else>{{scope.$index}}</span> -->
					</template>
				</el-table-column>
				<el-table-column prop="name" label="货主姓名" min-width="130"></el-table-column>
				<el-table-column prop="phone" label="账号" min-width="107"></el-table-column>
				<el-table-column prop="cardNumber" label="身份证号" min-width="162"></el-table-column>
				<el-table-column prop="company" label="所属企业名称" min-width="110"></el-table-column>
				<el-table-column prop="certificateAddressUrl" label="授权书">
					<template slot-scope="scope">
						<span class="btn_css" @click="lookBook(scope.row)">查看</span>
					</template>
				</el-table-column>
				<el-table-column prop="authorizationDeadline" label="授权截止日期" min-width="105"></el-table-column>
				<el-table-column prop="updateDate" label="认证日期" min-width="93"></el-table-column>
				<el-table-column prop="backStageStatus" label="状态"></el-table-column>
				<el-table-column label="操作" min-width="350">
					<template slot-scope="scope">
						<el-link  target="_blank" @click="adopt(scope.row)" type="primary" :underline="false" :disabled="scope.row.status != '平台审核中'">通过</el-link>
						<el-divider direction="vertical"></el-divider>
						<el-link target="_blank" @click="reject(scope.row)" type="primary" :underline="false" :disabled="scope.row.status != '平台审核中'">驳回</el-link>
					</template>
				</el-table-column>
			</el-table>
		</div>
		<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
			style="text-align: center; margin-top: 10px" :page-size="deptCircularPage.pageSize"
			layout="total, sizes, prev, pager, next, jumper" :total="deptBudgetTotal">
		</el-pagination>
		<el-dialog :close-on-click-modal='false' title="授权书" :visible.sync="lookInfo" width="500px" center :before-close="lookBookClose">
			<div class="InfoBook_css">

					<img v-for='item in bookUrlArray' :src="item" class="InfoBook_img">

			</div>

		</el-dialog>
		<el-dialog :close-on-click-modal='false' title="驳回认证" :visible.sync="rejectInfo" width="400px" :before-close="rejectClose">
			<div>
				<!-- <div><span class="sign">*</span>选择驳回原因</div> -->
				<div class="form_css">
					<el-form ref="form" :model="form" label-width="80px">
						<!-- <el-checkbox-group v-model="form.checkList">
							<el-checkbox label="证件照片不清晰"></el-checkbox>
							<el-checkbox label="证件照片上传错误"></el-checkbox>
							<el-checkbox label="身份信息填写错误"></el-checkbox>
							<el-checkbox label="证件信息填写错误"></el-checkbox>
							<el-checkbox label="其他"></el-checkbox>
						</el-checkbox-group> -->
						<div style="margin-bottom: 20px;">驳回原因描述（必填）</div>
						<el-input type="textarea" :rows="3" resize="none" placeholder="输入驳回原因，6-100个字" maxlength="100"
							v-model="form.rejectReasonDescription"></el-input>
						<div class="form_btn">
							<el-button @click="rejectClose">取消</el-button>
							<el-button @click="submit" type="primary">确定</el-button>
						</div>
					</el-form>
				</div>
			</div>
		</el-dialog>

	</div>
</template>
<script>
	import {
		GrantList,
		toGrantExamine
	} from '@/api/cargoOwnerManagement'
	export default {
		data() {
			return {
				tableData: [],
				//分页
				searchkeyWord: "",
				currentPage: 1,
				pageSize: 10,
				deptBudgetTotal: 0,
				deptCircularPage: {},
				search: "",
				addressUrl: [],
				disabled: false,
				lookInfo: false,
				rejectInfo: false,
				form: {},
				bookUrlArray:[]

			};
		},
		mounted() {
			this.getList()
		},
		methods: {
			getList() {
				this.loading = true
				let _obj = {}
				_obj.currentPage = this.currentPage
				_obj.pageSize = this.pageSize
				_obj.searchKeyWord = this.searchkeyWord
				_obj.searchType = this.search
				GrantList(_obj).then(response => {
						this.tableData = response.data.records
						this.deptBudgetTotal = response.data.total
						this.listLoading = false
					})
					.catch(() => {
						this.loading = false
					})
			},
			adopt(row) {
				this.$confirm('确定通过'+row.name+'的审核？', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning',
					})
					.then(() => {
						this.listLoading = true
						var _examine = {}
						_examine.id = row.id
						_examine.flag = 1
						toGrantExamine(_examine).then(response => {
							this.$notify({
								title: '成功',
								message: '通过成功！',
								type: 'success'
							});
							this.getList()
								this.listLoading = false
							})
							.catch(() => {
								this.loading = false
							})
					})
			},
			reject(row) {
				this.form.id = row.id
				this.form.flag = 2
				this.rejectInfo = true
			},
			rejectClose() {
				this.form = {}
				this.rejectInfo = false
			},
			submit() {
				if (!this.form.rejectReasonDescription) {
					this.$message.error("请输入驳回原因！")
					return
				}
				if (this.form.rejectReasonDescription.length < 6 || this.form.rejectReasonDescription.length > 100) {
					this.$message.error("驳回原因字数应在6-100之间")
					return
				}
				this.listLoading = true
				toGrantExamine(this.form).then(response => {
						this.$notify({
							title: '成功',
							message: '驳回成功！',
							type: 'success'
						});
						this.form.rejectReasonDescription = ""
						this.rejectInfo = false
						this.getList()
						this.listLoading = false
					})
					.catch(() => {
						this.loading = false
					})
			},

			lookBook(row) {
				this.bookUrlArray=[]
				var arr=row.certificateAddressUrl.split(',')
				for (let i = 0; i < arr.length; i++) {
					if(arr[i]!=''){
						this.bookUrlArray.push(arr[i])
					}
					
				}
				this.lookInfo = true;
			},
			lookBookClose() {
				this.lookInfo = false;
			},
			searchBtn(num) {
				this.search = num;
				this.getList();
			},
			find() {
				this.currentPage = 1
				this.getList();
			},
			onChange() {
				this.$refs.upload
					.handleSaveBill()
					.then(async (response) => {
						this.formData.addressUrl = response;
					})
					.catch((res) => {
						EventBus.$emit("error", (JSON.parse(res) || {}).message);
						this.$refs.upload.clearFiles();
					});
			},
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`);
				this.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.currentPage = val;
				console.log(`当前页: ${val}`);
				this.getList();
			},
		},
	};
</script>
<style lang="scss" scoped>
	.center {
		padding: 10px 20px;
		background: #f5f6f7;
		min-height: calc(100vh - 50px);

		.top_css {
			padding: 10px;

			.search_btn {
        height: 80px;
        background: linear-gradient(#fafbfb, #ffffff);
				display: flex;
				margin-top: 20px;
        .search_block{
          margin-left: 20px;
        }

				.search_item {
					text-align: center;
					font-size: 14px;
					font-weight: 600;
					line-height: 40px;
					width: 112px;
					height: 40px;
					background: #f7f8f9;
					cursor: pointer;
           margin-top: 30px;
				}

				.searchNo {
					color: #323233;
				}

				.search {
					color: #2f53eb;
					background: #ffffff;
				}
			}
		}

		.center_css {
			background: #ffffff;
			border-radius: 1px;
			margin-top: 10px;
			padding-bottom: 10px;
		}

		.screen {
			display: flex;

			.search {
				width: 40px;
				height: 40px;
				background: #2f53eb;
				border-radius: 0px 2px 2px 0px;
				border: 1px solid #DCDFE6;
        		margin-left:-1px;
			}

			.count_css {
				width: 80px;
				text-align: center;
				line-height: 40px;
				color: #666666;
			}
		}

		.el-button {
			padding: 10px 20px !important;
		}

		.center_css {

			::v-deep .el-table th,
			::v-deep .el-table td {
				text-align: center;
			}

			.fujian {
				font-size: 24px;
				color: #409eff;
			}

			.warning {
				font-size: 14px;
				color: #ed1d1d;
			}
		}
	}

	.car_css {
		width: 50%;
		display: inline-block;
		text-align: center;
		margin-top: 20px;
	}

	.car_item {
		width: 100px;
		height: 100px;
	}

	.user {
		margin-bottom: 20px;

		.user_id {
			display: flex;
			height: 30px;
		}

		.name_css,
		.id_css {
			width: 50%;
		}

		.name_css {
			text-align: right;
		}

		.user_item {
			width: 450px;
			height: 300px;
		}
	}

	::v-deep .el-table--border .el-table__header th {
		background: #f7f8f9;
	}

	.btn_css {
		color: #409EFF;
		cursor: pointer
	}

	.sign {
		font-size: 14px;
		color: red;
	}

	.form_css {
		width: 100%;
		margin: 0px auto 20px;

		::v-deep .el-checkbox {
			width: 40%;
			height: 30px;
		}

		::v-deep .el-dialog__body {
			padding: 10px 20px;
		}

		::v-deep .el-dialog__title {
			font-size: 16px;
		}

		::v-deep .el-textarea__inner {
			background: #F0F1F2;
		}

		.form_btn {
			text-align: right;
			margin-top: 10px;
		}
	}
	//发送信息
	.Info_css{
		.Info_title{
			color: #323233;
			font-size: 16px;
		}
		.Info_item{
			margin: 20px 0;
		}
		.Info_btn {
			text-align: right;
			margin-top: 10px;
		}
	}
	//授权信息
	.InfoBook_css{

		.InfoBook_img{
			width: 100%;
			height: 220px;
			margin-top: 10px;
		}
	}
.find::v-deep input.el-input__inner{
    border-radius:0;
  }
</style>
