<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2017年11月28日 上午10:11:01
    $Revision: 1.0
    $Purpose:
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="bp_agent_create_link" url="${/request/@context_path}/modules/hls/HLS303/bp_agent_create.lview"/>
        <a:link id="bp_agent_modify_link" url="${/request/@context_path}/modules/hls/HLS303/bp_agent_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="first_add_agent_link_id" model="db.hls_bp_master_pkg.first_add_agent" modelaction="execute"/>
        <script type="text/javascript"><![CDATA[
        function bp_agent_query() {
            $('bp_agent_grid_result_ds').query();

        }

        function bp_agent_reset() {
            $('bp_agent_query_ds').reset();

        }

        function bp_agent_grid_update(record_id) {
            var record = $('bp_agent_grid_result_ds').findById(record_id);
            var param = record.data;

            param['document_id'] = record.get('bp_id');
            param['function_code'] = 'HLS303';
            param['function_usage'] = 'MODIFY';
            param['maintain_type'] = 'MODIFY';
            param['cdd_list_id'] = record.get('cdd_list_id');
            param['dsid'] = 'bp_agent_grid_result_ds';
            param['url_title'] = '代理店管理';
            param['bp_id'] = record.get('bp_id');
            // Leaf.request({
            //     url: $('first_add_agent_link_id').getUrl(),
            //     para: {
            //         bp_id: record.get('bp_id')
            //     },
            //     success: function(res) {
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'bp_agent_modify_link', 'bp_agent_grid_result_ds');
            //     },
            //     error: function() {},
            //     failure: function() {},
            //     sync: true,
            //     scope: this
            // });
        }

        function bp_agent_fin_query(record_id) {
            var record = $('bp_agent_grid_result_ds').findById(record_id);
            var bp_id = record.get('bp_id');
            new Leaf.Window({
                id: 'rsc_fin_statement_prj_all_query_winid',
                url: '${/request/@context_path}/modules/rsc/RSC303/rsc_fin_statement_prj_all_query.lview',
                params: {
                    bp_id: bp_id,
                    winid: 'rsc_fin_statement_prj_all_query_winid'
                },
                title: '${l:STATEMENTS_BUSINESS_DATA_IMPORT}',
                fullScreen: true,
                draggable: true
            });
        }

        function bp_agent_info(record_id) {
            var record = $('bp_agent_grid_result_ds').findById(record_id);
            var param = record.data;

            param['document_id'] = record.get('bp_id');
            param['function_code'] = 'HLS303F';
            param['function_usage'] = 'MODIFY';
            param['maintain_type'] = 'MODIFY';
            param['url_title'] = '代理店信息补充';
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'bp_agent_modify_link', 'bp_agent_grid_result_ds');
        }

        function bp_agent_renew(record_id) {
            var record = $('bp_agent_grid_result_ds').findById(record_id);
            var param = record.data;

            param['document_id'] = record.get('bp_id');
            param['function_code'] = 'HLS303R';
            param['function_usage'] = 'MODIFY';
            param['maintain_type'] = 'MODIFY';
            param['url_title'] = '代理店续约';
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'bp_agent_modify_link', 'bp_agent_grid_result_ds');
        }

        function bp_agent_fin_import(record_id) {
            var record = $('bp_agent_grid_result_ds').findById(record_id);
            var bp_id = record.get('bp_id');

            if (!bp_id) {
                return;
            }
            new Leaf.Window({
                id: 'rsc_fin_statement_prj_import_handle_winid',
                url: '${/request/@context_path}/modules/rsc/RSC303/rsc_fin_statement_prj_import_handle.lview',
                params: {
                    bp_id: bp_id,
                    winid: 'rsc_fin_statement_prj_import_handle_winid'
                },
                title: '${l:STATEMENTS_BUSINESS_DATA_IMPORT}',
                width: 950,
                height: 250
            });
        }

        function bp_agent_render(value, record, name) {
            if (name == 'bp_code') {
                return '<a href="javascript:bp_agent_grid_update(' + record.id + ')">' + value + '</a>';
            } else if (name == 'financial_statements') {
                return '<a href="javascript:bp_agent_fin_query(' + record.id + ')">' + '明细' + '</a>';
            } else if (name == 'agent_info') {
                return '<a href="javascript:bp_agent_info(' + record.id + ')">' + '信息补充' + '</a>';
            } else if (name == 'agent_renew') {
                return '<a href="javascript:bp_agent_renew(' + record.id + ')">' + '续约' + '</a>';
            } else if (name == 'financial_statements_import') {
                return '<a href="javascript:bp_agent_fin_import(' + record.id + ')">' + '导入' + '</a>';
            }
        }


        function bp_agent_add() {
            var param = {};
            param['function_code'] = 'HLS303';
            param['function_usage'] = 'MODIFY';
            param['maintain_type'] = 'MODIFY';
            //param['dsid'] = 'bp_agent_grid_result_ds';
            param['url_title'] = '代理店新增';
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'bp_agent_create_link');
        }


        function enterprise_certification_render(value, record, name) {
            return '<a href="javascript:open_certification(' + record.get("bp_id") + ');">' +'认证'+  '</a>';
        }

        function open_certification(bp_id) {
            $jq.ajax({
                url: '${/request/@context_path}/contract/signature/enterprise/certification',
                data: {
                    bpId: bp_id
                },
                type: 'get',
                success: function (datas) {
                    if (datas.success) {
                        var certUrl = datas.message;
                        window.open(certUrl, "", "width=1100, height=900, scrollbars=yes, toolbar=no, location=no, status=no, menubar=no");
                    } else {
                        Leaf.showErrorMessage('提示', '保存失败' + data.message);
                    }
                }
            })
        }

        function bp_agent_export() {
            $('bp_agent_grid')._export();
        }

        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
        <a:dataSets>
            <a:dataSet id="hls303_bp_agent_ds" lookupCode="BP_CATEGORY"/>
            <a:dataSet id="hls303_instance_status_ds" lookupCode="HLS303_WFL_STATUS"/>
            <a:dataSet id="hls303_agent_type_ds" lookupCode="HLS_AGENT_TYPE"/>
            <a:dataSet id="bp_agent_query_ds" model="hls.HLS303.hls_bp_master_asgent_modify">
                <a:fields>
                    <a:field name="bp_code" lovHeight="500" lovService="hls.HLS303.hls_bp_master_lov" lovWidth="700"
                             title="代理店选择">
                        <a:mapping>
                            <a:map from="bp_id" to="bp_id"/>
                            <a:map from="bp_code" to="bp_code"/>
                            <a:map from="bp_name" to="bp_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_category_n" displayField="code_value_name" options="hls303_bp_agent_ds"
                             returnField="code_value" valueField="code_value"/>
                    <a:field name="agent_type_n" displayField="code_value_name" options="hls303_agent_type_ds"
                             returnField="code_value" valueField="code_value"/>
                    <a:field name="agent_instance_status_n" displayField="code_value_name"
                             options="hls303_instance_status_ds" returnField="code_value" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="bp_agent_grid_result_ds" autoPageSize="true" autoQuery="true"
                       model="hls.HLS303.hls_bp_master_asgent_modify" queryDataSet="bp_agent_query_ds" selectable="true"
                       selectionModel="single">
                <a:fields>
                    <a:field name="enabled_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="sbo_bp_message" readOnly="true"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="bp_agent_query" text="HLS.QUERY"/>
                <a:gridButton click="bp_agent_reset" text="HLS.RESET"/>
                <a:gridButton click="bp_agent_add" text="HLS.NEW"/>
                <a:gridButton click="bp_agent_export" text="导出"/>
            </a:screenTopToolbar>
            <a:form Width="1030" column="4" labelWidth="130" marginWidth="40" title="HAP_QUERY_TITLE">
                <a:lov name="bp_code" bindTarget="bp_agent_query_ds" prompt="代理店编码"/>
                <a:textField name="bp_name" bindTarget="bp_agent_query_ds" prompt="代理店名称"/>
                <a:textField name="extra_nam" bindTarget="bp_agent_query_ds" prompt="代理店简称"/>
            </a:form>
            <a:grid id="bp_agent_grid" bindTarget="bp_agent_grid_result_ds" marginHeight="190" marginWidth="40"
                    navBar="true">
                <a:columns>
                    <a:column name="bp_code" align="center" prompt="代理店编码" renderer="bp_agent_render" width="120"/>
                    <a:column name="bp_name" align="center" prompt="代理店名称" width="280"/>
                    <a:column name="extra_nam" align="center" prompt="代理店简称" width="130"/>
                    <a:column name="enabled_flag" align="center" prompt="代理店状态" width="100"/>
                    <a:column name="sbo_bp_message" align="left" prompt="SBO反馈信息" width="350"/>
<!--                    <a:column name="agent_instance_status_n" align="center" prompt="工作流状态" width="150"/>-->
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>