<template>
	<view>
		<view class="cu-bar search bg-gray">
			<view class="search-form round text-center">
				<text class="cuIcon-search"></text>
				<input v-model="searchval" :adjust-position="false" type="text" placeholder="请输入关键字"
					confirm-type="search" @confirm="btnSearch()"></input>
			</view>
			<view class="action" v-if="searchval!==''">
				<button class="cu-btn bg-white shadow-blur round" @click="btnSearch()">搜索</button>
			</view>
		</view>

		<view class="filterbg">
			<view class="flex justify-between solids-bottom padding bg-white">
				<view class="text-bold">
					<view class="cu-tag radius bg-red" @tap="resetFilter">重置</view>
				</view>
				<view class="flex justify-end">
					<!-- <view class="cu-tag radius bg-green" data-filterbox="rectype" @tap="showFilter">
						{{rectypelist.title}}</view> -->
					<view class="cu-tag radius bg-green" data-filterbox="wtype" @tap="showFilter">{{wtypelist.title}}
					</view>
					<view class="cu-tag radius bg-green" data-filterbox="cate" @tap="showFilter">{{catelist.title}}
					</view>
					<view class="cu-tag radius bg-green" data-filterbox="area" @tap="showFilter">{{arealist.title}}
					</view>
				</view>
			</view>

			<view class="filtercon" v-if="filterbox!==null" @click="hideFilter()">
				<view class="padding bg-white" v-if="filterbox=='rectype'" @click.stop>
					<block v-for="(item,index) in rectypelist.data" :key="index">
						<button class="cu-btn margin-lr-xs margin-tb-xs"
							@click="checkRectype(item.title,item.value)">{{item.title}}</button>
					</block>
				</view>

				<view class="padding bg-white" v-if="filterbox=='wtype'" @click.stop>
					<block v-for="(item,index) in wtypelist.data" :key="index">
						<button class="cu-btn margin-lr-xs margin-tb-xs"
							@click="checkWtype(item.title,item.value)">{{item.title}}</button>
					</block>
				</view>
				<view class="padding bg-white" v-if="filterbox=='cate'" @click.stop>
					<block v-for="(item,index) in catelist.data" :key="index">
						<button class="cu-btn margin-lr-xs margin-tb-xs"
							@click="checkCate(item.title,item.value)">{{item.title}}</button>
					</block>
				</view>

				<view class="grid margin-bottom text-left col-3 bg-white" v-if="filterbox=='area'" @click.stop>
					<view class="solids-right padding-bottom">
						<scroll-view scroll-y="true" style="height: 600rpx;">
							<view class="solid-bottom text-gray padding-lr-sm padding-tb-sm">选择市</view>
							<view class="solid-bottom padding-lr-sm padding-tb-sm" @click="checkArea(4,0)">全部</view>
							<block v-for="(item,index) in arealist.data" :key="index">
								<view class="solid-bottom padding-lr-sm padding-tb-sm" @click="checkArea(1,index)">
									{{item.title}}</view>
							</block>
						</scroll-view>
					</view>
					<view class="solids-right padding-bottom">
						<scroll-view scroll-y="true" style="height: 600rpx;">
							<view class="solid-bottom text-gray padding-lr-sm padding-tb-sm">选择区县</view>
							<block v-for="(item,index) in arealist.cityarr" :key="index">
								<view class="solid-bottom padding-lr-sm padding-tb-sm" @click="checkArea(2,index)">
									{{item.title}}</view>
							</block>
						</scroll-view>
					</view>
					<view class="padding-bottom">
						<scroll-view scroll-y="true" style="height: 600rpx;">
							<view class="solid-bottom text-gray padding-lr-sm padding-tb-sm">选择镇街</view>
							<block v-for="(item,index) in arealist.districtarr" :key="index">
								<view class="solid-bottom padding-lr-sm padding-tb-sm" @click="checkArea(3,index)">
									{{item.title}}</view>
							</block>
						</scroll-view>
					</view>
				</view>
			</view>
		</view>

		<view class="comjobsList">
			<view class="listCard" v-for="(item,index) in plist" :key="index" @tap="goDetail(item.id)">
				<view class="listCard-item">
					<image class="item-icon" :src="$getImageUrl('static/images/applet/index/cardA.png')"
						mode="widthFix"></image>
					<view class="item-content bold">{{item.title}}</view>
				</view>
				<view class="listCard-item short">
					<image class="item-icon" src="../../static/images/comJobs/icon-sum.png"
						mode="widthFix"></image>
					<view class="item-content red">{{item.zwagall}}</view>
				</view>
				<view class="listCard-item bottom">
					<image class="item-icon" :src="$getImageUrl('static/images/applet/index/cardD.png')"
						mode="widthFix"></image>
					<view class="item-content">地点：{{item.address}}</view>
				</view>
				<view class="listCard-item short bottom">
					<image class="item-icon" src="../../static/images/comJobs/icon-pageView.png"
						mode="widthFix"></image>
					<view class="item-content">浏览量：{{item.volume}}</view>
				</view>
			</view>
		</view>

		<block v-for="(item,index) in plist" :key="index" v-if="false">
			<view class="cu-card dynamic no-card solid-bottom echo-comjobs-item padding-top-sm padding-lr-sm radius">
				<view class="cu-item shadow padding-top-sm padding-bottom" @tap="goDetail(item.id)">
					<view class="padding-lr flex justify-between align-center">
						<view class="basis-lg text-bold text-df text-cut">
							{{item.title}}
							<text class="text-red text-sm" v-if="item.wtype==1">(按月)</text>
							<text class="text-red text-sm" v-if="item.wtype==2">(按时)</text>
							<text class="text-red text-sm" v-if="item.wtype==3">(按件)</text>
							<text class="text-red text-sm" v-if="item.wtype==4">(按项目)</text>
							<text class="text-sm">{{item.recruit_num}}名</text>
						</view>
						<view class="basis-sm text-cut text-right text-gray text-sm">
							<view><text class="text-red text-bold">{{item.zwagall}}</text></view>
							<view v-if="item.recruitment_cate == 2"><text
									class="text-red text-bold">悬赏{{item.retmoney}}{{item.is_pay == 1 ? '（已支付）' : ''}}</text>
							</view>
						</view>
					</view>
					<view class="padding-lr padding-tb-xs text-cut">
						<view v-for="(titem,tindex) in item.tags" :key="tindex"
							class="cu-tag light bg-blue lg echo-tags-item">{{titem}}</view>
					</view>
					<view class="padding-lr text-cut text-sm flex justify-between align-center">
						<view class="basis-lg text-df text-cut">{{item.worker.title}}</view>
						<view class="basis-sm text-cut text-right text-sm">
							浏览量:{{item.volume}}
						</view>
					</view>
					<!-- <view class="text-gray padding-lr flex align-center justify-between" @tap="goShop(item.workerid)">
						<view class="flex align-center">
							<image class="iconyrz" :src="$getImageUrl('static/images/applet/iconyrz.png')" mode="scaleToFill"></image>
							<image class="iconwyp" :src="$getImageUrl('static/images/applet/iconwyp.png')" mode="scaleToFill" v-if="item.recruitment_cate==2"></image>
						</view>
						<view class="text-gray text-right basis-xs text-sm">
							<text class="cuIcon-shop margin-right-xs text-lg"></text>
							进店
						</view>
					</view> -->
				</view>
			</view>
		</block>
		<uni-load-more :status="pstatus"></uni-load-more>
		<wxContact></wxContact>

		<view class="padding-sm"></view>
		<view class="padding-xl"></view>
		<view class="cu-bar tabbar bg-white foot">
			<view class="action text-gray" @tap="goNavPage('/pages/index/index')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/index.png"></image>
				</view>
				首页
			</view>
			<view class="action text-blue" @tap="goNavPage('/pages/comjobs/comjobs')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/jobsSelected.png"></image>
				</view>
				招聘
			</view>
			<!-- #ifndef MP-WEIXIN -->
			<view class="action text-gray videoimg" @tap="goNavPage('/pages/video/videolist')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/video.png"></image>
				</view>
				微工作
			</view>
			<!-- #endif -->

			<view class="action text-gray" @tap="goNavPage('/pages/broker/brokerlist')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/broker.png"></image>
				</view>
				经纪人
			</view>

			<view class="action text-gray" @tap="goNavPage('/pages/my/my')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/my.png"></image>
				</view>
				我的
			</view>
		</view>
	</view>
