<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
        <a:model-query defaultWhereClause="t1.contract_id = ${/parameter/@contract_id}" fetchAll="true" model="cont.CON632.con_ast_car_gps_lv" rootPath="con_car_gps_path"/>
    </a:init-procedure>
    <a:view>
        <a:link id="${/parameter/@layout_code}_con632_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_car_modify_link" url="${/request/@context_path}/modules/prj/PRJ501N/prj_project_maintain.lview"/>
        <a:link id="${/parameter/@layout_code}_prj_project_modify_link" url="${/request/@context_path}/modules/prj/PRJ501N/prj_project_create_tree_n.lview"/>
        <a:link id="${/parameter/@layout_code}_car_modify_special_link" url="${/request/@context_path}/modules/prj/PRJ500N/prj_project_create_special.lview"/>
        <a:link id="${/parameter/@layout_code}_call_phone_det_id" url="${/request/@context_path}/modules/cont/CON632/con_collection_call_phone.lview"/>
        <a:link id="${/parameter/@layout_code}_Collection_tool" url="${/request/@context_path}/modules/cont/CON632/con_collection_tool.lview"/>
        <a:link id="${/parameter/@layout_code}_con_contract_gps_link" url="${/request/@context_path}/modules/gps/con_contract_gps_send.lview"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <a:link id="${/parameter/@layout_code}_con_contract_cashflow_id" url="${/request/@context_path}/modules/cont/CON632/con_contract_cashflow.lview"/>
        <a:link id="${/parameter/@layout_code}_con_collection_tool_ln_id" url="${/request/@context_path}/modules/cont/CON632/con_collection_tool_ln.lview"/>
        <script type="text/javascript"><![CDATA[
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                alert("短信发送");
            };
            
            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 record = $(ds_id).getCurrentRecord();
                var contract_number = record.get('contract_number');
                var project_number = record.get('project_number');
                var contract_id = record.get('contract_id');
                var date = new Date();
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var day = date.getDate();
                var dd = year + '-' + month + '-' + day;

                var win = new Leaf.Window({
                    id: 'Collection_tool_id',
                    url: $('${/parameter/@layout_code}_Collection_tool').getUrl(),
                    params: {
                        contract_number: contract_number,
                        project_number: project_number,
                        staff_name: '${/parameter/@staff_name}',
                        staff_id: '${/parameter/@staff_id}',
                        times: dd,
                        project_id: '${/parameter/@project_id}',
                        contract_id: contract_id,
                        col_id: '${/parameter/@col_id}',
                        type_id: '${/parameter/@type_id}',
                        winId: 'Collection_tool_id'
                    },
                    title: '催收工具',
                    width: 1000,
                    height: 530
                });
                win.on('close', function() {
                    var con_collection_tool = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection_tool');
                    $(con_collection_tool).query();
                });
            };
            
            window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {
                //alert('GPS定位');
                var win = new Leaf.Window({
                    url: $('${/parameter/@layout_code}_con_contract_gps_link').getUrl(),
                    title: '实时定位',
                    params: {
                        contract_id: '${/parameter/@contract_id}',
                        gps_provider: '${/model/con_car_gps_path/record/@gps_provider}',
                        winid: '${/parameter/@layout_code}_con_contract_gps_send_address_win_link_winid'
                    },
                    id: '${/parameter/@layout_code}_con_contract_gps_send_address_win_link_winid',
                    width: 600,
                    height: 400
                });
            };
            
            //超链接渲染
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
                if (name == 'project_number') {
                    return '<a href="javascript:open_project_Window(\'' + record.id + '\',\'' + record.ds.id + '\');">' + value + '</a>';
                } else if (name == 'call_phone') {
                    return '<a href="javascript:open_ref_win(\'' + record.id + '\',\'' + record.ds.id + '\');">' + '备注' + '</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_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 ref="img" href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                                } else {
                                    url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                                }
                            }
                        }
                        return url;
                    }
                    //逾期信息
                } else if (name == 'due_times') {
                    link_function = '${/parameter/@layout_code}_overdue_cashflow';
                    return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + record.ds.id + '\');">' + value + '</a>';
                } else if (name == 'rejest') {
                    if ((record.get('collection_measures') == 'C_CAR' || record.get('collection_measures') == 'VISIT') && record.get('wfl_state') == 'APPROVING' && record.get('cancel_status') != 'APPROVING') {
                        link_function = '${/parameter/@layout_code}_con_collection_tool_ln';
                        return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + record.ds.id + '\');">' + config_record.get('prompt') + '</a>';
                    } else {
                        return config_record.get('prompt');
                    }
            
                }
            };
            //附件上传
            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}', '请先保存!');
                }
            };
            //打开现金流逾期信息
            window['${/parameter/@layout_code}_overdue_cashflow'] = function(record_id, ds_id) {
                var win = new Leaf.Window({
                    url: $('${/parameter/@layout_code}_con_contract_cashflow_id').getUrl(),
                    title: '逾期状态',
                    params: {
                        contract_id: '${/parameter/@contract_id}',
                        winid: '${/parameter/@layout_code}_con_contract_cashflow_winid'
                    },
                    id: '${/parameter/@layout_code}_con_contract_cashflow_winid',
                    width: 1140,
                    height: 400
                });
            };
            
            //打开催收拒绝页面
            window['${/parameter/@layout_code}_con_collection_tool_ln'] = function(record_id, ds_id) {
                var record = $(ds_id).findById(record_id);
                var win = new Leaf.Window({
                    url: $('${/parameter/@layout_code}_con_collection_tool_ln_id').getUrl(),
                    title: '催收取消申请',
                    params: {
                        collection_id: record.get('collection_id'),
                        project_id: '${/parameter/@project_id}',
                        contract_id: '${/parameter/@contract_id}',
                        collection_measures_n: record.get('collection_measures_n'),
                        tool_number: record.get('tool_number'),
                        create_time: record.get('create_time'),
                        create_by: record.get('create_by'),
                        winid: 'con_collection_tool_ln_winid'
                    },
                    id: 'con_collection_tool_ln_winid',
                    width: 850,
                    height: 300
                });
                win.on('close', function() {
                    var con_collection_tool = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_collection_tool');
                    $(con_collection_tool).query();
                });
            };
            
            function open_project_Window(record_id, ds_id) {
                var record = $(ds_id).findById(record_id);
                var maintain_type = 'QUERY';
                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'] = maintain_type;
                param['window_open_flag'] = 'Y';
                param['show_history_flag'] = 'Y';
                param['url_title'] = '${l:HLS.PROJECT_MAITAIN}';
                hls_doc_get_layout_code('${/parameter/@layout_code}_con632_get_layout_code_link_id', param, '${/parameter/@layout_code}_car_modify_special_link', ds_id, '${/parameter/@layout_code}');
            }
            
            function open_ref_win(record_id, ds_id) {
                var contract_ds = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var contract_record = $(contract_ds).getAt(0);
                var record = $(ds_id).findById(record_id);

                var win = new Leaf.Window({
                    id: 'con_contract_content_window',
                    url: $('${/parameter/@layout_code}_call_phone_det_id').getUrl(),
                    params: {
                        contract_id: contract_record.get('contract_id'),
                        contract_number: contract_record.get('contract_number'),
                        project_id: contract_record.get('project_id'),
                        project_number: contract_record.get('project_number'),
                        bp_id_tenant_n: contract_record.get('bp_id_tenant_n'),
                        bp_name: record.get('bp_name'),
                        bp_id_tenant: contract_record.get('bp_id_tenant'),
                        staff_id: '${/parameter/@staff_id}',
                        type_desc: record.get('type_desc'),
                        cell_phone: record.get('cell_phone'),
                        staff_name: '${/parameter/@staff_name}',
                        type: record.get('type'),
                        col_id: '${/parameter/@col_id}',
                    },
                    title: '电话催收登记',
                    fullScreen: true
                });
            
            
            }
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
