<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: 38823
    $Date: 2023-01-09
    $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="asset_wfl_link_id"
                url="${/request/@context_path}/modules/hls/HLS303/bp_asset_batch.lsc"/>
        <script type="text/javascript"><![CDATA[
        $L.onReady(function(){
            debugger;
            if('${/parameter/@function_usage}' == 'MODIFY'){
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'asset_management_fee');
                $(ds_id).setQueryParameter('agent_division_id','${/parameter/@agent_division_id}');
                $(ds_id).query();
            }
            if('${/parameter/@function_usage}' == 'QUERY'){
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'asset_management_fee');
                $(ds_id).setQueryUrl('${/request/@context_path}/autocrud/hls.HLS303.asset_wfl_approval/query');
                $(ds_id).setQueryParameter('asset_batch_id','${/parameter/@asset_batch_id}');
                $(ds_id).query();
                if(document.getElementById('${/parameter/@layout_code}_exit')){
                    $jq('#${/parameter/@layout_code}_exit').hide();
                }
                if(document.getElementById('${/parameter/@layout_code}_submit_approval')){
                    $jq('#${/parameter/@layout_code}_submit_approval').hide();
                }
                //uat环境设置query只会不能对grid按钮隐藏处理
                if($jq('#${/parameter/@layout_code}_ASSET_FEE_ADD_layout_dynamic_button_id')){
                    $jq('#${/parameter/@layout_code}_ASSET_FEE_ADD_layout_dynamic_button_id').hide();
                }
                if($jq('#${/parameter/@layout_code}_ASSET_FEE_SAVE_layout_dynamic_button_id')){
                    $jq('#${/parameter/@layout_code}_ASSET_FEE_SAVE_layout_dynamic_button_id').hide();
                }
                if($jq('#${/parameter/@layout_code}_ASSET_FEE_USER_BUTTON1_layout_dynamic_button_id')){
                    $jq('#${/parameter/@layout_code}_ASSET_FEE_USER_BUTTON1_layout_dynamic_button_id').hide();
                }
            }
        });
        //加载时调用(grid,table,gridBox)
        window['${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function(ds, record, config_records, bp_seq) {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'asset_management_fee');
            if(ds_id){
                var record = $(ds_id).getAll();
                for(var i=0;i<record.length;i++){
                    if(record[i].get('wfl_status')=='APPROVED' || record[i].get('wfl_status')=='APPROVING'){
                        record[i].getField('group_rate').setReadOnly(true);
                        record[i].getField('internal_rate').setReadOnly(true);
                        record[i].getField('external_rate').setReadOnly(true);
                    }
                }
            }
        };
        //新增时调用(grid,table,gridBox)
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_add'] = function(ds, record, config_records, bp_seq) {
            var line_records = ds.getAll();
            for (var i = 0;i < line_records.length;i++) {
                if(line_records[i].get('asset_id') == undefined){
                    line_records[i].set('wfl_status','NEW');
                    line_records[i].set('wfl_status_n','新建');
                    line_records[i].set('bp_id','${/parameter/@bp_id}');
                    line_records[i].set('agent_division_id','${/parameter/@agent_division_id}');
                    line_records[i].set('division','${/parameter/@division}');
                }
            }
        };

        //提交审批
        window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function() {
            debugger;
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'asset_management_fee');
            var records = $(ds_id).getSelected();
            var ParaData = [];
            if(records.length ==0){
                $L.showMessage("提示",'请至少选择一条数据！');
                return;
            }
            for(var i=0; i<records.length;i++){
                if(records[i].data.wfl_status == 'APPROVING' || records[i].data.wfl_status == 'APPROVED'){
                    $L.showMessage("提示",'请选择新建或者审批拒绝的单据！');
                    return;;
                }
                records[i].set('_status','execute');
                ParaData.push(records[i].data);
            }
            Leaf.showConfirm('${l:PROMPT}', '确认提交资产管理费组合利率审批工作流?', function () {
                Leaf.request({
                    url: $('asset_wfl_link_id').getUrl(),
                    para: ParaData,
                    success: function () {
                        Leaf.SideBar.show({
                            msg: '提交成功',
                            duration: 2000
                        });
                        $(ds_id).query();
                    },
                    scope: this
                });
            }, function () {
            }, null, null);
        };
        //删除
        window['${/parameter/@layout_code}_ASSET_FEE_USER_BUTTON1_layout_dynamic_tab_click'] = function() {
             var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'asset_management_fee');
             Leaf.showConfirm('提示', '是否确认删除', function() {
                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]);
                }
            });
        };

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