<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: xuls  
    $Date: 2017-4-21 下午01:54:29  
    $Revision: 1.0  
    $Purpose: 合同维护入口界面
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
        <a:model-query model="cont.CON620.get_sys_role" rootPath="role_info"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con311_create_entrusts_link" model="cont.CON311.create_entrusts" modelaction="execute"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@pre_layout}zj_wfl_approve_history_check" url="${/request/@context_path}/modules/zjwfl/zj_wfl_approve_history_check.lview"/>
        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="con_contract_change_link_id" model="cont.CON1300.con_print_incept" modelaction="execute"/>
        <a:link id="con_contract_modify_link" url="${/request/@context_path}/modules/cont/CON3200/con_re_incept_modify.lview"/>
        <a:link id="${/parameter/@layout_code}con_contract_query_link"
                url="${/request/@context_path}/modules/cont/CON3200/con_re_incept_modify.lview"/>
        <a:link id="car_modify_special_link" url="${/request/@context_path}/modules/prj/PRJ501N/prj_project_maintain.lview"/>
        <a:link id="cont_con_sale_contract_info_print_link"
                url="${/request/@context_path}/modules/cont/CON3200/contract_receipt_detail_print.lsc"/>
        <a:link id="car_modify_link_readonly_c" url="${/request/@context_path}/modules/prj/PRJ501N/prj_project_maintain_constru.lview"/>
        <script type="text/javascript"><![CDATA[

        Leaf.onReady(function() {
            if("${/model/role_info/record/@role_code}"!="0018"&&"${/model/role_info/record/@role_code}"!="0019") {
                // document.getElementById("CONTRACT_QUERY_ENTRANCE_F_QUERY_NULL_AGENT_EXTRA_NAM_prompt").style.display = "";
                // document.getElementById("CONTRACT_QUERY_ENTRANCE_F_QUERY_NULL_AGENT_EXTRA_NAM").style.display = "";
                document.getElementById("CONTRACT_INCEPT_ENTRANCE_F_QUERY_NULL_BP_ID_AGENT_LEVEL1_prompt").style.display = "";
                document.getElementById("CONTRACT_INCEPT_ENTRANCE_F_QUERY_NULL_BP_ID_AGENT_LEVEL1").style.display = "";
            } else {
                // document.getElementById("CONTRACT_QUERY_ENTRANCE_F_QUERY_NULL_AGENT_EXTRA_NAM_prompt").style.display = "none";
                // document.getElementById("CONTRACT_QUERY_ENTRANCE_F_QUERY_NULL_AGENT_EXTRA_NAM").style.display = "none";
                document.getElementById("CONTRACT_INCEPT_ENTRANCE_F_QUERY_NULL_BP_ID_AGENT_LEVEL1_prompt").style.display = "none";
                document.getElementById("CONTRACT_INCEPT_ENTRANCE_F_QUERY_NULL_BP_ID_AGENT_LEVEL1").style.display = "none";
            }

        });
            function open_contract_win(ds_id, record_id) {
                var record = $(ds_id).findById(record_id);
                var param = record.data;
                if((record.get('contract_status')=='NEW' || record.get('contract_status')=='INCEPT_RETURN')&& (record.get('sign_contract_status')=='SIGNING' || record.get('sign_contract_status') =='SIGN')){
                    param['function_code'] = 'CON3200N';
                    param['function_usage'] = 'MODIFY';
                }
                else{
                    param['function_code'] = 'CON3200Q';
                    param['function_usage'] = 'QUERY';
                }
                param['winid'] = 'con_contract_modify_win_id';
                param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, '${/parameter/@layout_code}con_contract_query_link', ds_id);
            }

        function open_project_Window(record_id, ds_id) {
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            var url;
            param['hide_flag'] = 'Y';
            param['company_id'] = record.get('company_id');
            param['project_id'] = record.get('project_id');
            param['function_usage'] = 'QUERY';
            param['bp_class'] = record.get('bp_class');
            param['maintain_type'] = 'QUERY';
            /*  param['window_open_flag'] = 'Y';
             param['show_history_flag'] = 'Y'; */
            param['url_title'] = '${l:HLS.PROJECT_MAITAIN}';
            if(record.get('is_constru_unit') == 'N'){
                //不是虚拟店
                param['function_code'] = 'PRJ501_WFL';
                url = 'car_modify_special_link';
            }else{
                //虚拟店
                param['function_code'] = 'PRJ501Q_CONSTRU';
                url = 'car_modify_link_readonly_c';
            }
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, url, ds_id, '${/parameter/@layout_code}');
        }


            function open_bs_Window(record_id, ds_id) {
                var record = $(ds_id).findById(record_id);
                var param = record.data;
                param['function_code'] = 'CON301BS';
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = 'QUERY';
                param['contract_id'] = record.get('contract_id');
                param['url_title'] = 'BS明细';
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_modify_link', ds_id);
            }

            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
                if (name == 'contract_number' && value) {
                    return '<a href="javascript:open_contract_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
                }
                if (name == 'project_id_c' && value) {
                    return '<a href="javascript:open_project_Window(\'' + record.id + '\',\'' + record.ds.id + '\')">' + value + '</a>';
                }
                if (name == 'bs_link') {
                    return '<a href="javascript:open_bs_Window(\'' + record.id + '\',\'' + record.ds.id + '\')">明细</a>';
                }

                return value;
            };
            window['${/parameter/@layout_code}_on_layout_dynamic_grid_query'] = function(ds, qpara, bp_seq) {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');

                if (ds == $(ds_id)) {
                    aut_authority_list_validate_query(ds, qpara);

                }
            };
       //应收明细打印
        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function() {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var selectedDS=$(ds_id).getSelected();
            if(selectedDS.length!=1){
                $L.showErrorMessage("提示",'请选择一条数据进行打印！');
                return;
            }
            if((selectedDS[0].get('contract_status')!='INCEPTING')&&(selectedDS[0].get('contract_status')!='INCEPT')){
                $L.showErrorMessage("提示",'只有起租或者起租中的合同才能打印！');
                return;
            }
            var contract_id=selectedDS[0].get('contract_id');
            Leaf.Masker.mask(Ext.getBody());
            Leaf.request({
                url: $('con_contract_change_link_id').getUrl(),
                para: {
                    contract_id:contract_id
                },
                success: function(res) {
                    var file_name = '应收明细表';
                    var template_name='aa.xls';
                    var print_contract_id=res.result.print_contract_id;
                    var url = $('cont_con_sale_contract_info_print_link').getUrl() + '?template_name=' + template_name + '&contract_id=' + print_contract_id + '&file_name=' + encodeURI(file_name);
                    window.location.href =url;
                    Leaf.Masker.unmask(Ext.getBody());

                },
                failure: function() {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                error: function() {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                scope: this
            });

        }
            //单据跟踪
       window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {
                // var prj_project_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project');
                // var records = $('prj_project_ds_id').getSelected();
                var ds = $('CONTRACT_QUERY_ENTRANCE_G_CONTRACT_RESULT_con_contract_ds');
                var records = ds.getSelected();
                if (records.length != 1) {
                    Leaf.showMessage('提示', '请选择一条数据！');
                    return;
                }
                var instance_id = records[0].get('wfl_instance_id');
                var win = new Leaf.Window({
                    id: 'history_check',
                    url: $('${/parameter/@layout_code}${/parameter/@pre_layout}zj_wfl_approve_history_check').getUrl(),
                    params: {
                        instance_id: instance_id
                    },
                    title: '单据历史查看',
                    height: 500,
                    width: 860,
                    fullScreen: true
                });
            };
            //合同文本打印
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var records = $(ds_id).getSelected();
                for (var i = 0;i < records.length;i++) {
                    var param = records[i].data;
                    param['function_code'] = 'CON311D';
                    if(records[i].data.contract_status=='NEW'){
                         param['maintain_type'] = 'UPDATE';
                         param['function_usage'] = 'UPDATE';
                         param['query_only'] = 'N';
                         }
                    else{
                         param['maintain_type'] = 'QUERY';
                         param['function_usage'] = 'QUERY';
                         param['query_only'] = 'Y';
                         }
                    param['winid'] = 'con_contract_modify_link_winid';
                    param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
                    hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_modify_link', ds_id);
                }
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=CONTRACT&amp;function_code=CON501"/>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
