<?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="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'
                },
                title: '投保信息',
                fullScreen: true,
                draggable: true
            });
            win.on('close', function () {
                $(con_ds_id).query();
            });
        }

        //超链接渲染
        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>';
            }
        };

        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>
