<template>
	<view>

		<sl-filter :ref="'slFilter'" :topFixed="false" :isTransNav="true" :navHeight="0" :color="titleColor" :themeColor="themeColor"
		 :menuList="menuList" @result="result"></sl-filter>


		<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 " @click="goUserDetail(item.user.id)">
					<view class="cu-avatar radius lg" :style="'background-image:url('+item.user.avatar+');'"></view>
					<view class="content">
						<view class="text-red">
							<view class="text-cut">{{item.user.realname}}</view>
						</view>
						<view class="text-gray text-sm flex">
							<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-itemlogid="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.user.mobile"><text class="cuIcon-phone padding-right-xs"></text> 电话 </view>
				</view>

			</block>
		</view>

		<uni-load-more :status="pstatus"></uni-load-more>
		
		
		<view class="cu-modal" :class="modalName=='statusModal'?'show':''" @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" :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" :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" :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" :checked="itemstatus==4?true:false" value="4"></radio>
								</label>
							</view>
							<view class="cu-item">
								<label class="flex justify-between align-center flex-sub">
									<view class="flex-sub">用户放弃</view>
									<radio class="round" :checked="itemstatus==5?true:false" value="5"></radio>
								</label>
							</view>
							<view class="cu-item">
								<label class="flex justify-between align-center flex-sub">
									<view class="flex-sub">已入职</view>
									<radio class="round" :checked="itemstatus==6?true:false" value="6"></radio>
								</label>
							</view>
							<view class="cu-item">
								<label class="flex justify-between align-center flex-sub">
									<view class="flex-sub">已离职</view>
									<radio class="round" :checked="itemstatus==7?true:false" value="7"></radio>
								</label>
							</view>
						</view>
					</radio-group>
				</view>
			</view>
		</view>

	</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 {
				isRotate: false,
				userinfo: false,
				workerinfo: false,
				
				themeColor: '#0081ff',
				titleColor: '#666666',
				filterResult: '',
				menuList: [{
					'title': '岗位',
					'detailTitle': '请选择招聘岗位...',
					'isMutiple': false,
					'key': 'comjobsid',
					'detailList': []
				}, {
					'title': '状态',
					'detailTitle': '请选择记录状态...',
					'isMutiple': false,
					'key': 'status',
					'detailList': []
				}],
				comjobsid: 0,
				status: 0,
				
				modalName: null,
				itemlogid: 0,
				itemindex: 0,
				itemstatus: 0,

				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/pagecomlog",
				data: {
					userid: _this.userinfo.id,
					workerid: _this.workerinfo.id,
				}
			}).then((data) => {
				_this.menuList[0].detailList = data.comjobslist;
				_this.menuList[1].detailList = data.statuslist;
				_this.$refs.slFilter.resetMenuList(_this.menuList);
				_this.getMore();
			}).catch((err) => {
				console.log("err: " + JSON.stringify(err));
			});
		},
		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: "wcomjobs/listcomlog",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						workerid: _this.workerinfo.id,
						comjobsid: _this.comjobsid,
						status: _this.status
					}
				}).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
				});
			},
			goUserDetail: function(userid) {
				uni.navigateTo({
					url: '/pages/worker/wcomuserdetail?userid=' + userid
				});
			},
			showModal: function(e) {
				_this.itemlogid = e.currentTarget.dataset.itemlogid;
				_this.itemindex = e.currentTarget.dataset.itemindex;
				_this.itemstatus = e.currentTarget.dataset.itemstatus;
				_this.modalName = e.currentTarget.dataset.target;
			},
			hideModal: function(e) {
				_this.modalName = null;
			},
			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;
				}
				_this.$req.ajax({
					path: "wcomjobs/statuslog",
					data: {
						userid: _this.userinfo.id,
						workerid: _this.workerinfo.id,
						logid: _this.itemlogid,
						status: _this.itemstatus
					}
				}).then((data) => {
					_this.modalName = null;
					_this.plist[_this.itemindex] = data.comjobslog;
				}).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% - 96rpx - 60rpx - 170rpx - 20rpx);
	}
	.cu-list.menu-avatar>.cu-item .action {
		text-align: right;
		width: 150rpx;
	}
</style>
