<template>
	<div>
				<div style="display: inline-block;">
					<div style="position: relative;display: inline-block;margin: 5px;">
						<span>岗位偏好名称：</span>
						<el-input style="width: 200px;" @keydown.enter.native="select" placeholder="请输入岗位偏好名称"
							v-model="preferenceNameS">
						</el-input>&nbsp;&nbsp;
					</div>
					<el-button style='margin: 5px;' size="mini" type="primary" icon="document" @click="select">查询
					</el-button>
					<el-button style='margin: 5px;' size="mini" type="primary" icon="document" @click="cleans">重置
					</el-button>
					<el-button style="margin:10px;" size="mini" type="primary" icon="document"
						:disabled="!isAuth('positionList:add')" @click="classAdd(1)">添加
					</el-button>
				</div>
				<!-- 职业方向-->
				<el-table v-loading="tableDataLoading" :data="tableData.records">
					<el-table-column prop="postPreferenceId" label="编号" width="200">
					</el-table-column>
					<el-table-column prop="ruleClassifyName" label="岗位名称">
					</el-table-column>
					<el-table-column prop="preferenceName" label="岗位偏好名称" width="200">
					</el-table-column>
					<el-table-column prop="isUse" label="启用">
						<template slot-scope="scope">
							<el-switch v-model="scope.row.isUse" @change="change(scope.row.postPreferenceId,scope.row.isUse,scope.row)"
								:disabled="!isAuth('positionList:update')" :active-value="openValue"
								:inactive-value="closeValue" active-color="#13ce66" inactive-color="#ff4949">
							</el-switch>
						</template>
					</el-table-column>
					<el-table-column label="操作" prop="id" width="200" fixed='right' align="center">
						<template slot-scope="scope">
							<el-button size="mini" type="primary" :disabled="!isAuth('positionList:update')" style="margin: 5px;"
								@click="classAdd(0,scope.row)">修改
							</el-button>
							<el-button size="mini" type="danger" :disabled="!isAuth('positionList:delete')" style="margin: 5px;"
								@click="classdelete(scope.row)">删除
							</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,jumper" :total="tableData.total">
					</el-pagination>
				</div>
			<!-- 添加、修改职业偏好 -->
			<el-dialog :title="titles" :visible.sync="dialogFormVisible9" center>
				<div style="margin-bottom: 10px;position: relative;">
					<div style="width: 200px;display: inline-block;text-align: right;position: absolute;top: 0;">所属岗位：</div>
					<div class="ruleitem" style="display: inline-block;margin-left: 200px;">
						<div>
							<span>一级岗位分类：<el-radio v-for="(item,index) in yijiData" :key="index" v-model="yijiid"
									:label="item.ruleClassifyId"
									@change="yijiBtn(yijiid)">{{item.ruleClassifyName}}</el-radio></span>
						</div>
						<div v-if="yijiid!=''">
							<span>二级级岗位分类：<el-radio v-for="(item,index) in erjiData" :key="index" v-model="erjiId"
									:label="item.ruleClassifyId"
									@change="erjiBtn(erjiId)">{{item.title}}</el-radio></span>
						</div>
						<div v-if="erjiId!=''">
							<span>岗位名称：<el-radio v-for="(item,index) in sanjiData" :key="index" v-model="sanjiTypr"
									:label="item.ruleClassifyId">{{item.ruleClassifyName}}</el-radio></span>
						</div>
					</div>
				</div>

				<div style="margin-bottom: 10px;">
					<span style="width: 200px;display: inline-block;text-align: right;">职业偏好名称：</span>
					<el-input style="width:50%;" v-model="preferenceName" type="text" placeholder="请输入职业偏好名称"></el-input>
				</div>

				<div style="margin-bottom: 10px;display:flex;">
					<span style="width: 200px;display: inline-block;text-align: right;">状态：</span>
					<el-radio-group v-model="gameStatus">
						<el-radio :label="1">启用</el-radio>
						<el-radio :label="0">禁用</el-radio>
					</el-radio-group>
				</div>
				<div slot="footer" class="dialog-footer">
					<el-button @click="dialogFormVisible9 = false">取 消</el-button>
					<el-button type="primary" @click="refuseto1()">确 定</el-button>
				</div>
			</el-dialog>

		<!-- </el-tabs> -->
	</div>
</template>

