zoukankan      html  css  js  c++  java
  • flex 分页

    <?xml version="1.0" encoding="utf-8"?>
    <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:afc="com.aflag.afcTree.*"
    xmlns:mx="library://ns.adobe.com/flex/mx"
    xmlns:components="com.aflag.components.*"
    xmlns:cti="http://www.a-flag.com/cti"
    xmlns:presentation="com.aflag.presentation.*"
    width="100%" height="100%" creationComplete="init(event)">
    <fx:Declarations>
    </fx:Declarations>
    <fx:Script>
    <![CDATA[
    import com.aflag.components.AFCDate;
    import com.aflag.components.serverError;
    import com.aflag.events.ComponentEvent;
    import com.aflag.misc.RenderFactory;
    import com.aflag.services.api.ISalesDeliveryReminderService;
    import com.aflag.services.impl.SalesDeliveryReminderService;
    import com.aflag.utils.Tool;

    import flash.utils.Timer;
    import flash.utils.getDefinitionByName;

    import mx.collections.IList;
    import mx.collections.XMLListCollection;
    import mx.controls.Alert;
    import mx.core.ClassFactory;
    import mx.core.FlexGlobals;
    import mx.core.IVisualElement;
    import mx.events.FlexEvent;
    import mx.formatters.DateFormatter;
    import mx.managers.PopUpManager;

    import spark.events.TextOperationEvent;

    import org.as3commons.async.command.impl.GenericOperationCommand;
    import org.as3commons.async.operation.event.OperationEvent;
    import org.as3commons.collections.Map;
    import org.as3commons.lang.DateUtils;



    [Bindable]
    public var codeItemEditor:ClassFactory;
    private var pageInstance:ViewBase;
    private var _timer:Timer;
    private var inbound:String;
    private var _hasOpen:Boolean=false;
    public var currentBusinessType:String;
    private var _incomingBarTimer:Timer;
    [Bindable]
    private var _dataProvider:IList;
    private const _incomingBarTotal:int=180;
    private var service:ISalesDeliveryReminderService=new SalesDeliveryReminderService();
    public var scheduleMap:Map=new Map();
    private var _serviceSite:XML;
    [Bindable]
    private var _queryString:String;

    protected function searchByType(type:String):void{
    var currentDate:String = AFCDate.parseCurrentCalendar(new Date()) ;
    var endDateString:String = currentDate;
    if(type=="week"){
    endDateString = AFCDate.parseCurrentCalendar(DateUtils..addWeeks(new Date() , 1));
    }else if(type == "month"){
    endDateString = AFCDate.parseCurrentCalendar(DateUtils..addMonths(new Date() , 1));
    }

    startDate.value=currentDate;
    endDate.value=endDateString;
    query();
    }

    protected function query():void {
    if(!startDate.value){ Alert.show("开始日期不能为空"); return; }
    if(!endDate.value){ Alert.show("结束日期不能为空"); return; }


    var scheduleQueryWarp:XML=new XML("<scheduleQueryWarp/>");
    scheduleQueryWarp.queryString = _queryString;
    scheduleQueryWarp.@startDate=startDate.value.toString();
    scheduleQueryWarp.@endDate=endDate.value.toString();
    if(_requery || _index > _resultCount){
    _index = 0;
    nowPage.text = "1";
    }
    if(_index > 0) _index++;
    scheduleQueryWarp.@startPosition = _index ;
    scheduleQueryWarp.@maxResults = _pageSize;

    var _cmd:GenericOperationCommand = service.findSalesDeliveryReminder(scheduleQueryWarp);
    _cmd.addCompleteListener(function (event:OperationEvent):void{
    var _result:XML =new XML(event.result);
    _dataProvider = new XMLListCollection(_result.result.entity);

    _requery = false;
    _resultCount = int(_result.@resultCount);
    _pageCount = _resultCount / int(_pageSize);
    if(_resultCount % int(_pageSize) > 0) _pageCount++;

    preImg.enabled = true;
    firstImg.enabled = true;
    nextImg.enabled = true;
    lastImg.enabled = true;

    //重置分页按钮可用状态
    if(int(_pageSize) >= _resultCount){
    preImg.enabled = false;
    firstImg.enabled = false;
    nextImg.enabled = false;
    lastImg.enabled = false;
    }else if(int(nowPage.text) >= _pageCount){
    nextImg.enabled = false;
    lastImg.enabled = false;
    }else if(int(nowPage.text) <= 1){
    preImg.enabled = false;
    firstImg.enabled = false;
    }
    });
    _cmd.addErrorListener(function (e:OperationEvent):void{
    serverError("加载发货信息失败","系统消息",e);
    });
    _cmd.execute();
    }

    //序号
    public function documentDGNum(item:Object, column:GridColumn):String{


    return ((documentDG.dataProvider.getItemIndex(item) + 1+_index).toString());
    }


    protected function init(event:FlexEvent):void {
    var currentDate:Date=new Date();
    startDate.value=AFCDate.parseCurrentCalendar(currentDate);
    currentDate.setDate(currentDate.date+6);
    endDate.value=AFCDate.parseCurrentCalendar(currentDate);

    startDate.addEventListener(ComponentEvent.VALUE_CHANGE,onStartDateChanged);
    endDate.addEventListener(ComponentEvent.VALUE_CHANGE,onEndDateChanged);
    }


    protected function documentDGDoubleClick(event:MouseEvent):void {
    if(!documentDG.selectedItem){ return; }
    var selectedId:Number=Number(documentDG.selectedItem.@id);
    popInfo(selectedId);
    }
    public function popInfo(selectedId:Number):void{
    var menu:XML=FlexGlobals.topLevelApplication.getElementAt(0).getMenu("SALES_DELIVERY_HEAD");
    var menuName:String=menu.@name.toString();

    if(menu!=null){
    popBizTag(menu.@clientClass, "SALES_DELIVERY_HEAD" ,menuName,selectedId);
    }else{
    Alert.show("加载失败:没有权限或者参数配置出错!");
    }
    }

    public var page:IVisualElement;

    private function popBizTag(fullName:String, bizCode:String,modelName:String,onLoadId:Number=0):void{
    var pt:Point = new Point(0, 0);
    const POPUP_OFFSET:int = 10;

    if(!page){
    var WIN:Class = getDefinitionByName(fullName) as Class;
    page = new WIN() as IVisualElement;
    }
    if(page){
    page["bizCode"] = bizCode;
    var pageWindow:ScheduleInformationEachWindow=new ScheduleInformationEachWindow();
    pageWindow.pageInstance=page as ViewBase;
    page.percentWidth=100;
    page.percentHeight=100;
    pageWindow.onLoadId=onLoadId;
    PopUpManager.addPopUp(pageWindow, FlexGlobals.topLevelApplication as DisplayObject, false);
    PopUpManager.centerPopUp(pageWindow);
    }
    }

    protected function onStartDateChanged(event:ComponentEvent):void {
    _requery = true;
    if(Tool.emptyString(event.currentTarget.value)){ return ;}
    var starDay:Date = DateFormatter.parseDateString(event.currentTarget.value);
    endDate.value = AFCDate.parseCurrentCalendar(DateUtils.addMonths(starDay,3));
    }

    protected function onEndDateChanged(event:ComponentEvent):void {
    _requery = true;
    if(Tool.emptyString(event.currentTarget.value)){ return ;}
    var endDay:Date = DateFormatter.parseDateString(event.currentTarget.value);
    startDate.value = AFCDate.parseCurrentCalendar(DateUtils.addMonths(endDay,-3));
    }


    /**是否重置查询 -- 如果查询条件发生改变则重置 -- 查询开始位置为0*/
    private var _requery:Boolean = true;

    /** 当前下标 */
    [Bindable] protected var _index:int = 0;
    /**记录总数**/
    [Bindable] protected var _resultCount:int = 0;
    /**页数**/
    [Bindable] protected var _pageCount:int = 0;

    [Bindable] protected var _pageSize:String = "25";

    /**跳至首页**/
    private function onFirstBtnClick(event:MouseEvent):void{
    _index = 0;
    nowPage.text = "1";
    query();
    }
    /**上一页**/
    private function onPreBtnClick(event:MouseEvent):void{
    _index = _index - int(_pageSize) -1;
    if(_index < 0) _index = 0;
    nowPage.text = Tool.trimString(int(nowPage.text) - 1);
    query();
    }
    /**跳至指定页**/
    private function onNowPageEnter(event:Event):void{
    _index = (int(nowPage.text) - 1) * int(_pageSize) - 1;
    if(_index < 0) _index = 0;
    query();
    }
    /**下一页**/
    private function onNextBtnClick(event:MouseEvent):void{
    nowPage.text = Tool.trimString(int(nowPage.text) + 1);
    _index = (int(nowPage.text) - 1) * int(_pageSize) - 1;
    if(_index < 0) _index = 0;
    query();
    }
    /**末页**/
    private function onLastBtnClick(event:MouseEvent):void{
    nowPage.text = Tool.trimString(_resultCount / int(_pageSize));
    if(_resultCount % int(_pageSize) > 0) nowPage.text = Tool.trimString(int(nowPage.text) + 1);
    _index = (int(nowPage.text) - 1) * int(_pageSize) - 1;
    if(_index < 0) _index = 0;
    query();
    }

    protected function onQueryStringChanged(event:TextOperationEvent):void
    {
    _requery = true;
    }

    ]]>
    </fx:Script>

    <s:states>
    <s:State name="normal"/>
    <s:State name="open"/>
    <s:State name="disabled"/>
    </s:states>

    <!--适用于第三方支付公司-->

    <s:layout>
    <s:VerticalLayout>

    </s:VerticalLayout>
    </s:layout>
    <!--抬头-->
    <mx:HDividedBox id="header" width="100%" height="100%">


    <s:SkinnableContainer id="documentButtonContainer" width="220" height="100%"
    mouseDownOutside="currentState='normal'"
    skinClass="com.aflag.skins.frame.DefaultFrameSkin">
    <s:layout>
    <s:VerticalLayout gap="4" paddingBottom="2" paddingLeft="2" paddingRight="2"
    paddingTop="4"/>
    </s:layout>
    <s:HGroup width="100%" height="24" gap="10" verticalAlign="justify">
    <s:Label width="60" height="100%" text="开始时间" verticalAlign="middle"/>
    <components:AFCDate id="startDate" width="100%" height="100%" datePattern="showDate"/>
    </s:HGroup>
    <s:HGroup width="100%" height="24" verticalAlign="justify">
    <s:Label width="60" height="100%" text="结束时间" verticalAlign="middle"/>
    <components:AFCDate id="endDate" width="100%" height="100%" datePattern="showDate"/>
    </s:HGroup>
    <s:HGroup width="100%" height="24" verticalAlign="justify">
    <s:Label width="60" height="24" text="过滤" verticalAlign="middle"/>
    <s:TextInput width="100%" change="onQueryStringChanged(event)" text="@{_queryString}"/>
    </s:HGroup>

    <s:HGroup width="100%" height="24" gap="11" verticalAlign="justify">
    <s:Button width="40" height="20" label="今天" click="searchByType('today')"/>
    <s:Button width="40" height="20" label="一周" click="searchByType('week')"/>
    <s:Button width="40" height="20" label="一月" click="searchByType('month')"/>
    <s:Button width="40" height="20" label="查询" click="query()"/>

    </s:HGroup>

    </s:SkinnableContainer>
    <!--历史-->
    <!--单击该Tab时刷新对应的内容表单-->
    <s:SkinnableContainer id="history1" width="100%" height="100%"
    skinClass="com.aflag.skins.frame.DefaultFrameSkin">
    <s:layout>
    <s:VerticalLayout gap="0"/>
    </s:layout>
    <s:TabBar width="100%" height="24" dataProvider="{historyViewStack1}"
    skinClass="com.aflag.skins.tabBar.AFCTabBarSkin"/>
    <mx:ViewStack id="historyViewStack1" width="100%" height="100%"
    borderSkin="com.aflag.skins.standard.AFCViewStackBorderSkin"
    creationPolicy="all">

    <s:NavigatorContent width="100%" height="100%" label="列表视图">
    <s:layout>
    <s:VerticalLayout gap="5"/>
    </s:layout>
    <s:DataGrid id="documentDG" width="100%" height="100%"
    dataProvider="{_dataProvider}"
    doubleClick="documentDGDoubleClick(event)" doubleClickEnabled="true"
    editable="false" horizontalScrollPolicy="auto">
    <s:columns>
    <s:ArrayList>
    <s:GridColumn width="40" editable="false" headerText="序号"
    labelFunction="documentDGNum"/>

    <s:GridColumn dataField="code" headerText="编码"/>

    <s:GridColumn dataField="opWarehouse" headerText="发货仓库"
    labelFunction="{RenderFactory.finderLabelFunction}"/>

    <s:GridColumn dataField="confirmed" headerText="是否发货"
    labelFunction="{RenderFactory.booleanFunction}"/>

    <s:GridColumn dataField="requiredDate" headerText="要求发货时间"/>

    <s:GridColumn dataField="priority" headerText="优先级"
    labelFunction="{RenderFactory.finderLabelFunction}"/>

    <s:GridColumn dataField="customer" headerText="售达方"
    labelFunction="{RenderFactory.finderLabelFunction}"/>

    <s:GridColumn dataField="receiver" headerText="送达方"
    labelFunction="{RenderFactory.finderLabelFunction}"/>

    <s:GridColumn dataField="receiverContact" headerText="送达方联系人"
    labelFunction="{RenderFactory.finderLabelFunction}"/>

    <s:GridColumn dataField="remark" headerText="备注"/>
    </s:ArrayList>
    </s:columns>
    </s:DataGrid>

    <s:HGroup width="100%" height="24" gap="12" horizontalAlign="center"
    verticalAlign="justify">
    <s:Label text="{'共查询到 '+_resultCount+ ' 行数据,分 '+_pageCount+' 页,每页显示'}"
    textAlign="center" verticalAlign="middle"/>
    <s:TextInput width="40" height="100%" enter="onNowPageEnter(event)"
    restrict="0-9-" text="@{_pageSize}" textAlign="center"/>
    <s:Label text="行" textAlign="center" verticalAlign="middle"/>
    <s:Button id="firstImg" click="onFirstBtnClick(event)"
    skinClass="com.aflag.skins.arrow2.AFCFirstArrow2Skin" toolTip="首页"/>
    <s:Button id="preImg" click="onPreBtnClick(event)"
    skinClass="com.aflag.skins.arrow2.AFCPreviousArrow2Skin"
    toolTip="上一页"/>
    <s:TextInput id="nowPage" width="100" enter="onNowPageEnter(event)"
    restrict="0-9-" textAlign="center"/>
    <s:Button id="nextImg" click="onNextBtnClick(event)"
    skinClass="com.aflag.skins.arrow2.AFCNextArrow2Skin" toolTip="下一页"/>
    <s:Button id="lastImg" click="onLastBtnClick(event)"
    skinClass="com.aflag.skins.arrow2.AFCLastArrow2Skin" toolTip="末页"/>

    </s:HGroup>
    </s:NavigatorContent>
    </mx:ViewStack>
    </s:SkinnableContainer>
    </mx:HDividedBox>
    </s:Group>

    -----

    interface SalesDeliveryReminderRepositoryCustom {

    QueryPagination<SalesDeliveryHead> findSalesDeliveryReminder(ScheduleQueryWarp wrap);
    }

    class SalesDeliveryReminderRepositoryImpl implements SalesDeliveryReminderRepositoryCustom {

    @Autowired
    private QueryUtils queryUtils;

    @SuppressWarnings("unchecked")
    @Override
    public QueryPagination<SalesDeliveryHead> findSalesDeliveryReminder(ScheduleQueryWarp wrap) {

    StringBuffer hql = new StringBuffer("SELECT obj FROM ");
    hql.append(SalesDeliveryHead.class.getCanonicalName()).append(" obj ");
    hql.append(" LEFT JOIN FETCH obj.customer customer ");
    hql.append(" LEFT JOIN FETCH obj.opWarehouse opWarehouse ");
    hql.append(" LEFT JOIN FETCH obj.receiver receiver ");
    hql.append(" LEFT JOIN FETCH obj.carrier carrier");
    hql.append(" LEFT JOIN FETCH obj.receiverContact receiverContact ");
    hql.append(" LEFT JOIN FETCH obj.priority priority");

    StringBuffer str = new StringBuffer(" WHERE obj.requiredDate between ? and ? ");

    List<Object> params = new ArrayList<Object>();
    Date startDate = wrap.getStartDate();
    Date endDate = wrap.getEndDate();

    params.add(startDate);
    params.add(endDate);

    if (!StringUtils.isEmpty(wrap.getQueryString())) {
    str.append(" AND (obj.code LIKE ? OR obj.name LIKE ? )");
    params.add("%" + wrap.getQueryString() + "%");
    params.add("%" + wrap.getQueryString() + "%");
    }
    StringBuffer countHql = new StringBuffer("SELECT COUNT(obj.id) FROM ");
    countHql.append(SalesDeliveryHead.class.getCanonicalName()).append(" obj ");

    hql.append(str);
    countHql.append(str);

    hql.append(" ORDER BY obj.requiredDate ");
    return (QueryPagination<SalesDeliveryHead>) queryUtils.limiteQuery(countHql.toString(), hql.toString(),
    wrap.getStartPosition(), wrap.getMaxResults(), params);
    }

    -----

    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public class ScheduleQueryWarp {

    private String queryString;

    @XmlAttribute
    private Long employeeId;

    @XmlAttribute
    @XmlJavaTypeAdapter(value = DateAdapter.class)
    private Date startDate;

    @XmlAttribute
    @XmlJavaTypeAdapter(value = DateAdapter.class)
    private Date endDate;

    @XmlAttribute
    private int startPosition;

    @XmlAttribute
    private int maxResults = 25;

    public Long getEmployeeId() {

    return employeeId;
    }

    public void setEmployeeId(Long employeeId) {

    this.employeeId = employeeId;
    }

    public Date getStartDate() {

    return startDate;
    }

    public void setStartDate(Date startDate) {

    this.startDate = startDate;
    }

    public Date getEndDate() {

    return endDate;
    }

    public void setEndDate(Date endDate) {

    this.endDate = endDate;
    }

    public String getQueryString() {

    return queryString;
    }

    public void setQueryString(String queryString) {

    this.queryString = queryString;
    }

    public int getStartPosition() {

    return startPosition;
    }

    public void setStartPosition(int startPosition) {

    this.startPosition = startPosition;
    }

    public int getMaxResults() {

    return maxResults;
    }

    public void setMaxResults(int maxResults) {

    this.maxResults = maxResults;
    }
    }

  • 相关阅读:
    IOS开发之——绘图(CGContext)
    网站相关人员信息记录humans.txt
    统一代码风格工具——editorConfig
    Bootstrap自动定位浮标
    Bootstrap图片轮播
    Bootstrap手风琴效果
    Bootstrap按钮插件
    Bootstrap弹出框
    Bootstrap提示框
    Bootstrap选项卡
  • 原文地址:https://www.cnblogs.com/lanliying/p/3501780.html
Copyright © 2011-2022 走看看