<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Calvin  
    $Date: 2018年03月14日22:09:20
    $Revision: 1.0  
    $Purpose: 中诚信数据查询
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query defaultWhereClause="t1.project_id = ${/parameter/@project_id}" fetchAll="true" model="interface.CCX_INTERFACE.hls_ccx_interface" rootPath="project_info_path"/>
    </a:init-procedure>
    <a:view>
        <a:link id="hls_master_ccx_risk_report_id" url="${/request/@context_path}/modules/hls/HLS236/hls_ccx_risk_report.lview"/>
        <a:link id="hls_master_ccx_transaction_report_id" url="${/request/@context_path}/modules/hls/HLS236/hls_ccx_transaction_report.lview"/>
        <a:link id="transfer_ccx_link" url="${/request/@context_path}/modules/interface/INTERFACE_CCX/deron_interface_ccx.lsc"/>
        <script type="text/javascript"><![CDATA[
            //锁屏
            
            function lock_current_window() {
                Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            }
            
            //解屏
            
            function unlock_current_window() {
                Leaf.Masker.unmask(Ext.getBody());
            }
            
            function open_bp_information_win(ds_id, record_id) {
                var record = $(ds_id).findById(record_id);
                var bp_id = record.get('bp_id');
                var url;
                if (record.get('interface_type_result') == '查看风险报告' || record.get('interface_type_result') == '查看个人交易报告') {
                    if (record.get('type_interface') == '7') {
                        //风险报告
                        url = $('hls_master_ccx_risk_report_id').getUrl() + '?bp_id=' + bp_id + '&chk_list_id=' + record.get('chk_list_id');
                    } else if (record.get('type_interface') == '8') {
                        //个人交易报告
                        url = $('hls_master_ccx_transaction_report_id').getUrl() + '?bp_id=' + bp_id + '&chk_list_id=' + record.get('chk_list_id');
                    }
                    window.open(url);
                }
            }
            
            function bp_information_renderer(value, record, name) {
                if (name == 'interface_type_result') {
                    if (value == '查看风险报告' || value == '查看个人交易报告') {
                        return '<a href="javascript:open_bp_information_win(\'' + record.ds.id + '\',\'' + record.id + '\')">' + value + '</a>';
                    } else {
                        if (record.get('res_code') == '0000') {
                            return value;
                        } else if (record.get('res_code') == '2030') {
                            return value;
                        } else if (record.get('res_code') == '2010') {
                            return value;
                        } else {
                            return '<font color="red">' + value + '</font> ';
                        }
                    }
                }
                return value;
            }
            
            function transfer_ccx(interface_type) {
                var url = $('transfer_ccx_link').getUrl();
                Leaf.showConfirm('提示', '确认发起查询吗？', function() {
                    lock_current_window();
                    Leaf.request({
                        url: url,
                        para: {
                            project_id: '${/parameter/@project_id}',
                            bp_id: '${/model/project_info_path/record/@bp_id}',
                            interface_type: interface_type
                        },
                        success: function(res) {
                            unlock_current_window();
                            Leaf.SideBar.show({
                                msg: '${l:HLS.SUBMIT_SUCCESS}',
                                duration: 2000
                            });
                            $('chk_list_ds').query();
                        },
                        failure: function() {
                            unlock_current_window();
                        },
                        error: function() {
                            unlock_current_window();
                        },
                        scope: this
                    });
                }, function() {
                    unlock_current_window();
                });
            }
            
            //身份核验
            
            function masterDs_grid_user_button1() {
                transfer_ccx(1);
            }
            
            //二维核验（已弃用）
            
            function masterDs_grid_user_button2() {
                transfer_ccx(2);
            }
            
            //三维核验
            
            function masterDs_grid_user_button3() {
                transfer_ccx(3);
            }
            
            //四维核验
            
            function masterDs_grid_user_button4() {
                transfer_ccx(4);
            }
            
            //手机号状态查询
            
            function masterDs_grid_user_button5() {
                //判断手机号所属运营商
                var CMCC = /(^((13[4-9]{1})|(147)|(148)|(198)|(15[0-2]{1})|(15[7-9]{1})|(178)|(18[2-4]{1})|(18[7-8]{1}))\d{8}$)|(^((1703)|(1705)|(1706))\d{7}$)/; //中国移动
                var CUCC = /(^((13[0-2]{1})|(145)|(146)|(155)|(156)|(166)|(171)|(175)|(176)|(185)|(186))\d{8}$)|(^(170[7-9]{1})\d{7}$)/; //中国联通
                var CTCC = /(^((133)|(149)|(153)|(173)|(177)|(180)|(181)|(189)|(199))\d{8}$)|(^(170[0-2]{1})\d{7}&)/; //中国电信
                var phone = '${/model/project_info_path/record/@mobile}';
                var phoneType = "其他";
                if (CMCC.test(phone)) {
                    phoneType = "移动";
                } else if (CUCC.test(phone)) {
                    phoneType = "联通";
                } else if (CTCC.test(phone)) {
                    phoneType = "电信";
                }
            
                if (phoneType == '联通' || phoneType == '电信') {
                    transfer_ccx(5);
                } else if (phoneType == '移动') {
                    transfer_ccx(6);
                } else if (phoneType == '其他') {
                    Leaf.showMessage('提示', '无法获取手机号所属运营商！请联系系统管理员！');
                    return;
                }
            }
            
            //个人交易报告查询
            
            function masterDs_grid_user_button6() {
                transfer_ccx(7);
            }
            
            //风险信息查询
            
            function masterDs_grid_user_button7() {
                transfer_ccx(8);
            }
            
            //四维核验简项（做好暂时不放出）
            
            function masterDs_grid_user_button8() {
                transfer_ccx(9);
            }
            
            
            function control_button() {
                var records = $('chk_list_ds').getAll();
            
                for (var i = 0;i < records.length;i++) {
                    //身份核验
                    if (records[i].get('type_interface') == '1') {
                        $('${/parameter/@layout_code}_user_button1').disable();
                    }
            
                    //二维核验
                    if (records[i].get('type_interface') == '2' && records[i].get('type_swhy') == '1' && records[i].get('res_code') == '2030') {
                        $('${/parameter/@layout_code}_user_button2').disable();
                    }
            
                    //三维核验
                    if (records[i].get('type_interface') == '2' && records[i].get('type_swhy') == '5' && records[i].get('res_code') == '2030') {
                        $('${/parameter/@layout_code}_user_button2').disable();
                        $('${/parameter/@layout_code}_user_button3').disable();
                    }
            
                    //四维核验
                    if (records[i].get('type_interface') == '2' && records[i].get('type_swhy') == '2' && records[i].get('res_code') == '2030') {
                        $('${/parameter/@layout_code}_user_button2').disable();
                        $('${/parameter/@layout_code}_user_button3').disable();
                        $('${/parameter/@layout_code}_user_button4').disable();
                    }
            
                    //手机号状态
                    if (records[i].get('type_interface') == '5' || records[i].get('type_interface') == '6' && records[i].get('res_code') == '0000') {
                        $('${/parameter/@layout_code}_user_button5').disable();
                    }
            
                    //个人交易报告
                    if (records[i].get('type_interface') == '8' && (records[i].get('res_code') == '0000' || records[i].get('res_code') == '2001')) {
                        $('${/parameter/@layout_code}_user_button6').disable();
                    }
            
                    //风险报告
                    if (records[i].get('type_interface') == '7' && (records[i].get('res_code') == '0000' || records[i].get('res_code') == '2001')) {
                        $('${/parameter/@layout_code}_user_button7').disable();
                    }
            
                    //法人控制
                    if (records[i].get('bp_class') == 'ORG') {
                        $('${/parameter/@layout_code}_user_button1').disable();
                        $('${/parameter/@layout_code}_user_button2').disable();
                        $('${/parameter/@layout_code}_user_button3').disable();
                        $('${/parameter/@layout_code}_user_button4').disable();
                        $('${/parameter/@layout_code}_user_button5').disable();
                        $('${/parameter/@layout_code}_user_button6').disable();
                    }
                }
            }
            
            function on_result_query() {
                control_button();
            }
            
            function on_result_load(ds) {
                control_button();
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="basic_info_ds" autoQuery="true" queryUrl="${/request/@context_path}/autocrud/interface.CCX_INTERFACE.hls_ccx_interface/query?project_id=${/parameter/@project_id}"><![CDATA[
            ]]></a:dataSet>
            <a:dataSet id="chk_list_ds" autoQuery="true" fetchAll="true" queryUrl="${/request/@context_path}/autocrud/interface.CCX_INTERFACE.chk_list_lv/query?project_id=${/parameter/@project_id}">
                <a:events>
                    <a:event name="load" handler="on_result_load"/>
                    <a:event name="query" handler="on_result_query"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton id="${/parameter/@layout_code}_user_button1" click="masterDs_grid_user_button1" text="身份核验"/>
                <!-- <a:gridButton id="${/parameter/@layout_code}_user_button2" click="masterDs_grid_user_button2" text="二维核验"/> -->
                <a:gridButton id="${/parameter/@layout_code}_user_button3" click="masterDs_grid_user_button3" text="三维核验"/>
                <a:gridButton id="${/parameter/@layout_code}_user_button4" click="masterDs_grid_user_button4" text="四维核验"/>
                <a:gridButton id="${/parameter/@layout_code}_user_button5" click="masterDs_grid_user_button5" text="手机号状态查询"/>
                <a:gridButton id="${/parameter/@layout_code}_user_button6" click="masterDs_grid_user_button6" text="个人交易报告查询"/>
                <a:gridButton id="${/parameter/@layout_code}_user_button7" click="masterDs_grid_user_button7" text="风险信息查询"/>
                <!-- <a:gridButton id="${/parameter/@layout_code}_user_button8" click="masterDs_grid_user_button8" text="四维核验（简项）"/> -->
            </a:screenTopToolbar>
            <a:form column="4" labelWidth="150" marginWidth="80" title="基本信息">
                <a:textField name="bp_code" bindTarget="basic_info_ds" prompt="商业伙伴编码" readOnly="true"/>
                <a:textField name="bp_name" bindTarget="basic_info_ds" prompt="商业伙伴名称" readOnly="true"/>
                <a:textField name="bp_class_n" bindTarget="basic_info_ds" prompt="商业伙伴分类" readOnly="true"/>
                <a:textField name="bp_category_n" bindTarget="basic_info_ds" prompt="商业伙伴类别" readOnly="true"/>
                <a:textField name="id_card_no" bindTarget="basic_info_ds" prompt="身份证" readOnly="true"/>
                <a:textField name="phone" bindTarget="basic_info_ds" prompt="电话" readOnly="true"/>
                <a:textField name="address" bindTarget="basic_info_ds" colspan="2" prompt="地址" readOnly="true" width="468"/>
                <a:textField name="project_number" bindTarget="basic_info_ds" prompt="订单编号" readOnly="true"/>
                <a:textField name="project_name" bindTarget="basic_info_ds" prompt="订单名称" readOnly="true"/>
            </a:form>
            <a:grid bindTarget="chk_list_ds" marginHeight="360" marginWidth="80" navBar="true" showRowNumber="true">
                <a:columns>
                    <a:column name="type_interface_n" align="center" prompt="查询类型" width="230"/>
                    <a:column name="interface_type_result" align="center" prompt="查询结果" renderer="bp_information_renderer" width="590"/>
                    <a:column name="create_time" align="center" prompt="查询时间" width="150"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
