<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>签约管理</title>
		<link rel="shortcut icon" href="../../../favicon.ico">
		<link rel="stylesheet" type="text/css" href="../../../css/cross.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/cross.ui.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/style.min.css" />
		<link href="../../../plugins/toastr/toastr.min.css" rel="stylesheet">
		<link rel="stylesheet" type="text/css" href="../css/sign_manage.css"/>
	</head>
	<body class="m0">
	<div id="app" v-cloak>
		<div class="re-title no-select">
			<div class="name">签约管理</div>
		</div>
		<div class="c-h100 p10">
	        <div class="c-h100  c-border">
	            <div class="lh28 pt10 plr10 clearfix">
	                <div class="c-position-r fl mr20 mb10">
						签约状态：<span class="list-tit set-bg cur-pit c-999" @click="selectStatus()">{{statusTit}}</span>
	                    <ul class="pull-list m0 p0 c-border-l c-border-r c-border-b" v-if="isShowList">
	                        <li class="cur-pit c-999" v-for="(status, index) in statusArr" :key="index" @click="selectLi(status)">{{status.statusName}}</li>
	                    </ul>
	                </div>
	                <p class="fl plr5 c-border mb10"><input type="text" v-model="keyword" class="inp c-999" placeholder="搜索居民姓名、手机号"><span class="sosou-btn" @click="suosou()"></span></p>
	                <p class="fr btn plr10 mb10 c-fff h30 bgc-12b7f5 cur-pit" v-if="statusCode == 3 && isFocus" @click="remainFocus(1)">全部提醒关注</p>
	                <p class="fr btn plr10 mb10 c-fff h30 bgc-12b7f5 cur-pit" v-if="statusCode == 5 && isMoney" @click="remainMoney(1)">全部提醒缴费</p>
	            </div>
	            <table width="100%" class="c-border-t lh40 p0 patient-table">
	                <tr class="c-border-b c-999 clearfix">
	                    <th class="w-14">居民姓名</th>
	                    <th class="w-20">{{ statusCode == 3 ? "签约时间" : (statusCode == 1 ? "申请时间" : "预签约时间")}}</th>
	                    <th class="w-10">性别</th>
	                    <th class="w-10">年龄</th>
	                    <th class="w-10">类型</th>
	                    <th class="w-18">联系方式</th>
	                    <th class="w-18">操作</th>
	                </tr>
	                <tr v-for="(list, index) in resultList" :key="index" class="c-border-b clearfix">
	                    <td class="w-14">{{list.patientName || ""}}</td>
	                    <td class="w-20">{{list.applyDate || "无时间记录"}}</td>
	                    <td class="w-10">{{list.sex == 1 ? '男' : '女'}}</td>
	                    <td class="w-10">{{list.age ? list.age : '<1'}}岁</td>
	                    <td class="w-10">{{+list.renewFlag ? '续签' : '新签'}}</td>
	                    <td class="w-18">{{list.mobile || "无联系方式"}}</td>
	                    <td class="w-18">
	                    	<span v-if="statusCode == 1" class="mr10 c-12b7f5 cur-pit" @click="handle(list)">处理</span>
	                        <span v-if="list.status == 1" class="mr10 c-12b7f5 cur-pit" @click="looking(list)">查看</span>
	                        <span v-if="list.expensesRemindStatus == 0" class="mr10 c-12b7f5 cur-pit" @click="remainMoney(0, list)">提醒缴费</span>
	                        <span v-if="!list.openid && list.wechatFocusRemind == 0" class="c-12b7f5 cur-pit" @click="remainFocus(0, list)">提醒关注</span>
	                        <span v-if="list.expensesRemindStatus == 1 || (list.wechatFocusRemind == 1 && !list.openid)" class="c-999">已提醒</span>
	                    </td>
	                </tr>
	            </table>
	            <div class="mt20 mb10 lh24 pr30 c-t-center clearfix" v-show="resultList.length">
	                <div class="fr ml10 clearfix">
	                    <span class="fl c-border w40 m0">
	                        <input class="fl w40 h22 c-f999" v-model="editPage" />
	                    </span>
	                    <span class="fr bgc-12b7f5 c-fff c-f12 btn sure-btn" @click="setPage(editPage)">跳转</span>
	                </div>
	                <span class="fr btn page-btn ml10" @click="setPage(page + 2)" v-if="page == 1 && (page + 2) <= allPage">{{page + 2}}</span>
	                <span class="fr btn page-btn ml10" @click="setPage(page + 1)" v-if="(page + 1) <= allPage">{{page + 1}}</span>
	                <span class="fr btn page-btn ml10 btn-active">{{page}}</span>
	                <span class="fr btn page-btn ml10"  @click="setPage(page - 1)" v-if="page != 1">{{page - 1}}</span>
	                <span class="fr btn page-btn ml10"  @click="setPage(page - 2)" v-if="page > 2 && page == allPage">{{page - 2}}</span>
	                <span class="fr">当前第{{page}}页，共{{allPage}}页，{{allRecords}}条数据</span>
	            </div>
	            <p class="pt60 c-t-center c-999 c-f24" v-show="!resultList.length">无数据</p>
	        </div>
	    </div>
	</div>
		<script src="../../../js/vue.js" type="text/javascript" charset="utf-8"></script>
        <script src="../../../js/jquery-2.2.4.js"></script>
        <script src="../../../plugins/layer/layer.min.js"></script>
        <script src="../../../js/bootstrap.min.js"></script>
        <script src="../../../js/es6-promise.js" type="text/javascript" charset="utf-8"></script>
        <script src="../../../plugins/toastr/toastr.min.js"></script>
        <script src="../../../js/underscore.js" type="text/javascript" charset="utf-8"></script>
        <script src="../../../js/util.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../api/http-request.js" type="text/javascript"></script>
		<script src="../../../api/sign_api.js" type="text/javascript"></script>
		<script type="text/javascript">
			var doctorType = (JSON.parse(window.localStorage.getItem('wlyyAgent'))||{}).doctorType
			var httpData=GetRequest()
			function showSuccessMessage(msg) {
				layer.msg(msg, {
					icon: 1
				})
			}
			
			function showErrorMessage(msg) {
				layer.msg(msg, {
					icon: 5
				})
			}
			
			function showWarningMessage(msg) {
				layer.msg(msg, {
					icon: 2
				})
			}
			
			function showInfoMessage(msg) {
				layer.msg(msg, {
					icon: 6
				})
			}
			
			gobalVue = new Vue({
                el: "#app",
                data: {
		            isShowList: false,
		            keyword: "",
		            isFocus: false,
		            isMoney: false,
		            statusTit: null,
		            statusCode: httpData.statusCode || 3,
		            statusArr: [{
		                statusName: '待签约',
		                statusCode: '1'
		            }, {
		                statusName: '待缴费',
		                statusCode: '5'
		            }, {
		                statusName: '已签约',
		                statusCode: '3'
		            }],
		            resultList: [],
		            editPage: null,
		            page: 1,
		            allPage: null,
		            allRecords: null,
		            allCount: null
                },
                mounted: function() {
                	this.getStatusTit();
                	this.isRemainFocus();
                	this.isRemainMoney();
                	this.signCount();
                },
                methods: {
                	signCount: function() {
                		var vm = this,
                			param = {
                				patientInfo: this.keyword
                			},
                			loadding = layer.load(0, {shade: false});
						signAPI.signCount(param).then(function(res) {
							layer.close(loadding)
							if(res.status == 200) {
								vm.allCount = res.data;
								vm.signList();
							} else {
								showErrorMessage(res.msg);
							}
						})
                	},
                	isRemainFocus: function() {
                		var vm = this,
                			loadding = layer.load(0, {shade: false});
						signAPI.isRemainFocus().then(function(res) {
							layer.close(loadding)
							if(res.status == 200) {
								if(!res.data) {
									vm.isFocus = true;
								}
							} else {
								showErrorMessage(res.msg);
							}
						})
                	},
                	isRemainMoney: function() {
                		var vm = this,
                			loadding = layer.load(0, {shade: false});
						signAPI.isRemainMoney().then(function(res) {
							layer.close(loadding)
							if(res.status == 200) {
								if(!res.data) {
									vm.isMoney = true;
								}
							} else {
								showErrorMessage(res.msg);
							}
						})
                	},
                	signList: function() {
                		var vm = this
                		vm.allPage = null
						var params = {
							doctorType: doctorType,
							status: vm.statusCode, //处理方式(1待签约 5待缴费 3已签约)
							page: vm.page,
							pageSize: 10,
							patientInfo: vm.keyword
						}
						var loadding = layer.load(0, {shade: false});
						signAPI.signList(params).then(function(res) {
							layer.close(loadding)
							if(res.status == 200) {
								if(vm.statusCode == 3) {
									vm.allRecords = vm.allCount.signCount
								} else if(vm.statusCode == 5) {
									vm.allRecords = vm.allCount.waitPayCount
								} else {
									vm.allRecords = vm.allCount.waitSignCount
								}
								vm.allPage = Math.ceil(vm.allRecords / 10)
								vm.resultList = res.data.list
							} else {
								showErrorMessage(res.msg);
							}
						})
                	},
                    selectStatus: function() {
			            this.isShowList = !this.isShowList;
			        },
			        selectLi: function(data) {
			            this.isShowList = false;
			            if (this.statusTit === data.statusName) {
			                return false;
			            }
			            this.page = 1;
			            this.statusTit = data.statusName;
			            this.statusCode = data.statusCode;
			            this.keyword = "";
			            this.signCount();
			        },
			        getStatusTit: function() {
			        	if(!httpData.statusCode) {
			        		this.statusTit = "已签约"
			        	} else {
				        	for (var i = 0; i < 3; i++) {
				        		if(this.statusArr[i].statusCode == httpData.statusCode) {
				        			this.statusTit = this.statusArr[i].statusName
				        		}
				        	}
				        	if (httpData.signStatus) {
				        		this.handle(httpData)
				        	}
				        }
			        },
			        suosou: function() {
			        	this.page = 1;
			        	this.signCount();
			        },
			        handle: function(list) {
			        	var status;
			        	if(list.signStatus) {
			        		status = list.signStatus == 1 ? 0 : 1;
			        	} else {
			        		status = list.renewFlag == 1 || list.renewFlag == 2 ? 1 : 0;
			        	}
			        	layer.open({
							type: 2,
							area: ['80%', '648px'],
							shade: 0.5,
							title: '签约申请处理',
							fixed: true, //不固定
							maxmin: true,
							closeBtn: 1,
							shift: 5,
							shadeClose: false, //点击遮罩关闭层
							content: "sign_handle.html?patientCode="+list.patientCode+'&signCode='+list.code + '&status=' + status + '&msgid=' + list.msgid + "&renewFlag=" + list.renewFlag + "&applyDate=" + list.applyDate
						});
			        },
			        looking: function(list) {
			        	if(this.statusCode == 3) {
			        		layer.open({
								type: 2,
								area: ['80%', '648px'],
								shade: 0.5,
								title: '签约申请详情',
								fixed: true, //不固定
								maxmin: true,
								closeBtn: 1,
								shift: 5,
								shadeClose: false, //点击遮罩关闭层
								content: "sign_detail.html?patientCode="+list.patientCode+'&signCode='+list.code
							});
			        	} else {
			        		// 居民信息页 
			        		layer.open({
								type: 2,
								area: ['740px', '645px'],
								shade: 0.5,
								title: '修改居民标签',
								fixed: true, //不固定
								maxmin: true,
								closeBtn: 1,
								shift: 5,
								shadeClose: false, //点击遮罩关闭层
								content: "userInfo.html?patient="+list.patientCode
							});
			        	}
			        },
			        remainMoney: function(status, list) {
			        	showInfoMessage("功能正在优化中，暂停使用，谢谢！")
			        	return false;
			        	var vm = this,
			        		loading = layer.load(0, {shade: false})
			        		param = {
			        			patient: list ? list.patientCode : "",
			        			isAll: status
			        		}
			        	signAPI.remainMoney(param).then(function(res) {
			        		layer.close(loading)
							if(res.status == 200) {
								showSuccessMessage(res.msg)
								vm.signList()
							} else {
								showErrorMessage(res.msg);
							}
			        	})
			        },
			        remainFocus: function(status, list) {
			        	showInfoMessage("功能正在优化中，暂停使用，谢谢！")
			        	return false;
			        	var vm = this,
			        		loading = layer.load(0, {shade: false})
			        		param = {
			        			patient: list ? list.patientCode : "",
			        			isAll: status
			        		}
			        	signAPI.remainFocus(param).then(function(res) {
			        		layer.close(loading)
							if(res.status == 200) {
								showSuccessMessage(res.msg)
								vm.signList()
							} else {
								showErrorMessage(res.msg);
							}
			        	})
			        },
			        setPage: function(key) {
			            if (+key && +key > 0 && +key <= this.allPage) {
			                this.page = +key;
			                this.signList()
			            } else {
			                showWarningMessage('无效的页数跳转！');
			            }
			        }
                }
            })
		</script>
	</body>
</html>
