flex開發卡片加入購物車(六)

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"  width="770" height="42">
  3. <mx:Script>
  4.     <![CDATA[
  5.     import code.ProductHandlerBasic;
  6.     import mx.validators.NumberValidator;
  7.     import mx.controls.TextInput;
  8.     import mx.controls.Text;
  9.     import mx.core.Container;
  10.     import mx.events.CloseEvent;
  11.     import mx.controls.Alert ;
  12.     import mx.styles.StyleManager;
  13.     import mx.managers.PopUpManager; 
  14.     private var alertCSS:CSSStyleDeclaration;
  15.     
  16.     [Bindable]
  17.     private var _productname:String;
  18.      
  19.     
  20.     /*產品價格(單價)*/
  21.     [Bindable]
  22.     private var _price:Number ;
  23.     
  24.     /*產品價格單位.如:元/套*/
  25.     [Bindable]
  26.     private var _unit:String ;
  27.     
  28.     private var _phander:ProductHandlerBasic ;
  29.     
  30.     private var _leftContainer:Container ;
  31.     
  32.     /**
  33.     * 控制標籤欄
  34.     */ 
  35.     public function set leftContainer(l:Container):void{
  36.         this._leftContainer = l ;
  37.     }
  38.     public function get leftContainer():Container{
  39.         return this._leftContainer ;
  40.     }
  41.     public function set phander(p:ProductHandlerBasic):void{
  42.         _phander = p ;
  43.         this._price = p.price ;
  44.         this._unit = p.unit ;
  45.         this._productname = p.productInfo.product.(@id==p.productID).name ;
  46.     }
  47.     public function get phander():ProductHandlerBasic{
  48.         return this._phander ;
  49.     }
  50.     public function set price(p:Number):void{
  51.         this._price = p ;
  52.     }
  53.     public function get price():Number{
  54.         return this._price ;
  55.     }
  56.     public function set unit(u:String):void{
  57.         this._unit = u ;
  58.     }
  59.     public function get unit():String{
  60.         return this._unit ;
  61.     }
  62.     public function set productName(productname:String):void{
  63.         this._productname = productname ;
  64.     } 
  65.     public function get porudctName():String{
  66.         return this._productname ;
  67.     }
  68.     private var _currentButton:Button ; 
  69.     
  70.     /**
  71.      * 創建舞臺標籤導航.因爲每種那個型號的導航菜單都不一樣,所以需要動態創建。如下:(第一張,正面等)
  72.      */ 
  73.     public function createStageButtonMenu():void{
  74.          
  75.         for(var i:String in this._phander.productInfo.product.(@id==_phander.productID)..label){
  76.             var but:Button = new Button() ; 
  77.             but.styleName ="myBtn";
  78.             but.name=i ;
  79.             but.x =this._phander.productInfo.product.(@id==_phander.productID)..label[i].@x ;
  80.             but.y = 19 ;
  81.             but.width =97 ;
  82.             but.height = 20;  
  83.             but.label = this._phander.productInfo.product.(@id==_phander.productID)..label[i] ;
  84.             but.addEventListener(MouseEvent.CLICK,buttonClickHandler) ;
  85.             
  86.             if(i=="0"){
  87.                 _currentButton = but ;
  88.                 but.styleName ="myBtn2";
  89.             }
  90.             this.leftContainer.addChild(but); 
  91.         
  92.         }    
  93.     }
  94.     public function changeCurrentButton(btname:String):void{
  95.         _currentButton.styleName="myBtn";
  96.         _currentButton = leftContainer.getChildByName(btname) as Button ;
  97.         _currentButton.styleName="myBtn2";
  98.         _phander.currentpageNum = Number(_currentButton.name) ;
  99.         _phander.initCurrentPageInfoToStage(false);
  100.     } 
  101.     
  102.     /**
  103.      * 如果需要郵票或信封。需要重新計算價格
  104.      * @param  p. 價格增量
  105.      */ 
  106.     public function recomputePrice():void{
  107.            
  108.         this._price=this._phander.duplexPrice ;
  109.     }
  110.               
  111.     private function buttonClickHandler(e:MouseEvent):void{
  112.         changeCurrentButton(Button(e.target).name);
  113.     } 
  114.      
  115.     private function addShoppingCartResult():void{
  116.         
  117.         var url:String = "/pages/shopping/shoppingCart.faces" ;
  118.         var request:URLRequest = new URLRequest(url);  
  119.         if(addcartId.lastResult.toString()=="success"){
  120.             navigateToURL(request,"_self"); 
  121.         }
  122.     }
  123.   
  124.     /*****************對用戶輸入的產品數量進行驗證***********/
  125.     private function numberCheck():void{
  126.         var reg:RegExp = /^[1-9]/d*$/ ;
  127.         errorID.visible =!reg.test(numberID.text) ; 
  128.     } 
  129.     
  130.     /******************加入購物車*********************/   
  131.     private function addShoppingCart():void{     
  132.         var paras:Object = new Object(); 
  133.         paras.content = _phander.productDataContent.toXMLString() ;
  134.         paras.randow = Math.random() ;
  135.         paras.methodName="addToshoppingCart";  
  136.         paras.productInnerNum =  _phander.productInnerNum;
  137.         paras.productid = _phander.productID ;   
  138.         paras.previewURL =_phander.previewURL ;
  139.         paras.pid = _phander.recordID ;
  140.         paras.number = numberID.text ;
  141.         paras.classid=  _phander.classid  ; 
  142.         addcartId.send(paras);    
  143.     }   
  144.     /**
  145.      * 驗證是否製作完成。如果製作完成,定位到該頁 。
  146.      * 
  147.      */ 
  148.     private function checkSubmit():void{
  149.         if(errorID.visible){ 
  150.             return ;
  151.         } 
  152.         //總的頁數
  153.         var b:Boolean = true ;
  154.       //  this._phander._testTextArea.text = this._phander.pages +"";
  155.         out
  156.         for (var i:int=0;i< this._phander.pages;i++) { 
  157.             //當前版式的照片張數
  158.             var bsleng:Number =_phander.getCurrentPhotoCount(i);
  159.             for(var j:int=0;j<bsleng;j++){ 
  160.                 if(_phander.productDataContent.item[i]..img[j].@url==""){
  161.                     b = false ;
  162.                     _phander.currentpageNum = i ;//定位到,錯誤頁
  163.                     break out;
  164.                 } 
  165.             } 
  166.               
  167.             //清空沒有無用的照片,如不清空會下載無用圖片
  168.             for(var h:int=bsleng;h<13;h++){ 
  169.                 _phander.productDataContent.item[i]..img[j].@url="" ;
  170.                 _phander.productDataContent.item[i]..img[j].@x=-1 ; 
  171.             }
  172.         }   
  173.         if(!b){ 
  174.             var hint:String = "您還沒有製作完成,請您繼續完成製作。";
  175.             alertCSS = StyleManager.getStyleDeclaration("Alert");
  176.             alertCSS.setStyle("fontSize""12"); 
  177.             
  178.             var alert:Alert = Alert.show(hint,"提醒",Alert.OK,this,selectHandler,null,Alert.NO); 
  179.             PopUpManager.centerPopUp (alert);  
  180.             callLater (alert.move, [(this._phander.currentStage.width-200)/2, (this._phander.currentStage.height-200)/2]);   
  181.         }  
  182.         else{   
  183.             addcardID.enabled = false ;
  184.             addShoppingCart();
  185.         } 
  186.     }   
  187.     private function selectHandler(e:CloseEvent):void{
  188.         changeCurrentButton(_phander.currentpageNum+"");
  189.     }    
  190.     ]]> 
  191. </mx:Script>
  192.  <mx:HTTPService showBusyCursor="true" url="/HttpServiceSlt" id="addcartId"  
  193.    method="POST" resultFormat="text"  result="addShoppingCartResult();">
  194.  </mx:HTTPService>  
  195.  <mx:Button x="651" y="5" useHandCursor="true" buttonMode="true" id="addcardID" label="加入購物車" click="checkSubmit();" fontSize="13" fontWeight="bold" width="102" fillAlphas="[1.0, 1.0]" fillColors="[#ED7F02, #ED7F02]" color="#FFFFFF" height="30" cornerRadius="15"/>
  196.  <mx:TextInput id="numberID" x="453" text="1"  maxChars="4" y="10" change="numberCheck();" width="46" height="20"/>
  197.  <mx:Label x="370" y="10" text="輸入購買數量:"   fontSize="12" fontWeight="normal" width="86"/>
  198.      
  199.  <mx:Label id="errorID" visible="false"  x="506" y="11" text="請輸半角阿拉伯數字" fontSize="12" color="#FE0000"  width="129" height="20"/>
  200.  <mx:Label x="199" y="10" text="單價:{this._price}{this._unit}" fontSize="12"/> 
  201.  <mx:Label x="14" id="pnameID" y="10" text="名稱:{_productname}" fontSize="12"/>
  202. </mx:Canvas>
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章