// components/condition-screening/condition-screening.js
Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		// 默认城市名
		cityName: {
			type: String,
			value: '',
			observer(city_name) {
				this.setData({
					city_name
				})
			}
		},
		//地区编码
		countryCode: {
			type: String,
			value: ''
		},
		// 默认地区列表
		areaList: {
			type: Array,
			value: wx.getStorageSync('areaList')
		},
		// 是否展示地区
		show_area: {
			type: Boolean,
			value: true
		},
		// 是否展示薪资
		show_salay: {
			type: Boolean,
			value: true
		},
		// 是否展示距离
		show_distince: {
			type: Boolean,
			value: true
		},
		// 是否展示结算方式
		show_settlement: {
			type: Boolean,
			value: true
		}
	},

	/**
	 * 组件的初始数据
	 */
	data: {
		// 结算方式
		settlementMethod: [
			{
				index: '',
				name: '不限'
			},
			{
				index: 2,
				name: '日结'
			},
			{
				index: 1,
				name: '周结'
			},
			{
				index: 0,
				name: '月结'
			},
			{
				index: 3,
				name: '完工结'
			},
			{
				index: 4,
				name: '其他'
			},
		],
		showAreaList: false, // 显示地区选择开关
		showSettlement: false, // 显示地区选择开关
		totalSalary: '', //薪资待遇排序(1：正序；2：倒序)
		sort: '', //距离排序（1：正序；2：倒序）
		settle: '', //结算方式索引
		selectId: -1, //选中筛选的条件
		city_name: '' //实际显示的地区变量
	},
	/**
	 * 组件的方法列表
	 */
	methods: {
		// 显示地区选择
		showArea() {
			this.setData({
				selectId: -1,
				showSettlement: false,
				showAreaList: !this.data.showAreaList
			})
		},
		// 显示结算方式
		showSettlementMethod() {
			this.setData({
				selectId: 0,
				showSettlement: !this.data.showSettlement,
				showAreaList: false
			})
		},
		// 选择地区
		chooseArea(e) {
			const { cityname, countrycode } = e.currentTarget.dataset;
			this.setData({
				city_name: countrycode ? cityname : this.data.cityName,
				countryCode: countrycode,
				showAreaList: false,
			}, () => {
				const { countryCode, totalSalary, sort, settle } = this.data;
				this.triggerEvent('area', { countryCode, totalSalary, sort, settle })
			})
		},
		// 选择结算方式
		doSettlemethod(e) {
			const { settle } = e.currentTarget.dataset;
			this.setData({
				showSettlement: false,
				settle
			}, () => {
				const { countryCode, totalSalary, sort, settle } = this.data;
				this.triggerEvent('settlemethod', { countryCode, totalSalary, sort, settle })
			})
		},
		// 按照薪资排序
		doSalay() {
			let totalSalary = null;
			if (this.data.totalSalary == 1) {
				totalSalary = 2;
			} else {
				totalSalary = 1;
			}
			this.setData({
				selectId: 1,
				totalSalary,
				sort: '',
				showSettlement: false,
				showAreaList: false
			}, () => {
				const { countryCode, totalSalary, sort, settle } = this.data;
				this.triggerEvent('salay', { countryCode, totalSalary, sort, settle })
			})
		},
		// 按照地区排序
		doDistince() {
			let sort = null;
			if (this.data.sort == 1) {
				sort = 2;
			} else {
				sort = 1;
			}
			this.setData({
				selectId: 2,
				sort,
				totalSalary: '', //重置
				showAreaList: false,
				showSettlement: false,
			}, () => {
				const { countryCode, totalSalary, sort, settle } = this.data;
				this.triggerEvent('distince', { countryCode, totalSalary, sort, settle })
			})
		}
	}
})
