<template>
	<view>
		<view class="cu-bar search">
			<view class="search-form round text-center">
				<text class="cuIcon-search"></text>
				<input @input="bindInput" :adjust-position="false" type="text" placeholder="搜索岗位或公司" confirm-type="search"></input>
			</view>
			<view class="action" v-if="searchval!==''">
				<button class="cu-btn bg-white shadow-blur round" @click="btnSearch()">搜索</button>
			</view>
		</view>
		<scroll-view scroll-x class="bg-white nav solid-bottom solid-bottom">
			<view class="flex text-center">
				<view class="cu-item flex-sub" :class="wtype==0?'text-blue cur':''" @tap="tabSelect" data-wtype="0">全部</view>
				<view class="cu-item flex-sub" :class="wtype==1?'text-blue cur':''" @tap="tabSelect" data-wtype="1">按月</view>
				<view class="cu-item flex-sub" :class="wtype==2?'text-blue cur':''" @tap="tabSelect" data-wtype="2">按时</view>
				<view class="cu-item flex-sub" :class="wtype==3?'text-blue cur':''" @tap="tabSelect" data-wtype="3">按件</view>
				<view class="cu-item flex-sub" :class="wtype==4?'text-blue cur':''" @tap="tabSelect" data-wtype="4">按项目</view>
				<view class="cu-item flex-sub" :class="wtype==5?'text-blue cur':''" @tap="tabSelect" data-wtype="5">其他</view>
			</view>
		</scroll-view>

		<block v-for="(item,index) in plist" :key="index">
			<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}}</view>
						<view class="basis-sm text-cut text-right text-gray text-sm">
							<view v-if="item.wtype==1"><text class="text-red text-bold">{{item.zwagall}}</text></view>
							<view v-if="item.wtype==5"><text class="text-red text-bold">其他</text></view>
							<view v-else><text class="text-red text-bold">{{item.bwagall}}</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>
			</view>
		</block>
		<uni-load-more :status="pstatus"></uni-load-more>
		<wxContact></wxContact>
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	var _this;
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				searchval: "",
				wtype: 0,
				
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: []
			};
		},
		onLoad: function(option){
			_this = this;
			_this.wtype = option.wtype || 0;
			_this.getMore();
		},
		onPullDownRefresh: function() {
			_this.pageRefresh();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		onShareAppMessage: function(res) {
			return {
				title: "企业招聘",
				path: "/pages/comjobs/comjobs"
		    }
		},
		methods: {
			// 搜索
			bindInput: function(e) {
				_this.searchval = e.detail.value;
			},
			btnSearch: function() {
				if (_this.searchval == "") {
					uni.showModal({
						title: '信息提示',
						content: "请输入要搜索的关键字...",
						showCancel: false
					});
					return false;
				}
				_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,
						wtype: _this.wtype
					}
				}).then((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
				});
			},
			tabSelect: function(e) {
				_this.wtype = e.currentTarget.dataset.wtype;
				_this.pageRefresh();
			},
		}
	}
</script>

<style>
</style>
