<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: wangwei  
    $Date: 2016-1-8 下午2:18:21  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:view>
        <a:link id="${/parameter/@layout_code}_hls_fin_doc_quotation_link_id" url="${/request/@context_path}/modules/hls/HLS500/hls_fin_doc_quotation.lsc"/>
        <a:link id="${/parameter/@layout_code}_hls_fin_calculator_update_link_id" url="${/request/@context_path}/modules/hls/HLS500N/hls_fin_calculator_update_n.lview"/>
        <a:link id="${/parameter/@layout_code}_hls_fin_calculator_readonly_link_id" url="${/request/@context_path}/modules/hls/HLS500/hls_fin_calculator_readonly.lview"/>
        <a:link id="confirm_sdic_other_con_write_off_link_id" model="sdic.SDIC110.sdic_other_con_write_off" modelaction="batch_update"/>
        <script type="text/javascript"><![CDATA[
           
            
            //报价
            
            function quote_link(name, record_id, query_only) {
                window['${/parameter/@layout_code}_lock_layout_dynamic_window'];
                var head_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'sdic_other_contract');
                var head_record = $(head_ds_id).getAt(0);
                var prj_quotation_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_quotation');
                //var prj_quotation_record = $(prj_quotation_ds_id).getCurrentRecord();
                var prj_quotation_record = $(prj_quotation_ds_id).findById(record_id);
                var calc_recreate_L_formula;
                var saveData = [];
                if (prj_quotation_record.get('wfl_status') == 'APPROVING' || prj_quotation_record.get('wfl_status') == 'APPROVED' || query_only == 'Y' || prj_quotation_record.get('main_contract_flag') == 'Y') {
                    url = $('${/parameter/@layout_code}_hls_fin_calculator_readonly_link_id').getUrl();
                    new Leaf.Window({
                        id: '${/parameter/@layout_code}_hls_fin_calc_readonly_link_winid',
                        params: {
                            document_id: head_record.get('contract_id'),
                            document_category: head_record.get('document_category'),
                            maintain_type: 'READONLY',
                            calc_session_id: prj_quotation_record.get('calc_session_id'),
                            winId: '${/parameter/@layout_code}_hls_fin_calc_readonly_link_winid',
                            global_flag: 'Y',
                            calc_type: 'CLASSIC_CALCULATOR'
                        },
                        url: url,
                        fullScreen: true,
                        draggable: true
                    });
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window'];
                    return;
                } else {
                    url = $('${/parameter/@layout_code}_hls_fin_calculator_update_link_id').getUrl();
            
                    prj_quotation_record.set('to_doc_table', 'HLS_FIN_CALCULATOR_HD');
                    prj_quotation_record.set('function_code', '${/parameter/@function_code}');
                    prj_quotation_record.set('function_usage', '${/parameter/@function_usage}');
                    prj_quotation_record.set('document_id', head_record.get('contract_id'));
            
                    if (prj_quotation_record.get('quotation_id') && !prj_quotation_record.get('calc_session_id')) {
                        calc_recreate_L_formula = 'Y';
                        prj_quotation_record.set('_status', 'update');
                    } else if (prj_quotation_record.get('quotation_id') && prj_quotation_record.get('calc_session_id')) {
                        calc_recreate_L_formula = 'N';
                        prj_quotation_record.set('_status', 'execute');
                    } else if (!head_record.get('contract_id')) {
                        Leaf.showMessage('${l:HLS.PROMPT}', '${l:HLS.EXECUTE_AFTER_SAVE}');
                        return;
                    } else {
                        calc_recreate_L_formula = 'Y';
                        prj_quotation_record.set('_status', 'insert');
                    }
            
                    prj_quotation_record.set('from_doc_table', 'PRJ_QUOTATION');
                    prj_quotation_record.set('from_doc_pk', prj_quotation_record.get('quotation_id'));
                    prj_quotation_record.set('calculate_flag', 'N');
                    saveData.push(prj_quotation_record.data);
                    Leaf.request({
                        url: $('${/parameter/@layout_code}_hls_fin_doc_quotation_link_id').getUrl(),
                        para: saveData,
                        success: function(res) {
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window'];
                            var quotation_id = prj_quotation_record.get('quotation_id') || res.result.quotation_id;
                            var win = new Leaf.Window({
                                id: '${/parameter/@layout_code}_hls_fin_calc_quotation_link_winid',
                                params: {
                                    document_id: head_record.get('contract_id'),
                                    document_category: '${/parameter/@document_category}',
                                    maintain_type: '${/parameter/@maintain_type}',
                                    calc_session_id: res.result.record.calc_session_id,
                                    quotation_id: quotation_id,
                                    dsId: prj_quotation_ds_id,
                                    winId: '${/parameter/@layout_code}_hls_fin_calc_quotation_link_winid',
                                    global_flag: 'Y',
                                    id_num: 0,
                                    calc_type: 'CLASSIC_CALCULATOR',
                                    recreate_L_formula: calc_recreate_L_formula
                                },
                                url: url,
                                // title: '${l:HLS.FIN_CALCULATOR}',
                                fullScreen: true,
                                draggable: true
                            });
                            win.on('close', function() {
                                $(prj_quotation_ds_id).setQueryParameter('chance_id', prj_quotation_record.get('chance_id'));
                                //$(hls_fin_calculator_ln_ds_id).setQueryParameter('project_id', project_id);
                                $(prj_quotation_ds_id).query();
                                //$(hls_fin_calculator_ln_ds_id).query();
                                window['${/parameter/@layout_code}_unlock_layout_dynamic_window'];
                            });
                        },
                        failure: function() {
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window'];
                        },
                        error: function() {
                            window['${/parameter/@layout_code}_unlock_layout_dynamic_window'];
                        },
                        scope: this
                    });
                }
            }
            
            //超链接渲染
            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 === 'quote' && !record.isNew) {
                    return '<a href="javascript:quote_link(\'' + name + '\',\'' + record.id + '\',\'' + config_record.get('query_only') + '\')">报价</a>';
                } else {
                    return '';
                }
            };
            
            
            
            // window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function() {
            // window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            // var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'sdic_other_contract');
            // var quote_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_quotation');
            // var head_record = $(ds_id).getAt(0);
            // var quotation_rec = $(quote_ds_id).getSelected()[0];
            
            // Leaf.showConfirm('${HLS.PROMPT}', '确认提交当前所选单据吗？', function() {
            // Leaf.request({
            // url: $('sdic110d_other_contract_quotation_submit_link_id').getUrl(),
            // para: {
            // contract_id: head_record.get('contract_id'),
            // quotation_id: quotation_rec.get('quotation_id')
            // },
            // success: function(res) {
            // window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            // Leaf.SideBar.show({
            // msg: '${l:HLS.SUBMIT_SUCCESS}',
            // duration: 2000
            // });
            // $(quote_ds_id).query();
            // },
            // failure: function() {
            // window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            // },
            // error: function() {
            // window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            // },
            // scope: this
            // });
            // }, function() {
            // window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            // });
            
            //确定
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'sdic_other_con_write_off');
                var records = $(ds_id).getSelected();
                if (records.length == 0) {
                    Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                    return;
                }
                var param_list = [];
                var param = {};
                for (var i = 0;i < records.length;i++) {
                    var write_off_id = records[i].get('write_off_id');
                    if (!write_off_id) {
                        Leaf.showMessage('${l:PROMPT}', '请先保存数据再确认！');
                        return;
                    }
                    param = {
                        'write_off_id': records[i].get('write_off_id'),
                        '_status': 'update'
                    };
                    param_list.push(param);
                }
                window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.showConfirm('${HLS.PROMPT}', '是否确认当前款项？', function() {
                Leaf.request({
                    url: $('confirm_sdic_other_con_write_off_link_id').getUrl(),
                    para: param_list,
                    success: function(res) {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        $(ds_id).query();
                    },
                    failure: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function() {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    scope: this
                });
                 }, function() {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                });
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
