<template>
	<view>
		<view class="box">
			<view class="flex align-center justify-between margin-bottom" @click="getPost">
				<view class=" text-bold">岗位</view>
				<view class="text-right flex align-center ">
					<view class="">{{postName?postName:'请选择岗位'}}</view>
					<view class="margin-left-sm">
						<image src="../../static/images/my/right_icon.png" style="width: 12upx;height: 21upx;"></image>
					</view>
				</view>
			</view>
			<view class="margin-tb-sm" style="width: 100%;height: 1rpx;background: #F2F2F2;"></view>
			<view class="flex align-center justify-between" @click="getPostlist">
				<view class=" text-bold">专业</view>
				<view class="text-right flex align-center padding-tb-sm">
					<view>{{rulePostName? rulePostName:'请选择专业'}}</view>
					<view class="margin-left-sm">
						<image src="../../static/images/my/right_icon.png" style="width: 12upx;height: 21upx;"></image>
					</view>
				</view>
			</view>
			<view class="margin-tb-sm" style="width: 100%;height: 1rpx;background: #F2F2F2;"></view>
			<view class="flex align-center justify-between" @click="getMonyList">
				<view class=" text-bold">工资</view>
				<view class="text-right flex align-center padding-tb-sm">
					<view>{{postPrice? postPrice:'请选择薪资'}}</view>
					<view class="margin-left-sm">
						<image src="../../static/images/my/right_icon.png" style="width: 12upx;height: 21upx;"></image>
					</view>
				</view>
			</view>
			<view class="margin-tb-sm" style="width: 100%;height: 1rpx;background: #F2F2F2;"></view>
			<view class="flex align-center justify-between">
				<view class=" text-bold">人数</view>
				<view class="text-right flex align-center ">
					<u-input v-model="postPeopleNum" type="number" placeholder="请填写人数" placeholder-style="color:#999999;"
						@input="input" :clearable="false" />
					<view class="margin-left-sm">
						<image src="../../static/images/my/right_icon.png" style="width: 12upx;height: 21upx;"></image>
					</view>
				</view>
			</view>
			<view class="margin-tb-sm" style="width: 100%;height: 1rpx;background: #F2F2F2;"></view>
			<view class="flex align-center justify-between" @click="SexShow=true">
				<view class=" text-bold">性别</view>
				<view class="text-right flex align-center margin-tb-sm">
					<view v-if="postSex">{{postSex}}</view>
					<view v-else style="color:#999999;">请选择性别</view>
					<view class="margin-left-sm">
						<image src="../../static/images/my/right_icon.png" style="width: 12upx;height: 21upx;"></image>
					</view>
				</view>
			</view>
			<view class="margin-tb-sm" style="width: 100%;height: 1rpx;background: #F2F2F2;"></view>
			<view class="flex align-center justify-between" @click="getAgeList">
				<view class=" text-bold">年龄</view>
				<view class="text-right flex align-center padding-tb-sm">
					<view>{{postAge? postAge:'请选择年龄'}}</view>
					<view class="margin-left-sm">
						<image src="../../static/images/my/right_icon.png" style="width: 12upx;height: 21upx;"></image>
					</view>
				</view>
			</view>
			<view class="margin-tb-sm" style="width: 100%;height: 1rpx;background: #F2F2F2;"></view>
			<view class="flex align-center justify-between" @click="getxueliList">
				<view class=" text-bold">学历要求</view>
				<view class="text-right flex align-center padding-tb-sm">
					<view>{{education? education:'请选择学历'}}</view>
					<view class="margin-left-sm">
						<image src="../../static/images/my/right_icon.png" style="width: 12upx;height: 21upx;"></image>
					</view>
				</view>
			</view>

		</view>

		<view class="margin-lr " style="color: #82A9FE;" v-if="offlinePrice">
			当前岗位线下需要支付{{offlinePrice?offlinePrice:'0'}}元，支付后保证金会退回账户。</view>

		<!-- 求职岗位 -->
		<u-select v-model="postShow" :list="postlist" @confirm="postConfirm"></u-select>

		<!-- 专业 -->
		<u-select v-model="show" :list="ErjiList" @confirm="postlistConfirm"></u-select>
		<!-- 性别 -->
		<u-select v-model="SexShow" :list="list" @confirm="SexConfirm"></u-select>

		<!-- 薪资 -->
		<u-select v-model="monyShow" :list="monyList" @confirm="moneyConfirm"></u-select>
		<!-- 年龄 -->
		<u-select v-model="ageShow" :list="ageList" @confirm="ageConfirm"></u-select>
		<!-- 学历选择 -->
		<u-select v-model="educationShow" :list="educationList" @confirm="educationyConfirm"></u-select>
		<view class="subbtn" @click="save">
			<view class="padding-left flex align-center" style="color: red;">
				<!-- <view class="text-df">￥</view> -->
				<view style="font-size: 48upx;">{{customizationPrices?customizationPrices:'0'}}<span style="font-size:24rpx;margin-left: 5rpx;margin-right: 5rpx;">积分</span></view>
				<view class=" margin-left-xs" style="color:#82A9FE;font-size: 22rpx;">*发布当前岗位需支付的保证金价格</view>
			</view>
			<view class="btn">保存</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				educationList:[],
				educationShow:false,
				education:'',//学历
				ageShow:false,
				ageList:[],
				monyShow:false,
				monyList:[],//薪资列表
				postName: '', //岗位名称
				rulePostName: '', //岗位职称
				rulePostId: '',
				postMajor: [], //岗位专业
				postPeopleNum: '', //岗位人数
				postSex: '', //性别
				postAge: '', //年龄段
				postPrice: '', //岗位工资
				postShow: false, //一级岗位
				postlist: [],
				show: false, //二级岗位
				ErjiList: [],
				price: '',
				totalPrice: '',
				member: '', //1 会员
				SexShow: false, //性别
				list: [{
					value: '1',
					label: '男'
				}, {
					value: '2',
					label: '女'
				}, {
					value: '3',
					label: '男女不限'
				}],
				postDetailsList: [],
				postDetailsIndex: '',
				classify: '', //1.定制化  2.精准推送
				offlinePrice: '', //线下价格
				customizationPrice: '', //保证金价格
				customizationPrices: '', //保证金价格
			}
		},
		onLoad(e) {
			this.member = uni.getStorageSync('member')
			if(uni.getStorageSync('postDetailsList')){
				this.postDetailsList = uni.getStorageSync('postDetailsList')
			}
			if(e.index){ //修改
				this.postDetailsIndex = e.index
				let obj = this.postDetailsList[this.postDetailsIndex]
				this.postName = obj.postName
				this.rulePostName = obj.rulePostName
				this.ruleClassifyId = obj.ruleClassifyId
				this.rulePostId = obj.rulePostId
				this.getPostList()
				this.postPrice = obj.postPrice
				this.postPeopleNum = obj.postPeopleNum
				this.postSex = obj.postSex
				this.postAge = obj.postAge
				this.education = obj.education
				this.offlinePrice = obj.offlinePrice
				this.customizationPrices = obj.customizationPrices
				this.customizationPrice = obj.customizationPrice
			}
			
		},
		onShow() {

		},
		methods: {
			//学历选择
			educationyConfirm(e){
				this.education = e[0].value
			},
			//年龄选择
			ageConfirm(e){
				this.postAge = e[0].value
			},
			//学历
			getxueliList(){
				this.$Request.get('/app/dict/list', {
					type:'学历'
				}).then(res => {
					if (res.code == 0) {
						let arr = res.data
						arr = JSON.parse(JSON.stringify(arr).replace(/code/g,'label'))
						this.educationList = arr
						this.educationShow = true
						
					}
				})
			},
			//年龄
			getAgeList(){
				this.$Request.get('/app/dict/list', {
					type:'年龄'
				}).then(res => {
					if (res.code == 0) {
						let arr = res.data
						arr = JSON.parse(JSON.stringify(arr).replace(/code/g,'label'))
						this.ageList = arr
						this.ageShow = true
						
					}
				})
			},
			moneyConfirm(e){
				console.log(e)
				this.postPrice = e[0].value
			},
			//薪资列表
			getMonyList(){
				this.$Request.get('/app/dict/list', {
					type:'薪资'
				}).then(res => {
					if (res.code == 0) {
						let arr = res.data
						arr = JSON.parse(JSON.stringify(arr).replace(/code/g,'label'))
						this.monyList = arr
						this.monyShow = true
						
					}
				})
			},
			input(e) {
				if(this.postPeopleNum==''){
					this.customizationPrices = this.customizationPrice
				}else{
					this.customizationPrices = parseInt(this.customizationPrice * this.postPeopleNum).toFixed(0)
				}
				
			},
			SexConfirm(e) { //选择性别
				this.postSex = e[0].label
			},
			//获取一级岗位
			getPost() {
				this.getClassifyList()
			},
			//获取岗位
			getClassifyList() {
				let data = {
					status: 1
				}
				this.$Request.get('/app/rule/selectRuleClassifyList', data).then(res => {
					if (res.code == 0) {
						var arr = []
						res.data.forEach((d, index) => {
							var data = {}
							data.label = d.ruleClassifyName
							data.value = d.ruleClassifyId
							data.offlinePrice = d.offlinePrice
							data.offlineMemberPrice = d.offlineMemberPrice
							data.customizationPrice = d.customizationPrice
							data.customizationMemberPrice = d.customizationMemberPrice
							arr.push(data)
						})
						this.postlist = arr
						this.postShow = true
					}
				})
			},
			postConfirm(e) {
				this.postName = e[0].label
				this.ruleClassifyId = e[0].value
				this.postlist.map(res=>{
					if(this.ruleClassifyId==res.value){
						if(this.member>0){//会员
							this.offlinePrice = res.offlineMemberPrice //会员线下价格
							this.customizationPrice = res.customizationMemberPrice //会员定金单价
						}else{//非会员
							this.offlinePrice = res.offlinePrice //非会员线下价格
							this.customizationPrice = res.customizationPrice //非会员定金单价
						}
					}
				})
				this.getPostList()
			},
			getPostlist() {
				this.show = true
			},
			//获取专业
			getPostList() {
				let data = {
					ruleClassifyId: this.ruleClassifyId
				}
				this.$Request.post('/app/rule/selectRulePostList', data).then(res => {
					if (res.code == 0) {
						var arr = []
						res.data.forEach((d, index) => {
							var data = {}
							data.label = d.rulePostName
							data.value = d.rulePostId
							arr.push(data)
						})
						this.ErjiList = arr
					}
				})
			},
			postlistConfirm(e) {
				this.rulePostName = e[0].label //专业名称
				this.rulePostId = e[0].value//专业id
			},
			save() {
				if (!this.postName) {
					uni.showToast({
						title: '请选择岗位',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.rulePostName) {
					uni.showToast({
						title: '请选择专业',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.postPrice) {
					uni.showToast({
						title: '请选择工资',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.postPeopleNum) {
					uni.showToast({
						title: '请填写人数',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.postSex) {
					uni.showToast({
						title: '请选择性别',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.postPrice) {
					uni.showToast({
						title: '请填写工资',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.postAge) {
					uni.showToast({
						title: '请选择年龄',
						icon: 'none',
						duration: 1000
					})
					return
				}
				if (!this.education) {
					uni.showToast({
						title: '请选择学历',
						icon: 'none',
						duration: 1000
					})
					return
				}
				let data = {
					postName: this.postName, //岗位名称
					ruleClassifyId: this.ruleClassifyId,
					rulePostName: this.rulePostName, //岗位职称
					rulePostId: this.rulePostId,
					postPeopleNum: this.postPeopleNum, //岗位人数
					postSex: this.postSex, //性别
					postAge: this.postAge, //年龄段
					offlinePrice: this.offlinePrice, //线下价格
					postPrice:this.postPrice,//薪资
					education:this.education,//学历要求
					customizationPrice: this.customizationPrice, //保证金价格
					customizationPrices:this.customizationPrices,//总积分
				}
				if(this.postDetailsIndex){
					this.postDetailsList[this.postDetailsIndex] = data //修改的时候直接替换数组
				}else{
					this.postDetailsList.push(data) //否则直接追加
				}
				console.log(this.postDetailsList)
				uni.setStorageSync('postDetailsList', this.postDetailsList)
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="less">
	page {
		background: #F2F2F7;
	}

	.box {
		background: #FFFFFF;
		border-radius: 24upx;
		margin: 30upx;
		padding: 30upx;
	}

	.u-input__input {
		text-align: right !important;
	}

	.subbtn {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #fff;
		border-radius: 10upx;
		height: 90upx;
		// padding: 30upx 0upx;
		color: #000;
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 99;

	}

	.btn {
		background: #82A9FE;
		color: #FFFFFF;
		width: 30%;
		height: 90upx;
		line-height: 90upx;
		text-align: center;
	}
</style>
