<template>
	<view>

		<view class="filterbg">
		<view class="flex justify-between solids-bottom padding bg-white">
			<view class="text-bold">推荐</view>
			<view class="flex justify-end">
				<view class="cu-tag radius" data-filterbox="comjobs" @tap="showFilter">{{comjobslist.title}}</view>
				<view class="cu-tag radius" data-filterbox="status" @tap="showFilter">{{statuslist.title}}</view>
			</view>
		</view>
		 
		<view class="filtercon" v-if="filterbox!==null">
			<view class="padding bg-white" v-if="filterbox=='comjobs'">
				<block v-for="(item,index) in comjobslist.data" :key="index">
					<button class="cu-btn margin-lr-xs margin-tb-xs" @click="checkComjobs(item.title,item.value)">{{item.title}}</button>
				</block>
			</view>
			<view class="padding bg-white" v-if="filterbox=='status'">
				<block v-for="(item,index) in statuslist.data" :key="index">
					<button class="cu-btn margin-lr-xs margin-tb-xs" @click="checkStatus(item.title,item.value)">{{item.title}}</button>
				</block>
			</view>
		</view>
		</view>

		<view class="cu-list menu-avatar">
			<block v-for="(item,index) in plist" :key="index">

				<view class="padding-lr padding-top-sm padding-bottom-xs bg-white margin-top-sm solid-bottom">{{item.comjobs.title}}</view>
				<view class="cu-item" style="height: 180rpx;">
					<view class="content">
						<view class="text-red">
							<view class="text-cut">{{item.realname}} - {{item.mobile}}</view>
						</view>
						<view class="text-gray text-sm">
							<view class="text-cut">预计到达日期：{{item.arrivetime}}</view>
							<view class="text-cut">报名时间：{{item.createtime}}</view>
						</view>
					</view>
					<view class="action">
						<view class="cu-tag round bg-gray sm">{{item.status_text}}</view>
					</view>
				</view>
				
				<view class="grid solids-top text-center col-3 padding-tb-sm bg-white">
					<!-- <view @tap="delComlog" :data-itemlogid="item.id" :data-itemindex="index"><text class="cuIcon-delete padding-right-xs"></text> 删除 </view> -->
					<view @tap="makeTelephone" :data-telephone="item.comjobs.telephone"><text class="cuIcon-phone padding-right-xs"></text> 岗位电话 </view>
					<view @tap="showModal" :data-itemid="item.id" :data-itemindex="index" :data-itemstatus="item.status" data-target="detailModal"><text class="cuIcon-search padding-right-xs"></text> 详情 </view>
				</view>

			</block>
		</view>

		<uni-load-more :status="pstatus"></uni-load-more>
		
		<view class="cu-modal bottom-modal show" v-if="modalName=='detailModal'">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">报备详情</view>
					<view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view>
					<scroll-view scroll-y="true" class="echo-orderinfo">
						<view class="cu-bar bg-white solids-bottom margin-top-xs">
							<view class="action">
								<text class="cuIcon-title text-blue"></text> 报备信息
							</view>
						</view>
						<view class="padding bg-white">
							<view class="flex justify-start padding-bottom-sm">
								<view class="basis-xs text-gray padding-right-sm">招聘标题</view>
								<view class="basis-xl text-left"><text>{{nowreport.comjobs.title}}</text></view>
							</view>
							<view class="flex justify-start padding-bottom-sm">
								<view class="basis-xs text-gray padding-right-sm">报备姓名</view>
								<view class="basis-xl text-left"><text>{{nowreport.realname}}</text></view>
							</view>
							<view class="flex justify-start padding-bottom-sm">
								<view class="basis-xs text-gray padding-right-sm">手机号码</view>
								<view class="basis-xl text-left"><text>{{nowreport.mobile}}</text></view>
							</view>
							<view class="flex justify-start padding-bottom-sm">
								<view class="basis-xs text-gray padding-right-sm">身份证号</view>
								<view class="basis-xl text-left"><text>{{nowreport.idcard}}</text></view>
							</view>
							<view class="flex justify-start padding-bottom-sm">
								<view class="basis-xs text-gray padding-right-sm">报备状态</view>
								<view class="basis-xl text-left"><text>{{nowreport.status_text}}</text></view>
							</view>
							<view class="flex justify-start padding-bottom-sm">
								<view class="basis-xs text-gray padding-right-sm">预到时间</view>
								<view class="basis-xl text-left"><text>{{nowreport.arrivetime}}</text></view>
							</view>
							<view class="flex justify-start padding-bottom-sm">
								<view class="basis-xs text-gray padding-right-sm">报备备注</view>
								<view class="basis-xl text-left"><text>{{nowreport.remark==''?"无":nowreport.remark}}</text></view>
							</view>
							<view class="flex justify-start padding-bottom-sm">
								<view class="basis-xs text-gray padding-right-sm">报备时间</view>
								<view class="basis-xl text-left"><text>{{nowreport.createtime}}</text></view>
							</view>
							<view class="flex justify-start padding-bottom-sm">
								<view class="basis-xs text-gray padding-right-sm">反馈备注</view>
								<view class="basis-xl text-left"><text>{{nowreport.retremark==''?"无":nowreport.retremark}}</text></view>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</view>
	</view>
