<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Calvin  
    $Date: 2017年11月22日18:21:48
    $Revision: 1.0  
    $Purpose:德融动态页面通用页面 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" dynamiccreateenabled="true" trace="true">
    <a:view>
        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="car_modify_special_link" url="${/request/@context_path}/modules/prj/PRJ500N/prj_project_create.lview"/>
        <a:link id="con_contract_modify_link" url="${/request/@context_path}/modules/cont/CON505/con_contract_modify.lview"/>
        <a:link id="col_detail_link" url="${/request/@context_path}/modules/cont/CON632/con_collection_phone_detail.lview"/>
        <script src="${/request/@context_path}/javascripts/jquery-1.6.4.min.js" type="text/javascript"/>
        <script type="text/javascript"><![CDATA[
            jQuery.noConflict();
            
            //锁屏
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window'] = function() {
                var detail_mask;
                if ('${/parameter/@winid}') {
                    if (parent.$L.CmpManager.get('${/parameter/@winid}')) {
                        detail_mask = parent.$('${/parameter/@winid}').wrap;
                        parent.Leaf.Masker.mask(detail_mask, '${l:HLS.EXECUTING}');
                    } else {
                        detail_mask = $('${/parameter/@winid}').wrap;
                        Leaf.Masker.mask(detail_mask, '${l:HLS.EXECUTING}');
                    }
                } else {
                    detail_mask = Ext.getBody();
                    Leaf.Masker.mask(detail_mask, '${l:HLS.EXECUTING}');
                }
            };
            //解屏
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window'] = function() {
                var detail_mask;
                if ('${/parameter/@winid}') {
                    if (parent.$L.CmpManager.get('${/parameter/@winid}')) {
                        detail_mask = parent.$('${/parameter/@winid}').wrap;
                        parent.Leaf.Masker.unmask(detail_mask);
                    } else {
                        detail_mask = $('${/parameter/@winid}').wrap;
                        Leaf.Masker.unmask(detail_mask);
                    }
                } else {
                    detail_mask = Ext.getBody();
                    Leaf.Masker.unmask(detail_mask);
                }
                if (Ext.get(document.documentElement)) {
                    $L.Masker.unmask(Ext.get(document.documentElement));
                }
            };
            
            function check_releated_layout(releated_table) {
                var str = '${/parameter/@layout_code}';
                //商机
                if (str.indexOf(releated_table) >= 0) {
                    return true;
                } else {
                    return false;
                }
            }
            
            //关闭
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                var root_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection');
                var record = $(root_ds).getCurrentRecord();
                if ($(root_ds).validate()) {
                    Leaf.showConfirm('提示', '确定要关闭该催收单据吗？', function() {
                        window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                        Leaf.request({
                            url: '${/request/@context_path}/autocrud/cont.CON632.con_collection/update',
                            para: {
                                col_id: '${/parameter/@col_id}',
                                closed_reason: record.get('closed_reason')
                            },
                            success: function(res) {
                                Leaf.SideBar.show({
                                    msg: '操作成功',
                                    duration: 2000
                                });
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                $('${/parameter/@winid}').close();
                            },
                            failure: function() {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            error: function() {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            sync: true,
                            scope: this
                        });
                    });
                }
            };
            
//            //查询时调用(grid,table,gridBox)
//            window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_query'] = function(ds, qpara, bp_seq) {
//                var ds_check_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
//                if (ds_check_id == ds.id && ds_check_id) {
//                    $(ds_check_id).setQueryParameter('bp_id', '${/parameter/@bp_id}');
//                }
//            };
            
//            var load_count = 0;
//            //加载时调用(grid,table,gridBox)
//            window['${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function(ds, record) {
//                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
//                //全选框有bug 隐藏
//                jQuery("[atype='grid.headcheck']").removeClass("grid-ckb item-ckb-u");
//                jQuery("div").hover(function() {
//                    var ds_call_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection_call_hd');
//                    if (ds_call_id) {
//                        var records = $(ds_call_id).getAll();
//                        for (var i = 0;i < records.length;i++) {
//                            var id = "#${/parameter/@layout_code}_G_PHONE_COLLECTION_con_collection_call_hd_layout_grid_id__" + records[i].id;
//                            if (records[i].get('col_type') != 'VISIT' && '${/parameter/@function_type}' == 'VISIT' && !records[i].isNew) {
//                                // var id = "#CON_COLLECTION_DETAIL_G_PHONE_COLLECTION_con_collection_call_hd_layout_grid_id__" + records[i].id;
//                                jQuery(id).removeClass("grid-ckb item-ckb-u").addClass('grid-ckb item-ckb-readonly-u');
//                            } else if ('${/parameter/@function_type}' == 'PHONE' && records[i].get('col_type') == 'VISIT') {
//                                jQuery(id).removeClass("grid-ckb item-ckb-u").addClass('grid-ckb item-ckb-readonly-u');
//                            }
//                            jQuery("div").unbind(); //移除所有
//                        }
//                    }
//                });
//                // jQuery("div").unbind(); //移除所有
//                var ds_check_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
//                var ds_call_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection_call_hd');
//                if (ds.id == ds_check_id) {
//                    $(ds_check_id).setQueryParameter('bp_id', '${/parameter/@bp_id}');
//                } else if (ds.id == ds_call_id) {
//                    if (load_count <= 1) {
//                        jQuery("#${/parameter/@layout_code}_G_PHONE_COLLECTION_con_collection_call_hd_layout_grid_id_wrap .nav-refresh").click();
//                        jQuery("div").unbind(); //移除所有
//                        load_count++;
//                    }
//
//                    var col_number = '${/parameter/@col_number}';
//                    col_number = col_number.replace('CC', '');
//                    $(ds_call_id).setQueryParameter('col_id', col_number);
//                    var records = $(ds_call_id).getAll();
//                    for (var i = 0;i < records.length;i++) {
//                        var id = "#${/parameter/@layout_code}_G_PHONE_COLLECTION_con_collection_call_hd_layout_grid_id__" + records[i].id;
//                        if (records[i].get('col_type') != 'VISIT' && '${/parameter/@function_type}' == 'VISIT') {
//                            // var id = "#CON_COLLECTION_DETAIL_G_PHONE_COLLECTION_con_collection_call_hd_layout_grid_id__" + records[i].id;
//                            jQuery(id).removeClass("grid-ckb item-ckb-u").addClass('grid-ckb item-ckb-readonly-u');
//                            records[i].getField('bp_id').setReadOnly(true);
//                            records[i].getField('bp_id_n').setReadOnly(true);
//                            records[i].getField('col_type').setReadOnly(true);
//                            records[i].getField('col_type_n').setReadOnly(true);
//                            records[i].getField('col_time').setReadOnly(true);
//                            records[i].getField('col_person').setReadOnly(true);
//                            records[i].getField('col_person_n').setReadOnly(true);
//                        } else if ('${/parameter/@function_type}' == 'PHONE' && records[i].get('col_type') == 'VISIT') {
//                            // var id = "#CON_COLLECTION_DETAIL_G_PHONE_COLLECTION_con_collection_call_hd_layout_grid_id__" + records[i].id;
//                            jQuery(id).removeClass("grid-ckb item-ckb-u").addClass('grid-ckb item-ckb-readonly-u');
//                            records[i].getField('bp_id').setReadOnly(true);
//                            records[i].getField('bp_id_n').setReadOnly(true);
//                            records[i].getField('col_type').setReadOnly(true);
//                            records[i].getField('col_type_n').setReadOnly(true);
//                            records[i].getField('col_time').setReadOnly(true);
//                            records[i].getField('col_person').setReadOnly(true);
//                            records[i].getField('col_person_n').setReadOnly(true);
//                        }
//
//                        if (records[i].get('col_type') == 'RETURN_VISIT' || !records[i].get('col_type')) {
//                            jQuery(id).removeClass("grid-ckb item-ckb-readonly-u").addClass('grid-ckb item-ckb-u');
//                            records[i].getField('bp_id').setReadOnly(false);
//                            records[i].getField('bp_id_n').setReadOnly(false);
//                            records[i].getField('col_type').setReadOnly(false);
//                            records[i].getField('col_type_n').setReadOnly(false);
//                            records[i].getField('col_time').setReadOnly(false);
//                            records[i].getField('col_person').setReadOnly(false);
//                            records[i].getField('col_person_n').setReadOnly(false);
//                        }
//                    }
//                }
//                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
//            };
            
//            function open_contract_win(ds_id, record_id) {
//                var record = $(ds_id).findById(record_id);
//                var param = record.data;
//                param['function_code'] = 'CON301'; /* param['function_usage'] = 'QUERY'; */
//                param['maintain_type'] = 'UPDATE';
//                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, '${/parameter/@layout_code}');
//            }
//
//            function open_project_Window(ds_id, record_id) {
//                var record = $(ds_id).findById(record_id);
//                var param = {};
//                param['company_id'] = record.get('company_id');
//                param['project_id'] = record.get('project_id');
//                param['function_code'] = 'PRJ502D';
//                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}';
//                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'car_modify_special_link', ds_id, '${/parameter/@layout_code}');
//            }
            
            function open_col_detail_win(ds_id, record_id) {

                var record = $(ds_id).findById(record_id);
                var param = record.data;
                if (record.get('col_type') == 'VISIT') {
                    param['function_code'] = 'CON632_VT';
                    param['function_usage'] = 'UPDATE';
                    param['maintain_type'] = 'MODIFY';
                } else if (record.get('col_type') == 'PHONE') {
                    param['function_code'] = 'CON632_PD';
                    param['function_usage'] = 'UPDATE';
                    param['maintain_type'] = 'MODIFY';
                }
//                else {
//                    param['function_code'] = 'CON632_PDQ';
//                    param['function_usage'] = 'QUERY';
//                    param['maintain_type'] = 'READONLY';
//                }
                // param['function_code'] = 'CON632_PD';
                // param['function_usage'] = 'UPDATE';
                // param['maintain_type'] = 'MODIFY';
                param['url_title'] = '催收详情';
                param['winid'] = 'col_detail_id';
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'col_detail_link', ds_id, '${/parameter/@layout_code}');
            }
            //超链接渲染
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
//                if (name == 'project_number' && value) {
//                    return '<a href="javascript:open_project_Window(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
//                } else if (name == 'contract_number' && value) {
//                    return '<a href="javascript:open_contract_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
//                } else
                if (name == 'col_detail' && !record.isNew) {
                    return '<a href="javascript:open_col_detail_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + config_record.get('prompt') + '</a>';
                }
                return value;
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
