<?xml version="1.0" encoding="UTF-8"?>

<!--
    $Author:Think
    $Date: 2018/8/2
    $Revision: 1.0
    微件-客户管理
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure/>
    <a:view template="default" package="leaf.ui.std">
        <a:link id="widget_hls_bp_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>
        <a:link id="widget_hls_bp_master_modify_link"
                url="${/request/@context_path}/modules/hls/HLS214N/hls_bp_master_modify.lview"/>
        <a:link id="widget_hls_bp_master_authorize_pkg_link_id" model="hls.HLS214N.bgfl_bp_master_authorize_pkg"
                modelaction="execute"/>
        <a:link id="widget_hls_bp_master_add_link_id"
                url="${/request/@context_path}/modules/hls/HLS213N/hls_bp_master_create_entrance.lview"/>
        <style>
            html, body {
                width: 840px;
                height: 648px;
                margin: 0;
                padding: 0;
            }

            .widget-bp-manege {
                width: 840px;
                height: 648px;
                background: #FFFFFF;
                border: 1px solid #F0F0F3;
            }

            .widget-bp-manege .widget_label {
                position: absolute;
                width: 40px;
                height: 4px;
                top: 0;
                left: 16px;
                background-color: #5A7FFF;
            }

            .widget-bp-manege .title {
                position: relative;
                padding: 10px 0 12px 16px;
                font-size: 14px;
                color: rgba(75, 80, 90, 1);
                letter-spacing: 0;
                border-bottom: 1px solid #F0F0F3;
            }

            .widget-bp-manege .add-button {
                width: 100%;
            / / height: 48 px;
                border-bottom: 1px solid #F0F0F3;
            }

            .widget-bp-manege .add-button .new-button {
                width: 72px;
                height: 24px;
                background: #7386FF;
                border-radius: 2px;
                font-size: 12px;
                color: #FFFFFF;
                letter-spacing: 0;
                text-align: center;
                line-height: 22px;
                margin: 12px 16px;
                cursor: pointer;
            }

            .widget-bp-manege .form {
                height: 206px;
                border-bottom: 1px solid #F0F0F3;
            }

            .widget-bp-manege .form .content {
                height: 24px;
                line-height: 24px;
                margin-left: 17px;
                margin-top: 16px;
            }

            .widget-bp-manege .form .content:first-child {
                margin-bottom: 18px;
            }

            .widget-bp-manege .form .label {
                display: inline-block;
                font-size: 14px;
                color: #4B505A;
                text-align: left;
                min-width: 90px;
                float: left;
                margin-right: 16px;
            }

            .widget-bp-manege .form input[type='text'] {
                box-sizing: border-box;
                width: 200px;
                height: 24px;
                margin: 0 30px 0px 0px;
                padding-left: 8px;
                display: inline-block;
                border: 1px solid rgba(83, 93, 127, 0.60);
                border-radius: 2px;
                font-size: 12px;
                color: rgba(75, 80, 90, 0.85);
            }

            .widget-bp-manege .form .ckeck-box {
                display: inline-block;
                text-align: center;
                float: left;
                height: 24px;
                line-height: 24px;
                font-size: 14px;
                color: rgba(0, 0, 0, 0.65);
                letter-spacing: 0;
                min-width: 88px;
                margin-right: 24px;
                cursor: pointer;

            }

            .widget-bp-manege .form .ckeck-box img {
                width: 16px;
                height: 16px;
                margin-right: 8px;
                margin-top: 4px;
                float: left;
            }

            .widget-bp-manege .form .ckeck-box span {
                font-size: 14px;
                color: #4B505A;
                text-align: left;
                min-width: 60px;
                float: left;
            }

            .widget-bp-manege .form .content .submit-button {
                float: right;
                width: 64px;
                height: 24px;
                line-height: 24px;
                margin-right: 8px;
                font-size: 12px;
                letter-spacing: 0;
                text-align: center;
                cursor: pointer;
            }

            .widget-bp-manege .form .content .button-blue {
                background-color: rgba(90, 127, 255, 1);
                color: #fff;
                border-radius: 2px;
            }

            .widget-bp-manege .form .content .button-default {
                width: 62px;
                height: 22px;
                line-height: 22px;
                border: 1px solid rgba(83, 93, 127, 0.30);
                border-radius: 2px;
                color: rgba(83, 93, 127, 1);
                margin-right: 24px;
            }

            .widget-bp-manege .hls-pagging-grid {
                width: 100%;
                height: 345px;
                -webkit-box-shadow: none;
                box-shadow: none;
            }

            .widget-bp-manege .hls-pagging-grid .grid-title {
                display: none;
            }

            .widget-bp-manege .hls-pagging-grid .grid-body {
                padding: 0;
            }

            .widget-bp-manege .hls-pagging-grid .hls-table tr td {
                text-align: center;
            }

            /*表头*/
            .widget-bp-manege .hls-pagging-grid .grid-body table > tr {
                height: 48px;
                border-bottom: 1px solid #F0F0F3;
                font-size: 14px;
                color: rgba(83, 93, 127, 1);
            }

            .widget-bp-manege .hls-pagging-grid .hls-table tr td {
                text-align: center;

            }

            .widget-bp-manege .hls-pagging-grid .hls-table tbody tr {
                height: 48px !important;
                font-size: 14px !important;
                color: rgba(0, 0, 0, 0.65);
                letter-spacing: 0;
                border-bottom: 1px solid #F0F0F3;
            }

            .widget-bp-manege .hls-pagging-grid .hls-table tbody td {
                max-width: 13em;
            }

            .widget-bp-manege .hls-pagging-grid .hls-table tbody td div p {
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
            }

            .widget-bp-manege .hls-pagging-grid .hls-table tbody tr:hover {
                background: rgba(90, 127, 255, 0.08);
            }

            .widget-bp-manege .hls-table-active {
                background-color: rgba(90, 127, 255, 0.08);
            }

            .widget-bp-manege .hls-pagging-grid .icon {
                cursor: pointer;
                width: 16px;
                height: 16px;
            }

        </style>
        <script><![CDATA[
        var we_bp_class = [];
        var we_bp_category = [];
        var we_collection = [];
        function we_isInArray(arr, value) {
            var index = jQuery.inArray(value, arr);
            if (index >= 0) {
                return true;
            }
            return false;
        }
        function we_removeArray(arr, item) {
            var result = [];
            arr.forEach(function (value) {
                if (value != item) {
                    result.push(value);
                }
            });
            return result;
        }

        function chooseBox(dom, type) {
            jQuery(dom).children(":first")[0].src = "${/request/@context_path}/leafresource/images/checkbox-selected@2x.png";
            if (type == 'CLASS') {
                var temp = jQuery(dom).children(":last").attr('data-bp-class');
                if (we_isInArray(we_bp_class, temp)) {
                    we_bp_class = we_removeArray(we_bp_class, temp);
                    jQuery(dom).children(":first")[0].src = "${/request/@context_path}/leafresource/images/checkbox-default@2x.png";
                } else {
                    we_bp_class.push(temp);
                }
            } else if (type == 'CATEGORY') {
                var temp = jQuery(dom).children(":last").attr('data-bp-category');
                if (we_isInArray(we_bp_category, temp)) {
                    we_bp_category = we_removeArray(we_bp_category, temp);
                    jQuery(dom).children(":first")[0].src = "${/request/@context_path}/leafresource/images/checkbox-default@2x.png";
                } else {
                    we_bp_category.push(temp);
                }
            } else {
                var temp = jQuery(dom).children(":last").attr('data-collect');
                if (we_isInArray(we_collection, temp)) {
                    we_collection = we_removeArray(we_collection, temp);
                    jQuery(dom).children(":first")[0].src = "${/request/@context_path}/leafresource/images/checkbox-default@2x.png";
                } else {
                    we_collection.push(temp);
                }
            }
        }

        function resetForm() {
            //window.location.reload();
            we_bp_class = [];
            we_bp_category = [];
            we_collection = [];
            $jq('[name="wei_bp_name"]').val('');
            jQuery(".ckeck-box-img").attr("src", "${/request/@context_path}/leafresource/images/checkbox-default@2x.png");
            $("hls_bp_master_comp_assign_ds_id").qpara = {};
            $("hls_bp_master_comp_assign_ds_id").query();
        }

        function queryForm() {
            var qbp_class = we_bp_class.join(",");
            var qbp_category = we_bp_category.join(",");
            var bp_name = $jq('[name="wei_bp_name"]').val();
            var queryParam = {
                "bp_class": qbp_class,
                "bp_category": qbp_category,
                "bp_name": bp_name
            }
            $("hls_bp_master_comp_assign_ds_id").qpara = queryParam;
            $("hls_bp_master_comp_assign_ds_id").query();

        }
        function open_bp_modify_win(ds_id, record_id) {
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            Leaf.request({
                url: $('widget_hls_bp_master_authorize_pkg_link_id').getUrl(),
                para: {
                    bp_id: record.get('bp_id')
                },
                success: function (res) {
                    var bp_type = param['bp_type'];
                    if (res.result.opt_type === 'MODIFY') {
                        if (record.get('bp_class') == 'NP') {
                            param['function_code'] = 'HLS214S';
                        } else {
                            if (bp_type == 'INTERMEDIARY_AGENCY') {
                                param['function_code'] = 'HLS214D_MI';
                            } else {
                                param['function_code'] = 'HLS214D';
                            }
                        }
                        param['cond_para2'] = param['bp_type'];
                        param['function_usage'] = 'MODIFY';
                        param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                        hls_doc_get_layout_code('widget_hls_bp_get_layout_code_link_id', param, 'widget_hls_bp_master_modify_link', ds_id);
                    } else {
                        param['cond_para2'] = param['bp_type'];
                        if (bp_type == 'INTERMEDIARY_AGENCY') {
                            param['function_code'] = 'HLS306_MI';
                        } else {
                            param['function_code'] = 'HLS306';
                        }
                        param['function_usage'] = 'QUERY';
                        param['url_title'] = '${l:HLS212.BP_MASTER_MAINTAIN}';
                        hls_doc_get_layout_code('widget_hls_bp_get_layout_code_link_id', param, 'widget_hls_bp_master_modify_link', ds_id);
                    }
                },
                failure: function () {
                },
                error: function () {
                },
                scope: this
            });
        }

        function clange_img(dom) {
            //jQuery(dom).src=
        }
        function hls_bp_collect_renderer(record, index) {
            return "<img onclick='clange_img(this)' class='icon' src='${/request/@context_path}/leafresource/images/uncollect@2x.png'/>";
        }
        function hls_bp_details_renderer(record, index) {
            return "<img onclick='open_bp_modify_win(\"" + record.ds.id + "\",\"" + record.id + "\")' class='icon' src='${/request/@context_path}/leafresource/images/menu-details@2x.png'/>";
        }

        function addBpMaster() {
            var param = {};
            param['function_code'] = 'HLS213N';
            param['function_usage'] = 'CREATE';
            param['url_title'] = ' ';
            param['screen_width'] = 410;
            param['screen_height'] = 350;
            param['pre_layout_code'] = '${/parameter/@layout_code}';
            hls_doc_get_layout_code('widget_hls_bp_get_layout_code_link_id', param, 'widget_hls_bp_master_add_link_id', 'hls_bp_master_comp_assign_ds_id');
        }
        ]]>

        </script>
        <a:dataSets>
            <a:dataSet id="hls_bp_master_comp_assign_ds_id" autoQuery="true"
                       model="hls.HLS214N.hls_bp_master_comp_assign" pageSize="5">
                <a:fields>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <div class="widget-bp-manege">
            <span class="widget_label"> </span>
            <div class="title">客户管理</div>
            <div class="add-button">
                <div class="new-button" onclick="addBpMaster()">客户新增</div>
            </div>
            <div class="form">
                <div class="content">
                    <span class="label">客户编码/名称</span>
                    <input type="text" id="wei_bp_name" name="wei_bp_name" placeholder="客户编码/名称"/>
                </div>
                <div class="content">
                    <span class="label">分类</span>
                    <div class="ckeck-box" onclick="chooseBox(this,'CLASS')">
                        <img class="ckeck-box-img"
                             src="${/request/@context_path}/leafresource/images/checkbox-default@2x.png"/>
                        <span data-bp-class="'NP'">自然人</span>
                    </div>
                    <div class="ckeck-box" onclick="chooseBox(this,'CLASS')">
                        <img class="ckeck-box-img"
                             src="${/request/@context_path}/leafresource/images/checkbox-default@2x.png"/>
                        <span data-bp-class="'ORG'">企业</span>
                    </div>
                </div>
                <div class="content">
                    <span class="label">角色</span>
                    <div class="ckeck-box" onclick="chooseBox(this,'CATEGORY')">
                        <img class="ckeck-box-img"
                             src="${/request/@context_path}/leafresource/images/checkbox-default@2x.png"/>
                        <span data-bp-category="'TENANT'">承租人</span>
                    </div>
                    <div class="ckeck-box" onclick="chooseBox(this,'CATEGORY')">
                        <img class="ckeck-box-img"
                             src="${/request/@context_path}/leafresource/images/checkbox-default@2x.png"/>
                        <span data-bp-category="'VENDER'">供应商</span>
                    </div>
                    <div class="ckeck-box" onclick="chooseBox(this,'CATEGORY')">
                        <img class="ckeck-box-img"
                             src="${/request/@context_path}/leafresource/images/checkbox-default@2x.png"/>
                        <span data-bp-category="'GUARANTOR'">担保人</span>
                    </div>
                    <div class="ckeck-box" onclick="chooseBox(this,'CATEGORY')">
                        <img class="ckeck-box-img"
                             src="${/request/@context_path}/leafresource/images/checkbox-default@2x.png"/>
                        <span data-bp-category="'INSURER'">保险人</span>
                    </div>
                    <div class="ckeck-box" onclick="chooseBox(this,'CATEGORY')">
                        <img class="ckeck-box-img"
                             src="${/request/@context_path}/leafresource/images/checkbox-default@2x.png"/>
                        <span data-bp-category="'PLEDGER'">抵质押人</span>
                    </div>
                    <div class="ckeck-box" onclick="chooseBox(this,'CATEGORY')">
                        <img class="ckeck-box-img"
                             src="${/request/@context_path}/leafresource/images/checkbox-default@2x.png"/>
                        <span data-bp-category="'BORROWER_ORGANIZATION'">贷款机构</span>
                    </div>
                </div>
                <div class="content">
                    <span class="label">收藏标志</span>
                    <div class="ckeck-box" onclick="chooseBox(this,'')">
                        <img class="ckeck-box-img"
                             src="${/request/@context_path}/leafresource/images/checkbox-default@2x.png"/>
                        <span data-collect="'Y'">收藏</span>
                    </div>
                    <div class="ckeck-box" onclick="chooseBox(this,'')">
                        <img class="ckeck-box-img"
                             src="${/request/@context_path}/leafresource/images/checkbox-default@2x.png"/>
                        <span data-collect="'N'">未收藏</span>
                    </div>
                </div>
                <div class="content">
                    <div class="submit-button button-default" onclick="resetForm()">重置</div>
                    <div class="submit-button button-blue" onclick="queryForm()">查询</div>
                </div>
            </div>
            <div class="body">
                <a:hapGrid id="hls_bp_master_grid" bindTarget="hls_bp_master_comp_assign_ds_id" canWheel="true">
                    <a:columns>
                        <a:column name="bp_code" prompt="客户编码"/>
                        <a:column name="bp_name" prompt="客户名称"/>
                        <a:column name="bp_category_n" prompt="角色"/>
                        <a:column name="bp_class_n" prompt="分类"/>
                        <!--<a:column name="lease_item_amount" prompt="业务部门"/>-->
                        <a:column name="owner_user_id_n" prompt="项目经理"/>
                        <a:column template="hls_bp_collect_renderer" prompt="收藏"/>
                        <a:column template="hls_bp_details_renderer" prompt="明细"/>
                        <!--<a:column template="con_asset_securitization_renderer" prompt="资产证券化"/>-->
                    </a:columns>
                </a:hapGrid>
            </div>
        </div>

        <a:screenBody style="display:none">

        </a:screenBody>
        <!--<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>