<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="module.*" width="770" height="798" backgroundGradientColors="[#FFFFFF, #FFFFFF]" creationComplete="initUI();" verticalScrollPolicy="off"> <mx:Script> <!--[CDATA[ import event.HintCloseEvent; import mx.events.CloseEvent; import module.hintcomview; import mx.managers.PopUpManager; import module.albumPhotoItem; import module.photoSizeItem; import module.photoItem; import mx.containers.VBox; import module.price; import mx.controls.Alert; import event.AlbumPhotoClickEvent; import code.*; private var alertCSS:CSSStyleDeclaration; private static var SMGM:String = "数码光面" ; private static var SMRM:String = "数码绒面" ; private static var kDHJGM:String = "柯达皇家光面" ; public static var MAIN:shopcart ; /*冲印照片的的数据结构。购物车解析此数据结构. *格式形如: * <wdxc> * <papertype>1</papertype> * <cuttype>1</cuttype> * <photoindex>1</photoindex> * <img src=""> * <printinfo measurement="6寸" number="1" x="" y="" width="" height=""/> * <printinfo measurement="7寸" number="1" x="" y="" width="" height=""/> * </img> * </wdxc> */ public var printphotoXML:XML ; /*冲印统计信息 如:全景6寸2张,7寸3张*/ private var infoObj:Object = {} ; private var _priceInfo:price = new price() ; public function initUI():void{ alertCSS = StyleManager.getStyleDeclaration("Alert"); alertCSS.setStyle("fontSize", "12"); alertCSS.setStyle("fontWeight", "normal"); loadExistXML(); //加入js调用接口 ExternalInterface.addCallback("refreshAlbumList",refreshAlbumList); //loadSelectPhoto(); } /** * 加载用户在相册中选中的照片 */ private function loadSelectPhoto():void { var selecttype : String = this.parameters["selecttype"] ; if(selecttype!=null && selecttype!="" && selecttype!="null"){ setPhotoXMLbySelectRequest(this.parameters["selecttype"]) ; } } /** * 上传照片后,重新刷新相册信息 */ public function refreshAlbumList():void{ this.albumviewid.sendAlbumInfoRequest(); } /** * 创建新的数据类型 */ public function createNewobject():void{ MAIN = this ; initInitObj() ; albumviewid.sendAlbumInfoRequest() ; initprintphotoXML(); //初始化价格,数量统计信息 recomputerTotalInfo(); loadSelectPhoto(); } /** * 如果已经创建冲印池,则加载出来 。 */ public function createOldobject(oldxml:String):void{ MAIN = this ; initInitObj() ; printphotoXML = new XML(oldxml) ; header.reSetHeader(); //初始化裁剪方式及相纸类型 。 leftview_id.initPhotoList(1); //生成照片及尺寸对象 recomputerTotalInfo(); //初始化价格,数量统计信息 albumviewid.sendAlbumInfoRequest() ; loadSelectPhoto(); } /** * 冲印统计信息 如:全景6寸2张,7寸3张 */ private function initInitObj():void{ infoObj[Constants.R5C] = 0 ; infoObj[Constants.R6C] = 0 ; infoObj[Constants.RQJ6C] = 0 ; infoObj[Constants.R7C] = 0 ; infoObj[Constants.RHBZ] = 0 ; infoObj[Constants.R8C] = 0 ; infoObj[Constants.R10C] = 0 ; infoObj[Constants.R12C] = 0 ; infoObj[Constants.R16C] = 0 ; infoObj[Constants.R18C] = 0 ; infoObj[Constants.R20C] = 0 ; infoObj[Constants.R24C] = 0 ; infoObj[Constants.R30C] = 0 ; infoObj[Constants.R40C] = 0 ; } /** * 删除照片时,同时删除XML数据 。 */ public function deletePhotoXML(src:String):void{ delete printphotoXML.img.(@src==src)[0]; } /** * 删除所有照片,对应的xml */ public function deleteAllphotoXML():void{ delete printphotoXML.img ; } /** * 如果尺寸被删除,对应的xml数据同步删除 。 */ public function deleteSizeXML(src:String,sizename:String):void{ var xml:XML = printphotoXML.img.(@src==src)[0] ; for(var i:int=0;i<xml.printinfo.length();i++){ if(xml.printinfo[i].@measurement==sizename){ delete xml.printinfo[i] ; break ; } } } /** * 如果改尺寸的冲印数量被改变,相应的xml也应该改变 。 * @param src :该照片URL * @param sizename:尺寸名称 * @parma number:冲印数量 */ public function modifySizeXML(src:String,sizename:String,number:String):void{ var xml:XML = printphotoXML.img.(@src==src)[0] ; for(var i:int=0;i<xml.printinfo.length();i++){ if(xml.printinfo[i].@measurement==sizename){ xml.printinfo[i].@number = number ; break ; } } } /** * 取得单张照片的尺寸的信息 。 * @param src 照片URL * @return XMLList 尺寸列表 */ public function getSingleprintphotoXML(src:String):XML{ return printphotoXML.img.(@src==src)[0] ; } /** * 改变相纸 */ public function changePaper(p:String):void{ this.printphotoXML.papertype=p ; } /** * 得到纸张类型 */ public function getPaperType():String{ return printphotoXML.papertype ; } /** * 冲印比如与照片比例不一样时,选择处理方式 * 2:留白边 * 1:裁剪 */ public function changeCutType(c:String):void{ this.printphotoXML.cuttype=c ; } /** * 取得裁剪类型 */ public function getCuttype():String { return printphotoXML.cuttype ; } /** * 得到全称呼. */ public function getFullname(sn:String):String{ if(getPaperType()=="1"){ return SMGM+sn; } if(getPaperType()=="31"){ if(sn==Constants.R5C||sn==Constants.R6C||sn==Constants.RQJ6C ||sn==Constants.R7C||sn==Constants.R8C||sn==Constants.RHBZ){ return SMRM+sn ; } return SMGM+sn ; } if(sn==Constants.R5C||sn==Constants.R6C||sn==Constants.RQJ6C ||sn==Constants.R7C||sn==Constants.R8C||sn==Constants.RHBZ){ return kDHJGM+sn ; } return SMGM+sn ; } /* 初始化数据结构。*/ private function initprintphotoXML():void{ printphotoXML = new XML(<wdxc></wdxc>) ; printphotoXML.appendChild(<papertype>1</papertype>); printphotoXML.appendChild(<cuttype>0</cuttype>); printphotoXML.appendChild(<photoindex></photoindex>); } /** * 增加冲印照片节点. * 默认增加一个全集6寸照片 。 * @params src :图片url * @params length :图片长边长度 。 */ public function addPhotoItem(src:String,length:String,photoname:String):void{ var pitem:XML = addPhotoItemXML(src,length,photoname); leftview_id.addphoto(pitem,getPhotoNumber(),photoname) ; //在容器中加入组件 } /** * 只是加入xml数据,不增减组件。 * 用于在冲印整个相册的时候,提高效率 * 或者从购物车中加载已经存在的数据时候。 */ public function addPhotoItemXML(src:String,length:String,photoname:String):XML{ var pitem:XML =<img src="{src}/" mce_src="{src}">; pitem.appendChild(<length>{length}</length>); pitem.appendChild(<photoname>{photoname}</photoname>); pitem.appendChild(<printinfo measurement={Constants.R5C} number="0" x="-1" y="0" width="0" height="0" d="-1"/>); pitem.appendChild(<printinfo measurement={Constants.R6C} number="0" x="-1" y="0" width="0" height="0" d="-1"/>); pitem.appendChild(<printinfo measurement={Constants.RQJ6C} number="1" x="-1" y="0" width="0" height="0" d="-1"/>); pitem.appendChild(<printinfo measurement={Constants.R7C} number="0" x="-1" y="0" width="0" height="0" d="-1"/>); pitem.appendChild(<printinfo measurement={Constants.RHBZ} number="0" x="-1" y="0" width="0" height="0" d="-1"/>); printphotoXML.appendChild(pitem) ; return pitem ; } /** * 当前照片的编号 */ private var _PHOTO_NUM:Number ; /*********************************************** * 单击相册照片,增加一条照片记录到当前容器 。 ***********************************************/ public function photoClickHandler(e:AlbumPhotoClickEvent):void{ var photourl:String = e.clickItem. getSource(); _PHOTO_NUM = getPhotoPageInfo(photourl) ; /** * 如果改尺寸已经存在时处理。 */ if(_PHOTO_NUM!=-1){ var hint:String ="该照片已经选中,在第" +getPagenumByPhotonum(_PHOTO_NUM)+"页,"; hint+="编号为"+(_PHOTO_NUM)+"。" ; mx.controls.Alert.yesLabel = "确定" ; mx.controls.Alert.show(hint,null,Alert.YES,null,hintCloseHandler) ; return ; } this.addPhotoItem(photourl,e.clickItem.getLength(),e.clickItem.getPhotoName()) ; //加入xml 节点 recomputerTotalInfo(); //重新计算价格信息 } /** * 提示框关闭. * 跳到改照片所在页面 。 */ private function hintCloseHandler(e:CloseEvent):void{ leftview_id.initPhotoList(getPagenumByPhotonum(_PHOTO_NUM)) ; } /** * 得到某找照片,在某页及某个编号 */ private function getPhotoPageInfo(photourl:String):Number{ for(var i:int=0;i<printphotoXML.img.length();i++){ if(printphotoXML.img[i].@src==photourl){ return i+1 ; } } return -1 ; } /** * 选择整本相册填充列表,相册填充列表 * @params xmllist:该相册所有的照片xml数据 */ public function fillListByAlbum(xmllist:XMLList):void { for each(var n:XML in xmllist) { if(isexist(n.abbrurl)){ continue ; }else{ this.addPhotoItemXML(n.abbrurl, n.length,n.photoname) ; //加入xml 节点 } } leftview_id.initPhotoList(1); recomputerTotalInfo(); //重新计算价格信息 } /** * 改变尺寸或者改变数量等。重新统计冲印信息的数量,价格。 */ public function recomputerTotalInfo():void { /*得到所有尺寸信息*/ var itemxml:XMLList = printphotoXML.img.printinfo ; this.initInitObj() ; //重置统计信息数组列表 for (var i:int=0;i<itemxml.length();i++){ //统计该尺寸总共有多少个 infoObj[itemxml[i].@measurement]= int(itemxml[i].@number) + int(infoObj[itemxml[i].@measurement]) ; } totalInfoId.text ="" ; for(var key:String in infoObj){ if(infoObj[key]!=0){ totalInfoId.text +=getFullname(key)+"("+infoObj[key]+"张)"+" " ; } } recomputerPrice(); leftview_id.checkPhotoIndex() ;//索引判断 } /** * 重新生成价格 */ public function recomputerPrice():void{ //testid.text += "c="+_priceInfo.getMesurePrice("全景6寸"); var totalprice:Number = 0 ; for(var key:String in infoObj){ if(infoObj[key]!=0){ totalprice += getMesurePrice(key)*infoObj[key] ; totalprice=Math.round(totalprice*100); totalprice = totalprice/100 ; } } totalprice_id.text = totalprice +" 元" ; } /** * 改变相纸的时,更改已选照片的价格显示 */ public function reChangePriceview():void{ //照片项存放容器 var v:VBox = leftview_id.printphotopool_vboxid ; for(var i:int=0;i < v.numChildren ;i++){ var p:photoItem = v.getChildAt(i) as photoItem; //尺寸项存放容器 var v2:VBox = p.photoitemCanvas ; for(var j:int=0;j < v2.numChildren;j++){ var p2:photoSizeItem = v2.getChildAt(j) as photoSizeItem ; p2.refreshDisname();//刷新全称 p2.pirceHandler(); //重新计算价格 } } } /** * 通过尺寸名称,求出改尺寸对应的价格。 */ public function getMesurePrice(sizename:String):Number{ return _priceInfo.getMesurePrice(sizename,printphotoXML.papertype); } /** * 判断照片是否已经存在容器当前 */ public function isexist(src:String):Boolean{ var x:XMLList = printphotoXML.img.(@src==src) ; if(x==null||x.length()==0){ return false ; } return true ; } /** * 像素判断. * @return false 像素不够 。 * @return true 像素够 */ public function piexCheck(src:String,sizename:String):Boolean{ var xml:XML = printphotoXML.img.(@src==src)[0] ; var piex:String = xml.length ; var a:Array = piex.split("-"); if(a[0]*a[1] < getminPiex(sizename)){ return false ; } return true ; } /** * 通过尺寸名称,求出改尺寸的最低像素要求 */ public function getminPiex(sizename:String):Number{ return PrintScale.getPels(sizename); } /** * 得到所加入照片总数 */ public function getPhotoNumber():String{ return printphotoXML.img.length(); } /** * 导入存在 XML . */ public function loadExistXML():void { var paras:Object = new Object(); paras.randow = Math.random() ; paras.methodName="getPrintpoolXML"; loadExistxmlId.send(paras); } public function loadXMLcallBack() : void { if(loadExistxmlId.lastResult.toString()=="null"){ createNewobject(); }else{ createOldobject(loadExistxmlId.lastResult.toString()); } } private function addShoppingCart():void{ /** * 如果没有选择冲印的照片尺寸数量都是0的情况,重新刷新组件数据。 */ if(!dataCheck()){ Alert.okLabel = "确定" ; var alert:Alert = Alert.show("您还没有选择照片!"); //callLater (alert.move, [300, 300]); return ; } /* * 此处调用js中函数 */ ExternalInterface.call("refreshFlag"); // addshoppingcart_id.label = "正在处理..." ; addshoppingcart_id.enabled = false ; var paras:Object = new Object(); paras.content = printphotoXML ; paras.randow = Math.random() ; paras.methodName="addToshoppingCart"; addcartId.send(paras); } private function addShoppingCartResult():void{ var url:String = "/pages/product/photoTransfer.faces" ; var request:URLRequest = new URLRequest(url); if(addcartId.lastResult.toString()=="0"){ navigateToURL(request,"_self"); }else{ Alert.show("发生错误, 尝试重新登录","提醒",Alert.OK,this,null,null,1); } } /** * 加入购物车前,进行验证。 */ private function dataCheck():Boolean{ /*得到所有尺寸信息*/ var tempxml:XML = printphotoXML.copy() ; var itemxml:XMLList = tempxml.img ; if(itemxml.length()<=0){ return false ; } for (var i:int=0;i<itemxml.length();i++){ var size_list:XMLList = itemxml[i].printinfo ; var bool:Boolean = false ; /** * 去除数量等于0的尺寸。 */ for(var j:int=0;j < size_list.length();j++){ if(size_list[j].@number==0){ continue ; } bool = true ; break ; } /** * 如果没有选择尺寸,删除该照片,以免下载的时候,出现无效图片。 */ if(!bool){ delete itemxml[i] ; i-- ; } } /** * 过滤成功后,把简化后的,xml赋值给当前xml 。 */ if(itemxml.length()>0){ printphotoXML = tempxml ; return true ; } else{ return false ; } } /** * 请求用户在相册中选择的照片信息 */ private function setPhotoXMLbySelectRequest(selecttype:String):void{ var obj:Object = new Object() ; obj.random = Math.random() ; obj.selecttype = selecttype ; obj.methodName ="getPhotoXMLbySelect" ; selectphotoNameListId.send(obj); } /** *得到请求结果 */ private function getPhotoXMLbySelectResponse():void{ var xml:XML = new XML(selectphotoNameListId.lastResult); var xmllist:XMLList = xml.photos ; /*把该相册所有照片填充到显示列表当中*/ fillListByAlbum(xmllist); } /** * 该尺寸是否存在列表中,针对当张照片的 * 不存在 -1 */ public function hasInSizeXML(sizename:String,sizexml:XML):int { for(var i:int=0;i<sizexml.printinfo.length();i++){ if(sizexml.printinfo[i].@measurement==sizename){ return i ; } } return -1 ; } /** * 加入尺寸所需要的XML */ public function getSizeXML(sizename:String,number:String):XML { return new XML(<printinfo measurement={sizename} number={number} x="-1" y="0" width="0" height="0" d="-1"/>) ; } /** * 批量更改所有尺寸XML * */ public function bathChangeSizeXMLHandler(sizename:String,number:String):void{ var imgxml:XMLList = printphotoXML.img ; for(var i:int=0 ;i<imgxml.length();i++){ var num:int = hasInSizeXML(sizename,imgxml[i]); if(num==-1){ if(number=="0"){ continue ; } imgxml[i].appendChild(getSizeXML(sizename,number)) ; }else{ imgxml[i].printinfo[num].@number = number ; } if(imgxml[i].printinfo[num].@number=="0"){ if(isBasicSize(sizename)){ continue ; } delete imgxml[i].printinfo[num] ; } } } /** * 判断该尺寸是否需要删除。 * 如果是基本尺寸则不删除。 * 否则如果数量为0,就删除。 */ public function isBasicSize(sizename:String):Boolean { if(sizename==Constants.R5C || sizename==Constants.R6C || sizename==Constants.RQJ6C || sizename==Constants.R7C||sizename==Constants.RHBZ){ return true ; } return false ; } /** * 批量修改尺寸组件 。 */ public function bathChangeCom():void { var v:VBox = shopcart.MAIN.leftview_id.printphotopool_vboxid ; for(var i:int=0;i < v.numChildren ;i++){ var p:photoItem = v.getChildAt(i) as photoItem; /*如果改尺寸已经存在,就修改其数量。如果不尺寸则加入新的 尺寸*/ p.refreshSizeList() ; } } ]]--> </mx:Script> <mx:Script source="code/ExtendCode.as"/> <ns1:leftview id="leftview_id" x="0" y="182" width="550" height="617" borderColor="#A0AFB6" borderStyle="solid" borderThickness="0"> </ns1:leftview> <ns1:albumview photoclick="photoClickHandler(event)" id="albumviewid" x="555" y="182" width="215" height="617" backgroundColor="#A0AFB6"> </ns1:albumview> <ns1:header1view id="header" x="0" y="1" height="85"> </ns1:header1view> <!--总数量及价格统计信息 --> <mx:Canvas x="0" y="94" width="770" height="80" backgroundColor="#F4F4F4"> <mx:Label x="6" y="5" text="总数量:" fontSize="12" fontWeight="bold" color="#323232"/> <mx:Text maxHeight="40" id="totalInfoId" x="57" y="5" width="496" height="70" fontSize="12"/> <mx:Label x="598" y="6" text="合计金额:" fontWeight="bold" fontSize="12" width="71" color="#323232"/> <mx:Label id="totalprice_id" x="663" y="5" width="82" fontSize="12" height="19" color="#FA0000"/> <!-- <mx:Button id="addshoppingcart_id" x="602" y="35" useHandCursor="true" buttonMode="true" label="加入购物车" click="addShoppingCart();" fontSize="16" fontWeight="bold" width="120" fillAlphas="[1.0, 1.0]" fillColors="[#ED7F02, #ED7F02]" color="#FFFFFF" height="40" cornerRadius="6"/> --> <mx:Image id="addshoppingcart_id" useHandCursor="true" buttonMode="true" x="582" y="25" source="./assets/addshoppingcart.jpg" click="addShoppingCart();" /> </mx:Canvas> <mx:HTTPService showBusyCursor="true" url="/PhotopoolServlet" id="addcartId" method="POST" resultFormat="text" result="addShoppingCartResult();"> </mx:HTTPService> <mx:HTTPService showBusyCursor="true" url="/PhotopoolServlet" id="loadExistxmlId" method="POST" resultFormat="text" result="loadXMLcallBack();"> </mx:HTTPService> <mx:HTTPService showBusyCursor="true" url="/PhotopoolServlet" method="POST" id="selectphotoNameListId" resultFormat="xml" result="getPhotoXMLbySelectResponse();" useProxy="false"/> </mx:Application>