<%@ Page Language="C#" AutoEventWireup="true" debug="true" Inherits="WinLibClass.Form.Admin.Product.UI_Pic_List"  CodePage="65001" %>

<script>
//编辑

function GetPicList()
{
	$.ajax({
		type: "POST",
		url: "/index.aspx?s=/UserInfo/UserInfo_Pic_List&PhotoType=<%=PhotoType%>&PhotoUserType=<%=PhotoUserType%>",
		data:{"InfoId":<%=InfoId%>},//"PhotoType":3},//产品编号,图片分类////广告类图:3,4晒图类
		cache: false,
		dataType:"json",
		success: function(msg){
			//ID,PID,PhotoPath,PhotoTitle,PhotoExplain,PhotoUserType,PhotoType,PhotoOrderId,InfoId,PhotoTypeFormatType
	
			var json = msg;
			var s="";
			if(json)
			{
				$.each(json,function(i,DataRow)
				{
				
					//if(DataRow["filename"]!="Thumbs.db")
					{
						s += '<div id="div_'+ i +'">\r\n'
						  +  '<li id="li_'+ i +'" >'
						  + '<a  href="'+ DataRow["PhotoPath"]+'" target="_blank">'
						  +  '<img src="'  + DataRow["PhotoPath"].replace("imglarge","imgmiddle") +'" alt="(预览)标题:'+ DataRow["PhotoTitle"] +'" />'
						  +  '</a></li>\r\n'//图片
						  + '<li  id="li_Char_'+ i +'">';
						  /*
						  if($("#td_a_<%=InfoId%>").attr("href")==DataRow["PhotoPath"].replace("imgmiddle","imglarge"))
						  	s +=' <font color="red"><b>使用中</b></font> ';
						  else
						  	s += ' <a href="javascript:;" onclick="return SetPicToUsing('+ DataRow["id"] +',\''+ DataRow["PhotoPath"] +'\')">使用</a> | ';
						  	*/
						  	
						  s += ' <a href="javascript:;" onclick="return PicDelBox('+ DataRow["id"] +')">删除</a> </li>\r\n' //标题
						  + '</div>\r\n';	 
						i++;
					}
				});
				//ShowErrorMsg(s);
				$("#MyPic").html(s);
			}
			else
				$("#MyPic").html("暂无图片");
		}
		,error:function(msg)
		{
			ShowErrorMsg(msg.responseText);
		}
	});	

}
//使用指定图
function SetPicToUsing(Id,PhotoPath)
{
	var _url = '/Admin/Upload/UpFile.aspx?PhotoUserType=<%=PhotoUserType%>'
			+ '&PhotoType=<%=PhotoType%>&InfoId=<%=InfoId%>&PhotoTypeFormatType=0"';
	$.ajax({
		type: "GET",
		url: _url,
		data:{"PhotoId":Id},//晒图类图:4
		cache: false,
		success: function(msg){
			if(msg==1)
			{
				//操作成功
				//alert("广告"+PhotoPath);
				$("#td_a_<%=InfoId%>").attr("href",PhotoPath);
				removeDialogbox("#Div_AdminEdit");
			}
			else
			{
				//操作失败
				ShowErrorMsg("操作失败("+ msg +")");
			}
			//alert(msg)
		}
	});				
}


//删除
function PicDelBox(id)
{

	if(confirm("您确认删除该图片吗?")==true)
	{
		PicUpdate(id,3);
	}
	else
	{
		//_removeDialogbox();
	}
	
}

//删除弹出框专用
function _removeDialogbox(){
	RemoveDialogbox('Ajax_User_UpPic','Ajax_User_UpPic_screenMask');	
}

//0:添加(不用);1:修改;2:删除PhotoTypeFormatType
function PicUpdate(id,type){
	var InfoId = <%=InfoId%>;
	$.ajax({
		type: "POST",
		url: "/index.aspx?s=/UserInfo/UserInfo_Pic_Update/",
		data:{"InfoId":<%=InfoId%>,"ID":id,"PhotoType":<%=PhotoType%>,"OpeType":type},//广告类图:3
		cache: false,
		success: function(msg){
			if(msg==1)
			{
				//操作成功
				//_removeDialogbox();
				GetPicList();
			}
			else
			{
				//操作失败
				ShowErrorMsg("操作失败("+ msg +")");
			}
			//alert(msg)
		}
	});
}

