<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2018年7月16日 上午11:03:45  
    $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.CON350.con_insurance_import_batch_id" rootPath="batch_id"/>
    </a:init-procedure>
    <a:view>
        <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="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>
        <a:link id="con_change_ds_inusurance_link"
                url="${/request/@context_path}/modules/cont/CON350/con350_change_ds_inusurance.lview"/>
        <a:link id="con_change_other_inusurance_link"
                url="${/request/@context_path}/modules/cont/CON350/con350_change_other_inusurance.lview"/>
        <a:link id="con_insurance_upload_link"
                url="${/request/@context_path}/modules/cont/CON350/con350_insurance_import.lview"/>
        <a:link id="con_insurance_modify_link"
                url="${/request/@context_path}/modules/cont/CON350/con350_modify_insurance.lview"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@pre_layout}_insurance_cdd_uploadFile_id"
                url="${/request/@context_path}/uploadFile.lview"/>

        <script src="${/request/@context_path}/javascripts/hap/dynamicStopAutoQuery.js" type="text/javascript"/>

        <script type="text/javascript"><![CDATA[
        // stopDymanicAutoQuery('${/parameter/@layout_code}', 'G_INSUR', 'con_contract');

        //变更为宏菱代办
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {
            var con_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var records = $(con_ds_id).getSelected();
            var insurance_method = records[0].get('insurance_method');
            var contract_status = records[0].get('contract_status');
            if (records.length != 1) {
                Leaf.showMessage('${l:PROMPT}', '请选择一条记录');
                return;
            } else if (insurance_method == 'DS') {
                Leaf.showMessage('${l:PROMPT}', '该合同已为宏菱代办方式,无需更改!');
                return;
            }else if(contract_status == 'PENDING' || contract_status == 'ETING' ){
                Leaf.showMessage('${l:PROMPT}', '该合同处于变更流程中,不可进行保费变更!');
                return;
            }else if(contract_status == 'ET' || contract_status == 'TERMINATE' ){
                Leaf.showMessage('${l:PROMPT}', '该合同已结清完成,不可进行保费变更!');
                return;
            }
            var win = new Leaf.Window({
                id: 'con_change_ds_ins_link_winId',
                url: $('con_change_ds_inusurance_link').getUrl(),
                params: {
                    contract_id: records[0].get('contract_id'),
                    winId: 'con_change_ds_ins_link_winId'
                },
                title: '变更宏菱代办',
                draggable: true,
                width: 900,
                height: 300
            });
            win.on('close', function () {
                $(con_ds_id).query();
            });

        }

        //宏菱代办变更为其他
        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function () {
            var con_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var records = $(con_ds_id).getSelected();
            var insurance_method = records[0].get('insurance_method');
            var contract_status = records[0].get('contract_status');

            if (records.length != 1) {
                Leaf.showMessage('${l:PROMPT}', '请选择一条记录');
                return;
            } else if (insurance_method != 'DS') {
                Leaf.showMessage('${l:PROMPT}', '该合同投保方式不是宏菱投保,请检查数据!');
                return;
            }else if(contract_status == 'PENDING' || contract_status == 'ETING' ){
                Leaf.showMessage('${l:PROMPT}', '该合同处于变更流程中,不可进行保费变更!');
                return;
            }else if(contract_status == 'ET' || contract_status == 'TERMINATE' ){
                Leaf.showMessage('${l:PROMPT}', '该合同已结清完成,不可进行保费变更!');
                return;
            }
            var win = new Leaf.Window({
                id: 'change_other_ins_link_winId',
                url: $('con_change_other_inusurance_link').getUrl(),
                params: {
                    contract_id: records[0].get('contract_id'),
                    winId: 'change_other_ins_link_winId'
                },
                title: '宏菱代办变更其他',
                draggable: true,
                width: 900,
                height: 300
            });
            win.on('close', function () {
                $(con_ds_id).query();
            });

        }

        //维护投保信息
        window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function () {
            var con_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var records = $(con_ds_id).getSelected();
            if (records.length != 1) {
                Leaf.showMessage('${l:PROMPT}', '请选择一条记录');
                return;
            }

            var win = new Leaf.Window({
                id: 'con_insurance_modify_link_winId',
                url: $('con_insurance_modify_link').getUrl(),
                params: {
                    contract_id: records[0].get('contract_id'),
                    winId: 'con_insurance_modify_link_winId'
                },
                title: '信息维护',
                width: 1300,
                height: 320,
                draggable: true
            });
            win.on('close', function () {
                $(con_ds_id).query();
            });

        }

        //批量导入
        window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function () {
            var con_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
           // var records = $(con_ds_id).getSelected();
            var win = new Leaf.Window({
                id: 'con_insurance_upload_link_winId',
                url: $('con_insurance_upload_link').getUrl(),
                params: {
                    batch_id: '${/model/batch_id/record/@batch_id}',
                    winId: 'con_insurance_upload_link_winId',
                    con_ds_id:con_ds_id
                },
                title: '投保信息',
                fullScreen: true,
                draggable: true
            });
            win.on('close', function () {
                $(con_ds_id).query();
            });
        }

        //新增
        // window['${/parameter/@layout_code}_user_button5_layout_dynamic_click'] = function () {
        //
        //
        // }
            //超链接渲染
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_dynamic_link_renderer'] = function (value, record, name, config_record, bp_seq) {
            //
            var link_function = '';
            var contract_id = record.get('contract_id');
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
            if (name == 'attachment') {
                return '<a href="javascript:hls_attachment_window_open(\'' + contract_id + '\',\'' + record.id + '\',\'' + record.ds.id + '\');">' + '上传' + '</a>';
            }
            //
            if (name == 'contract_number' && value) {
                return '<a href="javascript:open_contract_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
            }


        };
        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['function_code'] = 'CON3200Q';
            param['maintain_type'] = 'QUERY';
            param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';

            //hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_modify_link', null);
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, '${/parameter/@layout_code}con_contract_query_link', ds_id);
        }
        function hls_attachment_window_open(contract_id, record_id, ds_id) {
            url = $('${/parameter/@layout_code}${/parameter/@pre_layout}_insurance_cdd_uploadFile_id').getUrl() + '?table_name=CONTRACT_INSURANCE&header_id=' + contract_id;
            wd = new Leaf.Window({
                id: 'open_attachment_window',
                url: url,
                title: '附件上传',
                height: 350,
                width: 850
            });
        }

        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);

            }

            ds.setQueryParameter('__async__', 'Y');
        };


        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=CONTRACT"/>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>