<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true"
          trace="true">
    <a:view>
        <a:link id="con1030_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>
        <a:link id="litigation_entrance_detail" url="${/request/@context_path}/modules/cont/CON1030/con_litigation_entrance_detail.lview"/>
        <a:link id="litigation_agent_detail" url="${/request/@context_path}/modules/cont/CON1030/con_litigation_agent_detail.lview"/>
        <a:link id="litigation_authorize_agent" url="${/request/@context_path}/modules/cont/CON1030/con_litigation_authorize_agent.lview"/>
        <a:link id="con_contract_modify_link" url="${/request/@context_path}/modules/cont/CON505/con_contract_modify.lview"/>
        <a:link id="bp_agent_modify_link" url="${/request/@context_path}/modules/hls/HLS303/bp_agent_modify.lview"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@pre_layout}_sms_query_link" url="${/request/@context_path}/modules/sys/SYS402/sys_sms_query.lview"/>
        <script type="text/javascript"><![CDATA[
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {
            open_contract_win1();
        };

        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function () {
            open_contract_win2();
        };

        window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function () {
            open_contract_win3();
        };

        function open_contract_win1() {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_litigation');
            var param = {};
            param['function_code'] = 'CON1030A';
            param['maintain_type'] = 'INSERT';
            param['url_title'] = '起诉客户/被诉';
            param['winid'] = '${/parameter/@layout_code}_create_win_id'
            hls_doc_get_layout_code('con1030_get_layout_code_link_id', param, 'litigation_entrance_detail', ds_id);
        }

        function open_contract_win2() {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_litigation');
            var param = {};
            param['function_code'] = 'CON1030B';
            param['maintain_type'] = 'INSERT';
            param['url_title'] = '起诉代理商';
            param['winid'] = '${/parameter/@layout_code}_create_win_id'
            hls_doc_get_layout_code('con1030_get_layout_code_link_id', param, 'litigation_agent_detail', ds_id);
        }

        function open_contract_win3() {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_litigation');
            var param = {};
            param['function_code'] = 'CON1030C';
            param['maintain_type'] = 'INSERT';
            param['url_title'] = '授权代理商起诉';
            param['winid'] = '${/parameter/@layout_code}_create_win_id'
            hls_doc_get_layout_code('con1030_get_layout_code_link_id', param, 'litigation_authorize_agent', ds_id);
        }
        function open_contract_win_detail(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'] = 'QUERY';
            param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
            hls_doc_get_layout_code('con1030_get_layout_code_link_id', param, 'con_contract_modify_link', null);
        }

        function open_project_modify_win(record_id, ds_id) {

            var record = $(ds_id).findById(record_id);
            //项目类layout_code

            var maintain_type = 'QUERY';
            var param = record.data;
            param['litigation_id'] = record.get('litigation_id');
            param['function_code'] = 'CON1030A';
            param['function_usage'] = 'MODIFY';
            param['maintain_type'] = maintain_type;
            param['url_title'] = '${l:HLS.PROJECT_MAITAIN}';
            hls_doc_get_layout_code('con1030_get_layout_code_link_id', param, 'litigation_entrance_detail', ds_id);

        }

        function open_project_modify_win2(record_id, ds_id) {

            var record = $(ds_id).findById(record_id);
            //项目类layout_code

            var maintain_type = 'QUERY';
            var param = record.data;
            param['litigation_id'] = record.get('litigation_id');
            param['function_code'] = 'CON1030B';
            param['function_usage'] = 'MODIFY';
            param['maintain_type'] = maintain_type;
            param['url_title'] = '${l:HLS.PROJECT_MAITAIN}';
            hls_doc_get_layout_code('con1030_get_layout_code_link_id', param, 'litigation_agent_detail', ds_id);

        }

        function open_project_modify_win3(record_id, ds_id) {

            var record = $(ds_id).findById(record_id);
            //项目类layout_code

            var maintain_type = 'QUERY';
            var param = record.data;
            param['litigation_id'] = record.get('litigation_id');
            param['function_code'] = 'CON1030C';
            param['function_usage'] = 'MODIFY';
            param['maintain_type'] = maintain_type;
            param['url_title'] = '${l:HLS.PROJECT_MAITAIN}';
            hls_doc_get_layout_code('con1030_get_layout_code_link_id', param, 'litigation_authorize_agent', ds_id);

        }

        function bp_agent_renew(record_id) {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_litigation');
            var record = $(ds_id).findById(record_id);
            var param = record.data;

            param['document_id'] = record.get('litigation_sourse_id');
            param['bp_id'] = record.get('litigation_sourse_id');
            param['function_code'] = 'HLS303R';
            param['function_usage'] = 'MODIFY';
            param['maintain_type'] = 'MODIFY';
            param['url_title'] = '代理商续约';
            hls_doc_get_layout_code('con1030_get_layout_code_link_id', param, 'bp_agent_modify_link', ds_id);
        }

        function sms_query(record_id, ds_id) {
            var record = $(ds_id).findById(record_id);
            url = $('${/parameter/@layout_code}${/parameter/@pre_layout}_sms_query_link').getUrl();
            var win = new Leaf.Window({
                id: 'open_sms_query_window',
                url: url,
                fullScreen: true
            });
            win.on('close', function () {
                record.ds.query();
            });
        }


        window['${/parameter/@bp_seq}${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record, bp_seq) {
            var litigation_sourse =  record.get('litigation_sourse');
            if (name == 'cntrt_no' && value) {
                return '<a href="javascript:open_contract_win_detail(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
            }
            else if (name == 'litigation_number' && value) {
                if (litigation_sourse == 'CONTRACT') {
                    return '<a href="javascript:open_project_modify_win(\'' + record.id + '\',\'' + record.ds.id + '\')">' + value + '</a>';
                }
                else if(litigation_sourse == 'AGENT') {
                    return '<a href="javascript:open_project_modify_win2(\'' + record.id + '\',\'' + record.ds.id + '\')">' + value + '</a>';
                }
                else if(litigation_sourse == 'AGENT_CONTRACT') {
                    return '<a href="javascript:open_project_modify_win3(\'' + record.id + '\',\'' + record.ds.id + '\')">' + value + '</a>';
                }
            }
            // else if (name == 'call_record_query' && litigation_sourse == 'AGENT'){
            //     return '<a href="javascript:bp_agent_renew(' + record.id + ')">' + '功能链接' + '</a>';
            // }
            // else if (name == 'call_record_query' && (litigation_sourse == 'CONTRACT'||litigation_sourse == 'AGENT_CONTRACT')) {
            //     var link_function = 'call140_super_link_renderer';
            //     window['${/parameter/@bp_seq}${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
            //     return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.get('litigation_sourse_id') + '\',\'' + name + '\');">' + '功能链接' + '</a>';
            // }
            else if (name == 'sms_query' ){
                return '<a href="javascript:sms_query(\'' + record.id + '\',\'' + record.ds.id + '\');">' + '短信查询' + '</a>';
            }
            return value;
        };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