</template>

<script>
	import slFilter from '@/components/sl-filter/sl-filter.vue';
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	var _this;
	export default {
		components: {
			slFilter,
			uniLoadMore
		},
		data() {
			return {
				filterbox: null,
				rectypelist: {
					title: "悬赏/普通",
					value: 0
				},
				wtypelist: {
					title: "类型",
					value: 0,
					data: []
				},
				catelist: {
					title: "岗位",
					value: 0,
					data: []
				},
				arealist: {
					title: "区域",
					value: "",
					cityarr: [],
					districtarr: [],
					area_2: 0,
					data: [],
					community: "",
				},

				searchval: "",
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: []
			};
		},
		onLoad: function(option) {
			_this = this;
			_this.searchval = option.searchval || "";
			// _this.rectypelist.value = option.rectypelistID || 0;
			// if(_this.rectypelist.value != 0) {
			// 	_this.rectypelist.title = "悬赏聘";
			// } else {
			// 	_this.rectypelist.title = "悬赏/普通";
			// }
			// console.log("参数",_this.rectypelist.value)
			_this.$req.ajax({
				path: "comjobs/pagecomjobs",
			}).then((data) => {
				console.log("分类", data)
				_this.catelist.data = data.catelist;
				_this.wtypelist.data = data.wtypelist;
				_this.rectypelist.data = data.rectypelist;
				_this.arealist.data = require('@/common/area.json');
				_this.getMore();
			}).catch((err) => {
				uni.showModal({
					title: '信息提示',
					content: err,
					showCancel: false
				});
			});
		},
		onPullDownRefresh: function() {
			_this.pageRefresh();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		onShareAppMessage: function(res) {
			return {
				title: "企业招聘",
				path: "/pages/comjobs/comjobs"
			}
		},
		methods: {
			showFilter: function(e) {
				var nowfilterbox = e.currentTarget.dataset.filterbox;
				if (_this.filterbox == nowfilterbox) {
					_this.filterbox = null;
				} else {
					_this.filterbox = nowfilterbox;
				}
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
			hideFilter: function(e) {
				_this.filterbox = null;
			},
			checkRectype: function(title, value) {
				_this.rectypelist.title = title;
				_this.rectypelist.value = value;
				console.log("悬赏聘", _this.rectypelist.title, _this.rectypelist.value)
				_this.filterbox = null;
				_this.pageRefresh();
			},
			checkWtype: function(title, value) {
				_this.wtypelist.title = title;
				_this.wtypelist.value = value;
				_this.filterbox = null;
				_this.pageRefresh();
			},
			checkCate: function(title, value) {
				_this.catelist.title = title;
				_this.catelist.value = value;
				_this.filterbox = null;
				_this.pageRefresh();
			},
			checkArea: function(level, index) {
				if (level == 1) {
					_this.arealist.cityarr = _this.arealist.data[index].children;
					_this.arealist.districtarr = [];
				} else if (level == 2) {
					_this.arealist.districtarr = _this.arealist.cityarr[index].children;
					_this.arealist.area_2 = _this.arealist.cityarr[index].value;
				} else if (level == 3) {
					_this.arealist.value = _this.arealist.community = "";
					_this.arealist.title = _this.arealist.districtarr[index].title;
					if (_this.arealist.area_2 == "350582") {
						//晋江
						if (_this.arealist.cityarr[index].value == "350582") {
							_this.arealist.value = _this.arealist.districtarr[index].title;
						} else {
							_this.arealist.community = _this.arealist.districtarr[index].value;
						}
					} else {
						//其他区域
						_this.arealist.value = _this.arealist.districtarr[index].title;
					}

					_this.filterbox = null;
					_this.pageRefresh();
				} else if (level == 4) {
					_this.arealist.cityarr = [];
					_this.arealist.districtarr = [];
					_this.arealist.title = "全部";
					_this.arealist.value = "";
					_this.filterbox = null;
					_this.pageRefresh();
				}
			},

			// 搜索
			bindInput: function(e) {
				_this.searchval = e.detail.value;
			},
			btnSearch: function() {
				if (_this.searchval == "") {
					uni.showModal({
						title: '信息提示',
						content: "请输入要搜索的关键字...",
						showCancel: false
					});
					return false;
				}
				_this.pageRefresh();
			},
			resetFilter: function() {
				_this.searchval = "";
				_this.rectypelist.title = '悬赏/普通';
				_this.rectypelist.value = 1;
				_this.wtypelist.title = '类型';
				_this.wtypelist.value = 0;
				_this.catelist.title = '岗位';
				_this.catelist.value = 0;
				_this.arealist.title = '区域';
				_this.arealist.value = '';
				_this.arealist.cityarr = [];
				_this.arealist.districtarr = [];
				_this.pageRefresh();
			},

			pageRefresh: function() {
				_this.pstatus = 'more';
				_this.ppage = 1;
				_this.plist = [];
				_this.getMore();
			},
			getMore: function() {
				_this.$req.ajax({
					path: "comjobs/listcomjobs",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						searchval: _this.searchval,
						cateid: _this.catelist.value,
						wtype: _this.wtypelist.value,
						rectype: _this.rectypelist.value,
						district: _this.arealist.value,
						community: _this.arealist.community
					}
				}).then((data) => {
					console.log("查看数据", data)
					_this.pstatus = data.pstatus;
					_this.plist = _this.plist.concat(data.plist);
					_this.ppage += 1;
					uni.stopPullDownRefresh();
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			goDetail: function(comjobsid) {
				uni.navigateTo({
					url: '/pages/comjobs/detail?comjobsid=' + comjobsid
				});
			},
			goShop: function(workerid) {
				uni.navigateTo({
					url: '/pages/worker/shop?workerid=' + workerid
				});
			},
			result: function(e) {
				_this.cateid = e.cateid;
				_this.wtype = e.wtype;
				_this.province = e.province;
				_this.pageRefresh();
			},

			goNavPage: function(pageurl) {
				uni.redirectTo({
					url: pageurl
				});
			}
		}
	}
</script>

<style lang="scss">
	.comjobsList {
		padding: 28rpx 26rpx 0;

		.listCard {
			margin-bottom: 40rpx;
			padding: 28rpx 24rpx;
			background: #FFFFFF;
			border-radius: 12rpx;
			display: flex;
			flex-wrap: wrap;

			.listCard-item {
				width: 60%;
				display: flex;
				align-items: center;

				.item-icon {
					width: 35rpx;
					height: 35rpx;
				}

				.item-content {
					flex: 1;
					margin-left: 15rpx;
					font-size: 28rpx;
					font-weight: 400;
					color: #747474;
					overflow: hidden;
					text-overflow: ellipsis;
					-webkit-line-clamp: 1;
					display: -webkit-box;
					-webkit-box-orient: vertical;
				}

				.bold {
					font-size: 28rpx;
					font-weight: 600;
					color: #383838;
				}

				.red {
					font-size: 28rpx;
					font-weight: 500;
					color: #CA151C;
				}
			}

			.short {
				width: 35%;
				margin-left: 15rpx;
			}

			.bottom {
				margin-top: 28rpx;
			}
		}
	}
</style>