//上传图片



var UpPic ={};
UpPic.Config={
	FileFilter:".jpg;.jpeg;.gif;.png;.bmp",//图片类型	
	SetTimeOutSecond :100 //倒计时的计时器
};

UpPic.Utils= {
	parseJson : function (text) {
		var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
		cx.lastIndex = 0;
		if (cx.test(text)) {
			text = text.replace(cx, function (a) {
				return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
			});
		}
		if (/^[\],:{}\s]*$/.
		test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
		replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
		replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
			return eval('(' + text + ')');
		}
		throw 'JSON parse error';
	}
	,
	addEvent : function () {  
	     if (window.addEventListener) {  
	         return function(el, eventName, fn, capture) {  
	             el.addEventListener(eventName, fn, (capture));  
	         };  
	     } else if (window.attachEvent) {  
	         return function(el, eventName, fn, capture) {  
	             el.attachEvent("on" + eventName, fn);  
	         };  
	     } else {  
	         return function() {  
	         };  
	     }  
	 }	
	 ,
	 getFileExt	:function(filePath){ //获取文件扩展名
	 	var extIndex = filePath.lastIndexOf(".");
		filePath = filePath.substr(extIndex);//.jpg
		return filePath.toLowerCase();
	 } 
	 ,
	 checkFileType:function(fileExt){//检查是否是图片.
	 	return (UpPic.Config.FileFilter.indexOf(fileExt)>=0);//查询不到的话,返回 false
	 }	 	 
};


function GetUploadPicPath(oIframe)
{

	try
	{
	
		var oIframe = document.getElementById("IFrame1");
		var s = oIframe.contentWindow.document.forms[0].action.split("?")[1].split("&");
		//body.innerHTML; 
		var t ;
		var t1=0;
		var t2=0;
		for(var param in s){
			t =s[param].split("="); 
			if(t[0].toLowerCase ()=="infoid"){
				t1=1;
				if(t[1].length<1)t2=1;
			}
		}
		if(t1==1 && t2==1){//正常返回.
			UpPic.Config.SetTimeOutSecond = 100;GetPicList();return true;		
		}
		else
		{
			//window.status =UpPic.Config.SetTimeOutSecond;
			UpPic.Config.SetTimeOutSecond -=1;
			if(UpPic.Config.SetTimeOutSecond>1) setTimeout(function(){GetUploadPicPath();},100);
		}

		
		
	}
	catch(e)
	{
		//window.status =UpPic.Config.SetTimeOutSecond + e;
		UpPic.Config.SetTimeOutSecond -=1;
		if(UpPic.Config.SetTimeOutSecond>1) setTimeout(function(){GetUploadPicPath();},100);
	}
}

function _RemoveDialogBox()
{
	RemoveDialogbox('Ajax_User_UpPic','Ajax_User_UpPic_screenMask');
}

function SaveUserNote()
{
	//ShowErrorMsg("dnal");return ;
	var data = $("#frmUserNote").serialize();
	alert(data);

	var url = "/index.aspx?s=/UserInfo/UserNoteUpdate/";
	AjaxSubmit(null,url,data,function(msg)
	{
		if(msg==1) ShowErrorMsg("感言保存成功.")
		else ShowErrorMsg("感言保存失败(返回代码:"+msg+")");
	
	},
	function(msg){alert("数据保存失败")}
	);
}

</script>
<style>
.tableStyle
{
	width:552px;
	height:300px;
	border:1px solid #DDD;
	margin:10px 10px 0px 10px;
}

.PicListTd
{
	height:260px;
	vertical-align: top;
	overflow-y: scroll;
	border:0px dotted #aaa;
	background-color:#efefef;
	
}
#MyPic
{
	display: block;
}
.PicListTd div
{
	width :112px;
	height:130px;
	border:1px dotted #aaa;
	margin:5px;
	padding:0px 0 0 0;
	float:left;
	text-align:center;
}
.PicListTd div li
{
	clear:both;
	width:100%;
	display: block;/*inline-*/
	float:none;
	margin:3px 2px 1px 1px;
text-align:center;

}

