<%@page contentType="text/html; charset=UTF-8"%>
<%@include file="/inc/init.jsp" %>
<%@include file="/inc/checklogin.jsp" %>
<%@include file="inc/header.jsp" %>
<%
Order_list_db oldb=new Order_list_db();
int orderid=pu.getInt("orderid");
DOC doc=oldb.getOne(orderid);
Product_db pdb=new Product_db();
DOC doc2=pdb.getOne(doc.geti("productid"));  //得到产品名称
Product_class_db pcdb=new Product_class_db();
DOC doc3 = pcdb.getOne(doc.geti("classid"));
String keyword=pu.getStringByPage("keyword");
%>
<div id="c">
<%@include file="inc/left.jsp" %>
<div id="right">
<%@include file="inc/position.jsp" %>
<div class="right">
<form method="post" name="mainform" action="fun/F_order.jsp" onSubmit="return checkform()" >
<div id="right_box">
<div class="blank20"></div>
<div id="tagscontent" class="right_box">
<div class="hid_box">
<div class="hbox" style="border:1px #999 solid;">
<table width="100%" cellspacing="1" cellpadding="1" class="table1" bgcolor="#CCCCCC" name="table1"> 
	  <%if(StringUtil.isFine(keyword)){%>
	  <tr> 
        <td width="15%" height="30" align="right" bgcolor="#FFFFFF">关键字：</td> 
        <td width="85%" height="30" bgcolor="#FFFFFF" onMouseOver="tooltip.show('可根据用户地址，留言，及自行备注搜索！');" onMouseOut="tooltip.hide();">&nbsp;<span style="font-size:14px; font-weight:bold;color:#F00"><%=keyword%></span></td> 
      </tr> 
	  <%}%>
      <tr> 
        <td width="15%" height="30" align="right" bgcolor="#FFFFFF">订单号：</td> 
        <td width="85%" height="30" bgcolor="#FFFFFF">&nbsp;<%=doc.get("orderid")%></td> 
      </tr>  
      <tr> 
        <td width="15%" height="30" align="right" bgcolor="#FFFFFF">下单时间：</td> 
        <td width="85%" height="30" bgcolor="#FFFFFF">&nbsp;<%=doc.get("create_time")%></td> 
      </tr>
      <tr> 
        <td height="150" align="right" bgcolor="#FFFFFF">订购产品：</td> 
        <td height="30" align="center" bgcolor="#FFFFFF">
          
  <table width="98%" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC" style="margin:2px 0px;">
    <tr>
      <th width="43%" height="30" bgcolor="#FFFFFF" scope="col">订单名称</th>
      <th width="8%" height="30" bgcolor="#FFFFFF" scope="col">单价</th>
      <th width="8%" bgcolor="#FFFFFF" scope="col">数量</th>
      <th width="43%" bgcolor="#FFFFFF" scope="col">客户留言</th>
      </tr>
    
    
    
    <tr>
      <td height="30" align="center" bgcolor="#FFFFFF"><a href="productEdit.jsp?productid=<%=doc.get("productid")%>"><%=doc2.get("name")%></a></td>
      <td height="30" align="center" bgcolor="#FFFFFF"><%=doc2.get("price2")%></td>
      <td align="center" bgcolor="#FFFFFF"><%=doc.geti("number")>0?doc.get("number"):"1"%></td>
      <td align="center" bgcolor="#FFFFFF"><font id="khremark"><%=doc.get("remark")%></font></td>
      </tr>
	<tr>
      <td height="30" colspan="4" align="left" bgcolor="#FFFFFF"><strong> &nbsp;合计原价：</strong><span style="font-size:14px; color:#F00"><%=doc.get("price2")%>元</span> &nbsp;<strong>实收</strong>：</strong>
      			<input type="text" name="price" id="price" class="input_c" value="<%=doc.get("price")%>" />
      		<span style="font-size:14px; color:#F00">元</span>（客户要求更优惠等原因的实收价）</td>
    </tr>
    <tr>
    	<td height="34" colspan="4" align="center" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    		<tr>
    			<td width="11%"><strong>套餐内容</strong></td>
    			<td width="89%" align="left"><%=doc2.get("remark")%></td>
    			</tr>
    		</table></td>
    	</tr>
	 <tr>
      <td height="30" colspan="4" bgcolor="#FFFFFF"><strong></td>
      </tr>
	 <tr >
      <td height="30" colspan="4" bgcolor="#FFFFFF">
      	<p style="font-size:14px; color:#006600" align="center"><input name="" value="发送短信" type="button" onClick="$('#sendsms').slideToggle('slow');$('#smshistory').hide();" class="btn_a" style="margin:1px 0px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" onClick="viewSmsHistory()" >查看发送历史</a><!--<a href="javascript:window.history.go(-1);" class="btn_e" style="float:right;">返回</a>--></p></td>
      </tr>
  </table>
  <div id="sendsms" style="display:none; padding:10px 10px;">
  <table width="100%" cellspacing="1" cellpadding="1" class="table2" bgcolor="#CCCCCC" name="table2"> 
    <%
      				String pdname=doc3.get(Product_class_db.Jname);
					String tempName=doc2.get("name");
					if(tempName.indexOf("装")!=-1){  //套装名字，如XX装，不需要后面的字了
						tempName=Util.sub_StringByKey(tempName,0,"装");
						tempName=pdname +" "+tempName;//加上产品品牌
					}else{
						tempName=pdname +" "+tempName;//加上产品品牌
					}
		 			String showcompany=doc3.get(Product_class_db.Jshowname);//显示XX发货客服
					String producturl=doc3.get(Product_class_db.Jproducturl);//显示产品网址
					String KFphone=doc3.get(Product_class_db.Jretain1);//显示客服电话
					String QQ=doc3.get(Product_class_db.Jretain2);//客服QQ
					String contactTitle=StringUtil.isFine(doc.get("retain5"))?doc.get("retain5"):Util.sub_String(doc.get("contact"),1)+"小姐";//使用客户的建议
					SMS_content_db scdb=new SMS_content_db();
					DOC[] docs4=scdb.getListByClassid(doc.geti("classid")); //得到
			%>
	<%for(int i=0;i<docs4.length;i++){%>
    <tr>
      <td height="30" colspan="2" bgcolor="#FFFFFF">
      	<p style="padding-left:10px;font-size:14px; color:#FF0000; font-weight:bold;" align="left"><%=StringUtil.isFine(docs4[i].get("remark"))?docs4[i].get("remark"):Select.getText("smstype",docs4[i].get("type"))%></p>
      	<p style="font-size:14px; color:#006600" id="smscontent<%=i%>">		
					<%
					String SMSContent=docs4[i].get("content");
					SMSContent=SMSContent.replaceAll("#companyname#", showcompany);
					SMSContent=SMSContent.replaceAll("#orderid#", String.valueOf(orderid));
					SMSContent=SMSContent.replaceAll("#productname#",pdname);//自动发送的不显示XX装
					SMSContent=SMSContent.replaceAll("#price#", doc.get("price2"));
					SMSContent=SMSContent.replaceAll("#paytype#", Select.getText("pay",doc.get("pay_type")));
					SMSContent=SMSContent.replaceAll("#phone#", doc.get("phone"));
					SMSContent=SMSContent.replaceAll("#address#", doc.get("address"));
					SMSContent=SMSContent.replaceAll("#producturl#", producturl);
					SMSContent=SMSContent.replaceAll("#kfphone#", KFphone);
					SMSContent=SMSContent.replaceAll("#QQ#", QQ);
					SMSContent=SMSContent.replaceAll("#surname#", contactTitle);  //尊称，我自己用，不显示到变量里面
					SMSContent=SMSContent.replaceAll("#truename#", doc.get("contact"));//全名
					SMSContent=SMSContent.replaceAll("#setname#", tempName);//产品+套装名tempName=PCname +" "+tempName;
					SMSContent=SMSContent.replaceAll("#number#", doc.get("number"));//订购数量
					if(SMSContent.indexOf("#kdh#")!=-1){
							SMSContent=SMSContent.replaceAll("#kdh#", Select.getText("kdtype",doc.get("kd_type"))+"："+doc.get("kd_number"));
					}
			out.print(SMSContent);
			%></p>
      	<p style="font-size:14px; color:#006600;float:right""><input type="button" name="submit" value="使用此模板内容" class="btn_a" onClick="showSMS('smscontent<%=i%>','<%=docs4[i].get("type")%>')" />&nbsp;&nbsp;&nbsp;<a href="SmsContentEdit.jsp?scid=<%=docs4[i].get("scid")%>" class="btn_a">编辑模板</a></p></td>
      </tr>
	  <%}%> 
  </table>
  	<p style="padding-top:10px;">
  		<textarea id="smscontent" name="smscontent" cols="" rows="" style="width:560px;height:90px;font-size: 12px;color: #006600;"  onkeyup="checklength();" onblur="checklength();"></textarea>
  	</p>
	现已输入<span id="contentnumber" style="color:#F00">0</span>个字，短信分<span id="contentpart" style="color:#F00">0</span>条发送
	<br />
  	<table width="100%" border="0" cellspacing="0" cellpadding="0">
  		<tr>
  			<td width="41%" valign="middle">短信定时发送：<input name="sendtime" type="text" id="sendtime"  class="Wdate"  onfocus="WdatePicker({isShowClear:true,readOnly:true,dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'<%=new DateUtil().getCurTime()%>'})" size="20" value="" style="height:28px; width:140px;" title="定时发送短信时间" /></td>
  			<td width="59%"><input id="sendsmsbutton" type="button" name="sendsmsbutton" value="发此短信给客户" class="btn_a" onclick="sensms('<%=orderid %>')" />
  				&nbsp;&nbsp;&nbsp;&nbsp;
  				<input id="sendemailbutton" type="button" name="sendemailbutton" value="发此邮件给自己" class="btn_a" onclick="senemail('<%=orderid %>')" /></td>
  			</tr>
  		</table>
  	<p>&nbsp;</p>
  </div>
         <!--发送记录-->
		 <div id="smshistory" style="display:none; padding:0px;width:98%" align="center">
 			<iframe id="smsiframe" style="width:100%; height:auto" src="orderSmsView.jsp?orderid=<%=orderid %>"  frameborder="0" scrolling="no" align="middle"></iframe>
		 </div>
  		<!--发送记录结束-->	
          </td> 
      </tr> 
	  <tr>
        <td height="30" align="right" bgcolor="#FFFFFF">联系人：</td>
        <td height="30" bgcolor="#FFFFFF">&nbsp;<%=doc.get("contact")%></td>
      </tr>
      <tr> 
      	<td height="30" align="right" bgcolor="#FFFFFF">联系电话：</td> 
      	<td height="30" bgcolor="#FFFFFF" onMouseOver="tooltip.show('点击可查询客户手机归属地！');" onMouseOut="tooltip.hide();">&nbsp;
      		<a href="http://www.ip138.com:8080/search.asp?mobile=<%=doc.get("phone")%>&action=mobile" target="_blank"><span style="font-size:16px;"><%=doc.get("phone")%></span></a>
      		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.baidu.com/#wd=<%=doc.get("phone")%>" target="_blank">百度</a>
      		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://www.google.com.hk/#q=<%=doc.get("phone")%>" target="_blank">谷歌</a>
      		</td> 
      	</tr> 
      <tr> 
        <td height="30" align="right" bgcolor="#FFFFFF">详细地址：</td> 
        <td height="30" bgcolor="#FFFFFF" onMouseOver="tooltip.show('双击可进行修改！');" onMouseOut="tooltip.hide();">&nbsp;<input name="address" id="address" type="text" value="<%=doc.get("address")%>" readonly="readonly"  class="input discss" onDblClick="$('#address').removeAttr('readonly');$('#address').removeClass('discss');" /></td> 
      </tr>
            <tr>
              <td height="30" align="right" bgcolor="#FFFFFF">订单状态：</td>
              <td height="30" bgcolor="#FFFFFF"><font color="red">&nbsp;<%=Select.getText("state",doc.get("state"))%></font> <br /></td>
            </tr>
            <tr>
              <td height="30" align="right" bgcolor="#FFFFFF">支付方式：</td>
              <td height="30" bgcolor="#FFFFFF">&nbsp;<%=Select.getText("pay",doc.get("pay_type"))%></td>
            </tr>
            <tr>
              <td height="30" align="right" bgcolor="#FFFFFF">客户IP：</td>
              <td height="30" bgcolor="#FFFFFF" onMouseOver="tooltip.show('点击可查询客户IP地址！');" onMouseOut="tooltip.hide();">&nbsp;<a href="http://ip138.com/ips138.asp?ip=<%=doc.get("ip")%>&action=2" target="_blank"><%=doc.get("ip")%></a></td>
            </tr>
			<tr>
              <td height="30" align="right" bgcolor="#FFFFFF">搜索关键词：</td>
              <td height="30" bgcolor="#FFFFFF">&nbsp;<input name="keyword" id="keyword" type="text" value="<%=doc.get("retain3")%>" class="input" /></td>
            </tr>
			<tr>
              <td height="30" align="right" bgcolor="#FFFFFF">下单网址：</td>
              <td height="30" bgcolor="#FFFFFF">&nbsp;<a href="<%=doc.get("retain1")%>" target="_blank"><%=doc.get("retain1")%></a></td>
            </tr>
			<tr>
              <td height="30" align="right" bgcolor="#FFFFFF">来源网址：</td>
              <td height="30" bgcolor="#FFFFFF">
			  <div style="padding-left:10px;width:580px;word-wrap:break-word;overflow:hidden; "><a href="<%=doc.get("retain2")%>" target="_blank"><%=doc.get("retain2")%></a></div>
				</td>
            </tr>
			<tr>
              <td height="35" align="right" bgcolor="#FFFFFF">快件号码：</td>
              <td height="30" bgcolor="#FFFFFF"> 
			  &nbsp;<select name="kd_type" id="kd_type" class="select">
			<%=Select.getSelectByKey("kdtype",doc.get("kd_type"))%>
			  </select>
		<input name="kd_number" id="kd_number" type="text" value="<%=doc.get("kd_number")%>" class="input_d" />&nbsp;&nbsp;<input id="FHsms" name="FHsms" type="checkbox" value="1" /> 发送发货短信</td>
            </tr>
			<tr>
              <td height="30" align="right" bgcolor="#FFFFFF">物流追踪：</td>
              <td height="30" bgcolor="#FFFFFF" onMouseOver="tooltip.show('选择在本网查询或者跳转到爱查快递网查询！');" onMouseOut="tooltip.hide();">&nbsp;<a href="viewkd.jsp?kdid=<%=doc.get("kd_number")%>&kd_type=<%=doc.get("kd_type")%>&orderid=<%=orderid%>&contact=<%=doc.get("contact")%>&address=<%=doc.get("address")%>&phone=<%=doc.get("phone")%>" target="_blank">本网查询</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.ickd.cn/" target="_blank">爱查快递</a>&nbsp;&nbsp;&nbsp;&nbsp;</td>
            </tr>
			<tr>
              <td height="30" align="right" bgcolor="#FFFFFF">最新状态：</td>
              <td height="30" bgcolor="#FFFFFF">&nbsp;<font color="#63b1ff"><%=doc.get("retain6")%></font></td>
            </tr>
			<tr>
				<td height="40" align="right" bgcolor="#FFFFFF"><strong>签收日期：</strong></td>
				<td height="30" bgcolor="#FFFFFF">&nbsp;<input name="signdate" type="text" id="signdate"  class="Wdate"  onfocus="WdatePicker({isShowClear:true,readOnly:true,dateFmt:'yyyy-MM-dd'})" size="20" value="<%=doc.get("retain4")%>" style="height:28px; width:140px;" title="签收时间" /></td>
			</tr>
			<tr>
			<%
			boolean disabled=false;  //暂时不启用
			if(doc.get("state").equals("12")||doc.get("state").equals("00")){
			//disabled=true;	
			}
			%>
				<td height="40" align="right" bgcolor="#FFFFFF"><strong>更改状态：</strong></td>
				<td height="30" bgcolor="#FFFFFF">&nbsp;<select name="state" id="state" class="select" <%=disabled?"disabled":""%> >
			<%for (int i = 0; i < Select.stateList.size(); i++) {
				String[] temps=Select.stateList.get(i).split(",");
			%>
					<option value="<%=temps[0]%>" <%=temps[0].equals(doc.get("state")) ? "selected": ""%>><%=temps[1]%></option>
			<%
				}
			%>
		</select></td>
			</tr>
			<tr>
				<td height="95" align="right" bgcolor="#FFFFFF"><strong>订单备注：</strong></td>
				<td height="30" bgcolor="#FFFFFF"><textarea name="admin_remark" id="admin_remark" cols="" rows="" style="width:590px;height:90px;font-size: 12px;color: #006600;"><%=doc.get("admin_remark")%></textarea></td>
			</tr>
    </table>
