<%@ Page Language="C#" AutoEventWireup="true" debug="true" Inherits="WinLibClass.Form.UpPic.PicList" CodePage="65001" %>

<script>
//update Tb_Photo set PhotoPath ='/'+PhotoPath ,infoid=0 where id<90
//编辑
//systemtype:0系统默认,1会员上传
//PhotoType="" PhotoUserType=""
function GetPicList( oDiv,systemtype )
{
	if(!oDiv) oDiv = "MyPic";if(!systemtype)systemtype=1;
	
	$.ajax({
		type: "POST",
		url: "/index.aspx?s=/UserInfo/UserInfo_Pic_List&PhotoType=<%=PhotoType%>&PhotoUserType=<%=PhotoUserType%>",
		data:{"InfoId":<%=InfoId%>,"SystemType":systemtype},
		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){
					{
						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);
				$("#"+oDiv).html(s);
			}
			else $("#"+oDiv).html("暂无图片");
		}
		,error:function(msg){ShowErrorMsg("异常=" + msg.responseText);}
	});	

}
//使用指定图
function SetPicToUsing(Id,PhotoPath,_SystemType)
{
	//更新会员表的头像字段
	var _url = '/Admin/Upload/UpFile.aspx?PhotoUserType=<%=PhotoUserType%>&PhotoType=<%=PhotoType%>&InfoId=<%=InfoId%>&PhotoTypeFormatType=0';
	$.ajax({type: "GET",url: _url,data:{"PhotoId":Id,"SystemType":_SystemType},//头像0
		cache: false,
		success: function(msg){
			if(msg==1){
				$("#UserInfoHeadImage").attr("src",PhotoPath);PaiPaiCMS.DialogBox.Close();
			}//更新当前显示
			else{ShowErrorMsg("操作失败("+ msg +")");}//操作失败
		},
		error:function(re){
			if(re && re.responseText){alert(re.responseText);}
			else alert("操作异常.");
		}
	});				
}
//删除
function PicDelBox(id){	if(confirm("您确认删除该头像吗?")==true)PicUpdate(id,3);}
//删除弹出框专用
function _removeDialogbox(){PaiPaiCMS.DialogBox.Close();
//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){
				//设置头像为默认头像(暂时未加)
				GetPicList("MyPic",1);
			}
			else ShowErrorMsg("操作失败("+ 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){ //获取文件扩展名//.jpg
	 	var extIndex = filePath.lastIndexOf(".");filePath = filePath.substr(extIndex);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("&");
		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("MyPic",1);
			return true;
		}//正常返回.
		else{UpPic.Config.SetTimeOutSecond -=1;if(UpPic.Config.SetTimeOutSecond>1) setTimeout(function(){GetUploadPicPath();},100);}
	}catch(e){UpPic.Config.SetTimeOutSecond -=1;if(UpPic.Config.SetTimeOutSecond>1) setTimeout(function(){GetUploadPicPath();},100);}
}

function _RemoveDialogBox()
{
	//RemoveDialogbox('Ajax_User_UpPic','Ajax_User_UpPic_screenMask');
	PaiPaiCMS.DialogBox.Close();
}

</script>
<style>
.tableStyle
{
	width:530px;
	height:300px;
	border:1px solid #DDD;
	margin:10px 10px 0px 0px;
		overflow-y: scroll;
}

.PicListTd
{
	clear:both;
	vertical-align: top;
	display: block;
	border:1px dotted #aaa;
	background-color:#efefef;
	
/*	background-color:#ffffff;*/
	height:260px;
	overflow-y: scroll;
}

.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
{
	width:100%;
	display: block;/*inline-*/
	float:none;
	margin:3px 2px 1px 1px;
	text-align:center;
	list-style:none;
}

.PicListTd div li img
{
	margin:2px;
	width:80px;
	height:80px;/**/

}
.DivBottom
{
	margin:-10px 0px 0px 0px;
	
}
.button
{
	width:50px;height:22px;margin:2px;
}
.HtmlTextBox{border:1px solid #6699FF}
.SelectDiv{
	margin:5px 0px 0px 10px;
	float:left;	
}
.SelectDiv span{display:block;margin:1px;float:left;cursor:pointer;}

.SelectDiv .SpanTitleSelected{
	color:#EEEEEE;
	font-weight:bold;
	background-color:#888888;
	width:100px;

	
}
.SelectDiv .SpanTitleNotSelected{
	color:#666666;
	font-weight:normal;
	background-color:#dddddd;
	width:100px;
}

</style>

<div>

<table border="0" class="tableStyle" id="table_1" style=";">

<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">
	<input type="checkbox" style="display:none" id="input_2_PhotoTypeFormatType"  />
	&nbsp;&nbsp;
	</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"><%//列表区 %>

	</td>
</tr>


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

</td>
</tr>
</table>






<input type="button" class="button" style="margin:6px 6px 6px 6px;" onclick='PaiPaiCMS.DialogBox.Close();' value="关 闭" />
</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");
						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{}
	});	
	GetPicList("MyPic",1);//上传头像
	
});

</script>