<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129
    $Date: 2014-8-4 下午01:58:31
    $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.CON620.get_sys_role" rootPath="role_info"/>
        <a:model-query fetchAll="true" model="basic.hls_sys_time_default_value" rootPath="default_value"/>
        <a:model-query defaultWhereClause="t1.user_id=${/session/@user_id}" model="hls.HLS214N.sys_user_lv" rootPath="user_name_path"/>
    </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="hls_bp_master_modify_link"
                url="${/request/@context_path}/modules/hls/HLS214N/hls_bp_master_modify.lview"/>
        <a:link id="hls_bp_master_op_modify_link"
                url="${/request/@context_path}/modules/hls/HLS214N/hls_bp_master_op_modify.lview"/>
        <a:link id="hls_bp_master_op_query_modify_link"
                url="${/request/@context_path}/modules/hls/HLS215N/hls_bp_master_op_query.lview"/>
        <a:link id="hls_bp_master_req_modify_link"
                url="${/request/@context_path}/modules/hls/HLS214N/hls_bp_master_req_modify.lview"/>
        <a:link id="hls_bp_master_req_op_modify_link"
                url="${/request/@context_path}/modules/hls/HLS214N/hls_bp_master_op_req_modify.lview"/>
        <a:link id="Identity_ccx_link"
                url="${/request/@context_path}/modules/interface/INTERFACE_CCX/hlcm_ccxIdentity_interface.lsc"/>
        <a:link id="IcInfo_ccx_link"
                url="${/request/@context_path}/modules/interface/INTERFACE_CCX/hlcm_ccxIcInfo_interface.lsc"/>
        <a:link id="hls_bp_ccx_info_link"
                url="${/request/@context_path}/modules/hls/HLS236/hls_bp_master_query_ccx_report.lview"/>
        <a:link id="hls_bp_ccx_icinfo_link"
                url="${/request/@context_path}/modules/hls/HLS236/hls_bp_master_query_ccx_icinfo.lview"/>
        <a:link id="hls_bp_master_billing_link"
                url="${/request/@context_path}/modules/hls/HLS214N/hls_bp_master_billing.lview"/>
        <a:link id="identify_cert_link" model="hls.HLS214N.hls_bp_master_modify_user"
                modelaction="query"/>
        <script src="${/request/@context_path}/javascripts/hap/dynamicStopAutoQuery.js" type="text/javascript"/>

        <script type="text/javascript"><![CDATA[

        //信息变更
        window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function () {

            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'hls_bp_master');
            var record=$(ds_id).selected[0];
            var param = record.data;
            var bp_class = record.get('bp_class');
            if(record.get('bp_type')=='THIRD_PARTY'){
                Leaf.showMessage('提示', '第三方不能开票申请');
                return;
            }
            if(record.get('invoice_wfl_status') == 'APPROVING' || record.get('bp_wfl_status') == 'APPROVING'){
                //审批中调用
                param['function_code'] = 'HLS214BR_Q';
                param['bp_class'] = bp_class;
                param['url_title'] = '开票申请信息';
                // param['change_req_id'] = res.result.change_req_id;
                param['document_id'] = record.get('bp_id');
                param['function_usage'] = 'QUERY';
                param['query_only'] = 'Y';
                // window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'hls_bp_master_billing_link', ds_id);
                // var url = '${/request/@context_path}/autocrud/hls.HLS214N.hls_bp_master_req_create/update';
                // Leaf.request({
                //     url: url,
                //     para: {
                //         bp_id: record.get('bp_id'),
                //         change_type: 'INVOICE_REQ'
                //     },
                //     success: function (res) {
                //         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                //         if (res.result.change_req_id) {
                //             // 展示变更信息
                //             param['winid'] = 'bp_master_invoice_detail_win';
                //             param['function_code'] = 'HLS214BR';
                //             param['function_usage'] = 'MODIFY';
                //             param['query_only'] = 'N';
                //             param['bp_class'] = bp_class;
                //             param['change_req_id'] = res.result.change_req_id;
                //             param['document_id'] = res.result.change_req_id;
                //             param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                //             hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'hls_bp_master_billing_link', ds_id);
                //         }
                //     },
                //     failure: function () {
                //         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                //     },
                //     error: function () {
                //         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                //     },
                //     scope: this
                // });
            }else if (record.get('invoice_wfl_status') != 'APPROVING' && record.get('bp_wfl_status') != 'APPROVING'){
                //审批通过调用
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                var url = '${/request/@context_path}/autocrud/hls.HLS214N.hls_bp_master_req_create/update';

                Leaf.request({
                    url: url,
                    para: {
                        bp_id: record.get('bp_id'),
                        change_type: 'INVOICE_REQ'
                    },
                    success: function (res) {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        if (res.result.change_req_id) {
                            param['winid'] = 'bp_master_invoice_detail_win';
                            param['function_code'] = 'HLS214B';
                            param['bp_class'] = bp_class;
                            param['url_title'] = '开票申请信息';
                            param['change_req_id'] = res.result.change_req_id;
                            param['document_id'] = res.result.change_req_id;
                            param['function_usage'] = 'MODIFY';
                            param['query_only'] = 'N';
                            param['delete_flag'] = 'Y';
                            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'hls_bp_master_billing_link', ds_id);
                        }

                    },
                    failure: function () {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function () {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            }
        };

        // stopDymanicAutoQuery('${/parameter/@layout_code}', 'G_BP_RESULT', 'hls_bp_master');

        function open_bp_modify_win(ds_id, record_id) {
debugger;
            var record = $(ds_id).findById(record_id);
            var bp_class = record.get('bp_class');
            var user_category ='${/model/default_value/record/@user_category}';
            var submit_flag = record.get('submit_flag');
            var param = record.data;
            if(record.get('bp_wfl_status') == 'APPROVING' || record.get('invoice_wfl_status') == 'APPROVING'){
                // 展示原始信息，后续待定
                if(record.get('bp_type')!='RENTER' && record.get('bp_type')!='MAN_FACTURER' && record.get('bp_type')!='ASSET_REGULATOR'){
                    param['function_code'] = 'HLS215D';
                    param['function_usage'] = 'QUERY';
                    param['bp_class'] = bp_class;
                    param['cond_para1'] = user_category;
                    param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                    param['query_only'] = 'Y';
                    var link_id = 'hls_bp_master_modify_link';
                }else {
                    param['function_code'] = 'HLS215D_OP';
                    param['function_usage'] = 'QUERY';
                    param['bp_class'] = bp_class;
                    param['cond_para1'] = user_category;
                    param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                    param['query_only'] = 'Y';
                    var link_id = 'hls_bp_master_op_query_modify_link';
                }
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, link_id, ds_id);
            }else if (record.get('invoice_wfl_status') != 'APPROVING' && record.get('bp_wfl_status') != 'APPROVING'){
                if (record.get('bp_type')=='THIRD_PARTY'&&"${/model/role_info/record/@role_code}"!="HAND"&&"${/model/user_name_path/record/@user_name}"!="DSF001"&&"${/model/user_name_path/record/@user_name}"!="DSF002") {
                    param['function_code'] = 'HLS215D';
                    param['function_usage'] = 'QUERY';
                    param['bp_class'] = bp_class;
                    param['cond_para1'] = user_category;
                    param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                    param['query_only'] = 'Y';
                    hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'hls_bp_master_modify_link', ds_id);
                    return;
                }

                if(submit_flag == 'Y'){
                    window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                    var url = '${/request/@context_path}/autocrud/hls.HLS214N.hls_bp_master_req_create/execute';
                    Leaf.request({
                        url: url,
                        para: {
                            bp_id: record.get('bp_id')                },
                        success: function (res) {
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            if(res.result.change_req_id){
                                if(record.get('bp_type')=='THIRD_PARTY'){
                                    param['function_code'] = 'HLS214F_N';
                                    param['function_usage'] = 'MODIFY';
                                    param['bp_class'] = bp_class;
                                    param['change_req_id'] = res.result.change_req_id;
                                    param['document_id'] = res.result.change_req_id;
                                    param['cond_para1'] = user_category;
                                    param['bp_name_updated_flag'] = record.get('bp_name_updated_flag');
                                    param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                                    param['query_only'] = 'N';
                                    param['delete_flag'] = 'Y';
                                    // param['layout_debugger_flag']='Y';
                                    hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'hls_bp_master_req_modify_link', ds_id);
                                }else if(record.get('bp_type')=='RENTER' || record.get('bp_type')=='MAN_FACTURER' || record.get('bp_type')=='ASSET_REGULATOR'){
                                    param['function_code'] = 'HLS214F_OP';
                                    param['function_usage'] = 'MODIFY';
                                    param['bp_class'] = bp_class;
                                    param['change_req_id'] = res.result.change_req_id;
                                    param['document_id'] = res.result.change_req_id;
                                    param['cond_para1'] = user_category;
                                    param['bp_name_updated_flag'] = record.get('bp_name_updated_flag');
                                    param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                                    param['query_only'] = 'N';
                                    param['delete_flag'] = 'Y';
                                    // param['layout_debugger_flag']='Y';
                                    hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'hls_bp_master_req_op_modify_link', ds_id);
                                } else{
                                    param['function_code'] = 'HLS214F';
                                    param['function_usage'] = 'MODIFY';
                                    param['bp_class'] = bp_class;
                                    param['change_req_id'] = res.result.change_req_id;
                                    param['document_id'] = res.result.change_req_id;
                                    param['cond_para1'] = user_category;
                                    param['bp_name_updated_flag'] = record.get('bp_name_updated_flag');
                                    param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                                    param['query_only'] = 'N';
                                    param['delete_flag'] = 'Y';
                                    // param['layout_debugger_flag']='Y';
                                    hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'hls_bp_master_req_modify_link', ds_id);
                                }
                            }
                        },
                        failure: function () {
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        error: function () {
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        },
                        scope: this
                    });
                }else{
                    if(record.get('bp_type')=='THIRD_PARTY'){
                        window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                        var url = '${/request/@context_path}/autocrud/hls.HLS214N.hls_bp_master_req_create/execute';
                        Leaf.request({
                            url: url,
                            para: {
                                bp_id: record.get('bp_id')
                            },
                            success: function (res) {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                                if(res.result.change_req_id){
                                    param['function_code'] = 'HLS214F_N';
                                    param['function_usage'] = 'MODIFY';
                                    param['bp_class'] = bp_class;
                                    param['change_req_id'] = res.result.change_req_id;
                                    param['document_id'] = res.result.change_req_id;
                                    param['cond_para1'] = user_category;
                                    param['bp_name_updated_flag'] = record.get('bp_name_updated_flag');
                                    param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                                    param['query_only'] = 'N';
                                    param['delete_flag'] = 'Y';
                                    // param['layout_debugger_flag']='Y';
                                    hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'hls_bp_master_req_modify_link', ds_id);
                                }

                            },
                            failure: function () {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            error: function () {
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            },
                            scope: this
                        });
                    }
                    //经营性租赁
                    else if(record.get('bp_type')=='RENTER' || record.get('bp_type')=='MAN_FACTURER' || record.get('bp_type')=='ASSET_REGULATOR'){
                        param['function_code']='HLS214OP';
                        param['bp_class'] =bp_class;
                        param['cond_para1'] = user_category;
                        param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                        param['query_only'] = 'Y';
                        hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'hls_bp_master_op_modify_link', ds_id);
                    }else{
                        param['function_code'] = 'HLS214D';
                        param['function_usage'] = 'MODIFY';
                        param['bp_class'] = bp_class;
                        param['cond_para1'] = user_category;
                        param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                        param['query_only'] = 'N';
                        hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'hls_bp_master_modify_link', ds_id);
                    }
                }
            }
        }

        function open_ccx_detail_win(ds_id, record_id) {
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            param['function_code'] = 'HLS236Q';
            param['bp_id'] = record.get('bp_id');
            param['function_usage'] = 'QUERY';
            param['url_title'] = '查询明细';
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'hls_bp_ccx_info_link', ds_id);

        }

        function open_ccx_icionfo_win(ds_id, record_id) {
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            param['function_code'] = 'HLS236I';
            param['bp_id'] = record.get('bp_id');
            param['function_usage'] = 'QUERY';
            param['url_title'] = '查询明细';
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'hls_bp_ccx_icinfo_link', ds_id);

        }

        window['${/parameter/@layout_code}_dynamic_link_renderer'] = function (value, record, name, config_record) {
            if (name == 'bp_code' && value) {
                return '<a href="javascript:open_bp_modify_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
            }
            if (name == 'detail') {
                return '<a href="javascript:open_ccx_detail_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' +  value + '</a>';
            }
            if (name == 'icinfo') {
                return '<a href="javascript:open_ccx_icionfo_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
            }
            return value;
        };

        //维护按钮
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
            var records = $(ds_id).getSelected();
            if (records.length != 1) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                return;
            }
            var record = records[0];
            open_bp_modify_win(ds_id, record.id);
        };

        //个人身份验证
        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
            var records = $(ds_id).getSelected();
            if (records.length != 1) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                return;
            }
            var record = records[0];
            if (record.get('bp_class') != 'NP') {
                Leaf.showMessage('${l:PROMPT}', '请选择自然人!');
                return;
            }
            var url = $('Identity_ccx_link').getUrl();
            Leaf.showConfirm('提示', '确认发起查询吗？', function () {
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: url,
                    para: {
                        bp_id: record.get('bp_id'),
                        bp_name: record.get('bp_name'),//姓名
                        id_card_no: record.get('id_card_no')//身份证号码
                    },
                    success: function (res) {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        Leaf.SideBar.show({
                            msg: '${l:HLS.SUBMIT_SUCCESS}',
                            duration: 2000
                        });
                        $('ds_id').query();
                    },
                    failure: function () {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function () {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            }, function () {
                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            });
        };

        //企业资信报告
        window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_bp_master');
            var records = $(ds_id).getSelected();
            if (records.length != 1) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                return;
            }
            var record = records[0];
            if (record.get('bp_class') != 'ORG') {
                Leaf.showMessage('${l:PROMPT}', '请选择法人!');
                return;
            }
            var url = $('IcInfo_ccx_link').getUrl();
            Leaf.showConfirm('提示', '确认发起查询吗？', function () {
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: url,
                    para: {
                        bp_id: record.get('bp_id'),
                        bp_name: record.get('bp_name'),//企业名称
                        business_license_num: record.get('business_license_num')//工商注册号
                    },
                    success: function (res) {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        Leaf.SideBar.show({
                            msg: '${l:HLS.SUBMIT_SUCCESS}',
                            duration: 2000
                        });
                        $('ds_id').query();
                    },
                    failure: function () {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function () {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            }, function () {
                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            });
        };

        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'], 'hls_bp_master');

            if(ds==$(ds_id)){
                aut_authority_list_validate_query(ds, qpara);

            }
        };
        //加载时调用(grid,table,gridBox)

        window.addEventListener("load", function (_event) {
            Leaf.request({
                url: $('identify_cert_link').getUrl(),
                para: {},
                success: function(res) {
                    var code=res.result.record.employee_type_id;
                    if(code==64){
                        //代理店进行隐藏
                        var elements=document.querySelector('td[title="SBO反馈信息"]');
                        elements.remove();
                        $('BP_MODIFY_ENTRANCE_G_BP_RESULT_hls_bp_master_layout_grid_id').hideColumn('SBO_BP_MESSAGE');
                    }
                },
                failure: function() {
                },
                error: function() {
                },
                scope: this
            });

        });
        Leaf.onReady(function() {
            if("${/model/role_info/record/@role_code}"!="0018"&&"${/model/role_info/record/@role_code}"!="0019") {

            } else {
                $('BP_MODIFY_ENTRANCE_G_BP_RESULT_hls_bp_master_layout_grid_id').hideColumn('SBO_BP_MESSAGE');
                var elements=document.querySelector('td[title="SBO反馈信息"]');
                elements.remove();
            }

        });
        /*  Leaf.onReady(function(){

             for (var i=0;i<elements.length;i++){
                 elements[i].parentNode.remove();
            }
              console.log(elements);

              var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'],'hls_bp_master');
              console.log($(ds_id));

          })*/
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=BP&amp;function_code=HLS214"/>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