<%
doc=null;
doc2=null;
doc3=null;
%>
</div>
</div>

<div class="blank10"></div>

<input name="action" value="update" type="hidden" />
<input name="orderid" value="<%=orderid%>" type="hidden" />
</div>
<div class="blank20"></div>
<input type="submit" name="submit" value="提交" class="btn_a"/>
<div class="clear"></div>
</div>
<input id="smstype" name="smstype" value="" type="hidden" />
</form>
</div>

<div class="right_bottom">
</div>
</div>

<div id="footer">
</div>
</div>
<script type="text/javascript">
function checkform(){

	//var state=$('#state option:selected').val();
	var kd_type=$('#kd_type option:selected').val();
	var kd_number=$('#kd_number').val();
	if(kd_type=='-1'&&kd_number!=''){
	 alert('请选择快递公司！');
	  return false;
	}else{
	  return true;
	}
	/*
	if(state=='12'||state=='00'){
	 if(confirm("确认修改吗？确认后，将不可再修改状态")){
	 	return true;
	 }else{
		return false; 
	 }
	}*/
}
function khremarkcolor(){
	var color=$('#khremark').css("color"); 
	if(color=='rgb(0, 196, 0)'||color=='#00c400'){
		$("#khremark").css({color: "#FF0000","font-weight": "bold","font-size": "12px"}); 
	}else{
		$("#khremark").css({color: "#00c400","font-weight": "bold","font-size": "14px"}); 
	}
}
//变换字体颜色
$(document).ready(function(){
		var speed=500;
		window.setInterval(function(){khremarkcolor()},speed);
});
function showSMS(id,smstype){
	var content=$.trim($('#'+id).text());
	$('#sendsms').show(); 
	if(content.length>0){
		$('#smscontent').val(content);
	}
	$('#smstype').val(smstype);
	checklength();
}
function sensms(id){
	checklength();
	var content=$('#smscontent').val();
	if(content.length<10||content.length>280){
		alert('短信内容不能少于10个字或超出280个字！');
		$('#smscontent').focus();
		return;
	}
	var part=0;
	if(content.length<=70){
		part=1;
	}else if(content.length<=134){
		part=2;
	}else if(content.length<=201){
		part=3;
	}else if(content.length<=268){
		part=4;
	}
	if(part==0){
		alert('短信内容过多，超出280个字！！');
		return;
	}
	if(confirm('短信总共'+content.length+'个字，分为'+part+'条发送，确定发送吗？')){
		$('#sendsmsbutton').attr("disabled","disabled"); 
		$.ajax({
		contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		url:'/msg.do',
		async:false,
		data:'action=add&orderid='+id+'&type='+$("#smstype").val()+'&sendtime='+$("#sendtime").val()+'&content='+content,
		type:'POST',
		success:function(html){
			alert($.trim(html));
			if($.trim(html).indexOf('成功')!=-1){
					$('#smscontent').val('');
				}
			$('#sendsmsbutton').removeAttr("disabled"); 
		}
		})
	}
	}
