<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zlf
    $Date: 2014-11-10 下午5:42:24
    $Revision: 1.0
    $Purpose:
-->
<a:screen xmlns:c="leaf.application.action" xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="cont.CON500.con_contract_get_guid_file_name" rootPath="file_name_path"/>
        <s:server-script import="con_print_path.js"><![CDATA[
            set_parameter_file_path();

        ]]></s:server-script>
    </a:init-procedure>
    <a:view>
        <a:link id="wfl_readonly_pageLink_projectQueryScreen_update_project" url="${/request/@context_path}/modules/prj/PRJ501N/prj_project_maintain_readonly.lview"/>
        <a:link id="${/parameter/@layout_code}_con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_con_contract_content_confirm_link_id" url="${/request/@context_path}/modules/cont/CON501N/con_contract_content_confirm.lview"/>
        <a:link id="contract_lease_item_query_link" url="${/request/@context_path}/modules/cont/CON505/con_lease_item_query.lview"/>
        <a:link id="contract_history_window_link" url="${/request/@context_path}/modules/cont/CON501N/con_document_history_query.lview"/>
        <a:link id="con505_hls_bp_master_query_link" url="${/request/@context_path}/modules/cont/CON505/hls_bp_master_query.lview"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="con731_quote_link" url="${/request/@context_path}/modules/hls/HLS500N/hls_fin_calculator_update_n.lview"/>
        <a:link id="con731_quote_readonly_link" url="${/request/@context_path}/modules/hls/HLS500/hls_fin_calculator_readonly.lview"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <!--打印使用-->
        <a:link id="${/parameter/@layout_code}_con505_contract_content_id" model="cont.CON505.con505_contract_content" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_creat_con_contract_content_link_id" model="cont.CON505.con505_contract_content" modelaction="execute"/>
        <a:link id="${/parameter/@layout_code}_file_copy_from_template_link_id" url="${/request/@context_path}/modules/cont/CON505/file_copy_from_template.lsc"/>
        <a:link id="${/parameter/@layout_code}_con_batch_dl_link_id" url="${/request/@context_path}/modules/cont/CON505/con_atm_batch_dl.lsc"/>
        <a:link id="get_xml" model="cont.CON1010.con_contract_case_submit" modelaction="execute"/>

        <a:link id="${/parameter/@layout_code}_hls_fin_doc_quotation_link_id" model="cont.CON1010.con_contract_case_submit" modelaction="insert"/>

        <link href="${/request/@context_path}/css/lightbox.css" rel="stylesheet" type="text/css"/>
        <script src="${/request/@context_path}/javascripts/lightbox.js" type="text/javascript"/>
        <script type="text/javascript"><![CDATA[
            Ext.ux.Lightbox.register('a[ref=img]', true);

            function lock_current_window() {
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            }

            function unlock_current_window() {
                Leaf.Masker.unmask(Ext.getBody());
            }

            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                //window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var req_record = $(req_ds_id).getAt(0);
                var calc_session_id = req_record.get('calc_session_id');
                var quo_win;
                var calc_type = 'CLASSIC_CALCULATOR';
                var document_category = req_record.get('document_category');
                if (req_record.dirty) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    return;
                }
                var url;
                if ('${/parameter/@function_usage}'=='QUERY'){
                   url= $('con731_quote_readonly_link').getUrl();
                }else{
                 url=$('con731_quote_link').getUrl();
                }
                //add By Eugene Song 20180917 当报价修改时 调整报价表和报价公式表
                Leaf.request({
                    url: $('${/parameter/@layout_code}_hls_fin_doc_quotation_link_id').getUrl(),
                    para: {
                        contract_id:'${/parameter/@contract_id}',
                        calc_session_id:calc_session_id
                    },
                    success: function (res) {
                        quo_win = new Leaf.Window({
                            id: '${/parameter/@layout_code}_hls_fin_calc_quotation_link_winid',
                            params: {
                                document_id: '${/parameter/@contract_id}',
                                document_category: document_category,
                                maintain_type: 'QUERY',
                                function_usage: 'QUERY',
                                calc_session_id: calc_session_id,
                                quotation_id: null,
                                dsId: req_ds_id,
                                winId: '${/parameter/@layout_code}_hls_fin_calc_quotation_link_winid',
                                global_flag: 'Y',
                                id_num: 0,
                                calc_type: calc_type,
                                recreate_L_formula: 'N',
                                recreate_H_formula: 'Y'

                            },
                            url: url ,
                            fullScreen: true,
                            draggable: true
                        });
                    },
                    failure: function () {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function () {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });

                quo_win.addListener('close', function() {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    $(req_ds_id).query();
                });
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            };

            function getXml() {
                var req_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_case_record');
                var req_record = $(req_ds_id).getCurrentRecord();
                var record_id = req_record.data.record_id;
                var contract_id = ${/parameter/@contract_id};
                if (req_record.dirty) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '页面数据存在修改,请先保存再发起起案!');
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    return;
                }
                if (record_id && typeof(record_id) != "undefined") {
                    Leaf.request({
                        url: $('get_xml').getUrl(),
                        para: {
                            contract_id: contract_id,
                            record_id: record_id,
                            interface_name: '${/parameter/@case_type}'
                        },
                        success: function(res) {
                            getUrl(res.result.xml)
                            //document.getElementById("doodream_iframe").contentWindow.ConnData(res.result.xml);
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        failure: function() {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        error: function() {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        scope: this
                    });
                } else {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    Leaf.showMessage('${l:HLS.PROMPT}', '请维护起案信息并保存');
                    return;
                }

            }


            function getUrl(xml) {
                Leaf.request({
                    url: '${/request/@context_path}/doodream/post/url',
                    para: {
                        xml: xml
                    },
                    success: function(res) {
                        window.open(res.message, "", "width=940, height=650, scrollbars=yes, toolbar=no, location=no, status=no, menubar=no");
                        Leaf.SideBar.show({
                            msg: '${l:HLS.SUBMIT_SUCCESS}',
                            duration: 2000
                        });
                    },
                    failure: function() {
                        Leaf.SideBar.show({
                            msg: 'failure',
                            duration: 2000
                        });
                    },
                    error: function() {
                        Leaf.SideBar.show({
                            msg: 'error',
                            duration: 2000
                        });
                    },
                    scope: this
                });
            }

            window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function() {

                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                getXml();
                $('${/parameter/@layout_code}_save').disable();
                $('${/parameter/@layout_code}_user_button1').disable();
                $('${/parameter/@layout_code}_user_button2').disable();

            };
            //保存前调用
            /*window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_before_submit'] = function(ds, record) {
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var check_flag = true;
                //单据提交起案,不允许保存
                Leaf.request({
                    url: '${/request/@context_path}/autocrud/cont.CON1010.con_contract_case_save_check/execute',
                    para: {
                        contract_id: ${/parameter/@contract_id},
                        interface_name: '${/parameter/@case_type}',
                    },
                    success: function(res) {
                        if(res.result.v_result=='APPROVING'||res.result.v_result=='APPROVED'){
                        Leaf.showMessage('${l:HLS.PROMPT}', '该信息已提交起案,不能进行修改保存操作!');
                        check_flag = false;
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
						return check_flag;}
                        else{
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
						return check_flag;}
                    },
                    failure: function() {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function() {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            };*/

            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record, bp_seq) {
                var link_function = '';
                window['${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
                if (name == 'project_number') {
                    return '<a href="javascript:wfl_prj501_grid_update(\'' + record.id + '\',\'' + record.ds.id + '\')">' + value + '</a>';
                } else if (name == 'gps_attch') {
                    link_function = '${/parameter/@layout_code}_ast_con_cdd4_attachtment_upload';
                    if (record.get('atm_num3') > 0) {
                        return '<a style="color:red" href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                    } else {
                        return '<a style="font-weight:bolder;font-size:1.2em" href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                    }
                } else if (name == 'description') {
                    if (record.get('important_flag') == 'Y') {
                        return '<font color="RED">' + value + '</font>';
                    }
                    return value;
                } else if (name == 'bp_link' && record.get('bp_id') && record.get('record_id')) {
                    link_function = '${/parameter/@layout_code}_open_bp_detail_window';
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\');">' + config_record.get('prompt') + '</a>';
                } else if (name == 'car_detail' && record.get('contract_lease_item_id')) {
                    link_function = '${/parameter/@layout_code}_open_lease_item_detail_window';
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\');">' + config_record.get('prompt') + '</a>';
                } else if (name == 'attachment') {
                    link_function = '${/parameter/@layout_code}_prj500_cdd_attachtment_upload';
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.ds.id + '\',\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                } else if (name == 'attach_file_name') {
                    if (value != null) {
                        var link = '${/request/@context_path}/atm_download.lsc?attachment_id=';
                        var str = value.split(';;');
                        var url = '';
                        for (var i = 0;i < str.length;i++) {
                            var temp = str[i].split('--');
                            if (!Leaf.isEmpty(temp[0])) {
                                var file_name = temp[0].toUpperCase();
                                var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                                if (file_name.indexOf('.PDF') >= 0) {
                                    url = url + '<a href=javascript:view_pdf(\'' + temp[1] + '\')>' + temp[0] + '</a>' + ',';
                                } else if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                    url = url + '<a href=' + link + temp[1] + ' ref="img">' + temp[0] + '</a>' + ',';
                                } else {
                                    url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                                }
                            }
                        }
                        return url;

                    }
                }
            };

            function wfl_prj501_grid_update(record_id, ds_id) {
                var record = $(ds_id).findById(record_id);
                var param = {};
                param['bp_class'] = record.get('bp_class');
                param['project_id'] = record.get('project_id');
                param['function_code'] = 'PRJ502D';
                param['function_usage'] = 'QUERY';
                param['url_title'] = '租赁申请查询';
                hls_doc_get_layout_code('${/parameter/@layout_code}_con_contract_get_layout_code_link_id', param, 'wfl_readonly_pageLink_projectQueryScreen_update_project', record.ds.id, '${/parameter/@layout_code}');
            }


            window['${/parameter/@layout_code}_ast_con_cdd4_attachtment_upload'] = function(ds_id, id, name, query_only) {
                var record = $(ds_id).findById(id);
                // if (record.get('con_contract_id')) {
                var url;
                if (query_only == 'Y') {
                    url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=CON_CONTRACT&header_id=' + record.get('contract_id');
                } else {
                    url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=CON_CONTRACT&header_id=' + record.get('contract_id');
                }
                var win = new Leaf.Window({
                    url: url,
                    title: 'gps附件上传',
                    id: '${/parameter/@layout_code}${/parameter/@tree_code}_ast_con_cdd4_attachtment_upload_id',
                    width: 850,
                    height: 400
                });
                // win.on('close', function(){
                // $(ds_id).query();
                // });
                // } else {
                // Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
                // }
            };

            window['${/parameter/@layout_code}_open_lease_item_detail_window'] = function(id, name) {
                var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
                var param = record.data;
                var contract_lease_item_id = record.get('contract_lease_item_id');
                new Leaf.Window({
                    id: 'contract_lease_item_maintain_window',
                    url: $('contract_lease_item_query_link').getUrl(),
                    params: {
                        contract_lease_item_id: contract_lease_item_id,
                        winid: 'contract_lease_item_maintain_window'
                    },
                    draggable: true,
                    fullScreen: true
                });
            };

            window['${/parameter/@layout_code}_open_bp_detail_window'] = function(id, name) {
                var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
                // var param = record.data;
                var param = {};
                param['bp_id'] = record.get('bp_id');
                param['cdd_list_id'] = record.get('cdd_list_id');
                param['company_id'] = '${/session/company_id}';
                param['document_id'] = record.get('bp_id');
                param['document_category'] = 'BP';
                param['bp_class'] = record.get('bp_class');
                param['bp_category'] = record.get('bp_category');
                param['bp_type'] = record.get('bp_type');
                param['function_code'] = 'CON505H';
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = 'QUERY';
                param['url_title'] = '${l:HLS212.BP_MASTER_QUERY}';
                hls_doc_get_layout_code('${/parameter/@layout_code}_con_contract_get_layout_code_link_id', param, 'con505_hls_bp_master_query_link', record.ds.id, '${/parameter/@layout_code}');
            };

            window['${/parameter/@layout_code}_prj500_cdd_attachtment_upload'] = function(ds_id, id, name, query_only) {
                var record = $(ds_id).findById(id);
                if (record.get('check_id')) {
                    var url;
                    if (query_only == 'Y') {
                        url = $('${/parameter/@layout_code}_prj500_cdd_downloadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                    } else {
                        url = $('${/parameter/@layout_code}_prj500_cdd_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + record.get('check_id');
                    }
                    var win = new Leaf.Window({
                        url: url,
                        title: '${l:HLS.SUPPORTING_DOCUMENT}',
                        id: '${/parameter/@layout_code}${/parameter/@tree_code}_prj500_cdd_uploadFile_screen_id',
                        width: 850,
                        height: 400
                    });

                    win.on('close', function() {
                        record.ds.query();
                    });
                } else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先保存!');
                }
            };

            var change_flag = 'N';
            //工作流中合同文本生成按钮
            //基本信息tab页 新增必输字段的校验  add by liukang 20160328
            window['${/parameter/@layout_code}_print_layout_dynamic_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var con_lease_item_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_lease_item');
                var record = $(ds_id).getCurrentRecord();
                var con_lease_record = $(con_lease_item_id).getCurrentRecord();
                var direct_debit_bank_id = record.get('direct_debit_bank_id');
                var dd_bank_account_name = record.get('dd_bank_account_name');
                var dd_bank_account_num = record.get('dd_bank_account_num');
                var color_of_apprearance = con_lease_record.get('color_of_apprearance');
                var item_frame_number = con_lease_record.get('item_frame_number');
                var item_engine_number = con_lease_record.get('item_engine_number');
                var license_number = con_lease_record.get('license_number');
                /* if (Ext.isEmpty(direct_debit_bank_id)) {
                 Leaf.showMessage('${l:HLS.PROMPT}', '请先填写数据并保存!');
                 } else */
                if (!Ext.isEmpty(record.get('contract_number'))) {
                    var win = new Leaf.Window({
                        id: '${/parameter/@layout_code}_con_contract_content_confirm_win_id',
                        params: {
                            contract_id: record.get('contract_id'),
                            company_id: record.get('company_id'),
                            document_category: record.get('document_category'),
                            business_type: record.get('business_type'),
                            winid: '${/parameter/@layout_code}_con_contract_content_confirm_win_id',
                            change_flag: change_flag,
                            contract_name: record.get('contract_name'),
                            contract_number: record.get('contract_number')
                        },
                        url: $('${/parameter/@layout_code}_con_contract_content_confirm_link_id').getUrl(),
                        title: '合同文本生成',
                        width: 1300,
                        height: 550
                    });
                    //在关闭页面之后,刷新一下ds
                    win.on('close', function() {
                        if (ds_id) {
                            $(ds_id).query();
                        }
                    });
                } else {
                    Leaf.showErrorMessage('错误', '请先点击保存生成合同编号!');
                }
            };

            //add by zhuxianfei 20180207

            function view_pdf(attachment_id) {
                Leaf.request({
                    url: '${/request/@context_path}/autocrud/fnd.fnd_atm_attachment/query',
                    para: {
                        attachment_id: attachment_id
                    },
                    success: function(res) {

                        var path = res.result.record.file_path;
                        path = path.substr(path.indexOf('hls_attachment'));
                        var tomcat_source = '${/parameter/@tomcat_source}';
                        var source_path = 'http://' + window.location.host + '/' + tomcat_source + '/' + path+'?type=pdf';
                        var oWin = window.open(source_path);
                    },
                    scope: this
                });
            }


        //新增和加载时调用(form)
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function (ds, record, config_records, bp_seq) {
            var ds_id = get_dsid_by_tabcode_basetable(
                window['${/parameter/@layout_code}_layoutDataSetList'],
                'LEASE_FIN_INFO_1',
                'con_contract'
            );
            if (ds.id == ds_id) {
                var records = $(ds_id).getAll();
                var price_list = records[0].get('price_list');
                if (price_list == 'DS_PRICE_30' || price_list == 'DS_PRICE_40' || price_list == 'DS_PRICE_50') {
                    records[0].getField('price_list').setReadOnly(false);
                    records[0].getField('price_list_n').setReadOnly(false);
                }
                else {
                    records[0].getField('price_list').setReadOnly(true);
                    records[0].getField('price_list_n').setReadOnly(true);
                }

            }


        };

        ]]></script>
        <!--<iframe name="doodream_iframe" id="doodream_iframe" style="display: none" src="${/request/@context_path}/doodream.html" frameborder="0"></iframe>-->
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>