<template>
	<view>
		<view class="industry">
			<view class="left">
				<view :class="'li dflex' + (checkIndex == index ? ' active':'')" v-for="(item,index) in industryList" :key="index" @click="checkIndustry(index)">
					{{item.name}}
				</view>
			</view>
			<view class="right">
				<view :class="'li' + (arrayIndex == index ? ' active':'')" v-for="(item,index) in rightArray" :key="index" @click="checkArray(index)">
					{{item.name}}
				</view>
			</view>
		</view>
		<view class="btn" @click="save()">确定</view>
	</view>
</template>

<script>
const req = require('../../utils/request.js');
const api = require('../../utils/api.js');
const util = require('../../utils/util.js');
var app = getApp();
export default {
	data() {
		return {
			industryList: [],
			checkIndex: 0,
			rightArray: [],
			arrayIndex: -1,
			industryName: '',
			tradeId: '',
			isPoistion: false
		};
	},
	onLoad(options) {
		this.isPoistion = options.isPoistion
		var titleTxt = '';
		if (this.isPoistion) {
			titleTxt = '选择职位';
			this.getPositionList();
		} else {
			titleTxt = '选择行业';
			this.getIndustry();
		}
		uni.setNavigationBarTitle({
			title: titleTxt
		});
	},
	methods: {
		getPositionList() {
			req.getRequest(api.api_position_list, {}, data => {
				this.industryList = data;
				this.rightArray = data[0].children;
			});
		},
		getIndustry() {
			req.getRequest(api.company_industry, {}, json => {
				this.industryList = json;
				this.rightArray = json[0].children;
			});
		},
		checkIndustry(index){
			if(this.checkIndex == index) return false;
			this.checkIndex = index;
			this.rightArray = this.industryList[this.checkIndex].children;
			this.arrayIndex=-1;
		},
		checkArray(index){
			if(this.arrayIndex == index) return false;
			this.arrayIndex = index;
			this.industryName = this.rightArray[this.arrayIndex].name;
			this.tradeId = this.rightArray[this.arrayIndex].id;
		},
		save(){
			if(this.arrayIndex < 0) return req.msg('请选择行业');
			let pages = getCurrentPages();             //获取所有页面栈实例列表
			let nowPage = pages[ pages.length - 1];    //当前页页面实例
			let prevPage = pages[ pages.length - 2 ];  //上一页页面实例
			if(this.isPoistion){
				prevPage.$vm.job = this.industryName;
			}else{
				prevPage.$vm.industryName = this.industryName;         //修改上一页面的 couponNumber 参数值为 value
				prevPage.$vm.tradeId = this.tradeId;         //修改上一页面的 couponNumber 参数值为 value
			}
			uni.navigateBack({                         //uni.navigateTo跳转的返回，默认1为返回上一级
				delta: 1
			});
		}
	}
};
</script>

<style>
	@import "./industry.css";
</style>