function senemail(id){
	var content=$('#smscontent').val();
	if(content.length<10){
		alert('内容不能少于10个字！');
		$('#smscontent').focus();
		return;
	}
	if(confirm('确认发送此内容的邮件吗？')){
		$('#sendemailbutton').attr("disabled","disabled"); 
		$.ajax({
		contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		url:'/msg.do',
		async:false,
		data:'action=email&orderid='+id+'&type='+$("#smstype").val()+'&content='+content,
		type:'POST',
		success:function(html){
			alert($.trim(html));
			}
		})
	}
	}
function checklength() {
	var content=$('#smscontent').val();
	var part;
	if(content.length<=70){
		part=1;
	}else if(content.length<=134){
		part=2;
	}else if(content.length<=201){
		part=3;
	}else if(content.length<=268){
		part=4;
	}else{
		part='短信内容超出范围';	
	}
	$('#contentpart').text(part);
	$('#contentnumber').text(content.length);
}
function viewSmsHistory(){
	$('#sendsms').hide();
	$('#smshistory').slideToggle('slow',function(){
  		if($("#smshistory").is(":visible")){
			window.setTimeout(function(){refreshiframe()},1000);
		}
	 }); 
}
function refreshiframe(){
$("#smsiframe").attr("src","orderSmsView.jsp?orderid=<%=orderid %>");   	
}
function refreshSms(){
		if($("#smshistory").is(":visible")){
			var height=$("#smsiframe").contents().find("#smsviewtable").height();
			if(height>0){
			$("#smsiframe").height(height+10);	
			}
		}
}
</script>
<%@include file="inc/msg.jsp" %>
<%@include file="inc/footer.jsp" %>