.PicListTd div li img
{
	margin:2px;
	width:100px;
	height:75px;

}
.DivBottom
{
	margin:-10px 0px 0px 0px;
	
}
.button
{
	width:50px;height:22px;margin:2px;
}
.HtmlTextBox{border:1px solid #6699FF}
</style>


<table border="0" class="tableStyle">

<tr style="height:30px;	font-weight: bold;">
<td align="center">
<%//编辑区 %>
		<div style="margin-left:0px;margin-top:2px;vertical-align: middle;" >
	<iframe id="IFrame1" src="/Admin/Product/UpPicForm.aspx?t=1" frameborder="0" marginwidth="0" marginheight="0" align="left" height="22" width="396px"  scrolling="no"  style="margin:5px 0 5px 5px;"></iframe>	</div>
	<div style="float:left;margin-left:0px;line-height:40px;margin-top:2px;vertical-align: middle;margin-top:0px">
<!--
	&nbsp;&nbsp;	
	<span style="display:inline-block;">首页横图：</span>
-->
	<input type="checkbox" style="display:none" id="input_2_PhotoTypeFormatType"  />
	
	&nbsp;&nbsp;	<!--
	<span style="display:inline-block;">使用新图：</span>
	<input type="checkbox" style="display:" id="input_2_Used"  />	
-->
	</div>
	<div style="float:left;line-height:40px;display:inline-block;margin:2px 10px 10px 10px">

	<input type="button" id="input_2_Submit" class="button" value="上传"  />
	</div>

	
</td>
</tr>

<tr>
	<td valign="top" id="MyPic" class="PicListTd" style="border:1px"><%//列表区 %>

	
<asp:Repeater id="rpList" runat="server">
<ItemTemplate>

<div>
<li ><%#Eval("id")%></li>
<li id="li_<%#Eval("id")%>"><img src="<%#Eval("PhotoPath")%>" style="width:60px;height:45px" /></li>
<li id="li_ope_<%#Eval("id")%>" ><a href="javascript:;" onclick="return PicDelBox('<%#Eval("id")%>')">删除</a></li>
</div>

</ItemTemplate>
</asp:Repeater>	


	</td>
</tr>


<tr>
<td style="text-align:left" valign="top">
<!--晒图-->

<form id="frmUserNote" >
<input type="hidden" maxlength = "100" id="txId" name ="txId" class="HtmlTextBox" value="0">
<input type="hidden" maxlength = "100" id="InfoId" name ="InfoId" class="HtmlTextBox" value="<%=InfoId%>">
标题:<input type="text" maxlength = "100" id="txTitle" name="txTitle" class="HtmlTextBox"> <br>
感言:<textarea id="txContent" name="txContent" class="HtmlTextBox" style="width:400px;height:100px"></textarea>
</form>

</td>
</tr>

</table>
<div class="DivBottom"  style="margin:10px 10px 10px -13px">

<button type="button" class="button" style="" onclick='SaveUserNote();' >保存</button>

<button type="button" class="button" style="" onclick='_RemoveDialogBox();' >返回</button>
</div>

<script>

//11:43 2010-9-29
$(document).ready(function(){

	//确定组
	$("#input_2_Submit").click(function()
	{
		var oIframe = document.getElementById("IFrame1");
		if( oIframe.contentWindow.document.getElementById("imgFile")!=null )
		{
			if(oIframe.contentWindow.document.getElementById("imgFile").value.length>5){
				var filename = oIframe.contentWindow.document.getElementById("imgFile").value;
				if(UpPic.Utils.checkFileType( UpPic.Utils.getFileExt(filename)))
				{
					if(oIframe.contentWindow.document.getElementById("frmImageUpload"))
					{
						var _tmp = $("#input_2_PhotoTypeFormatType").attr("checked");
						//alert(_tmp);return ;
						var _url = '/Admin/Product/UpPic.aspx?PhotoUserType=<%=PhotoUserType%>'
								+ '&PhotoType=<%=PhotoType%>&InfoId=<%=InfoId%>&PhotoTypeFormatType="'+ (_tmp?1:0) ;
						oIframe.contentWindow.document.getElementById("frmImageUpload").action = _url;
						
						oIframe.contentWindow.document.forms[0].submit(); //上传
						setTimeout(function(){GetUploadPicPath();},100);		
						
					}	
					else
					{
						alert("没找到文件,上传终止.");
					}			
				}
				else{
					alert("文件类型无效,上传已取消.");
				}
			}
			else{
				alert("请先选择待上传的文件.");
			}			
		}	
		else{
			
			//GetUploadPicPath(oIframe);
		}
	});	

GetPicList();


});

</script>