1. 程式人生 > >ajax 點贊收藏功能

ajax 點贊收藏功能

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
       <%@include file="/include.jsp"%>
<%@page import="java.util.Date"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>醫院科室-專家諮詢</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="<ph:root/>/s/css/rmyy/dept.css">
    <script type="text/javascript" src="<ph:root/>/s/js/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="<ph:root/>/s/js/css-util.js"></script>
    <script type="text/javascript">
    	var dzResult = '${dzResult}' ;
    	var num='${expertInfo.dznum }';
    	$(document).ready(function() {
    		if('${loginCustomer}' != null && '${loginCustomer}' != ""){
    			if(dzResult==true || dzResult == 'true'){ //已贊
    				document.getElementById('zan').src='<ph:root/>/s/images/index/zan.png';
    			}else{ 
    				document.getElementById('zan').src='<ph:root/>/s/images/index/zan1.png';
    			}
    		}else{
    			document.getElementById('zan').src='<ph:root/>/s/images/index/zan1.png';
    		}
    	}); 
    	   
    	function consult(){
    		if('${loginCustomer}' != null && '${loginCustomer}' != ""){
		    	openJsWidow("立即諮詢","<ph:root/>/f/department/consult/${channel.id}.html?id=${expertInfo.id}",600,680);
    		}else{
    			openJsWidow("登入","<ph:root/>/u/showLoginMin",700,400);
    		}
    	}
 
    	function dz(){
    		if('${loginCustomer}' != null && '${loginCustomer}' != ""){
    			if(dzResult==true || dzResult == 'true'){ //已贊
    				dianzan('${expertInfo.id}',0);
    			}else {
    				dianzan('${expertInfo.id}',1);
    			}
    		}else{
    			openJsWidow("登入","<ph:root/>/u/showLoginMin",700,400);
    		}
    	}
    	
    	function dianzan(id,flag){
    		$.ajax({
    			url:'<ph:root/>/f/department/dianzan',
    			type:'post',
    			data:{id:id,flag:flag},
    			dataType:'json',
    			success:function(result){
    				if(result == 0){
    					if(flag == 1){
    						dzResult = true;
    						document.getElementById('zan').src='<ph:root/>/s/images/index/zan.png';
    						num=num*1+1;
    						document.getElementById('zanNum').innerText=num;
    					}else if(flag ==0){
    						dzResult = false;
    						document.getElementById('zan').src='<ph:root/>/s/images/index/zan1.png';
    						num=num*1-1;
    						document.getElementById('zanNum').innerText=num;
    					}
    				}
    			}
    		});
    	}
    </script>
</head>
<body>
<%@include file="/WEB-INF/views/f/top1.jsp"%>
<%@include file="/WEB-INF/views/f/top.jsp"%>
    <div class="wrap">    
	    <%@include file="/WEB-INF/views/f/left.jsp"%>
		<div style="float:right;width:80%;padding:15px 0 0 5px;margin-bottom:20px;"> 
		    <div class="dept-content">
		    <sf:form modelAttribute="expertInfo" action="" method="post" id="form1" name="form1">
		        <div class="sys-title">
		            <p>${expertInfo.deptmentName }</p>
		            <small>${expertInfo.englishName }</small>
		        </div>
		        <div class="sys-contain" > 
		            <div class="expert-header">
		                <img src="${expertInfo.imgurl }"/>
		                <div class="expert-contain">
		                    <div style="font-size: 18px;padding: 5px 0">
		                    <div>${expertInfo.realName }
		                    <a style="margin-left:60px;" href="javascript:consult()" class="button">立即諮詢</a> </div>
		                    </div>
		                    <div class="expert-title">
		                        <p>${expertInfo.title }</p>
		                        <p>專業擅長:${expertInfo.expert }</p>
		                        <p style="padding:10px 0;">坐診資訊:坐診資訊坐診資訊坐診資訊</p>
		                    </div>
		                </div>
		                <div class="zan">
		                    <a href="javascript:dz()" ><img id="zan" src="<ph:root/>/s/images/index/zan1.png"/></a>
		                    <div style="clear:both;"><span id="zanNum" >${expertInfo.dznum }</span><span >贊</span></div>
		                </div>
		                <div style="clear:both;"></div>
		            </div>
		            
		            <div class="border-dashed"></div>
		            <div class="treat">
		                <p style="margin: 20px auto;">坐診資訊</p>
		                <table style="width: 100%">
		                    <tr>
		                        <th style="width: 9%"></th>
		                        <th style="width: 13%">星期一</th>
		                        <th style="width: 13%">星期二</th>
		                        <th style="width: 13%">星期三</th>
		                        <th style="width: 13%">星期四</th>
		                        <th style="width: 13%">星期五</th>
		                        <th style="width: 13%">星期六</th>
		                        <th style="width: 13%">星期七</th>
		                    </tr>
		                    <c:forEach items="${outpatientInfoList }" var="outp">
		                    	<tr>
		                    		<td style="color:#008385">
		                    			<c:if test="${outp.timenode == 1 }">
		                    				上午
		                    			</c:if>
		                    			<c:if test="${outp.timenode == 2 }">
		                    				下午
		                    			</c:if>
		                    		</td>
		                    		<td><ph:dictValue dictCode="${outp.mon }"/></td>
									<td><ph:dictValue dictCode="${outp.tues }"/></td>
			                        <td><ph:dictValue dictCode="${outp.wed }"/></td>
			                        <td><ph:dictValue dictCode="${outp.thurs }"/></td>
			                        <td><ph:dictValue dictCode="${outp.fri }"/></td>
			                        <td><ph:dictValue dictCode="${outp.sat }"/></td>
			                        <td><ph:dictValue dictCode="${outp.sun }"/></td>
		                    	</tr>
		                    </c:forEach>
		                </table>
		                <p style="color: #dddddd; text-align: left;padding-top: 5px;">以上資訊僅供參考,可根據實際情況有所調整。</p>
		            </div>
		            
		            <div class="border-dashed"></div>
		            <div class="intro">
		                <p style="margin: 20px auto;text-align: center">專家簡介</p>
		                <p style="color: #999999;text-indent:2em;">${expertInfo.introduction }</p>
		            </div>
		        </div>
		    </sf:form>
		    </div>
		</div>
	</div>
	<%@include file="/WEB-INF/views/f/foot.jsp"%>
</body>
</html>
/**
	 * 點贊
	 */
	@RequestMapping(value="/f/department/dianzan")
	public void dianzan(@RequestParam long id,@RequestParam int flag,ModelMap model,
			HttpSession session,HttpServletResponse response)throws Exception{
		Customer loginCus = (Customer) session.getAttribute(LOGIN_CUSTOMER_SESSION_KEY);
		long userId = loginCus.getId();
		Dianzan dianzan = new Dianzan();
		dianzan.setUserId(userId);
		dianzan.setDoctorId(id);
		if (flag==1) {
			long dzTime = new Date().getTime();
			dianzan.setDzTime(dzTime);
			customerService.addDianzan(dianzan);
			
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", id);
			map.put("dzNum", 1);
			customerService.updateDoctInfoDZ(map);
		}
		if (flag==0) {
			customerService.delDianzan(dianzan);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("id", id);
			map.put("dzNum", 0);
			customerService.updateDoctInfoDZ(map);
		}
		Customer expertInfo = customerService.getCustomerById(id);
		model.addAttribute("expertInfo", expertInfo);
		AjaxUtils.ajaxHtml("0", response);
	}