<?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:init-procedure>
        <a:model-query fetchAll="true" model="cont.CON621.con_get_unit_info" rootPath="sys_user"/>
        <a:model-query defaultWhereClause="t1.bp_id=${/parameter/@bp_id_tenant}" fetchAll="true" model="cont.CON621.con_get_bp_info" rootPath="bp_id_tenant"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="leg_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="leg_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <script type="text/javascript"><![CDATA[
            function con621_open_contract_win(record_id, ds_id) {
                var legal_record = $(ds_id).getCurrentRecord();
                var url_id = 'leg_downloadFile_id';
                //if(legal_record.data['legal_letter_id']){
                    var url = $(url_id).getUrl() + '?table_name=LEG_LEGAL_LETTER&header_id=' + legal_record.data['legal_letter_id'];
	                new Leaf.Window({
	                    url: url,
	                    title: '附件',
	                    id: 'leg_legal_letter_id',
	                    width: 850,
	                    height: 400
	                });
                //}else{
                //    Leaf.showMessage('提示','请先保存后再上传附件！');
                //}
            }
            
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                $('${/parameter/@winid}').close();
            };
            
            
            function con620n_attachment_win(record_id,ds_id){
                var record = $(ds_id).findById(record_id);
                var url_id =  'leg_uploadFile_id';
                if(record.data['collection_id']){
	                var url = $(url_id).getUrl() + '?table_name=CON_DUNNING&header_id=' + record.data['collection_id'];
	                new Leaf.Window({
	                    url: url,
	                    title: '附件',
	                    id: 'leg_legal_letter_id',
	                    width: 850,
	                    height: 400
	                }); 
                }else{
                    Leaf.showMessage('提示','请先保存后再上传附件！');
                }
            }
            
            window['${/parameter/@layout_code}_dynamic_link_renderer'] = function(value, record, name, config_record) {
                if (name == 'attachment') {
                    return '<a href="javascript:con620n_attachment_win(\'' + record.id + '\',\'' + record.ds.id + '\')">上传</a>';
                }
                return value;
            };
            //查询时调用(grid,table,gridBox)
            window['${/parameter/@layout_code}_on_layout_dynamic_grid_query'] = function(ds, qpara, bp_seq) {
               var ast_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'ast_collection_record');
               var legal_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'leg_legal_letter');
                if (ds.id == ast_ds_id) {
                    qpara.bp_id_tenant = '${/parameter/@bp_id_tenant}';
                }if (ds.id == legal_ds_id) {
                    qpara.contract_id = '${/parameter/@contract_id}';
                }
            };
            //新增时调用(grid,table,gridBox)
            window['${/parameter/@layout_code}_on_layout_dynamic_grid_add'] = function(ds, record, config_records, bp_seq) {
                record.set('bp_id_tenant', '${/parameter/@bp_id_tenant}');
                record.set('bp_id_tenant_n', '${/model/bp_id_tenant/record/@bp_name}');
                record.set('contact_person', '${/model/bp_id_tenant/record/@contact_person}');
                record.set('cell_phone', '${/model/bp_id_tenant/record/@cell_phone}');
                record.set('phone', '${/model/bp_id_tenant/record/@phone}');
                record.set('fax', '${/model/bp_id_tenant/record/@fax}');
                record.set('collector_user_id', '${/session/@user_id}');
                record.set('collector_user_id_n', '${/model/sys_user/record/@user_desc}');
                record.set('unit_id', '${/model/sys_user/record/@unit_id}');
                record.set('unit_id_n', '${/model/sys_user/record/@unit_name}');
            
            };
            //查询时调用(grid,table,gridBox)
            window['${/parameter/@layout_code}_on_layout_dynamic_grid_query'] = function(ds, qpara, bp_seq) {
                var ast_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'ast_collection_record');
                var legal_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'leg_legal_letter');
                if (ds.id == ast_ds_id) {
            
                    qpara.bp_id_tenant = '${/parameter/@bp_id_tenant}';
 
                }
                if (ds.id == legal_ds_id) {
            
                    qpara.contract_id = '${/parameter/@contract_id}';
 
                }
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
