<template>
	<div>
	<!-- <el-tabs v-model="activeName" @tab-click="handleClick">
		<el-tab-pane label="项目列表" name="first"> -->
			<div style="position: relative;display: inline-block;margin: 5px;">
				<span>状态：</span>
				<el-select v-model="statusId" style="width:150px;margin-left: 10px;" @change="select1(status)">
					<el-option v-for="item in statuss" :key="item.value" :label="item.title" :value="item.id">
					</el-option>
				</el-select>&nbsp;&nbsp;&nbsp;
			</div>
			<div style="position: relative;display: inline-block;margin: 5px;">
				<span>用户名称：</span>
				<el-input style="width: 200px;" @keydown.enter.native="select1" placeholder="请输入用户名称" v-model="search">
				</el-input>&nbsp;&nbsp;
			</div>
			<div style="position: relative;display: inline-block;margin: 5px;">
				<span>电话：</span>
				<el-input style="width: 200px;" @keydown.enter.native="select1" placeholder="请输入电话" v-model="phone">
				</el-input>&nbsp;&nbsp;
			</div>
			<div style="position: relative;display: inline-block;margin: 5px;">
				<span>公司名称：</span>
				<el-input style="width: 200px;" @keydown.enter.native="select1" placeholder="请输入公司名称"
					v-model="companyName">
				</el-input>&nbsp;&nbsp;
			</div>
			<div style="display: inline-block;margin: 5px;">
				<el-button style="margin-left:15px;" size="mini" type="primary" icon="document" @click="select1">查询
				</el-button>
				<el-button style="margin-left:15px;" size="mini" type="primary" icon="document" @click="cleans">重置
				</el-button>
			</div>
			<el-table v-loading="tableDataLoading" :data="tableData.records">
				<el-table-column prop="postPushId" label="编号" width="80" fixed="left">
				</el-table-column>
				<el-table-column prop="companyName" label="公司名称" width="100" fixed="left">
				</el-table-column>
				<el-table-column prop="projectType" label="项目类型" width="150">
				</el-table-column>
				<el-table-column prop="projectName" label="项目甲方" width="150">
				</el-table-column>
				<el-table-column prop="projectDayNum" label="工期(月)" width="150">
				</el-table-column>
				<el-table-column prop="projectAward" label="项目福利" width="100">
				</el-table-column>
				<el-table-column prop="address" label="地址" width="100">
				</el-table-column>
				<el-table-column prop="details" label="详细地址" width="150">
				</el-table-column>
				<el-table-column prop="construction" label="施工阶段" width="150">
				</el-table-column>
				<el-table-column prop="manning" label="岗位描述" width="150">
				</el-table-column>
				<el-table-column prop="userName" label="用户名称" width="140">
				</el-table-column>
				<el-table-column prop="phone" label="电话" width="140">
				</el-table-column>
				<el-table-column prop="email" label="电子邮箱" width="100">
				</el-table-column>
				<el-table-column prop="payMoney" label="支付定金" width="100">
				</el-table-column>
				<!-- <el-table-column prop="status" label="是否推荐" width="100" fixed="right">
					<template slot-scope="scope">
						<el-switch v-model="scope.row.isRecommend"
							:disabled="!isAuth('locality:update')" @change="change3(scope.row.isRecommend,scope.row)"
							:active-value="openValue" :inactive-value="closeValue" active-color="#13ce66"
							inactive-color="#ff4949">
						</el-switch>
					</template>
				</el-table-column> -->
				<el-table-column prop="status" label="状态" width="100" fixed="right">
					<template slot-scope="scope">
						<span style="color: #4f9dec;" v-if="scope.row.status === 1 ">待审核</span>
						<!-- <el-switch v-if="scope.row.status ==0 || scope.row.status ==2" v-model="scope.row.status"
							:disabled="!isAuth('locality:update')" @change="change3(scope.row.state,scope.row)"
							:active-value="openValue" :inactive-value="closeValue" active-color="#13ce66"
							inactive-color="#ff4949">
						</el-switch> -->
						<span style="color: #4f9dec;" v-if="scope.row.status === 2 ">正常</span>
						<span style="color: #4f9dec;" v-if="scope.row.status === 3 ">完成</span>
						<span style="color: #4f9dec;" v-if="scope.row.status === 4 ">未完成</span>
						<span style="color: #999;" v-if="scope.row.status === 5 ">已取消</span>
						<span style="color: #999;" v-if="scope.row.status === 6 ">拒绝</span>
					</template>
				</el-table-column>
				<el-table-column prop="updateTime" label="更新时间" width="180">
				</el-table-column>
				<el-table-column prop="createTime" label="创建时间" width="180">
				</el-table-column>
				<el-table-column label="操作" prop="id" width="100" fixed='right' align="center">
					<template slot-scope="scope">
						<el-button size="mini" type="primary" v-if="scope.row.status === 1 "
							@click="shenhe( scope.row)" style="margin: 5px;">项目审核</el-button>
						<el-button size="mini" type="primary" @click="delClicks(scope.row)" style="margin: 5px;">
							项目详情
						</el-button>
						<el-button size="mini" type="primary" v-if="scope.row.status === 2 "
							:disabled="!isAuth('locality:update')" style="margin: 5px;" @click="wanchengBtn(scope.row)">
							解冻定金
						</el-button>

						<el-button size="mini" type="danger" :disabled="!isAuth('locality:delete')"
							v-if="scope.row.status != 6 && scope.row.status != 5" @click="choidelete(scope.row)"
							style="margin: 5px;">删除项目
						</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div style="text-align: center;margin-top: 10px;">
				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
					:page-sizes="[10, 20, 30, 40]" :page-size="limit" :current-page="page"
					layout="total,sizes, prev, pager, next" :total="tableData.total">
				</el-pagination>
			</div>
		<!-- </el-tab-pane> -->

		<!-- 服务审核弹框 -->
		<el-dialog title="项目审核" :visible.sync="dialogFormVisible8" center>
			<el-radio-group v-model="radio" style="width: 100%;margin-bottom: 30px;margin-left: 200px;">
				<el-radio :label="1">通过</el-radio>
				<el-radio :label="2">驳回</el-radio>
			</el-radio-group>
			<div style="margin-bottom: 10px;">
				<span style="width: 200px;display: inline-block;text-align: right;">审核理由：</span>
				<el-input style="width:50%;" v-model="contents" type="text" placeholder="请输入审核理由"></el-input>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogFormVisible8 = false">取 消</el-button>
				<el-button type="primary" @click="refuseto()">确 定</el-button>
			</div>
		</el-dialog>
		<!-- 完成状态弹框 -->
		<el-dialog title="完成状态" :visible.sync="dialogFormVisible1" center>
			<el-radio-group v-model="radio" style="width: 100%;margin-bottom: 30px;margin-left: 200px;">
				<el-radio :label="3">已完成</el-radio>
				<el-radio :label="4">未完成</el-radio>
			</el-radio-group>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogFormVisible1 = false">取 消</el-button>
				<el-button type="primary" @click="wanchengBtn()">确 定</el-button>
			</div>
		</el-dialog>
	<!-- </el-tabs> -->
	</div>
