<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: lpc 9874
    $Date:
    $Revision: 1.0
    $Purpose: 租赁物查看
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" customizationEnabled="true"
          dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
        <s:server-script import="contract_print_path.js"><![CDATA[
            $ctx.parameter.file_path = con_print_path['con_print_path'];
            $ctx.parameter.tomcat_source = con_print_path['tomcat_source'];
            ]]>
        </s:server-script>
        <a:model-query model="cont.CON620.get_sys_role" rootPath="role_info"/>
    </a:init-procedure>
    <a:view>
        <a:link id="${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_uploadFile_id"
                url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_downloadFile_id"
                url="${/request/@context_path}/downloadFile.lview"/>
        <link href="${/request/@context_path}/css/lightbox.css" rel="stylesheet" type="text/css"/>
        <script src="${/request/@context_path}/javascripts/lightbox.js" type="text/javascript"/>
        <a:link id="contract_accounting_wait_link_id" model="cont.CON505N.contract_accounting_wait"
                modelaction="update"/>
        <a:link id="contract_accounting_finish_link_id" model="cont.CON505N.contract_accounting_finish"
                modelaction="update"/>
        <a:link id="con_contract_rent_dun_print_link"
                url="${/request/@context_path}/modules/cont/CON620/con_contract_rent_dun_print_excel.lsc"/>
        <a:link id="con_lease_org_print_link"
                url="${/request/@context_path}/modules/cont/CON620/create_content_for_collection.lsc"/>
        <a:link id="con_lease_confirm_print_link"
                url="${/request/@context_path}/modules/cont/CON620/create_content_con_lease_confirm.lsc"/>
        <a:link id="con_lease_print_link"
                url="${/request/@context_path}/modules/cont/CON620/create_content_con_lease.lsc"/>
        <a:link id="lease_return_print_link"
                url="${/request/@context_path}/modules/cont/CON620/create_content_lease_return.lsc"/>
        <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="con_collection_message_create_link_id" model="cont.CON620.con_collection_message_create" modelaction="update"/>
        <a:link id="con_lease_org_print_signatures_link"
                url="${/request/@context_path}/modules/cont/CON620/create_content_for_collection_signatures.lsc"/>
        <a:link id="cashflow_print_signatures_link_id"
                url="${/request/@context_path}/modules/cont/CON620/con_cashflow_print_signatures.lview"/>
        <script type="text/javascript"><![CDATA[
        Ext.ux.Lightbox.register('a[ref=img]', true);

        //保存submitsuccess调用
        window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function (ds, record, res, bp_seq) {
            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            /*var con_accounting_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_accounting_manage');
            var accounting_record = $(con_accounting_ds_id).getCurrentRecord();
            $('CONTRACT_LEGAL_MODIFY_G_CASHFLOW_con_contract_cashflow_ds').setQueryParameter('con_accounting_id', accounting_record.get('con_accounting_id'));
            $('CONTRACT_LEGAL_MODIFY_G_CASHFLOW_con_contract_cashflow_ds').query();*/
            $(ds.id).query();
        };

        //生成催收信息
        function create_message(contract_id,templet_code){
            //执行生成催收信息的bm
            var ds =  get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection');
            Leaf.request({
                url: $('con_collection_message_create_link_id').getUrl(),
                para: {
                    contract_id: contract_id,
                    templet_code: templet_code
                },
                success: function () {
                    $(ds).query();
                }
            });
        }

        // window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {
        //     var contract_id = '${/parameter/@document_id}';
        //     var templet_code = 'CON_LEASE_ORG';
        //     var  url=$('con_lease_org_print_link').getUrl() + '?contract_id=' + contract_id + '&templet_code=' + templet_code;
        //     window.open(url, '_self');
        //     create_message(contract_id,templet_code);
        // };
        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function () {
            var contract_id = '${/parameter/@document_id}';
            var templet_code = 'CON_LEASE_CONFIRM';
            var  url=$('con_lease_org_print_link').getUrl() + '?contract_id=' + contract_id + '&templet_code=' + templet_code;
            // var  url=$('con_lease_confirm_print_link').getUrl() + '?contract_id=' + contract_id + '&templet_code=' + templet_code;
            window.open(url, '_self');
            create_message(contract_id,templet_code);
        };
        window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function () {
            var contract_id = '${/parameter/@document_id}';
            var templet_code = 'CON_LEASE';
            var  url=$('con_lease_org_print_link').getUrl() + '?contract_id=' + contract_id + '&templet_code=' + templet_code;
            //var  url=$('con_lease_print_link').getUrl() + '?contract_id=' + contract_id + '&templet_code=' + templet_code;
            window.open(url, '_self');
            create_message(contract_id,templet_code);
        };
        window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function () {
            var contract_id = '${/parameter/@document_id}';
            var templet_code = 'LEASE_RETURN';
            var  url=$('con_lease_org_print_link').getUrl() + '?contract_id=' + contract_id + '&templet_code=' + templet_code;
            //var  url=$('lease_return_print_link').getUrl() + '?contract_id=' + contract_id + '&templet_code=' + templet_code;
            window.open(url, '_self');
            create_message(contract_id,templet_code);
        };

        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;
                    var oWin = window.open(source_path);
                },
                scope: this
            });
        }

        function upload_file(id, name, query_only) {

            var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
            var ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_accounting_manage_attch');
            if (record.get('con_accounting_attch_id')) {
                var url;
                if (query_only == 'Y') {
                    url = $('${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_downloadFile_id').getUrl() + '?table_name=CON_ACCOUNTING_MANAGE_ATTCH&header_id=' + record.get('con_accounting_attch_id');
                } else {
                    url = $('${/parameter/@layout_code}${/parameter/@pre_layout}prj500_cdd_uploadFile_id').getUrl() + '?table_name=CON_ACCOUNTING_MANAGE_ATTCH&header_id=' + record.get('con_accounting_attch_id');
                }
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'prj500_cdd_uploadFile_screen_id',
                    width: 850,
                    height: 400
                });

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

            }
        };

        //超链接渲染
        window['${/parameter/@layout_code}_dynamic_link_renderer'] = function (value, record, name, config_record) {

            window['${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
            if (name == 'attachment') {
                link_function = 'upload_file';
                if (record.get('attach_count') == 0 || !record.get('attach_count')) {
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '</a>';
                } else {
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' + config_record.get('prompt') + '(' + record.get('attach_count') + ')' + '</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_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;

                }
            }
        };
        //add by lihh 20210318 发送函件类型为只读
        //加载时调用(grid,table,gridBox)
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function(ds, record, config_records, bp_seq) {
            var col_ds =  get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection');
            var records = $(col_ds).getAll();
            if(ds.id == col_ds && col_ds){
                for(var i = 0;i<records.length;i++){
                    if(records[i].get('col_type') == 'LETTERS'){
                        records[i].getField('status').setReadOnly(true);
                        records[i].getField('phone').setReadOnly(true);
                        records[i].getField('col_time').setReadOnly(true);
                        records[i].getField('col_type').setReadOnly(true);
                        records[i].getField('col_type_n').setReadOnly(true);
                        records[i].getField('col_person').setReadOnly(true);
                        records[i].getField('col_object').setReadOnly(true);
                        records[i].getField('col_detail').setReadOnly(true);
                    }
                }
            }
        };
        Leaf.onReady(function() {
            if('${/parameter/@function_code}' == 'CON620D'){
                if("${/model/role_info/record/@role_code}"!="0018"&&"${/model/role_info/record/@role_code}"!="0019") {
                    document.getElementById("CON_DUE_DETAIL_user_button4").style.display = "";
                    document.getElementById("CON_DUE_DETAIL_user_button3").style.display = "";
                } else {
                    document.getElementById("CON_DUE_DETAIL_user_button4").style.display = "none";
                    document.getElementById("CON_DUE_DETAIL_user_button3").style.display = "none";
                }
            }

             if("${/parameter/@division}"=='70' || "${/parameter/@division}"=='92' ){
                 if(document.getElementById("${/parameter/@layout_code}_F_BASIC_CON_CONTRACT_MACHINE_NUMBER")){
                     document.getElementById("${/parameter/@layout_code}_F_BASIC_CON_CONTRACT_MACHINE_NUMBER_prompt").style.display = "none";
                     document.getElementById("${/parameter/@layout_code}_F_BASIC_CON_CONTRACT_MACHINE_NUMBER").style.display = "none";
                 }
             }else {
                 if (document.getElementById("${/parameter/@layout_code}_F_BASIC_CON_CONTRACT_MACHINE_NUMBER_70")) {
                     document.getElementById("${/parameter/@layout_code}_F_BASIC_CON_CONTRACT_MACHINE_NUMBER_70_prompt").style.display = "none";
                     document.getElementById("${/parameter/@layout_code}_F_BASIC_CON_CONTRACT_MACHINE_NUMBER_70").style.display = "none";
                 }
             }
        });

        //新增催款函pdf打印（盖章）
        window['${/parameter/@layout_code}_user_button5_layout_dynamic_click'] = function () {
            debugger;
            var ds = $('CON_DUE_DETAIL_F_BASIC_con_contract_ds');
            var records = ds.getCurrentRecord();
            var bp_name = records.get('bp_name');
            var contract_number = records.get('contract_number');
            var contract_name = records.get('contract_name');
            var contract_id = '${/parameter/@document_id}';
            var templet_code = 'CON_LEASE_ORG';
            var win = new Leaf.Window({
                id: 'cashflow_print_signatures',
                url: $('cashflow_print_signatures_link_id').getUrl(),
                params: {
                    contract_id: contract_id,
                    templet_code: templet_code,
                    bp_name : bp_name,
                    contract_number : contract_number,
                    contract_name : contract_name,
                    winid : 'contract_print_signatures_winid'
                },
                title: '催款函打印',
                height: 500,
                width: 800
            });

        };

        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
