<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">
			<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>
		</scroll-view>
		
		<block v-for="(item,index) in plist" :key="index">
			<view class="cu-card dynamic no-card solid-bottom echo-supply-item">
				
				<view class="cu-item shadow padding-top-sm padding-bottom" @tap="goShop(item.id)">
					<view class="flex justify-between">
						<view class="cu-avatar radius xl margin-left" :style="'background-image:url('+item.tilpic+');'"></view>
						<view class="echo-plistitem">
							<view class="padding-right padding-bottom-sm flex text-bold justify-between align-center">{{item.title}}</view>
							<view class="padding-right text-cut text-sm text-gray flex justify-between align-center"> 
								<view class="basis-xl text-cut">{{item.province}} {{item.city}}</view>
								<view class="basis-xs text-cut text-right text-gray text-sm">{{item.wtype_text}}</view>
							</view>
							<view class="text-gray padding-right padding-top-sm flex align-center justify-between" @tap="goShop(item.id)">
								<view class="flex align-center">
									<image class="iconyrz" :src="$getImageUrl('static/images/applet/iconyrz.png')" mode="scaleToFill"></image>
								</view>
								<view class="text-gray text-right basis-xs">
									<text class="cuIcon-shop margin-right-xs text-lg"></text>
									进店
								</view>
							</view>
						</view>
					</view>
					
					
				</view>
			</view>
		</block>
		<uni-load-more :status="pstatus"></uni-load-more>
		
		
		<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/worker/worker')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/windex.png"></image>
				</view>
				首页
			</view>
			<view class="action text-gray" @tap="goNavPage('/pages/demand/demand')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/wdemand.png"></image>
				</view>
				订单
			</view>
			<!-- #ifndef MP-WEIXIN -->
			<view class="action text-gray videoimg" @tap="goNavPage('/pages/video/video')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/video.png"></image>
				</view>
				录视频
			</view>
			<!-- #endif -->
			<view class="action text-gray" @tap="goNavPage('/pages/supply/supply')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/wsupply.png"></image>
				</view>
				供人
			</view>
			<!--
			<view class="action text-blue" @tap="goNavPage('/pages/worker/workerlist')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/wworkerSelected.png"></image>
				</view>
				企业1
			</view>
			-->
		</view>
		<wxContact></wxContact>
	</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 {
				userinfo: false,
				workerinfo: false,
				
				wtype: 0,
				searchval: "",
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: []
			};
		},
		onLoad: function(option){
			_this = this;
			_this.userinfo = _this.checkLogin("/pages/my/my");
			_this.workerinfo = uni.getStorageSync('workerinfo') || false;
			if (_this.userinfo === false || _this.workerinfo === false) {
				uni.reLaunch({
					url: "/pages/my/my"
				});
				return false;
			}
			_this.getMore();
		},
		onPullDownRefresh: function() {
			_this.pageRefresh();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		onShareAppMessage: function(res) {
			return {
				title: "招聘企业",
				path: "/pages/worker/workerlist"
		    }
		},
		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: "worker/listworker",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						wtype: _this.wtype,
						searchval: _this.searchval
					}
				}).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
					});
				});
			},
			
			tabSelect: function(e) {
				_this.wtype = e.currentTarget.dataset.wtype;
				_this.pageRefresh();
			},
			goShop: function(workerid) {
				uni.navigateTo({
					url: '/pages/worker/shop?workerid=' + workerid
				});
			},
			goNavPage: function(pageurl) {
				_this.userinfo = _this.checkLogin("/pages/my/my");
				if (_this.userinfo === false) {
					return false;
				}
				uni.redirectTo({
					url: pageurl
				});
			},
		}
	}
</script>

<style>
	
	.echo-plistitem{ width: 570rpx; }
	
</style>
