<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: ZLF  
    $Date: 2014-11-20 下午1:45:12  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query model="cont.CON508.con_contract_lease_import_batch_id" rootPath="batch_id"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con_contract_lease_link" url="${/request/@context_path}/modules/cont/CON508/con_contract_lease_item_query.lview"/>
        <a:link id="import_save_link" model="cont.CON508.save_data" modelaction="update"/>
        <a:link id="import_err_link" url="${/request/@context_path}/modules/cont/CON508/con_contract_lease_import_show_error.lview"/>
        <a:link id="csh508_import_check_link" model="cont.CON508.check_data" modelaction="update"/>
        <a:link id="import_upload_link" url="${/request/@context_path}/modules/cont/CON508/con_contract_lease_import_upload.lview"/>
        <script type="text/javascript"><![CDATA[
            var flag;
            var check_flag = 'N';
            //导入数据
            
            function loadData() {
                new Leaf.Window({
                    id: 'upload_window',
                    url: $('import_upload_link').getUrl() + '?batch_id=${/model/batch_id/record/@batch_id}',
                    title: '导入实例',
                    width: 420,
                    height: 275
                });
            }
            
            //校验数据
            
            function checkData() {
                var allData = $('con_contract_lease_item_ds').getAll();
                if (allData.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请导入数据!');
                } else {
                    var param = {};
                    param['batch_id'] = '${/model/batch_id/record/@batch_id}';
                    Leaf.request({
                        url: $('csh508_import_check_link').getUrl(),
                        para: param,
                        success: function(res) {
                            check_flag = 'Y';
                            flag = res.result.return_id;
                            if (res.result.return_id == 0) {
                                Leaf.showMessage('${l:PROMPT}', '有错误,请查看错误！');
                            } else {
                                Leaf.SideBar.show({
                                    msg: '核对操作成功！',
                                    duration: 2000
                                });
                            }
                        },
                        scope: this
                    });
                }
            }
            
            //提交数据
            
            function submitData() {

                if (check_flag == 'N') {
                    Leaf.showMessage('${l:PROMPT}', '请先核对通过再提交，谢谢！');
                    return;
                } else {
                    if (flag == 0) {
                        Leaf.showMessage('${l:PROMPT}', '导入的数据有错误，请重新导入，谢谢！');
                        return;
                    } else {
                        $('submitData_btn_id').disable(); //让按钮失效
                        var url = $('con_contract_lease_link').getUrl();
                        var param = {};
                        param['batch_id'] = '${/model/batch_id/record/@batch_id}';
                        Leaf.request({
                            url: $('import_save_link').getUrl(),
                            para: param,
                            success: function() {
                                Leaf.SideBar.show({
                                    //msg: res.result.v_save_message,
                                    msg: '提交操作成功！',
                                    duration: 2000
                                });
                                // Leaf.SideBar.show({
                                // msg: '操作成功',
                                // duration: 2000
                                // });
                                //$('csh_receipt_import_window').close();
                                Leaf.go(url);
                            },
                            scope: this
                        });
                    }
                }
            }
            
            function errorData() {
                var allData = $('con_contract_lease_item_ds').getAll();
                if (allData.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请导入数据!');
                    return;
                }
                new Leaf.Window({
                    id: 'error_window',
                    url: $('import_err_link').getUrl() + '?batch_id=${/model/batch_id/record/@batch_id}',
                    title: '错误信息',
                    width: 500,
                    height: 300
                });
                // window.open($('import_err_link').getUrl() + '?batch_id=${/model/batch_id/record/@batch_id}');
                //window.open($('import_err_link').getUrl()+'?batch_id=${/model/batch_id/record/@batch_id}');
            }
            
            function con508_quit() {
                window.location.href = $('con_contract_lease_link').getUrl();
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="con_contract_lease_item_ds" autoQuery="true" model="cont.CON508.con_contract_lease_temp" queryUrl="${/request/@context_path}/autocrud/cont.CON508.con_contract_lease_temp/query?batch_id=${/model/batch_id/record/@batch_id}"/>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:toolbarButton click="con508_quit" text="HLS.EXIT"/>
                <a:toolbarButton click="loadData" text="PROMPT.LOADDATA" width="80"/>
                <a:toolbarButton click="checkData" text="PROMPT.CHECK"/>
                <a:toolbarButton id="submitData_btn_id" click="submitData" text="PROMPT.SUBMIT" width="80"/>
                <!-- <a:toolbarButton bind="grid" text="HAP_EXPORT" type="excel" width="80"/> -->
                <a:toolbarButton click="errorData" text="PROMPT.ERROR"/>
            </a:screenTopToolbar>
            <a:grid bindTarget="con_contract_lease_item_ds" marginHeight="200" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="lease_item_seq" prompt="序号" width="50"/>
                    <a:column name="treasury_date" prompt="查库日期" renderer="Leaf.formatDate" width="120"/>
                    <a:column name="invoice_agent_id_n" prompt="经销商名称" width="200"/>
                    <a:column name="lease_start_date" prompt="融资日期" renderer="Leaf.formatDate" width="120"/>
                    <a:column name="vehicle_storage_place_n" prompt="车辆存放地点" width="120"/>
                    <a:column name="item_frame_number" prompt="车架号" width="150"/>
                    <a:column name="vehicle_check" prompt="车辆已查" width="100"/>
                    <a:column name="license_flag_n" prompt="车证已查" width="60"/>
                    <a:column name="key_flag_n" prompt="钥匙已查" width="60"/>
                    <a:column name="mention_flag_n" prompt="未提" width="60"/>
                    <a:column name="onway_flag_n" prompt="在途" width="60"/>
                    <a:column name="invoice_date" prompt="发票日期" renderer="Leaf.formatDate" width="100"/>
                    <a:column name="invoice_num" prompt="发票号码" width="200"/>
                    <a:column name="vehicle_license_flag_n" prompt="车辆或车证未正常查到" width="150"/>
                    <a:column name="damage_flag_n" prompt="损坏" width="60"/>
                    <a:column name="display_vehicles" prompt="展示车辆" width="150"/>
                    <a:column name="vis_major_n" prompt="不可抗力" width="200"/>
                    <a:column name="mortgage_third_flag_n" prompt="抵押给第三方" width="150"/>
                    <a:column name="vehicle_others" prompt="其他" width="250"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
