<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: 38823
    $Date: 2024-03-19
    $Revision: 1.0
    $purpose: 佣金政策
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script"
          customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
    </a:init-procedure>
    <a:view>
        <a:link id="${/parameter/@layout_code}commission_detail_link"
                url="${/request/@context_path}/modules/hls/HLS303/bp_agent_bounty_detail.lview"/>
        <script type="text/javascript"><![CDATA[
        $L.onReady(function(){
            debugger;
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hlcm_comsn_policy_hd');
            $(ds_id).setQueryParameter('bp_id','${/parameter/@bp_id}');
            $(ds_id).query();
        });
        //新建
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {
            debugger;
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hlcm_comsn_policy_hd');
            var param={};
            param['bp_id'] = '${/parameter/@bp_id}';
            param['bp_name'] = '${/parameter/@bp_name}';
            param['extra_nam'] = '${/parameter/@extra_nam}';
            param['function_code'] = 'HLS303_BD';
            param['function_usage'] = 'MODIFY';
            param['maintain_type'] = 'CREATE';
            param['winid'] = 'open_commission_detail_window';
            param['url_title'] = '佣金政策维护';
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, '${/parameter/@layout_code}commission_detail_link',ds_id);
        };

        function policy_detail(id, name, query_only){
            debugger;
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hlcm_comsn_policy_hd');
            var record = window['${/parameter/@layout_code}_hls_link_render_record'][id + '---' + name];
            var policy_hd_id=record.get('policy_hd_id');
            var wflStatus=record.get('wfl_status');
            var bpId=record.get('bp_id');
            var param = {};
            if(wflStatus=='NEW' || wflStatus=='APPROVED_RETURN'){
                param['function_code'] = 'HLS303_BD';
                param['function_usage'] = 'MODIFY';
                param['maintain_type'] = 'MODIFY';
                param['url_title'] = '佣金政策维护';
                param['policy_hd_id'] = policy_hd_id;
                param['bp_id'] = bpId;
                param['extra_nam'] = record.get('extra_nam');
            }
            if(wflStatus=='APPROVING' || wflStatus=='APPROVED'){
                param['function_code'] = 'HLS303_BD';
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = 'READONLY'
                param['url_title'] = '佣金政策维护';
                param['policy_hd_id'] = policy_hd_id;
                param['bp_id'] = bpId;
            }
            hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, '${/parameter/@layout_code}commission_detail_link', ds_id, '${/parameter/@layout_code}');

        }
       //删除
        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function () {
            debugger;
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hlcm_comsn_policy_hd');
            Leaf.showConfirm('提示', '是否确认删除', function() {
                debugger;
                var records = $(ds_id).getSelected();
                if(records.length ==0){
                    $L.showMessage('提示','请至少选择一条数据!');
                    return;
                }
                for(var i=0;i<records.length;i++){
                    if(records[i].data.wfl_status == 'APPROVED' || records[i].data.wfl_status == 'APPROVING'){
                        $L.showMessage('提示',' 请选择审批状态为新建/审批退回的单据!');
                        return;
                    }
                    $(ds_id).remove(records[i]);
                }
            });
        };
        //超链接渲染
        window['${/parameter/@layout_code}_dynamic_link_renderer'] = function (value, record, name, config_record) {
            var link_function = '';
            window['${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
            if (name == 'policy_name') {
                link_function = 'policy_detail';
                return '<a href="javascript:window[\'' + link_function + '\'](\'' + record.id + '\',\'' + name + '\',\'' + config_record.get('query_only') + '\');">' +value + '</a>';
            }
        };

        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
