<?xml version="1.0" encoding="UTF-8"?>
<!--
  create by nyl  2014-12-3 
  for contract context create
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:view>
        <a:link id="con644_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="con_penalty_pending_change_link_id" model="cont.CON644.con_contract_change" modelaction="batch_update"/>
        <a:link id="con644_import_upload_link" url="${/request/@context_path}/modules/cont/CON644/cus_con_pending_upload.lview"/>
        <a:link id="con_contract_modify_link" url="${/request/@context_path}/modules/cont/CON301/con_contract_query_n.lview"/>
        <script type="text/javascript"><![CDATA[
            //导出
            window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function() {
            
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                var grid_id = ds_id.replace('ds', 'layout_grid_id');
                $(grid_id)._export('xls', '${/model/default_function_name/record/@function_name}');
            
            
            };
            
            //修改
            window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            
            
                var records = $(ds_id).getSelected();
                if (records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '请选择需要修改合同数据');
                    return;
                }
                var datas = [];
                for (var i = 0;i < records.length;i++) {
                    if (records[i].dirty) {
                        var obj = {};
                        obj['contract_id'] = records[i].get('contract_id');
                        obj['penalty_nowrite_off_flag'] = records[i].get('penalty_nowrite_off_flag');
                        obj['penalty_release_date'] = records[i].get('penalty_release_date');
                        obj['penalty_nowrite_off_date'] = records[i].get('penalty_nowrite_off_date');
            
                        obj['_status'] = 'update';
                        datas[i] = obj;
                    }
                }
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: $('con_penalty_pending_change_link_id').getUrl(),
                    para: datas,
                    success: function(res) {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        Leaf.SideBar.show({
                            msg: '${l:HLS.SUBMIT_SUCCESS}',
                            duration: 2000
                        });
                        $(ds_id).query();
                    },
                    failure: function() {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function() {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
            
            
            
            };
            
            
            function open_contract_win(ds_id, record_id) {
                var record = $(ds_id).findById(record_id);
                var param = record.data;
                param['function_code'] = 'CON301R';
                param['function_usage'] = 'QUERY';
                param['maintain_type'] = 'QUERY';
                param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
                hls_doc_get_layout_code('con644_get_layout_code_link_id', param, 'con_contract_modify_link', ds_id);
            }
            
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
                if (name == 'contract_number' && value) {
                    return '<a href="javascript:open_contract_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'], 'con_contract');
                new Leaf.Window({
                    id: 'upload_window',
                    url: $('con644_import_upload_link').getUrl(),
                    params: {
                        session_id: '${/session/@session_id}',
                        winid: 'upload_window',
                        function_code: '${/parameter/@function_code}',
                        parent_ds_id: ds_id
                    },
                    title: '罚息暂挂导入',
                    width: 420,
                    height: 280
                });
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
