- <?xml version="1.0" encoding="utf-8"?>
- <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="770" height="42">
- <mx:Script>
- <![CDATA[
- import code.ProductHandlerBasic;
- import mx.validators.NumberValidator;
- import mx.controls.TextInput;
- import mx.controls.Text;
- import mx.core.Container;
- import mx.events.CloseEvent;
- import mx.controls.Alert ;
- import mx.styles.StyleManager;
- import mx.managers.PopUpManager;
- private var alertCSS:CSSStyleDeclaration;
- [Bindable]
- private var _productname:String;
- /*產品價格(單價)*/
- [Bindable]
- private var _price:Number ;
- /*產品價格單位.如:元/套*/
- [Bindable]
- private var _unit:String ;
- private var _phander:ProductHandlerBasic ;
- private var _leftContainer:Container ;
- /**
- * 控制標籤欄
- */
- public function set leftContainer(l:Container):void{
- this._leftContainer = l ;
- }
- public function get leftContainer():Container{
- return this._leftContainer ;
- }
- public function set phander(p:ProductHandlerBasic):void{
- _phander = p ;
- this._price = p.price ;
- this._unit = p.unit ;
- this._productname = p.productInfo.product.(@id==p.productID).name ;
- }
- public function get phander():ProductHandlerBasic{
- return this._phander ;
- }
- public function set price(p:Number):void{
- this._price = p ;
- }
- public function get price():Number{
- return this._price ;
- }
- public function set unit(u:String):void{
- this._unit = u ;
- }
- public function get unit():String{
- return this._unit ;
- }
- public function set productName(productname:String):void{
- this._productname = productname ;
- }
- public function get porudctName():String{
- return this._productname ;
- }
- private var _currentButton:Button ;
- /**
- * 創建舞臺標籤導航.因爲每種那個型號的導航菜單都不一樣,所以需要動態創建。如下:(第一張,正面等)
- */
- public function createStageButtonMenu():void{
- for(var i:String in this._phander.productInfo.product.(@id==_phander.productID)..label){
- var but:Button = new Button() ;
- but.styleName ="myBtn";
- but.name=i ;
- but.x =this._phander.productInfo.product.(@id==_phander.productID)..label[i].@x ;
- but.y = 19 ;
- but.width =97 ;
- but.height = 20;
- but.label = this._phander.productInfo.product.(@id==_phander.productID)..label[i] ;
- but.addEventListener(MouseEvent.CLICK,buttonClickHandler) ;
- if(i=="0"){
- _currentButton = but ;
- but.styleName ="myBtn2";
- }
- this.leftContainer.addChild(but);
- }
- }
- public function changeCurrentButton(btname:String):void{
- _currentButton.styleName="myBtn";
- _currentButton = leftContainer.getChildByName(btname) as Button ;
- _currentButton.styleName="myBtn2";
- _phander.currentpageNum = Number(_currentButton.name) ;
- _phander.initCurrentPageInfoToStage(false);
- }
- /**
- * 如果需要郵票或信封。需要重新計算價格
- * @param p. 價格增量
- */
- public function recomputePrice():void{
- this._price=this._phander.duplexPrice ;
- }
- private function buttonClickHandler(e:MouseEvent):void{
- changeCurrentButton(Button(e.target).name);
- }
- private function addShoppingCartResult():void{
- var url:String = "/pages/shopping/shoppingCart.faces" ;
- var request:URLRequest = new URLRequest(url);
- if(addcartId.lastResult.toString()=="success"){
- navigateToURL(request,"_self");
- }
- }
- /*****************對用戶輸入的產品數量進行驗證***********/
- private function numberCheck():void{
- var reg:RegExp = /^[1-9]/d*$/ ;
- errorID.visible =!reg.test(numberID.text) ;
- }
- /******************加入購物車*********************/
- private function addShoppingCart():void{
- var paras:Object = new Object();
- paras.content = _phander.productDataContent.toXMLString() ;
- paras.randow = Math.random() ;
- paras.methodName="addToshoppingCart";
- paras.productInnerNum = _phander.productInnerNum;
- paras.productid = _phander.productID ;
- paras.previewURL =_phander.previewURL ;
- paras.pid = _phander.recordID ;
- paras.number = numberID.text ;
- paras.classid= _phander.classid ;
- addcartId.send(paras);
- }
- /**
- * 驗證是否製作完成。如果製作完成,定位到該頁 。
- *
- */
- private function checkSubmit():void{
- if(errorID.visible){
- return ;
- }
- //總的頁數
- var b:Boolean = true ;
- // this._phander._testTextArea.text = this._phander.pages +"";
- out:
- for (var i:int=0;i< this._phander.pages;i++) {
- //當前版式的照片張數
- var bsleng:Number =_phander.getCurrentPhotoCount(i);
- for(var j:int=0;j<bsleng;j++){
- if(_phander.productDataContent.item[i]..img[j].@url==""){
- b = false ;
- _phander.currentpageNum = i ;//定位到,錯誤頁
- break out;
- }
- }
- //清空沒有無用的照片,如不清空會下載無用圖片
- for(var h:int=bsleng;h<13;h++){
- _phander.productDataContent.item[i]..img[j].@url="" ;
- _phander.productDataContent.item[i]..img[j].@x=-1 ;
- }
- }
- if(!b){
- var hint:String = "您還沒有製作完成,請您繼續完成製作。";
- alertCSS = StyleManager.getStyleDeclaration("Alert");
- alertCSS.setStyle("fontSize", "12");
- var alert:Alert = Alert.show(hint,"提醒",Alert.OK,this,selectHandler,null,Alert.NO);
- PopUpManager.centerPopUp (alert);
- callLater (alert.move, [(this._phander.currentStage.width-200)/2, (this._phander.currentStage.height-200)/2]);
- }
- else{
- addcardID.enabled = false ;
- addShoppingCart();
- }
- }
- private function selectHandler(e:CloseEvent):void{
- changeCurrentButton(_phander.currentpageNum+"");
- }
- ]]>
- </mx:Script>
- <mx:HTTPService showBusyCursor="true" url="/HttpServiceSlt" id="addcartId"
- method="POST" resultFormat="text" result="addShoppingCartResult();">
- </mx:HTTPService>
- <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"/>
- <mx:TextInput id="numberID" x="453" text="1" maxChars="4" y="10" change="numberCheck();" width="46" height="20"/>
- <mx:Label x="370" y="10" text="輸入購買數量:" fontSize="12" fontWeight="normal" width="86"/>
- <mx:Label id="errorID" visible="false" x="506" y="11" text="請輸半角阿拉伯數字" fontSize="12" color="#FE0000" width="129" height="20"/>
- <mx:Label x="199" y="10" text="單價:{this._price}{this._unit}" fontSize="12"/>
- <mx:Label x="14" id="pnameID" y="10" text="名稱:{_productname}" fontSize="12"/>
- </mx:Canvas>
flex開發卡片加入購物車(六)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.