<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: yimeng  
    $Date: 2014-11-14 
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="con_contract_content_asset_detail_link_id" url="${/request/@context_path}/modules/cont/CON505/con_contract_content_asset_detail.lview"/>
        <a:link id="con_contract_update_print_fin_link_id" url="${/request/@context_path}/modules/prj/PRJ702N/prj_content_print_word.lview"/>
        <a:link id="prj_create_content_link_id" model="prj.PRJ702N.prj_create_content" modelaction="update"/>
        <a:link id="con_contract_link_id" model="prj.PRJ702N.con_contract_print_information" modelaction="update"/>
        <a:link id="con_contract_content_bp_link" model="cont.CON505.con_contract_content_bp_for_lov" modelaction="query"/>
        <a:link id="prj_batch_dl_link_id" url="${/request/@context_path}/modules/prj/PRJ702N/prj_atm_batch_dl.lsc"/>
        <script type="text/javascript"><![CDATA[
            
            function con_print_detail_print() {
                if ($('prj_content_print_detail_line_ds').validate(true)) {
                    var records = $('prj_content_print_detail_line_ds').getSelected();
                    if (records.length == 0) {
                        Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                        return;
                    }
                    for(i=0;i<records.length;i++){               
	                    var record = records[i];
	                    
		               var templt_name, clause_usage = record.get('clause_usage'),
		                    business_type = '${/parameter/@business_type}',
		                    templet_id = record.get('templet_id'),
		                    bp_id = record.get('bp_id'),
		                    bp_class = record.get('bp_class'),
		                    mortgage_id = record.get('mortgage_id') || '',
		                    couple_guarantee_flag = record.get('couple_guarantee_flag'),
		                    content_number = record.get('content_number'),
		                    content_id = record.get('content_id');
	                  
	               	 	var file_path = 'E:\\Coding\\LSH_LEASE\\web\\files\\';
	                    var file_name = content_number;
	                    lock_current_window();
	                    
	                    Leaf.request({
	                        url: $('con_contract_link_id').getUrl(),
	                        para: {
	                            project_id: '${/parameter/@project_id}',
	                        	quotation_id: '${/parameter/@quotation_id}',
	                            content_id: record.get('content_id'),
	                            file_path:file_path,
	                            file_name:file_name,
	                            type:'doc'
	                        },
	                        success: function() {
	                            if (clause_usage == 'FIN') {
	                                templt_name = 'fwfl_fin_contract.xml';
	                                con_name='融资租赁合同';
	                            } else if (clause_usage == 'GUT' && bp_class == 'ORG') {
	                                templt_name = 'fwfl_gut_contract_org.xml';
	                                con_name='保证合同(法人)';
	                            } else if (clause_usage == 'GUT' && bp_class == 'NP') {
	                                templt_name = 'fwfl_gut_contract_np.xml';
	                                con_name='保证合同(自然人)';
	                            } else if (clause_usage == 'OWN') {
	                                templt_name = 'fwfl_own_contract.xml';
	                                con_name='资产转让合同';
	                            } else if (clause_usage == 'PUR') {
	                                templt_name = 'pur_contract.xml';
	                                con_name='购买合同';
	                            } else if (clause_usage == 'MOR') {
	                                templt_name = 'lsh_fin_contract.xml';
	                                con_name='抵押合同';
	                            } else if (clause_usage == 'DEPOSIT') {
	                                templt_name = 'fwfl_dept_contract.xml';
	                                con_name='保证金合同';
	                            } else if (clause_usage == 'COA') {
	                                templt_name = 'coa_contract.xml';
	                                con_name='';
	                            }
	                            var url = $('con_contract_update_print_fin_link_id').getUrl() + '?templt_name=' + templt_name + '&file_path=' + file_path + '&file_name=' + file_name + '&project_id=' + '${/parameter/@project_id}' + '&quotation_id=' + '${/parameter/@quotation_id}';
	                            var form = document.createElement("form");
	                            form.target = "word_export_window";
	                            form.method = "post";
	                            form.action = url;
	                            var iframe = Ext.get('word_export_window') || new Ext.Template('<iframe id ="word_export_window" name="word_export_window" style="position:absolute;left:-10000px;top:-10000px;width:1px;height:1px;display:none"></iframe>').insertFirst(document.body, {}, true);
	                            document.body.appendChild(form);
	                            form.submit();
	                            Ext.fly(form).remove();
	                            unlock_current_window();
	                        },
	                        failure: function() {
	                            unlock_current_window();
	                        },
	                        error: function() {
	                            unlock_current_window();
	                        },
	                        scope: this
	                    });
                    }

                }
            }
            
            function lock_current_window() {
                Leaf.Masker.mask($('${/parameter/@winid}').wrap, '${l:HLS.EXECUTING}');
            }
            
            function unlock_current_window() {
                Leaf.Masker.unmask($('${/parameter/@winid}').wrap);
            }
            
            function con_print_detail_create() {
                lock_current_window();
                Leaf.request({
                    url: $('prj_create_content_link_id').getUrl(),
                    para: {
                        project_id: '${/parameter/@project_id}',
                        quotation_id: '${/parameter/@quotation_id}'
                    },
                    success: function(res) {
                        var result_ds = $('prj_content_print_detail_line_ds');
                        result_ds.query(result_ds.currentPage);
                        unlock_current_window();
                    },
                    error: function() {
                        unlock_current_window();
                    },
                    failure: function() {
                        unlock_current_window();
                    },
                    scope: this
                });
            }
            
            function on_result_load(ds) {
                var records = ds.getAll();
                for (var i = 0;i < records.length;i++) {
                    var record = records[i];
                }
            }
            
            function download_file(value, record, name) {
                var content_id = record.get('content_id');
                return '<a href="javascript:downloadfile_link(' + content_id + ')">下载</a>';
            }
            
            function downloadfile_link(content_id) {
                var url = $('prj_batch_dl_link_id').getUrl() + '?content_id=' + content_id;
                window.open(url, '_self');
            }
            
            function prj_download_zip(){
                var url = $('prj_batch_dl_link_id').getUrl() + '?project_id=' + '${/parameter/@project_id}' + '&quotation_id=' + '${/parameter/@quotation_id}';
                window.open(url, '_self');
            }
            
        ]]></script>
        <a:dataSets>
            <a:dataSet id="basic_clause_tmplet_usage_ds" lookupCode="CON_TMPLET_USAGE"/>
            <a:dataSet id="prj_content_print_detail_line_ds" autoQuery="true" queryUrl="${/request/@context_path}/autocrud/prj.PRJ702N.prj_project_content_v/query?project_id=${/parameter/@project_id}&amp;quotation_id=${/parameter/@quotation_id}" selectable="true" submitUrl="${/request/@context_path}/modules/cont/CON505/con_contract_content_save.lsc">
                <a:fields>
                    <a:field name="clause_usage_name" displayField="code_value_name" options="basic_clause_tmplet_usage_ds" required="true" returnField="clause_usage" valueField="code_value"/>
                    <a:field name="clause_usage"/>
                    <a:field name="templet_name" lovGridHeight="350" lovHeight="500" lovService="basic.con_clause_templet_for_lov" lovWidth="500" title="CON505.CON_CONTENT_TEMPLET_NAME">
                        <a:mapping>
                            <a:map from="templet_id" to="templet_id"/>
                            <a:map from="description" to="templet_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="content_number"/>
                    <a:field name="available_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                </a:fields>
                <a:events>
                    <a:event name="load" handler="on_result_load"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar style="width:860px">
                <a:gridButton click="con_print_detail_create" text="PRJ702.GENERATE_FILE_NAME"/>
                <a:gridButton click="con_print_detail_print" text="PRJ702.GENERATE_THE_FILE"/>
                <a:gridButton click="prj_download_zip" text="PRJ702.THE_FILE_DOWNLOAD"/>
            </a:screenTopToolbar>
            <a:grid id="con_contract_update_print_detail_grid_id" bindTarget="prj_content_print_detail_line_ds" height="350" navBar="true" width="860">
                <a:columns>
                    <a:column name="content_number" prompt="CON505.CON_CONTENT_NUMBER" width="200"/>
                    <a:column prompt="PRJ702.NUMBER_OF_COPIES" width="80"/>
                    <a:column prompt="PRJ702.FILE_GENERATED_DATE" width="80"/>
                    <a:column name="bp_name" prompt="HLS.BP_NAME"/>
                    <a:column name="bp_category_desc" prompt="HLS.BP_CATEGORY"/>
                    <a:column name="content_print_flag_name" prompt="CON505.CON_CONTENT_STATUS" width="80"/>
                    <a:column name="attachment" align="center" prompt="PROMPT.DOWNLOAD" renderer="download_file" width="50"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>