<!-- include 'header' -->
<body>
	<div class="mainLayout">
		<div class="mainMenu">
			<div class="menuItem">
				<a href="#" class="mLogo">CLD</a>
				<ul>
					<!-- include 'menu' -->
				</ul>
			</div>
		</div>
		<div class="warpContent">
			<div class="contactTab">
				<a class="now" href="#">建筑计价</a>
				<div class="searchItem">
					<input type="text" placeholder="输入建筑用户手机号进行搜索" id="search_mobile">
					<input type="hidden" id="hidden_search" value="0">
					<input type="button" class="subBtn search-build" value="搜索">
				</div>
			</div>
			<div class="contactDatabase fL">
				<div class="contactCate">
					<ul class="cateList">
						<li class="clearfix filter">
							<select id="compilation_select">
								<option value="0">所有建筑版本</option>
								<!-- if !empty({{compilationList}}) -->
								<!-- loop compilationList -->
								<option value="{{compilationList' value.compilation_id}}">{{compilationList' value.cname}}专业版</option>
								<!-- endloop -->
								<!-- endif -->
							</select>&nbsp;
							<select id="year_select">
								{{year_option}}
							</select>&nbsp;
							<select id="month_select">
								<option value="0">所有月份</option>
								<option value="1">1月</option>
								<option value="2">2月</option>
								<option value="3">3月</option>
								<option value="4">4月</option>
								<option value="5">5月</option>
								<option value="6">6月</option>
								<option value="7">7月</option>
								<option value="8">8月</option>
								<option value="9">9月</option>
								<option value="10">10月</option>
								<option value="11">11月</option>
								<option value="12">12月</option>
							</select>&nbsp;
							<select id="category_select">
								<!-- loop categoryList -->
								<option value="{{categoryList' value.cid}}" <!-- if {{categoryList' value.cid}} == {{staff.0.cid}} -->selected<!-- endif -->>{{categoryList' value.title}}</option>
								<!-- endloop -->
							</select>&nbsp;
							<select id="staff_select">
								<option value="0">负责人</option>
								<!-- loop staffList -->
								<option value="{{staffList' value.sid}}">{{staffList' value.username}}</option>
								<!-- endloop -->
							</select>
						</li>
					</ul>
					<div class="contactTableHead">
						<table class="buildingUl">
							<tbody>
							<tr>
								<td width="150">通行帐号手机号</td>
								<td width="180">激活产品</td>
								<td width="100">办事处</td>
								<td width="75">责任人</td>
								<td width="90">状态</td>
								<td width="90">cld客户</td>
								<td>激活时间</td>
							</tr>
							</tbody>
						</table>
					</div>
				</div>
				<div class="contactList autoHeightL2">
					<table class="contactTable" id="build_list">
						<!-- if !empty({{blist}}) -->
						<!-- loop blist -->
						<tr>
							<td width="150"><a href="javascript:void(0);" class="getBuildingMsg" data-id="{{blist' value.sso_id}}" data-cid="{{blist' value.client_id}}">{{blist' value.mobile}}</a></td>
							<td width="180">{{blist' value.cname}}专业版</td>
							<td width="100">{{blist' value.categoryname}}</td>
							<td width="75"><a href="javascript:void(0);" class="getStaffMsg" data-sid="{{blist' value.sid}}">{{blist' value.staffname}}</a></td>
							<td width="90"><!-- if {{blist' value.status}} == 1 -->已激活<!-- endif --></td>
							<td width="90"><!-- if {{blist' value.client_id}} != 0 --><a href="javascript:void(0);" class="getClientMsg" data-cid="{{blist' value.client_id}}">{{blist' value.clientname}}</a><!-- endif --></td>
							<td>{{blist' value.addtime}}</td>
						</tr>
						<!-- endloop -->
						<!-- endif -->
					</table>
				</div>
			</div>
			<div class="lockDetil fL">
				<div class="lockRecord autoHeightR2">
					<!--build建筑信息页-->
					<div id="build_msg" style="display:none;">
						<div class="toolItem clearfix">
							<div class="contactInfo">
								<div class="contactPanel">
									<h1>建筑用户信息</h1>
									<table>
										<tbody id="buildUserInfo_msg">
										</tbody>
									</table>
								</div>
							</div>
						</div>
						<div class="toolItem clearfix">
							<div class="contactPanel">
								<div class="subNav">
									<ul class="navTabs">
										<li class="active tabChange" data-tab="build"><a href="#">建筑激活版本</a></li>
										<li class="tabChange" data-tab="cld"><a href="#">cld客户信息</a></li>
									</ul>
								</div>
								<table class="versionTabale" id="compilation_msg">
									<input type="hidden" id="build_ssoid" value="">
									<input type="hidden" id="build_mobile" value="">
									<input type="hidden" id="client_id" value="">
									<tr>
										<th>产品</th><th>免费版</th><th>专业版</th>
									</tr>
									<tbody id="compilation_list">

									</tbody>
									<tr id="activation_btn" style="display: none">
										<td colspan="2">
											<a href="javascript:void(0)" class="button">确定</a>
										</td><td></td>
									</tr>
								</table>
								<table id="clientInfo_msg" style="display: none;">
									<tr><th>姓名</th><td><a href="#">周乃君</a></td><th>昵称</th><td>周工</td></tr>
									<tr><th>性别</th><td>女</td><th>办事处</th><td>广东办</td></tr>
									<tr><th>手机</th><td>12345678910</td><th>电话</th><td>0000-564645654</td></tr>
									<tr><th>QQ</th><td>12345678</td><th>邮箱</th><td>123456@qq.com</td></tr>
									<tr><th>单位全称</th><td><a href="#">广东长誉公路工程有限公司</a></td></tr>
								</table>
							</div>
						</div>

						<div class="toolItem clearfix" id="add_client" style="display: none">
							<div class="contactInfo">
								<div class="contactPanel">
									<h1>绑定cld客户</h1>
									<div>
										<span data-placement="right" data-toggle="ctooltip" data-original-title="只允许填写库中存在的客户，若输入客户不存在，请先添加该客户。">
										<input type="text" id="client_result" value="">
										</span>
									</div>
									<a href="javascript:void(0)" class="button" id="addclient_btn">确定绑定</a>
								</div>
							</div>
						</div>

						<div id="activation_list">
						</div>
					</div>
					<!--end build-->

					<!--staff员工信息页-->
					<div class="toolItem clearfix" style="display: none;" id="staff_msg">
						<div class="contactPanel">
							<h1>刘飞</h1>
							<table>
								<tbody>
								<tr>
									<th>性别</th><td>男</td>
									<th>办事处</th><td>广东办</td>
								</tr>
								<tr>
									<th>手机</th><td>12345678910</td>
									<th>电话</th><td>0000-564645654</td>
								</tr>
								<tr>
									<th>QQ</th><td>12345678</td>
									<th>邮箱</th><td>123456@qq.com</td>
								</tr>
								</tbody>
							</table>
						</div>
					</div>
					<!--end staff-->

					<!--client客户信息页-->
					<div class="toolItem clearfix" style="display: none;" id="clientInfo">
					<!--<div class="toolItem clearfix" style="display: none;" id="client_msg">-->
						<div class="contactPanel">
							<h1><p class="fR">总部-<a href="javascript:void(0)" onclick="getStaffInfo('温秀娟')">温秀娟</a></p>周乃君<i class="icon- sport">5</i><a data-original-title="编辑客户" data-toggle="ctooltip" data-placement="right" href="javascript:clientEdit(80171)" class="icon- edit">I</a></h1>
							<table>
								<tbody><tr><th>性别</th><td>女</td><th>昵称</th><td>庄（青美）：</td></tr>
								<tr><th>手机</th><td>18299400510</td><th>QQ</th><td>409764520</td></tr>
								<tr><th>电话</th><td>0794-8223829</td><th>邮箱</th><td>409764520@qq.com</td></tr>
								<tr><th>备注</th><td colspan="3"></td></tr>
								<tr><td colspan="4"></td></tr>
								</tbody></table>
						</div>
						<div class="contactPanel">
							<table>
								<tbody>
								<tr><th>单位全称</th><td colspan="3"><a href="javascript:void(0)" onclick="getCompany('8668')">昆明苇杭科技有限公司</a></td></tr>
								<tr><th>单位主页</th><td colspan="3">http://www.xfxsoft.cn/</td></tr>
								<tr><th>客户地区</th><td>云南省,昆明市,西山区</td><th>部门/职位</th><td>/</td></tr>
								<tr><th>客户传真</th><td></td><th>办公室</th><td></td></tr>
								<tr><th>客户地址</th><td colspan="3">云南省昆明市盘龙区东风东路47号建业商务中心A2202</td></tr>
								<tr><th>客户乘车</th><td colspan="3"></td></tr>
								<tr><th>客户地标</th><td colspan="3">建业商务中心</td></tr>
								<tr><th>客户住宿</th><td colspan="3"></td></tr>
								</tbody></table>
						</div>
					</div>
					<!--end client-->
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">autoFlashHeight();</script>
	<link rel="stylesheet" href="<?= WEB_SITE_GLOBAL ?>/js/jquery-ui.css" />
	<script src="<?= WEB_SITE_GLOBAL ?>/js/jquery-ui.js"></script>

	<script src="<?= WEB_SITE_GLOBAL ?>/js/jquery.ui.core.js"></script>
	<script src="<?= WEB_SITE_GLOBAL ?>/js/jquery.ui.widget.js"></script>
	<script src="<?= WEB_SITE_GLOBAL ?>/js/jquery.ui.position.js"></script>
	<script src="<?= WEB_SITE_GLOBAL ?>/js/jquery.ui.autocomplete.js"></script>
	<script>
		$(function(){
			// 建筑激活页面cld客户搜索
			$("#client_result").blur(function(){

				var url="/checkClient";

				var name=$(this).val();

				$.ajax({
					url:url,
					type: "post",
					cache: false,
					dataType: "json",
					data: {
						name:name
					},
					global: true,
					success: function(data){

						if(data.success){
							$("#client_result").css("background-color","#fff");
						}else{
							$("#client_result").css("background-color","#f15b6c");
							$('#client_id').val('');
						}
					},
					error:function(err){
						$("#client_result").css("background-color","#f15b6c");
						$('#client_id').val('');
					}
				});


			});

			$("#client_result").autocomplete({
				source: function( request, response ) {
					$.ajax({
						url: "/searchClient",
						dataType: "json",
						data:{
							searchDbInforItem: request.term
						},
						success: function( data ) {

							response( $.map( data, function( item ) {

								return {
									name:item.cid,

									value: item.clientname+"-"+item.companyname
								}
							}));
						}
					});
				},
				minLength: 1,
				select: function( event, ui ) {
					$("#client_result").val(ui.item.dbId);
					$('#client_id').val(ui.item.name);
				}
			});
		})
	</script>
<script>
	$(function(){
		// 获取建筑用户信息
		$('body').on('click', '.getBuildingMsg', function(){
			var id = $(this).attr('data-id');
			var cid = $(this).attr('data-cid');
			getBuildMsg(id, cid);
		});

		// 获取cld客户信息
		$('body').on('click', '.getClientMsg', function(){
			var cid = $(this).attr('data-cid');
			$.ajax({
				type: 'get',
				url: '/building/getClientMsg?cid=' + cid,
				dataType: 'json',
				success: function(result) {
					if (result.code == '200') {
						var data = result.data;

						// 获取cld客户信息
						var clientInfo = data.clientInfo;
						var staffInfo = data.staffInfo;
						var clienthtml = '<div class="contactPanel"><h1><p class="fR">' + staffInfo.category + '-<a href="javascript:void(0)" class="getStaffMsg" data-sid="' + staffInfo.sid + '">' + staffInfo.username + '</a></p>' +
								clientInfo.clientname + '<i class="icon- sport">' + clientInfo.priority + '</i><a data-original-title="编辑客户" data-toggle="ctooltip" data-placement="right" href="javascript:clientEdit(' + clientInfo.cid + ')" class="icon- edit">I</a></h1> ' +
								'<table><tbody>' +
								'<tr><th>性别</th><td>' + clientInfo.gender + '</td><th>昵称</th><td>' + clientInfo.nicename + '</td></tr> ' +
								'<tr><th>手机</th><td>' + clientInfo.telephone + '</td><th>QQ</th><td>' + clientInfo.qq + '</td></tr> ' +
								'<tr><th>电话</th><td>' + clientInfo.phone + '</td><th>邮箱</th><td>' + clientInfo.email + '</td></tr> ' +
								'<tr><th>备注</th><td colspan="3">' + clientInfo.mark + '</td></tr> ' +
								'<tr><td colspan="4"></td></tr> ' +
								'</tbody></table></div>';
						$('#clientInfo_result').html(clienthtml);

						// 获取单位信息
						var companyInfo = data.companyInfo;
						var local = data.local;
						var companyhtml = '<div class="contactPanel"><table> <tbody> ' +
								'<tr><th>单位全称</th><td colspan="3"><a href="javascript:void(0)" onclick="getCompany(' + companyInfo.cid + ')">' + companyInfo.companyname + '</a></td></tr> ' +
								'<tr><th>单位主页</th><td colspan="3">' + clientInfo.webservice + '</td></tr> ' +
								'<tr><th>客户地区</th><td>' + local[0].name + ',' + local[1].name + ',' + local[2].name + '</td><th>部门/职位</th><td>' + clientInfo.department + '</td></tr> ' +
								'<tr><th>客户传真</th><td>' + clientInfo.fax + '</td><th>办公室</th><td>' + clientInfo.office + '</td></tr> ' +
								'<tr><th>客户地址</th><td colspan="3">' + clientInfo.address + '</td></tr> ' +
								'<tr><th>客户乘车</th><td colspan="3">' + clientInfo.ride + '</td></tr> ' +
								'<tr><th>客户地标</th><td colspan="3">' + clientInfo.landmarks + '</td></tr> ' +
								'<tr><th>客户住宿</th><td colspan="3">' + clientInfo.stay + '</td></tr> ' +
								'</tbody></table></div>';

						var html = clienthtml + companyhtml;

						$('#clientInfo').html(html);

						$('#clientInfo').show();
						$('#staff_msg').hide();
						$('#build_msg').hide();
					}
				}
			})
		});

		// 获取cld责任人信息
		$('body').on('click', '.getStaffMsg', function(){
			var sid = $(this).attr('data-sid');
			$.ajax({
				type: 'get',
				url: '/building/getStaffMsg?sid=' + sid,
				dataType: 'json',
				success: function(result) {
					if (result.code == '200') {
						var userinfo = result.data;
						var html = '<div class="contactPanel"><h1>' + userinfo.username + '</h1> ' +
								'<table> <tbody> ' +
								'<tr> ' +
								'<th>性别</th><td>' + userinfo.gender + '</td> ' +
								'<th>办事处</th><td>' + userinfo.category + '</td> ' +
								'</tr> ' +
								'<tr> ' +
								'<th>手机</th><td>' + userinfo.telephone + '</td> ' +
								'<th>电话</th><td>' + userinfo.phone + '</td> ' +
								'</tr> ' +
								'<tr> ' +
								'<th>QQ</th><td>' + userinfo.qq + '</td> ' +
								'<th>邮箱</th><td>' + userinfo.email + '</td> ' +
								'</tr> ' +
								'</tbody> ' +
								'</table></div>';
						$('#staff_msg').html(html);
						$('#staff_msg').show();
						$('#build_msg').hide();
						$('#clientInfo').hide();
					}
				}
			})
		});

		// 搜索建筑用户信息
		$('.search-build').on('click', function(){
			var mobile = $('#search_mobile').val();
			if (mobile == '') {
				alert('请输入建筑用户手机号');
			} else {
				$.ajax({
					type: 'get',
					url: '/building/checkMobile?mobile=' + mobile,
					dataType: 'json',
					success: function(result) {
						if (result.code == '200') {
							var data = result.data;
							getBuildList(data.id);
							getBuildMsg(data.id, data.cid);
						} else {
							alert(result.msg);
						}
					}
				})
			}
		});

		// 激活建筑产品
		$('#activation_btn a').click(function() {
			// 只获取第一个选中的值
			var cid = $('#compilation_list input:checked').attr('data-cid');
			var cname = $('#compilation_list input:checked').attr('data-cname');
			var id = $('#build_ssoid').val();
			var mobile = $('#build_mobile').val();
			var client_id = $('#client_id').val();
			if (cid !== undefined && id !== '') {
				$.ajax({
					type: 'post',
					url: '/building/setUserCompilation',
					data: {id: id, cid: cid, mobile: mobile, client_id: client_id, cname: cname},
					dataType: 'json',
					success: function(result) {
						if (result.code == '200') {
							$('#hidden_search').val() != 0 ? getBuildList(id) : getBuildList('');
							getBuildMsg(id, client_id);
						} else {
							alert('激活失败');
						}
					}
				})
			} else {
				alert('请选择需要激活的版本');
			}
		});

		// 绑定cld客户
		$('#addclient_btn').click(function() {
			var cid = $('#client_id').val();
			var id = $('#build_ssoid').val();
			if (cid == '' || id == '') {
				alert('请根据要求填入cld客户');
			} else {
				$.ajax({
					type: 'post',
					url: '/building/setUserClient',
					data: {id: id, cid: cid},
					dataType: 'json',
					success: function(result) {
						if (result.code == '200') {
							$('#hidden_search').val() != 0 ? getBuildList(id) : getBuildList('');
							getBuildMsg(id, cid);
						} else {
							alert('绑定失败');
						}
					}
				})
			}
		});

		// ajax 获取建筑信息方法
		function getBuildMsg(id, cid) {
			$.ajax({
				type: 'get',
				url: '/building/getBuildMsg',
				data: {id: id, cid: cid},
				dataType: 'json',
				success: function(result) {
					if (result.code == '200') {
						var data = result.data;
						var builduserinfo = data.userInfo;
						var buildmsghtml =
								'<tr><th>称呼</th><td>' + builduserinfo.real_name + '</td><th>使用时间</th><td>' + builduserinfo.create_time + '</td></tr> ' +
								'<tr><th>手机</th><td>' + builduserinfo.mobile + '</td><th>邮箱</th><td>' + builduserinfo.email + '</td></tr> ' +
								'<tr><th>企业名称</th><td>' + builduserinfo.company + '</td><th>企业规模</th><td>' + builduserinfo.company_scale + '</td></tr> ' +
								'<tr><th colspan="2" width="50">企业所在地区</th><td colspan="2">' + builduserinfo.province + '</td></tr> ';
						$('#buildUserInfo_msg').html(buildmsghtml);
						$('#build_ssoid').val(builduserinfo.ssoId);
						$('#build_mobile').val(builduserinfo.mobile);

						var compilationhtml = '';
						var addCompilation = false;
						$.each(data.compilationList, function(k, v) {
							compilationhtml += '<tr> <th>' + v.name + '</th>' +
									'<td>' + (v.isUpgrade !== undefined && v.isUpgrade === false ? '<img src="<?= WEB_SITE_GLOBAL ?>css/checkmark.png" width="20" height="20">' : '') + '</td>' +
									'<td>' + (v.isUpgrade !== undefined && v.isUpgrade === true ? '<img src="<?= WEB_SITE_GLOBAL ?>css/checkmark.png" width="20" height="20">' : '<input type="checkbox" data-cid="' + v._id + '" data-cname="' + v.name + '" >') + '</td> ' +
									'</tr>';
							if (v.isUpgrade === undefined || v.isUpgrade === false) {
								addCompilation = true;
							}
						});
						if (addCompilation) {
							$('#activation_btn').show();
						} else {
							$('#activation_btn').hide();
						}

						$('#compilation_list').html(compilationhtml);

						var addclienthtml = '';
						$('#add_client').hide();
						if (data.clientInfo != '') {
							var clientinfo = data.clientInfo;
							var clientInfohtml = '' +
									'<tr><th>姓名</th><td><a href="#" class="getClientMsg" data-cid="' + clientinfo.cid + '">' + clientinfo.clientname + '</a></td><th>昵称</th><td>' + clientinfo.nicename + '</td></tr> ' +
									'<tr><th>性别</th><td>' + clientinfo.gender + '</td><th>办事处</th><td>' + clientinfo.department + '</td></tr> ' +
									'<tr><th>手机</th><td>' + clientinfo.telephone + '</td><th>电话</th><td>' + clientinfo.phone + '</td></tr> ' +
									'<tr><th>QQ</th><td>' + clientinfo.qq + '</td><th>邮箱</th><td>' + clientinfo.email + '</td></tr> ' +
									'<tr><th>单位全称</th><td><a href="#">' + clientinfo.companyname + '</a></td></tr>';
							$('#clientInfo_msg').html(clientInfohtml);
							$('#client_id').val(clientinfo.cid);
						} else {
							$('#clientInfo_msg').html('暂未添加cld客户信息');
							$('#add_client input').val('');
							$('#add_client').show();
							$('#client_id').val('');
							$('#clientInfo').val('');
						}

						// 激活时间轴
						var activationListhtml = '';
						var activationList = data.buildActivationList;
						$.each(activationList, function(k, v) {
							activationListhtml += '<div class="infoFlowList"> <div class="dateTitle"> ' +
									'<em class="month"><span class="num">' + v.month + '</span><span class="text">-' + v.day + '</span></em> ' +
									'<span class="year">' + v.year + '</span> </div> ' +
									'<ul class="flowList"> ' +
									'<li class="item iconUpdate">激活 &lt; ' + v.categoryname + '<a href="#" class="getStaffMsg" data-sid="' + v.sid + '">' + v.staffname + '</a></li> ' +
									'<li class="item">' + v.cname + '专业版</li> </ul> </div>';
						});
						$('#activation_list').html(activationListhtml);

						$('#build_msg').show();
						$('#staff_msg').hide();
						$('#clientInfo').hide();
					} else {
						alert('没有此用户');
					}
				}
			})
		}

		// ajax 获取列表方法
		function getBuildList(ssoid) {
			if (ssoid != '') {
				$('#compilation_select').val(0);
				$('#year_select').val(0);
				$('#month_select').val(0);
				$('#category_select').val('{{staff.0.cid}}');
				$('#staff_select').val(0);
				$('#hidden_search').val(1);
			} else {
				$('#search_mobile').val('');
				$('#hidden_search').val(0);
			}
			var postData = {
				compilation_id: $('#compilation_select').val(),
				year: $('#year_select').val(),
				month: $('#year_select').val() != 0 ? $('#month_select').val() : 0,
				category: $('#category_select').val(),
				staff_id: $('#staff_select').val(),
				sso_id: ssoid
			};
			$.ajax({
				type: 'post',
				url: '/building/getBuildList',
				data: postData,
				dataType: 'json',
				success: function(result) {
					if (result.code == '200') {
						var data = result.data;
						var html = '';
						$.each(data, function(k,v) {
							html += '<tr> ' +
									'<td width="150"><a href="javascript:void(0);" class="getBuildingMsg" data-id="' + v.sso_id + '" data-cid="' + v.client_id + '">' + v.mobile + '</a></td> ' +
									'<td width="180">' + v.cname + '专业版</td> ' +
									'<td width="100">' + v.categoryname + '</td>' +
									'<td width="75"><a href="javascript:void(0);" class="getStaffMsg" data-sid="' + v.sid + '">' + v.staffname + '</a></td> ' +
									'<td width="90">' + (v.status == 1 ? '已激活' : '') + '</td> ' +
									'<td width="90">' + (v.client_id != 0 ? '<a href="javascript:void(0);" class="getClientMsg" data-cid="' + v.client_id + '">' + v.clientname + '</a>' : '') + '</td> ' +
									'<td>' + v.addtime + '</td> ' +
									'</tr>';
						});
						$('#build_list').html(html);
					} else {
						alert('获取列表数据失败');
					}
				}
			})
		}

		// 获取列表各种条件筛选方法
		$('#compilation_select').change(function() {
			getBuildList('');
		});
		$('#year_select').change(function() {
			getBuildList('');
		});
		$('#month_select').change(function() {
			getBuildList('');
		});
		$('#category_select').change(function() {
			getBuildList('');
		});
		$('#staff_select').change(function() {
			getBuildList('');
		});

		// tab切换
		$('.tabChange').click(function() {
			var tab = $(this).attr('data-tab');
			if (tab == 'build') {
				$('#compilation_msg').show();
				$('#clientInfo_msg').hide();
			} else {
				$('#compilation_msg').hide();
				$('#clientInfo_msg').show();
			}
			$(this).addClass('active');
			$(this).siblings().removeClass('active');
		})
	})
</script>
</body>
