<template>
	<view>
		<view class="bg-themeRed" style="position: relative; height: 130rpx;">
			<view class="text-center padding-tb-lg padding-lr" style="position: absolute;">
				<view class="cu-list menu-avatar codebox">
					<view class="cu-item">
						<view class="cu-avatar radius lg" v-if="shopworker!=false"
							:style="'background-image:url('+shopworker.tilpic+');'"></view>
						<view class="content">
							<view class="text-pink">
								<view class="text-cut text-black">{{shopworker.ftitle}}</view>
							</view>
							<view class="text-gray text-sm flex">
								<view class="text-cut">{{shopworker.title}}</view>
							</view>
						</view>
						<view class="action">
							<button class="cu-btn bg-red cuIcon" @tap="setAddress">
								<text class="cuIcon-locationfill"></text>
							</button>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="padding-tb-lg"></view>


		<view class="cu-bar bg-white solids-bottom margin-top-sm">
			<view class="action">
				<text class="cuIcon-titles text-red"></text> 企业介绍
			</view>
		</view>
		<view class="padding-tb-sm padding-lr bg-white margin-bottom-sm">
			<text>{{shopworker.details}}</text>
		</view>

		<!-- <view class="padding grid flex justify-between">
			<view class="padding-lr-xs bg-white echo-grid-item" @tap="makeTelephone" :data-telephone="shopworker.mobile">
				<view class="bg-white padding-bottom-xs padding-top-sm padding-lr-sm"><text class="padding-right-xs cuIcon-dianhua text-orange"></text> 拨打电话</view>
				<view class="bg-white padding-top-sm padding-bottom-xs padding-lr-sm text-sm text-gray">{{shopworker.mobile}}</view>
			</view>
			
			<view class="padding-lr-xs bg-white echo-grid-item">
				<view class="bg-white padding-bottom-xs padding-top-sm padding-lr-sm"><text class="padding-right-xs cuIcon-weixin text-green"></text> 加我微信</view>
				<view class="bg-white padding-top-sm padding-bottom-xs padding-lr-sm text-sm text-gray">{{shopworker.weixin}}</view>
			</view>
			
			<view class="padding-lr-xs bg-white echo-grid-item" @tap="setAddress">
				<view class="bg-white padding-bottom-xs padding-top-sm padding-lr-sm"><text class="padding-right-xs cuIcon-locationfill text-blue"></text> 公司地址</view>
				<view class="bg-white padding-top-sm padding-bottom-xs padding-lr-sm text-sm text-gray">{{shopworker.city}} {{shopworker.district}}</view>
			</view>
		</view> -->


		<view class="cu-bar bg-white solids-bottom" v-if="workerinfo==false">
			<view class="action">
				<text class="cuIcon-titles text-red"></text> 招聘推荐
			</view>
			<view class="action">
				<text class="text-df">共 {{countarr.comjobs}} 条 </text>
				<view class="cuIcon-right"></view>
			</view>
		</view>

		<scroll-view scroll-x class="bg-white nav" v-if="workerinfo!=false">
			<view class="flex text-center">
				<view class="cu-item flex-sub" :class="tablename=='comjobs'?'text-red cur':''" @tap="tabSelect"
					data-tablename="comjobs">招聘 <text
						class="cu-tag bg-red sm round margin-lr-sm">{{countarr.comjobs}}</text></view>
				<view class="cu-item flex-sub" :class="tablename=='demand'?'text-red cur':''" @tap="tabSelect"
					data-tablename="demand">订单 <text
						class="cu-tag bg-red sm round margin-lr-sm">{{countarr.demand}}</text></view>
				<view class="cu-item flex-sub" :class="tablename=='supply'?'text-red cur':''" @tap="tabSelect"
					data-tablename="supply">供人 <text
						class="cu-tag bg-red sm round margin-lr-sm">{{countarr.supply}}</text></view>
			</view>
		</scroll-view>
		<view class="solids-top">
			<block v-if="tablename=='comjobs'">
				<view class="listCard" v-for="(item,index) in plist" :key="index" @tap="goDetail(item.id)">
					<view class="listCard-item">
						<view class="item-left">
							<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="item-right">
							<image class="item-icon" :src="$getImageUrl('static/images/applet/index/cardD.png')"
								mode="widthFix"></image>
							<view class="item-content">{{item.city}}</view>
						</view>
					</view>
					<view class="listCard-item">
						<view class="item-left">
							<image class="item-icon" src="../../static/images/comJobs/icon-sum.png" mode="widthFix">
							</image>
							<view class="item-content red" v-if="item.wtype==1">{{item.zwagall}}</view>
							<view class="item-content red" v-else-if="item.wtype==5">其他</view>
							<view class="item-content red" v-else>{{item.bwagall}}</view>
						</view>
						<view class="item-right">
							<image class="item-icon" src="../../static/images/comJobs/icon-pageView.png"
								mode="widthFix"></image>
							<view class="item-content red">{{item.fwagall}}</view>
						</view>
					</view>
					<view class="listCard-tag">
						<view v-for="(titem,tindex) in item.tags" :key="tindex" class="tag-item">{{titem}}</view>
					</view>
				</view>
				<!-- <view class="cu-card dynamic no-card solid-bottom echo-comjobs-item" v-for="(item,index) in plist"
					:key="index">
					<view class="cu-item shadow padding-top-sm padding-bottom">
						<view class="padding-lr padding-bottom-xs flex justify-between align-center"
							@tap="goDetail(item.id)">
							<view class="basis-xl text-bold text-lg text-cut">{{item.title}}</view>
							<view class="basis-xs text-cut text-right text-gray text-sm">{{item.city}}</view>
						</view>
						<view class="padding-lr flex justify-between align-bottom" @tap="goDetail(item.id)">
							<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 class="text-red">{{item.fwagall}}</view>
						</view>
						<view class="padding-lr text-cut" @tap="goDetail(item.id)">
							<view v-for="(titem,tindex) in item.tags" :key="tindex"
								class="cu-tag light bg-red sm echo-tags-item">{{titem}}</view>
						</view>
					</view>
				</view> -->
			</block>

			<block v-if="tablename=='demand'">
				<view class="listCard" v-for="(item,index) in plist" :key="index" @tap="goDetail(item.id)">
					<view class="listCard-item">
						<view class="item-left">
							<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="item-right">
							<image class="item-icon" :src="$getImageUrl('static/images/applet/index/cardD.png')"
								mode="widthFix"></image>
							<view class="item-content">{{item.city}}</view>
						</view>
					</view>
					<view class="listCard-item">
						<view class="item-left">
							<image class="item-icon" src="../../static/images/comJobs/icon-sum.png" mode="widthFix">
							</image>
							<view class="item-content red" v-if="item.wtype==1">{{item.zwagall}}</view>
							<view class="item-content red" v-else-if="item.wtype==5">其他</view>
							<view class="item-content red" v-else>{{item.bwagall}}</view>
						</view>
						<!-- <view class="item-right">
							<image class="item-icon" src="../../static/images/comJobs/icon-pageView.png"
								mode="widthFix"></image>
							<view class="item-content red">{{item.fwagall}}</view>
						</view> -->
					</view>
					<view class="listCard-tag">
						<view v-for="(titem,tindex) in item.tags" :key="tindex" class="tag-item">{{titem}}</view>
					</view>
				</view>
				<!-- <view class="cu-card dynamic no-card solid-bottom echo-demand-item" v-for="(item,index) in plist"
					:key="index">
					<view class="cu-item shadow padding-top-sm padding-bottom">
						<view class="padding-lr padding-bottom-xs flex justify-between align-center"
							@tap="goDetail(item.id)">
							<view class="basis-lg text-bold text-lg text-cut">{{item.title}}</view>
							<view class="basis-sm text-cut text-right text-gray text-sm">{{item.city}}</view>
						</view>
						<view class="padding-lr text-lg" @tap="goDetail(item.id)">
							<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 class="padding-lr text-cut" @tap="goDetail(item.id)">
							<view v-for="(titem,tindex) in item.tags" :key="tindex"
								class="cu-tag light bg-gray text-grey sm">{{titem}}</view>
						</view>
					</view>
				</view> -->
			</block>

			<block v-if="tablename=='supply'">
				<view class="cu-card dynamic no-card solid-bottom echo-supply-item" v-for="(item,index) in plist"
					:key="index">
					<view class="cu-item shadow padding-top-sm padding-bottom" @tap="goDetail(item.id)">
						<view class="padding-lr padding-bottom-sm flex justify-between align-center">
							<view class="basis-xl text-bold text-lg text-cut"><text v-if="item.mnumber>0">
									男{{item.mnumber}}人，</text><text v-if="item.wnumber>0">
									女{{item.wnumber}}人</text>【{{item.agegroup}}】</view>
							<view class="basis-xs text-cut text-right text-gray text-sm">{{item.updatetime_text}}</view>
						</view>
						<view class="padding-lr padding-bottom-sm text-cut text-gray text-sm">
							{{item.province}} {{item.city}} <text class="cuIcon-move margin-lr-xs text-gray"></text>
							{{item.descity}}
						</view>
						<view class="padding-lr text-sm text-gray"> 可到岗日期：{{item.candate}} </view>
					</view>
				</view>
			</block>
		</view>
		<uni-load-more :status="pstatus"></uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	var _this;
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				userinfo: false,
				workerinfo: false,

				shopworker: false,
				countarr: {
					comjobs: 0,
					demand: 0,
					supply: 0
				},


				tablename: 'comjobs',
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: [],
			}
		},
		onLoad: function(option) {
			_this = this;
			var workerid = option.workerid || 0;
			var parentid = option.parentid || 0;
			if (option.scene) {
				const scene = decodeURIComponent(option.scene);
				if (scene != "undefined") {
					workerid = scene.split("&")[0];
					parentid = scene.split('&')[1];
				}
			}
			uni.setStorageSync('parentid', parentid);
			_this.userinfo = uni.getStorageSync('userinfo') || false;
			_this.workerinfo = uni.getStorageSync('workerinfo') || false;
			_this.$req.ajax({
				path: "worker/pageshop",
				data: {
					workerid: workerid,
					userid: _this.userinfo == false ? 0 : _this.userinfo.id
				}
			}).then((data) => {
				_this.countarr = data.countarr;
				_this.shopworker = data.shopworker;
				_this.getMore();
			}).catch((err) => {
				uni.showModal({
					title: '信息提示',
					content: err,
					showCancel: false,
					success: function(res) {
						if (res.confirm) {
							uni.navigateBack();
						}
					}
				});
			});
		},
		onShareAppMessage: function(res) {
			return {
				title: _this.shopworker.title,
				path: "/pages/worder/shop?workerid=" + _this.shopworker.id + "&parentid=" + _this.userinfo == false ?
					0 : _this.userinfo.id
			}
		},
		onPullDownRefresh: function() {
			_this.pageRefresh();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		methods: {
			pageRefresh: function() {
				_this.pstatus = 'more';
				_this.ppage = 1;
				_this.plist = [];
				_this.getMore();
			},
			getMore: function() {
				var path = "worker/shopcomjobs";
				if (_this.tablename == "demand") {
					path = "worker/shopdemand";
				} else if (_this.tablename == "supply") {
					path = "worker/shopsupply";
				}
				_this.$req.ajax({
					path: path,
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						workerid: _this.shopworker.id
					}
				}).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.tablename = e.currentTarget.dataset.tablename;
				_this.pageRefresh();
			},

			goDetail: function(id) {
				if (_this.tablename == "demand") {
					uni.navigateTo({
						url: '/pages/demand/detail?demandid=' + id
					});
				} else if (_this.tablename == "supply") {
					uni.navigateTo({
						url: '/pages/supply/detail?supplyid=' + id
					});
				} else {
					uni.navigateTo({
						url: '/pages/comjobs/detail?comjobsid=' + id
					});
				}
			},
			goShop: function(workerid) {
				uni.navigateTo({
					url: '/pages/worker/shop?workerid=' + workerid
				});
			},
			setAddress: function() {
				uni.openLocation({
					latitude: parseFloat(_this.shopworker.latitude),
					longitude: parseFloat(_this.shopworker.longitude),
					name: _this.shopworker.title,
					address: _this.shopworker.city + " " + _this.shopworker.district + " " + _this.shopworker
						.address,
					success: function() {
						console.log('success');
					}
				});
			},
			makeTelephone: function(e) {
				var telephone = e.currentTarget.dataset.telephone;
				uni.makePhoneCall({
					phoneNumber: telephone
				});
			}
		}
	}
