<template>
	<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="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 class="padding-sm"></view>
		<view class="padding-xl"></view>
		<view class="cu-bar tabbar bg-white foot">
			<view class="action" @tap="goNavPage('/pages/resident/resident')">
				<view class="cuIcon-upload"></view>
				悬赏报备
			</view>
			<view class="action" @tap="goNavPage('/pages/resident/order')">
				<view class="cuIcon-recharge"></view>
				订单报备
			</view>
		</view>
		 -->
	</view>
</template>

<script>
	var _this;
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				userinfo: false,
				residentinfo: false,
				
				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.residentinfo = uni.getStorageSync('residentinfo') || false;
			if (_this.userinfo===false || _this.residentinfo===false){
				uni.reLaunch({
					url: "/pages/my/my"
				});
				return false;
			}
			_this.getMore();
		},
		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() {
				_this.$req.ajax({
					path: "resident/comjobsReport",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						residentid: _this.residentinfo.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
					});
				});
			},
			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: "resident/comjobssetreportstatus",
					data: {
						residentid: _this.residentinfo.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
					});
				});
			},
			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>
	.codebox{ width: 680rpx; margin: 40rpx auto 0rpx auto; border-radius: 8rpx; overflow: hidden; }
</style>