<script>
	export default {

		data() {
			return {
				size: 10,
				page: 1,
				size1: 10,
				page1: 1,
				limit: 10,
				openValue: 1,
				closeValue: 0,
				openValue2: 1,
				closeValue2: 0,
				title: '',
				type: '',
				name: '',
				activeName: 'first',
				tableDataLoading: true,
				tableDataLoading4: false,
				dialogFormVisible9: false,
				dialogVisible: false,
				tableData: {},
				titles: '添加服务分类',
				ruleClassifyId: '',
				gameStatus: 1,
				postPreferenceId: '',
				preferenceName: '',
				stationList:{},
				flname:'',
				parentId:0,
				ruleClassifyName: '',
				yijiid: '',
				erjiId: '',
				yijiData: [],
				erjiData: [],
				sanjiData: [],
				erjiTypr: true,
				sanjiTypr: '',
				preferenceNameS:'',
			}
		},
		methods: {
			handleSizeChange(val) {
				this.limit = val
				this.classSelect()
			},
			handleCurrentChange(val) {
				this.page = val
				this.classSelect()
			},
			handleClick(tab, event) {

				this.page = 1
				if (tab._props.label == '岗位分类') {

					this.classSelect()
				}
			},
			// 获取服务分类数据
			classSelect() {
        		this.tableDataLoading = true
				this.$http({
					url: this.$http.adornUrl('postPreference/getPostPreferenceList'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.page,
						'limit': this.limit,
						'preferenceName': this.preferenceNameS,
					})
				}).then(({
					data
				}) => {
					if (data.code == 0) {
						this.tableDataLoading = false
						let returnData = data.data
						this.tableData = returnData
					} else {
						this.$notify({
							title: '提示',
							duration: 1800,
							message: data.msg,
							type: 'warning'
						});
					}


				})
			},

			// 添加服务分类
			classAdd(index,row) {  // index 1添加职业方向 2添加职业技能, 0修改   // jibie 1职业方向 2职业技能
				console.log(index,'row', row)
				this.classSelectYiji();
				if (index==0) {
					this.titles = '修改职业偏好'
					this.postPreferenceId = row.postPreferenceId
					this.preferenceName = row.preferenceName
					this.ruleClassifyId = row.ruleClassifyId
					this.sanjiTypr = ''
					this.erjiId = ''
					this.yijiid = ''
					this.gameStatus = row.isUse

				} else {
					this.titles = '添加职业偏好'
					this.postPreferenceId=''
					this.ruleClassifyId = ''
					this.preferenceName	 = ''
					this.gameStatus = 1
					this.sanjiTypr = ''
					this.erjiId = ''
					this.yijiid = ''

				}
				this.dialogFormVisible9 = true

			},
			// 获取一级岗位数据
			classSelectYiji() {
				this.$http({
					url: this.$http.adornUrl('admin/rule/adminGetClassifyList'),
					method: 'get',
					params: this.$http.adornParams({

					})
				}).then(({
					data
				}) => {
					if (data.code == 0) {
						this.tableDataLoading = false
						let returnData = data.data
						this.yijiData = returnData.records
						// this.erjiTypr = false
						if (this.title == '修改') {
							this.classSelectErT()
						}
					} else {
						this.$notify({
							title: '提示',
							duration: 1800,
							message: data.msg,
							type: 'warning'
						});
					}

				})
			},
			// 获取二级岗位数据
			classSelectErT() {
				this.$http({
					url: this.$http.adornUrl('admin/rule/adminGetParentId'),
					method: 'get',
					params: this.$http.adornParams({
						'parentId': this.yijiid,
						'industryName': '',
					})
				}).then(({
					data
				}) => {
					if (data.code == 0) {
						this.tableDataLoading = false
						let returnData = data.data
						this.erjiData = returnData.records
					} else {
						this.$notify({
							title: '提示',
							duration: 1800,
							message: data.msg,
							type: 'warning'
						});
					}

				})
			},
			// 选择一级岗位分类
			yijiBtn(yijiid) {
				this.erjiId = ''
				this.sanjiTypr = ''
				this.classSelectErT()
			},
			// 选择二级岗位分类
			erjiBtn(erjiId) {
				this.sanjiTypr = ''
				for (var i in this.erjiData) {
					if (this.erjiId == this.erjiData[i].ruleClassifyId) {
						if (this.erjiData[i].childrens) {
							this.sanjiData = this.erjiData[i].childrens
						} else {
							this.sanjiData = []
						}

					}
				}
			},
			// 查询
			select() {
				this.page = 1
				this.limit = 10
				this.classSelect()
			},
			// 重置
			cleans() {
				this.preferenceNameS = ''
				// this.userName = ''
				// this.companyNameT = ''
				// this.startTime = ''
				// this.endTime = ''
				this.classSelect()
			},
			// 启用与否
			change(id, isUse,row) {
				this.$http({
					url: this.$http.adornUrl('postPreference/updatePostPreference'),
					method: 'post',
					// data: this.$http.adornData({
					params: this.$http.adornParams({
						'isUse': isUse,
						'preferenceName': row.preferenceName,
						'ruleClassifyId': row.ruleClassifyId,
						'postPreferenceId': row.postPreferenceId,
					})
				}).then(({
					data
				}) => {
					if(data.code==0){
						this.$message({
							message: '操作成功',
							type: 'success',
							duration: 1500,
							onClose: () => {
								this.classSelect()
							}
						})
					}else{
							this.$message({
								message: data.msg,
								type: 'warning',
								duration: 1500,
								onClose: () => {
									this.classSelect()
								}
							})
						}

				})
			},
			// 提交修改、添加服务分类
			refuseto1() {

				if (this.preferenceName == '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请输入职业偏好名称',
						type: 'warning'
					})
					return
				}

				if (this.sanjiTypr == '') {
					this.$notify({
						title: '提示',
						duration: 1800,
						message: '请选择所属岗位',
						type: 'warning'
					});
					return
				}

					if (this.titles == '添加职业偏好') {
						var urls = 'postPreference/addPostPreference'
					} else {
						var urls = 'postPreference/updatePostPreference'
					}
					this.$http({
						url: this.$http.adornUrl(urls),
						method: 'post',
						params: this.$http.adornParams({
							'isUse': this.gameStatus,
							'preferenceName': this.preferenceName,
							'ruleClassifyId': this.sanjiTypr,
							'postPreferenceId': this.postPreferenceId,
						})
					}).then(({
						data
					}) => {
						if(data.code==0){
							this.dialogFormVisible9 = false
							this.$message({
								message: '操作成功',
								type: 'success',
								duration: 1500,
								onClose: () => {
									this.classSelect()
								}
							})
						}else{
							this.$message({
								message: data.msg,
								type: 'warning',
								duration: 1500,
								onClose: () => {
								}
							})
						}

					})
			},
			// 删除分类
			classdelete(row) {
				this.$confirm(`确定删除此条信息?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http({
						url: this.$http.adornUrl('postPreference/deletePostPreferenceById'),
						method: 'get',
						params: this.$http.adornParams({
							'postPreferenceId': row.postPreferenceId
						})
					}).then(({
						data
					}) => {
						if(data.code==0){
							this.$message({
								message: '删除成功',
								type: 'success',
								duration: 1500,
								onClose: () => {
										this.classSelect()
									// this.dialogVisibleS = false
								}
							})
						}else{
							this.$message({
								message: data.msg,
								type: 'warning',
								duration: 1500,
								onClose: () => {
								}
							})
						}

					})
				}).catch(() => {})
			},

		},
		mounted() {
			this.classSelect()
		}
	}
</script>

<style>
	.customWidth {
		width: 80% !important;
	}

	.adver_main.box {
		display: block;
		max-width: 100%;
		text-align: center;
		border: 1px dotted rgba(67, 79, 103, .4);
	}

	.cards {
		padding: 0 8px;
		margin-bottom: 15px;
	}

	.adver_main.box a {
		display: flex;
		justify-content: center;
		height: 150px;
		line-height: 150px;
		text-decoration: none
	}

	.bannerManin {
		border: 1px solid #e8e8e8;
		font-size: 14px;
		padding: 0 24px;
		display: flex;
		justify-content: center;
		align-items: center;
		height: 113px;
		color: rgba(0, 0, 0, .65);
	}

	.bannerManin span {
		display: inline-block;
		margin-left: 5px;
	}

	.bannerManin img {
		width: 48px;
		height: 48px;
		border-radius: 50%;
	}

	.bannerbtn {
		display: flex;
		border-top: none !important;
		border: 1px solid #e8e8e8;
		padding: 11px;
		font-size: 14px;
		color: #3E8EF7;
	}

	.bannerbtn a {
		flex: 1;
		text-align: center;
		color: #3E8EF7 !important;
		text-decoration: none;
	}

	.imgs {
		position: relative;
		border-radius: 6px;
		width: 148px;
		height: 148px;
		margin-right: 10px;
		display: inline-block;
	}

	.dels {
		position: absolute;
		top: 0;
		left: 0;
		display: none;
	}

	.dels .el-icon-delete {
		line-height: 148px;
		padding-left: 58px;
		font-size: 25px;
		color: #fff;
	}

	.imgs:hover .dels {
		width: 100%;
		height: 100%;
		background: #000;
		display: block;
		opacity: 0.5;
	}

	.bqList {
		padding: 4px 14px;
		margin: 4px;
		border: 1px solid #efefef;
		font-size: 12px;
		color: #999;
		border-radius: 4px;
		margin-right: 15px;
	}

	.delss {
		display: none;
		position: relative;
	}

	.delss .el-icon-delete {
		position: absolute;
		top: 0;
	}

	.bqList:hover .delss {
		display: initial;
		opacity: 0.5;

	}

	.tj {
		padding: 6px !important;
		margin: 4px;
		font-size: 12px;
		border: 1px solid #ccc;
		border-radius: 4px;
	}
</style>
