<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Calvin  
    $Date: 2017年12月11日17:29:18
    $Revision: 1.0  
    $Purpose:车辆处置界面 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" dynamiccreateenabled="true" trace="true">
    <a:view>
        <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}_hls_bp_master_query_link" url="${/request/@context_path}/modules/hls/HLS214N/hls_bp_master_modify.lview"/>
        <a:link id="${/parameter/@layout_code}_con632_close_link_id" url="${/request/@context_path}/modules/cont/CON632/con_collection_detail.lview"/>
        <a:link id="${/parameter/@layout_code}_con632_management_link_id" url="${/request/@context_path}/modules/cont/CON6323/con_collection_management_detail.lview"/>
        <a:link id="${/parameter/@layout_code}_confirm_car_link" model="cont.CON6323.con_collection_management_wfl" modelaction="update"/>
        <a:link id="con_collection_way_link" url="${/request/@context_path}/modules/cont/CON632/con_collection_transfer_visit.lview"/>
        <script src="${/request/@context_path}/javascripts/jquery-1.6.4.min.js" type="text/javascript"/>
        <style type="text/css"><![CDATA[
        .redBG{
            background-color:#FFC0CB;
            }
        .yellowBG{
            background-color:#FFFF00;
            }
    	]]></style>
        <script type="text/javascript"><![CDATA[
            jQuery.noConflict();
            
            var isLoaded = 'N';
            //	set单元格颜色  load事件无法实现效果
            //hongquan.dai 20180125
            var check_isload = setInterval(function() {
                if (isLoaded == 'N') {
                    var ids = $('${/parameter/@layout_code}_G_RESULT_con_col_management_hd_ds');
                    var idsRecord = ids.getAll();
                    for (var i = 0;i < idsRecord.length;i++) {
                        var rowData = idsRecord[i];
                        var management_flag = rowData.get('management_flag');
                        //management_flag 正常处置标记  Y表示 已收取车辆在规定天数审批通过   N 表示未在规定天数审批通过
                        if (management_flag == 'N') {
                            //
                            tr_id = '#${/parameter/@layout_code}_G_RESULT_con_col_management_hd_layout_grid_id-u-' + rowData.id;
                            jQuery(tr_id).addClass('redBG');
                        }
                    }
                } else {
                    clearInterval(check_isload);
                }
            }, 1000);
            //锁屏
            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));
                }
            };
            
            //确认车辆
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_col_management_hd');
                var record = $(ds_id).getCurrentRecord();
            
                if (record) {
                    if (record.get('col_management_status') != 'NOT_MANAGEMENTING') {
                        if (record.get('confirm_car_flag') != 'Y') {
                            Leaf.showConfirm('${l:HLS.PROMPT}', '是否进入停车场确认车辆真实收取？', function() {
                                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                                Leaf.request({
                                    url: $('${/parameter/@layout_code}_confirm_car_link').getUrl(),
                                    para: {
                                        management_id: record.get('management_id')
                                    },
                                    success: function(res) {
                                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                        $(ds_id).query();
                                        Leaf.SideBar.show({
                                            msg: '操作成功',
                                            duration: 2000
                                        });
                                    },
                                    failure: function() {
                                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    },
                                    error: function() {
                                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    },
                                    scope: this
                                });
                            });
                        } else {
                            Leaf.showMessage('${l:HLS.PROMPT}', '该车辆已经确认收取，无需重复确认！');
                        }
                    } else {
                        Leaf.showMessage('${l:HLS.PROMPT}', '该车辆已被赎回！');
                    }
                } else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '${l:CHOOSE_ONE_RECORD}');
                }
            };
            
            //详细信息
            window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_col_management_hd');
                var record = $(ds_id).getCurrentRecord();
                //
                if (record) {
                    if (record.get('confirm_car_flag') == 'Y') {
                        var param = record.data;
                        if (record.get('col_management_status') != 'NOT_MANAGEMENTING') {
                            if (record.get('wfl_status') == 'NEW' || record.get('wfl_status') == 'REJECT') {
                                param['function_code'] = 'CON6323_D';
                                param['function_usage'] = 'MODIFY';
                            } else {
                                param['function_code'] = 'CON6323_Q';
                                param['function_usage'] = 'QUERY';
                            }
                        } else {
                            param['function_code'] = 'CON6323_Q';
                            param['function_usage'] = 'QUERY';
                        }
                        param['bp_id'] = record.get('bp_id');
                        param['url_title'] = '处置申请';
                        hls_doc_get_layout_code('${/parameter/@layout_code}_con_contract_get_layout_code_link_id', param, '${/parameter/@layout_code}_con632_management_link_id', ds_id);
            
                    } else {
                        Leaf.showMessage('${l:HLS.PROMPT}', '请先确认收取车辆！');
                    }
                } else {
                    Leaf.showMessage('${l:HLS.PROMPT}', '${l:CHOOSE_ONE_RECORD}');
                }
            
            };
            
            //车辆赎回
            window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_col_management_hd');
                var records = $(ds_id).getSelected();
                for (var i = 0;i < records.length;i++) {
                    //
                    var contract_lease_item_id = records[i].get('contract_lease_item_id');
                    if (records[i].get('wfl_status') != 'APPROVING') {
                        if (records[i].get('col_management_status') != 'NOT_MANAGEMENTING') {
                            Leaf.showConfirm('提示', '确定要赎回该车辆吗？', function() {
                                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                                Leaf.request({
                                    url: '${/request/@context_path}/autocrud/cont.CON6323.con_collection/update',
                                    para: {
                                        contract_lease_item_id: contract_lease_item_id
                                    },
                                    success: function(res) {
                                        Leaf.SideBar.show({
                                            msg: '操作成功',
                                            duration: 2000
                                        });
                                        $(ds_id).query();
                                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    },
                                    failure: function() {
                                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    },
                                    error: function() {
                                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                    },
                                    sync: true,
                                    scope: this
                                });
                            });
                        } else {
                            Leaf.showMessage('${l:HLS.PROMPT}', '已赎回的车辆不能再次赎回！');
                        }
                    } else {
                        Leaf.showMessage('${l:HLS.PROMPT}', '审批中的车辆不能赎回！');
                    }
                }
            };
            
            function open_bp_code_query_win(ds_id, record_id) {
                var record = $(ds_id).findById(record_id);
                var param = record.data;
                param['function_code'] = 'CON505H';
                param['function_usage'] = '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, '${/parameter/@layout_code}_hls_bp_master_query_link', ds_id);
            }
            
            function open_collection_win(ds_id, record_id) {
                var record = $(ds_id).findById(record_id);
                var param = record.data;
            
                if (record.get('wfl_status') == 'NEW' || record.get('wfl_status') == 'REJECT') {
                    param['function_usage'] = 'MODIFY';
                } else {
                    param['function_usage'] = 'QUERY';
                }
                param['bp_id'] = record.get('bp_id');
                param['function_code'] = 'CON6322_M';
                param['function_type'] = 'VISIT';
                param['url_title'] = '催收详情';
                hls_doc_get_layout_code('${/parameter/@layout_code}_con_contract_get_layout_code_link_id', param, '${/parameter/@layout_code}_con632_callback_link_id', ds_id);
            }
            
            function open_contract_win_n(ds_id, record_id) {
                var record = $(ds_id).findById(record_id);
                var param = record.data;
                if (record.get('col_management_status') != 'NOT_MANAGEMENTING') {
                    if (record.get('wfl_status') == 'NEW' || record.get('wfl_status') == 'REJECT') {
                        param['function_code'] = 'CON6323_D';
                        param['function_usage'] = 'MODIFY';
                    } else {
                        param['function_code'] = 'CON6323_Q';
                        param['function_usage'] = 'QUERY';
                    }
                } else {
                    param['function_code'] = 'CON6323_Q';
                    param['function_usage'] = 'QUERY';
                }
                param['bp_id'] = record.get('bp_id');
                param['url_title'] = '处置申请';
                hls_doc_get_layout_code('${/parameter/@layout_code}_con_contract_get_layout_code_link_id', param, '${/parameter/@layout_code}_con632_management_link_id', ds_id);
            }
            
            //超链接渲染
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
                if (name == 'bp_id_n' && value) {
                    return '<a href="javascript:open_bp_code_query_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
                } else if (name == 'col_number' && value) {
                    return '<a href="javascript:open_collection_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
                } else if (name == 'contract_number' && value && record.get('confirm_car_flag') == 'Y') {
                    return '<a href="javascript:open_contract_win_n(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
                }
                return value;
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
