- <?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开发卡片加入购物车(六)
最新推荐文章于 2022-11-10 22:56:27 发布