<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<meta charset="UTF-8">
	<meta name="format-detection" content="telephone=no">
	<th:block th:include="include :: header('随访跟进人分配')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
	<div class="ui-layout-center">
			<div class="row">
				<div class="col-sm-12 search-collapse">
				<div class="query-condition-container">
					<h4 class="query-condition-title">查询条件</h4>
					<div class="query-buttons">
						<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
						<a class="btn btn-warning btn-rounded btn-sm" onclick="resetPre()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						<a class="btn btn-w-m btn-dark" onclick="defultConfig"><i class="glyphicon glyphicon-cog" style="top: 2px;"></i><span style="font-size: 15px;">默认分配--->请设置</span></a>
					</div>
				</div>
					<form id="followUpAssign-form"  class="customize-search-form">
						<div class="customize-form-group-container">
							<div class="customize-form-group">
								<label>患者信息:</label>
								<input type="text" class="styled-input" placeholder="请输入患者姓名或手机号" name="query"/>
							</div>
							<div class="customize-form-group">
								<label>门店:</label>
								<select name="storeId" class="styled-input">
									<option value="">全部</option>
									<!--									<option th:each="store : ${stores}" th:text="${store.name}" th:value="${store.id}"></option>-->
								</select>
							</div>
							<div class="customize-form-group">
								<label>药品:</label>
								<input type="text"  class="styled-input" placeholder="商品名,通用名或MDM编码"  name="product"/>
							</div>
							<div class="customize-form-group">
								<label>随访跟进人:</label>
								<input type="text"  class="styled-input" placeholder="随访跟进人姓名" name="followUpPersonName"/>
							</div>
						</div>
					</form>
				</div>

			</div>
			<button id="myButtonhzfp" style="margin-left: 20px" type="button" onclick="huanzhefp()" >患者分配</button>
			<button id="myButtonyglzjj" style="margin-left: 10px" type="button" onclick="yuanogngLZJJ()">员工离职交接</button>
			<div class="rows" id="tabsDiv">
				<ul class="nav nav-tabs" id="myTabs">
					<li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">全部</a>
					</li>
					<li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">待分配</a>
					</li>
					<li class=""><a data-toggle="tab" href="#tab-3" aria-expanded="false">已分配</a>
					</li>
					<li class=""><a data-toggle="tab" href="#tab-4" aria-expanded="false">无效跟进人</a>
					</li>
				</ul>
					<div class="tab-content">
						<div id="tab-1" class="tab-pane active">
							<div class="panel-body">
								<div class="col-sm-12 select-table table-striped" style="width: 100%; overflow-x: hidden;">
									<table id="bootstrap-table" class="fixed-layout-table"></table>
								</div>
							</div>
						</div>
						<div id="tab-2" class="tab-pane">
							<div class="panel-body">
								<div class="panel-body">
									<div class="col-sm-12 select-table table-striped" style="width: 100%; overflow-x: hidden;">
										<table id="bootstrap-table-2" class="fixed-layout-table"></table>
									</div>
								</div>
							</div>
						</div>
						<div id="tab-3" class="tab-pane">
							<div class="panel-body">
								<div class="col-sm-12 select-table table-striped" style="width: 100%; overflow-x: hidden;">
									<table id="bootstrap-table-3" class="fixed-layout-table"></table>
								</div>
							</div>
						</div>
						<div id="tab-4" class="tab-pane">
							<div class="panel-body">
								<div class="col-sm-12 select-table table-striped" style="width: 100%; overflow-x: hidden;">
									<table id="bootstrap-table-4" class="fixed-layout-table"></table>
								</div>
							</div>
						</div>
					</div>

			</div>
		<div class="lizhi" id="content-main-lz" >
			<div class="col-sm-12 select-table table-striped" style="width: 100%; overflow-x: hidden;">
				<table id="bootstrap-table-5" class="fixed-layout-table"></table>
			</div>
	    </div>
	</div>

	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: bootstrap-table-fixed-columns-js" />
	<th:block th:include="include :: ztree-js" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('dtp:pmService:edit')}]];
		var removeFlag = [[${@permission.hasPermi('dtp:pmService:remove')}]];
		var prefix = ctx + "dtp/pmService";
		var patientId='';
		$(function() {
		    var panehHidden = false;
		    if ($(this).width() < 1590) {
		        panehHidden = true;
		    }
		    $('body').layout({ initClosed: panehHidden, west__size: 185, resizeWithWindow: false });
	     	// 回到顶部绑定
	    	if ($.fn.toTop !== undefined) {
	    		var opt = {
	    			win:$('.ui-layout-center'),
	    			doc:$('.ui-layout-center')
	    		};
	    		$('#scroll-up').toTop(opt);
	    	}
			queryArchivesList();
		});
		 function queryArchivesList() {
		    var options = {
		        url: prefix + "/followUpAssignList",
		        viewUrl: prefix + "/followUpAssignView/{id}",
		        createUrl: prefix + "/followUpAssignAdd",
		        updateUrl: prefix + "/followUpAssignEdit/{id}",
		        removeUrl: prefix + "/followUpAssignRemove",
		        /*exportUrl: prefix + "/export",
		        importUrl: prefix + "/importData",
		        importTemplateUrl: prefix + "/importTemplate",*/
		        sortName: "id",
		        sortOrder: "asc",
		        modalName: "随访跟进人分配",
				fitColumns: true,
				striped: true,
				autoRowHeight: true,
				rowNumbers: true,
				showFooter:true,  //是否显示表格底部区域。
				clickToSelect: true, //是否启用点击行时选中整行的功能。
				singleSelect: false, //是否仅允许选择一行
            fixedColumns: true,
            //fixedNumber: 3,
            fixedRightNumber: 1,
		        columns: [{
		            checkbox: true
		        },
				{ field: 'patientName', title: '患者姓名', align: 'center' },
				{ field: 'patientPhone', title: '患者手机号', align: 'center' },
				{ field: 'gender', title: '性别', align: 'center' },
				{ field: 'age', title: '年龄', align: 'center' },
				{ field: 'disease', title: '疾病', align: 'center' },
				{ field: 'clinicalDiagnosis', title: '临床诊断', align: 'center' },
				{ field: 'medicineName', title: '药品名称', align: 'center' },
				{ field: 'status', title: '跟进人状态', align: 'center' },
				{ field: 'followUpPersonName', title: '随访跟进人姓名', align: 'center' },
				{ field: 'lastPurchaseDate', title: '最后一次购药', align: 'center' },
				{ field: 'followUpPersonPhone', title: '跟进人手机号', align: 'center' },
				{ field: 'filingDate', title: '建档日期', align: 'center' },
		        {
		            title: '操作',
		            align: 'center',
					width: 150,
		            formatter: function(value, row, index) {
		                if (row.id) {
		                	var actions = [];
			                actions.push('<a class="btn-xs' + editFlag + '" href="javascript:void(0)" onclick="selectUsersToParentCallBack2(\'' + row.id + '\')">修改跟进人</a> ');
			                actions.push('<a class="btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
			                return actions.join('');
		            	} else {
		                    return "";
		                }
		            }
		        }]
		    };
		    $.table.init(options);
		}

		/* 自定义重置-表单重置/隐藏框/树节点选择色/搜索 */
		function resetPre() {
			resetDate();
			$("#followUpAssign-form")[0].reset();
			$("#deptId").val("");
			$("#parentId").val("");
			$(".curSelectedNode").removeClass("curSelectedNode");
			$.table.search();
			_refresh();
		}

		var HZFPButton = document.getElementById('myButtonhzfp');
		var myButtonyglzjj = document.getElementById('myButtonyglzjj');
		// 定义要添加的class名称
		var className = 'btn btn-primary';
		var classWhiteName = 'btn btn-white';
		//初始化加载
		$(document).ready(function() {
			var HZFPButton = document.getElementById('myButtonhzfp');
			var myButtonyglzjj = document.getElementById('myButtonyglzjj');
			HZFPButton.className=className;
			myButtonyglzjj.className=classWhiteName;
			// 监听点击事件，激活指定的选项卡
			$('#myTabs li a').click(function(e) {
				// 阻止默认行为
				//e.preventDefault();
				// 获取当前点击的选项卡链接
				var $this = $(this);
				if($this.attr('href') === '#tab-1'){
					formSubmitted=true;
				}
				if($this.attr('href') === '#tab-2'){
					formSubmitted=false;
					// 添加 active 类到当前点击的选项卡
					$(this).addClass('active');
					$this.attr('aria-expanded', 'true');
				}
				// 检查是否为“用药购药”选项卡
				if ($this.attr('href') === '#tab-2') {
					// 初始化表格
					initializeTableForTab('tab-2');
				}
				if ($this.attr('href') === '#tab-3') {
					// 初始化表格
					initializeTableForTab('tab-3');
				}
				if ( $this.attr('href') === '#tab-4') {
					// 初始化表格
					initializeTableForTab('tab-4');
				}

			});
		});

		// 分别给每个按钮添加class
		HZFPButton.onclick = function() {
			debugger
			HZFPButton.className=className;
			myButtonyglzjj.className=classWhiteName;
			var x = document.getElementById("tabsDiv");
			var L = document.getElementById("content-main-lz");
			x.style.display = "block";
			L.style.display = "none";
			queryArchivesList();
		};
		myButtonyglzjj.onclick = function() {
			HZFPButton.className=classWhiteName ;
			myButtonyglzjj.className=className;
			var x = document.getElementById("tabsDiv");
			var L = document.getElementById("content-main-lz");
			x.style.display = "none";
			L.style.display = "block";
			initForLZYGJJTab();
		};
		/* 用户状态显示 */
		function statusTools(row) {
		    if (row.status == 1) {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.userId + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.userId + '\')"></i> ';
    		}
		}
		/*员工离职交接初始化*/
		function initForLZYGJJTab() {
			var datas=[];
			var tableId = 'bootstrap-table-5';
			var tableElement = $('#' + tableId);
			var data = $("#followUpAssign-form").serializeArray();
			data.push({name: 'flag', value: 5});
			$.ajax({
				cache : true,
				type : "POST",
				url: prefix + "/followUpAssignList",
				data : data,
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					datas=data.rows;
					$.operate.successCallback(data);
				}
			});
			tableElement.bootstrapTable({
				// 配置表格的相关属性
				// 例如数据源、列定义等
				// 示例配置
				modalName: "员工离职交接",
				fitColumns: true,
				striped: true,
				autoRowHeight: true,
				rowNumbers: true,
				showFooter:true,  //是否显示表格底部区域。
				clickToSelect: true, //是否启用点击行时选中整行的功能。
				singleSelect: false, //是否仅允许选择一行
				fixedColumns: true,
				//fixedNumber: 3,
				fixedRightNumber: 1,
				data: datas,
				columns: [
					{ field: 'patientName', title: '患者姓名', align: 'center' },
					{ field: 'name', title: '离职员工', align: 'center' },
					{ field: 'phone', title: '手机号', align: 'center'},
					{ field: 'storeName', title: '门店', align: 'center'},
					{
						title: '操作',
						align: 'center',
						width: 150,
						formatter: function(value, row, index) {
							if (row.id) {
								var actions = [];
								actions.push('<a class="tn-xs ' + editFlag + '" href="javascript:void(0)" onclick="selectUsersToParentCallBack2(\'' + row.id + '\')">一键分配</a> ');
								return actions.join('');
							} else {
								return "";
							}
						}
					}]

			});

		}
		function initializeTableForTab(tabId) {
			var datas=[];
			debugger
			var tableId = 'bootstrap-table-' + tabId.substring(4);
			var tableElement = $('#' + tableId);
			var data = $("#followUpAssign-form").serializeArray();
			data.push({name: 'flag', value: tabId.substring(4)});
			console.log("tableId="+tabId.substring(4));
			$.ajax({
				cache : true,
				type : "POST",
				url: prefix + "/followUpAssignList",
				data : data,
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					datas=data.rows;
					$.operate.successCallback(data);
				}
			});
			tableElement.bootstrapTable({
				// 配置表格的相关属性
				// 例如数据源、列定义等
				// 示例配置
				modalName: "随访跟进人分配",
				fitColumns: true,
				striped: true,
				autoRowHeight: true,
				rowNumbers: true,
				showFooter:true,  //是否显示表格底部区域。
				clickToSelect: true, //是否启用点击行时选中整行的功能。
				singleSelect: false, //是否仅允许选择一行
				fixedColumns: true,
				//fixedNumber: 3,
				fixedRightNumber: 1,
				data: datas,
				columns: [{
					checkbox: true
				},
					{ field: 'patientName', title: '患者姓名', align: 'center' },
					{ field: 'gender', title: '性别', align: 'center',width: 30 },
					{ field: 'age', title: '年龄', align: 'center',width: 30, },
					{ field: 'disease', title: '疾病', align: 'center' },
					{ field: 'clinicalDiagnosis', title: '临床诊断', align: 'center' },
					{ field: 'medicineName', title: '药品名称', align: 'center' },
					{ field: 'status', title: '跟进人状态', align: 'center',width: 50, },
					{ field: 'followUpPersonName', title: '随访跟进人姓名', align: 'center' },
					{ field: 'lastPurchaseDate', title: '最后一次购药', align: 'center' },
					{ field: 'filingDate', title: '建档日期', align: 'center' },
					{
						title: '操作',
						align: 'center',
						width: 150,
						formatter: function(value, row, index) {
							if (row.id) {
								var actions = [];
								actions.push('<a class="btn-xs' + editFlag + '" href="javascript:void(0)" onclick="selectUsersToParentCallBack2(\'' + row.id + '\')">修改跟进人</a> ');
								actions.push('<a class="btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
								return actions.join('');
							} else {
								return "";
							}
						}
					}]

			});
		}
		function selectUsersToParentCallBack2(rowid){
			console.log("rowid=="+rowid)
			patientId=rowid;
			var prefix_s = ctx + "dtp/recipe";
			//l: prefix + "/updateFollowUpPerson?id="+rowid,
			var options = {
				title: '修改随访跟进人',
				url: prefix_s + "/drugInfo",
				callBack: doSubmit2
			};
			$.modal.openOptions(options);
		}

		function doSubmit2(index, layero){
			console.log("id=="+index)
			var rows = layero.find("iframe")[0].contentWindow.selectColumns2();
			if (rows.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			rows.forEach(function(item, index) {
				var id =item.productId;
				var name = item.productName;


			});
			// 做修改操作 修改跟进人
			$.modal.close(index);
		}


	</script>
<style>
	.lizhi {
	display: none;
	}

</style>
</body>

</html>