</template>

<script>
	export default {

		data() {
			return {
				limit: 10,
				page: 1,
				openValue:2,
				closeValue:1,
				activeName: 'first',
				tableDataLoading: false,
				dialogFormVisible: false,
				dialogFormVisible1: false,
				dialogFormVisible8: false,
				tableData: {},
				radio: 1,
				contents: '',
				statuss: [{
						id: '',
						title: '全部'
					},
					{
						id: 1,
						title: '待审核'
					},
					{
						id: 2,
						title: '正常'
					},
					{
						id: 3,
						title: '完成'
					},
					{
						id: 4,
						title: '未完成'
					},
					{
						id: 5,
						title: '已取消'
					},
					{
						id: 6,
						title: '拒绝'
					}
				],
				statusId: '',
				phone: '', //电话
				companyName: '',
				search: '',
			}
		},
		methods: {

			handleSizeChange(val) {
				this.limit = val
				this.dataSelect()
			},
			handleCurrentChange(val) {
				this.page = val
				this.dataSelect()
			},

			// tabs切换
			handleClick(tab, event) {
				if (tab._props.label == '项目列表') {
					this.page = 1
					this.limit = 10
					this.dataSelect()
				}
			},


			// 查询
			select1() {
				this.page = 1
				this.limit = 10
				this.dataSelect()
			},
			cleans() {
				this.page = 1
				this.phone = ''
				this.statusId = ''
				this.search = ''
				this.companyName = ''
				this.dataSelect()
			},

			// 获取派单数据列表
			dataSelect() {
				this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('postPush/selectPostPushList'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.page,
						'limit': this.limit,
						'phone': this.phone,
						'status': this.statusId,
						'userName': this.search,
						'companyName': this.companyName,
						'classify': 1

					})
				}).then(({
					data
				}) => {
					this.tableDataLoading = false
					let returnData = data.data
					this.tableData = returnData
				})
			},

			// 查看详情
			delClicks(row) {
				this.$router.push({
					path: '/postPushDetails',
					query: {
						postPushId: row.postPushId
					}
				})
			},
			// 审核
			shenhe(row) {
				this.shenheId = row.postPushId
				this.dialogFormVisible8 = true
			},
			// 提交审核
			refuseto(row) {
				
				if (this.contents == '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请输入审核理由',
						type: 'warning'
					})
					return
				} else {
					let ids = this.shenheId
					let status = this.radio
					let content = this.contents
					this.$http({
						url: this.$http.adornUrl('postPush/auditPostPush'),
						method: 'post',
						params: this.$http.adornParams({
							'ids': ids,
							'status': status,
							'content': content
						})
					}).then(({
						data
					}) => {
						this.dialogFormVisible8 = false
						this.$message({
							message: '审核完成',
							type: 'success',
							duration: 1500,
							onClose: () => {
								this.radio = 0
								this.contents = ''
								this.dataSelect()
								this.dataSelectDzh()
							}
						})
					})
				}
			},
			// 完成状态弹框
			wanchengCompile(row) {
				this.radio = ''
				this.shenheId = row.postPushId
				this.dialogFormVisible1 = true

			},
			wanchengBtn(row) {
				// if (this.radio == '') {
				// 	this.$notify({
				// 		title: '提示',
				// 		duration: 1800,
				// 		message: '请选择完成状态',
				// 		type: 'warning'
				// 	})
				// 	return
				// }
				this.$confirm(`定金解冻后，定金金额将会退回到用户钱包，是否继续解冻？`, '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
							this.$http({
									// url: this.$http.adornUrl('postPush/updateResumesPushStatus'),
									url: this.$http.adornUrl('postPush/acquittalPostPush'),
										method: 'post',
										params: this.$http.adornParams({
											'postPushId': row.postPushId
										})
									}).then(({
									data
								}) => {
									if (data.code == 0) {
										this.dialogFormVisible1 = false
										this.$message({
											message: '操作完成',
											type: 'success',
											duration: 1500,
											onClose: () => {
												this.dataSelect()
											}
										})
									} else {
										this.$message({
											title: '提示',
											duration: 1800,
											message: data.msg,
											type: 'warning'
										});
									}

								})
							}).catch(() => {})
					},
					// 删除信息
					choidelete(row) {
						this.$confirm(`删除项目后，定金金额将会退回到用户钱包，是否删除项目？`, '提示', {
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							type: 'warning'
						}).then(() => {
							this.$http({
								url: this.$http.adornUrl('postPush/cleanPostPush'),
								method: 'post',
								params: this.$http.adornParams({
									'postPushId': row.postPushId
								})
							}).then(({
								data
							}) => {
								if (data.code == 0) {
									this.$message({
										message: '删除成功',
										type: 'success',
										duration: 1500,
										onClose: () => {
											this.dataSelect()
										}
									})
								} else {
									this.$message({
										message: data.msg,
										type: 'warning',
										duration: 1500,
										onClose: () => {}
									})
								}

							})
						}).catch(() => {})
					},
					change3(isRecommend,row){
						this.$http({
							url: this.$http.adornUrl('postPush/updatePostPushIsRecommend'),
							method: 'post',
							params: this.$http.adornParams({
								'postPushId': row.postPushId
							})
						}).then(({
							data
						}) => {
							if (data.code == 0) {
								this.$message({
									message: '修改成功',
									type: 'success',
									duration: 1500,
									onClose: () => {
										this.dataSelect()
									}
								})
							} else {
								this.$message({
									message: data.msg,
									type: 'warning',
									duration: 1500,
									onClose: () => {}
								})
							}
						
						})
					},
					// 获取精准推送待审核数据
					dataSelectDzh() {
						this.$http({
							url: this.$http.adornUrl('postPush/selectPostPushList'),
							method: 'get',
							params: this.$http.adornParams({
								'page':1,
								'limit': 10,
								'userName': '',
								'classify': 1,
								'status': 1,
								'companyName': '',
								'phone': '',
							})
						}).then(({
							data
						}) => {
							if(data.data){
								this.$cookie.set('numberDzh', data.data.total)
							}
						})
					},
			},
			mounted() {
				var statusN =  this.$route.query.status
				if(statusN){
					this.statusId = Number(statusN) 
				}else{
					this.statusId = ''
				}
				// this.homeSelect()
				this.dataSelect()
			}
		}
</script>

<style>

</style>