</template>

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

				filterbox: null,
				comjobslist: {
					title: "岗位",
					value: 0,
					data: []
				},
				statuslist: {
					title: "状态",
					value: 0,
					data: []
				},
				
				modalName: null,
				itemid: 0,
				itemindex: 0,
				itemstatus: 0,
				retremark: "",
				
				nowreport: {},

				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: []
			};
		},
		onLoad: function() {
			_this = this;
			_this.userinfo = uni.getStorageSync('userinfo') || false;
			_this.brokerinfo = uni.getStorageSync('brokerinfo') || false;
			if (_this.userinfo===false || _this.brokerinfo===false){
				uni.reLaunch({
					url: "/pages/my/my"
				});
				return false;
			}
			_this.$req.ajax({
				path: "wcomjobs/brokerPageReport",
				data: {
					userid: _this.userinfo.id,
				}
			}).then((data) => {
				_this.comjobslist.data = data.comjobslist;
				_this.statuslist.data = data.statuslist;
				_this.getMore();
			}).catch((err) => {
				console.log("err: " + JSON.stringify(err));
			});
		},
		onPullDownRefresh: function() {
			_this.pageRefresh();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		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
				});
			},
			checkComjobs: function(title,value) {
				_this.comjobslist.title = title;
				_this.comjobslist.value = value;
				_this.filterbox = null;
				_this.pageRefresh();
			},
			checkStatus: function(title,value) {
				_this.statuslist.title = title;
				_this.statuslist.value = value;
				_this.filterbox = null;
				_this.pageRefresh();
			},
			
			
			pageRefresh: function() {
				_this.pstatus = 'more';
				_this.ppage = 1;
				_this.plist = [];
				_this.getMore();
			},
			getMore: function() {
				_this.$req.ajax({
					path: "wcomjobs/brokerListReport",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						userid: _this.userinfo.id,
						comjobsid: _this.comjobslist.value,
						status: _this.statuslist.value
					}
				}).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
					});
				});
			},
			result: function(e) {
				_this.comjobsid = e.comjobsid;
				_this.status = e.status;
				_this.pageRefresh();
			},
			goDetail: function(comjobsid) {
				uni.navigateTo({
					url: '/pages/comjobs/detail?comjobsid=' + comjobsid
				});
			},
			
			showModal: function(e) {
				var itemindex = e.currentTarget.dataset.itemindex;
				_this.itemid = e.currentTarget.dataset.itemid;
				_this.itemindex = itemindex;
				_this.itemstatus = e.currentTarget.dataset.itemstatus;
				_this.nowreport = _this.plist[itemindex];
				_this.retremark = _this.nowreport.retremark;
				_this.modalName = e.currentTarget.dataset.target;
			},
			hideModal: function(e) {
				_this.modalName = null;
			},
			
			makeTelephone: function(e) {
				var telephone = e.currentTarget.dataset.telephone;
				uni.makePhoneCall({
					phoneNumber: telephone
				});
			},
			
			goNavPage: function(pageurl) {
				_this.userinfo = _this.checkLogin("/pages/my/my");
				if (_this.userinfo===false){
					return false;
				}
				uni.redirectTo({
					url: pageurl
				});
			},
		}
	}
</script>

<style>
	.cu-list.menu-avatar>.cu-item .content {
		width: calc(100% - 150rpx);
		left: 30rpx;
	}
	.cu-list.menu-avatar>.cu-item .action {
		text-align: right;
		width: 150rpx;
	}
</style>