</script>

<style lang="scss">
	.codebox {
		width: 690rpx;
		margin: 0rpx auto 0rpx auto;
		border-radius: 8rpx;
		overflow: hidden;
	}

	.codebox>view {
		margin-top: 20rpx;
	}

	.echo-grid-item {
		width: 220rpx;
		height: 140rpx;
	}

	.listCard {
		margin: 0 20rpx 20rpx;
		padding: 20rpx 24rpx 0;
		background: #FFFFFF;
		border-radius: 12rpx;

		.listCard-tag {
			display: flex;
			flex-wrap: wrap;

			.tag-item {
				margin-right: 15rpx;
				background: #E6F2FF;
				font-size: 20rpx;
				color: #CA151C;
				padding: 5rpx 12rpx;
				margin-bottom: 20rpx;
				white-space: nowrap;
				text-overflow: ellipsis;
				white-space: nowrap;
				overflow: hidden;
			}
		}

		.listCard-item {
			display: flex;
			margin-bottom: 28rpx;

			.item-left {
				width: 60%;
				display: flex;

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

				.item-content {
					flex: 1;
					margin-left: 15rpx;
					font-size: 28rpx;
					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: 600;
					color: #CA151C;
				}
			}

			.item-right {
				width: 35%;
				margin-left: 15rpx;
				display: flex;

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

				.item-content {
					flex: 1;
					margin-left: 15rpx;
					font-size: 28rpx;
					line-height: 35rpx;
					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: 600;
					color: #CA151C;
				}
			}
		}
	}
</style>