<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" @tap="makeTelephone" :data-telephone="item.mobile">{{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="showModal" :data-itemid="item.id" :data-itemindex="index" :data-itemstatus="item.status" data-target="statusModal"><text class="cuIcon-write padding-right-xs"></text> 状态 </view>
					<view @tap="makeTelephone" :data-telephone="item.broker.mobile"><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=='statusModal'" @tap="hideModal">
			<view class="cu-dialog" @tap.stop="">
				<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 class="solids-top">
					<radio-group class="block" @change="statusChange">
						<view class="cu-list menu text-left">
							<view class="cu-item">
								<label class="flex justify-between align-center flex-sub">
									<view class="flex-sub">待审核</view>
									<radio class="round" :class="itemstatus==1?'checked':''" :checked="itemstatus==1?true:false" value="1"></radio>
								</label>
							</view>
							<view class="cu-item">
								<label class="flex justify-between align-center flex-sub">
									<view class="flex-sub">待面试</view>
									<radio class="round" :class="itemstatus==2?'checked':''" :checked="itemstatus==2?true:false" value="2"></radio>
								</label>
							</view>
							<view class="cu-item">
								<label class="flex justify-between align-center flex-sub">
									<view class="flex-sub">已入职</view>
									<radio class="round" :class="itemstatus==3?'checked':''" :checked="itemstatus==3?true:false" value="3"></radio>
								</label>
							</view>
							<view class="cu-item">
								<label class="flex justify-between align-center flex-sub">
									<view class="flex-sub">无效报备</view>
									<radio class="round" :class="itemstatus==4?'checked':''" :checked="itemstatus==4?true:false" value="4"></radio>
								</label>
							</view>
						</view>
					</radio-group>
					<view class="cu-form-group align-start solids-top" v-if="itemstatus==4">
						<textarea style="text-align: left;" maxlength="140" placeholder="请输入反馈信息..." @input="retremarkInput" :value="setremark"></textarea>
					</view>
					<view class="padding bg-white flex flex-direction">
						<button class="cu-btn bg-blue margin-tb-sm lg" @tap="statusUpdate">确认提交</button>
					</view>
				</view>
			</view>
		</view>

		<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,
				workerinfo: 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 = _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.$req.ajax({
				path: "wcomjobs/pagereport",
				data: {
					userid: _this.userinfo.id,
					workerid: _this.workerinfo.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/listreport",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						workerid: _this.workerinfo.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;
			},
			retremarkInput: function(e) {
				_this.retremark = e.detail.value;
			},
			statusChange: function(e) {
				let origin_status = _this.itemstatus;
				_this.itemstatus = e.detail.value;
				if (_this.itemstatus <= origin_status) {
					uni.showModal({
						title: '信息提示',
						content: '状态只能往下面的选',
						showCancel: false
					});
					_this.itemstatus = String(origin_status);
					_this.modalName = null;
					return false;
				}
			},
			statusUpdate: function(e) {
				_this.$req.ajax({
					path: "wcomjobs/setreportstatus",
					data: {
						workerid: _this.workerinfo.id,
						id: _this.itemid,
						status: _this.itemstatus,
						retremark: _this.retremark
					}
				}).then((data) => {
					_this.modalName = null;
					_this.plist[_this.itemindex] = data.report;
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			
			
			delComlog: function(e) {
				var itemlogid = e.currentTarget.dataset.itemlogid;
				var itemindex = e.currentTarget.dataset.itemindex;
				uni.showModal({
					title: '信息提示',
					content: '删除后不可恢复，确定要删除吗？',
					success: function(res) {
						if (res.confirm) {
							_this.$req.ajax({
								path: "wcomjobs/dellog",
								data: {
									userid: _this.userinfo.id,
									workerid: _this.workerinfo.id,
									logid: itemlogid
								}
							}).then((data) => {
								_this.modalName = null;
								_this.plist.splice( itemindex, 1 );
							}).catch((err) => {
								uni.showModal({
									title: '信息提示',
									content: err,
									showCancel: false
								});
							});
						}
					}
				});
			},
			
			makeTelephone: function(e) {
				var telephone = e.currentTarget.dataset.telephone;
				uni.makePhoneCall({
					phoneNumber: telephone
				});
			}
		}
	}
</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>
