<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: hand  
    $Date: 2016-4-25 下午5:26:16  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="get_contranct_link_id" model="cont.CON555A.con_contract" modelaction="batch_update"/>
        <a:link id="submit_approval_link" model="cont.CON555A.contract_workflow_start" modelaction="batch_update"/>
        <script type="text/javascript"><![CDATA[
            // Leaf.onReady(init);
            // function init() {
            // alert('1');
            // var cons=${/parameter/@contracts};
            // alert(cons);
            // }
           // var lag='N';
            function application_submit() {
               // add_express_hd();
               // if(lag=='Y'){
                    // Leaf.showMessage('${l:HLS.PROMPT}', '未保存，不能提交！');
               // }
                var records = $('con_contract_v_for_query_result_ds').getSelected();
                var index1=0;
                // for (var i = 0;i < records.length;i++) {
                    // var contract_id=records[i].get('contract_id');
                    // Leaf.request({
                        // url: $('get_contranct_link_id').getUrl(),
                        // para: {
                            // contract_id: contract_id,
                            // status:'archive'
                        // },
                        // success: function(res) {
                           // index1+=1;
                        // },
                        // error: function() {
                           
                            // window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        // },
                        // failure: function() {
                            
                            // window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        // },
                        // sync: true,
                        // scope: this
                    // });
                  
                // }
                
                // if(index1==records.length){
                   // $('application_archive_mail_window').close();
               // }
               
               var prams=[];
                for(var i = 0;i < records.length;i++){
                    // var contract_id=records[i].get('contract_id');
                    // var data={'contract_id':contract_id,
                    // status:'archive'
                    // };
                    //prams.push(data);
                    var data={};
                    data['contract_id']=records[i].get('contract_id');
                    data['status']='archive';
                    data['_status'] = 'update';
                    prams[i]=data;
                }
               
                Leaf.request({
                        url: $('get_contranct_link_id').getUrl(),
                        para: prams,
                        success: function(res) {
                         $('application_archive_mail_window').close();
                        },
                        error: function() {
                           
                           
                        },
                        failure: function() {
                            
                           
                        },
                        sync: true,
                        scope: this
                    });
                    
                    
                     // Leaf.request({
                            // url: $('submit_approval_link').getUrl(),
                            // para: prams,
                            // success: function() {
                                
                               // $('application_archive_mail_window').close();
                                // Leaf.SideBar.show({
                                    // msg: '操作成功',
                                    // duration: 2000
                                // });
                            // },
                            // failure: function() {
                              
                            // },
                            // error: function() {
                                
                            // },
                            // scope: this
                        // });
            
               
            
            }
            
            function add_express_hd() {
               
                var hd_record = $('con_express_hd_result_ds').getCurrentRecord();
                if (hd_record.isNew) {
                    hd_record.set('_status', 'insert');
                } else {
                    hd_record.set('_status', 'update');
                }
                var records = $('con_contract_v_for_query_result_ds').getSelected();
                var con_express_ln_result_ds = $('con_express_ln_result_ds');
                for (var i = 0;i < records.length;i++) {
                    //cons.push(recodes[i].get('contract_id'));
                    //cons[i] = recodes[i].get('contract_id');
                    var current_record = con_express_ln_result_ds.create(Ext.apply({}, records[i].data));
                    current_record.set('_status', 'insert');
                }
                $('con_express_hd_result_ds').submit();
                lag='Y';
            
            }
            
            function express_province_change(t,value,value2,rec){
               var express_province= $('con_express_hd_result_ds').getCurrentRecord().get('express_province');
                $('fnd_city_ds').setQueryParameter('express_province',express_province);
                $('fnd_city_ds').query();
            }
            
            
            function back_to(){
                $('application_archive_mail_window').close();
            }
            
            function submitsuccess_express_hd(ds,res){
                application_submit();
            }
            function con_express_hd_add(ds,res,index){
                var date=new Date();
                var year=date.getFullYear();
                var month=date.getMonth()+1;
                var day=date.getDate();
                var dd=year+'-'+month+'-'+day;
                res.set('express_date',dd);
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="fnd_province_ds" autoQuery="true" fetchAll="true" model="cont.CON555A.fnd_province">
                <a:fields>
                    <a:field name="province_id"/>
                    <a:field name="description"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="fnd_city_ds" fetchAll="true" model="cont.CON555A.fnd_city" queryUrl="${/request/@context_path}/autocrud/cont.CON555A.fnd_city/query"/>
            <a:dataSet id="con_express_hd_result_ds" autoCreate="true" model="cont.CON555A.con_express_hd" submitUrl="${/request/@context_path}/modules/cont/CON555A/con_contract_archive.lsc">
                <a:fields>
                    <a:field name="invoice_agent_desc" defaultValue="${/parameter/@invoice_agent_desc}" readOnly="true"/>
                    <a:field name="invoice_agent" defaultValue="${/parameter/@invoice_agent}" readOnly="true"/>
                    <a:field name="express_id"/>
                    <a:field name="express_number" required="true"/>
                    <a:field name="express_company" required="true"/>
                    <a:field name="express_province_n" displayField="description" options="fnd_province_ds" returnField="express_province" valueField="province_id"/>
                    <a:field name="express_province"/>
                    <a:field name="express_city_n" displayField="description" options="fnd_city_ds" returnField="express_city" valueField="city_id"/>
                    <a:field name="express_city"/>
                    <a:field name="express_address"/>
                    <a:field name="express_date" readOnly="true"/>
                    <a:field name="express_person" defaultValue="${/session/@user_id}"/>
                    <a:field name="express_person_n" readOnly="true"/>
                    <a:field name="express_tel"/>
                    <a:field name="express_note"/>
                    <a:field name="express_type" defaultValue="AGENT"/>
                </a:fields>
                <a:events>
                    <a:event name="submitsuccess" handler="submitsuccess_express_hd"/>
                    <a:event name="add" handler="con_express_hd_add"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="con_express_ln_result_ds" bindName="result_ds" bindTarget="con_express_hd_result_ds" model="cont.CON555A.con_express_ln">
                <a:fields>
                    <a:field name="express_id"/>
                    <a:field name="contract_id"/>
                    <a:field name="contract_number"/>
                    <a:field name="express_number"/>
                    <a:field name="express_company"/>
                    <a:field name="express_province"/>
                    <a:field name="express_city"/>
                    <a:field name="express_address"/>
                    <a:field name="express_date"/>
                    <a:field name="express_ln_id"/>
                    <a:field name="express_age_flag" defaultValue="Y"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="back_to" text="退回"/>
                <!--  <a:gridButton click="add_express_hd" text="保存"/> -->
                <a:gridButton click="add_express_hd" text="确认邮寄"/>
            </a:screenTopToolbar>
            <a:form column="4" labelWidth="100" marginWidth="30" title="归档申请">
                <a:textField name="invoice_agent_desc" bindTarget="con_express_hd_result_ds" prompt="经销商"/>
                <a:textField name="express_company" bindTarget="con_express_hd_result_ds" prompt="快递公司"/>
                <a:textField name="express_number" bindTarget="con_express_hd_result_ds" prompt="快递单号"/>
                <a:datePicker name="express_date" bindTarget="con_express_hd_result_ds" prompt="寄出时间"/>
                <a:comboBox name="express_province_n" bindTarget="con_express_hd_result_ds" prompt="寄出省份">
                    <a:events>
                        <a:event name="select" handler="express_province_change"/>
                    </a:events>
                </a:comboBox>
                <a:comboBox name="express_city_n" bindTarget="con_express_hd_result_ds" prompt="寄出城市"/>
                <a:textField name="express_address" bindTarget="con_express_hd_result_ds" colspan="2" prompt="寄出地址" width="510"/>
                <a:textField name="express_person_n" bindTarget="con_express_hd_result_ds" prompt="寄送人"/>
                <a:textField name="express_tel" bindTarget="con_express_hd_result_ds" prompt="联系电话"/>
                <a:textField name="express_note" bindTarget="con_express_hd_result_ds" colspan="2" prompt="备注" width="510"/>
            </a:form>
            <!--   <a:grid id="grid_head" bindTarget="con_express_hd_result_ds" height="300" width="800">
                <a:toolBar>
                    <a:button type="add"/>
                    <a:button type="save"/>
                    <a:button type="delete"/>
                    <a:button type="excel"/>
                    <a:button type="clear"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="express_number" editor="grid_head_textField_id" prompt="CON_EXPRESS_HD.EXPRESS_NUMBER" width="100"/>
                    <a:column name="express_company" editor="grid_head_textField_id" prompt="CON_EXPRESS_HD.EXPRESS_COMPANY" width="100"/>
                    <a:column name="express_province" editor="grid_head_textField_id" prompt="CON_EXPRESS_HD.EXPRESS_PROVINCE" width="100"/>
                    <a:column name="express_city" editor="grid_head_textField_id" prompt="CON_EXPRESS_HD.EXPRESS_CITY" width="100"/>
                    <a:column name="express_address" editor="grid_head_textField_id" prompt="CON_EXPRESS_HD.EXPRESS_ADDRESS" width="100"/>
                    <a:column name="express_date" editor="grid_head_textField_id" prompt="CON_EXPRESS_HD.EXPRESS_DATE" width="100"/>
                </a:columns>
                <a:editors>
                    <a:textField id="grid_head_textField_id"/>
                </a:editors>
            </a:grid>
            <a:grid id="grid_detail" bindTarget="con_express_ln_result_ds" height="300" width="800">
                <a:toolBar>
                    <a:button type="add"/>
                    <a:button type="save"/>
                    <a:button type="delete"/>
                    <a:button type="excel"/>
                    <a:button type="clear"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="express_id" editor="grid_detail_numberField_id" prompt="CON_EXPRESS_LN.EXPRESS_ID" width="100"/>
                    <a:column name="contract_id" editor="grid_detail_numberField_id" prompt="CON_EXPRESS_LN.CONTRACT_ID" width="100"/>
                    <a:column name="contract_number" editor="grid_detail_textField_id" prompt="CON_EXPRESS_LN.CONTRACT_NUMBER" width="100"/>
                    <a:column name="express_number" editor="grid_detail_textField_id" prompt="CON_EXPRESS_LN.EXPRESS_NUMBER" width="100"/>
                    <a:column name="express_company" editor="grid_detail_textField_id" prompt="CON_EXPRESS_LN.EXPRESS_COMPANY" width="100"/>
                    <a:column name="express_province" editor="grid_detail_textField_id" prompt="CON_EXPRESS_LN.EXPRESS_PROVINCE" width="100"/>
                    <a:column name="express_city" editor="grid_detail_textField_id" prompt="CON_EXPRESS_LN.EXPRESS_CITY" width="100"/>
                    <a:column name="express_address" editor="grid_detail_textField_id" prompt="CON_EXPRESS_LN.EXPRESS_ADDRESS" width="100"/>
                    <a:column name="express_date" editor="grid_detail_textField_id" prompt="CON_EXPRESS_LN.EXPRESS_DATE" width="100"/>
                </a:columns>
                <a:editors>
                    <a:numberField id="grid_detail_numberField_id"/>
                    <a:textField id="grid_detail_textField_id"/>
                </a:editors>
            </a:grid>
            <a:hBox/> -->
        </a:screenBody>
    </a:view>
</a:screen>
