<?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 defaultWhereClause="t1.function_code = ${/parameter/@function_code}" model="cus.CUS100.cus_default_function_name" rootPath="default_function_name"/>
        <a:model-query defaultWhereClause="t1.specify_code=&apos;AMC_APPROVER&apos;" model="cont.CON543.cus_hls_specify_define" rootPath="hls_specify_define_info"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con638_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="legal_letter_cancel_link_id" model="cont.CON610.leg_legal_letter_submit" modelaction="execute"/>
        <a:link id="legal_letter_submit_link_id" model="cont.CON610.leg_legal_letter_submit" modelaction="update"/>
        <a:link id="con543_prj_secify_approver_link" url="${/request/@context_path}/modules/prj/PRJ501N/cus_hls_specify_approver.lview"/>
        <script type="text/javascript"><![CDATA[
            function con610d_window_close() {
                $('${/parameter/@winid}').close();
            
            }
            function get_confirm_flag(){
                return 'N';
            }
            //提交审批
            
            function con610_submit() {
                var document_id = ${/parameter/@letter_hd_id};
                var document_table = 'LEG_LEGAL_LETTER_HD';
                var title = '${/model/hls_specify_define_info/record/@description}';
                var win = new Leaf.Window({
                    id: 'cus_prj_secify_approver_screen',
                    url: $('con543_prj_secify_approver_link').getUrl(),
                    params: {
                        document_id: document_id,
                        specify_code: 'AMC_APPROVER'
                    },
                    title: title,
                    width: 550,
                    heigh: 650
                });
                win.on('close', function() {
                    ajax_flag = 'Y';
              		var confirm_flag = get_confirm_flag();
              		if (confirm_flag=='Y'){
              		   window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            		
                    Leaf.request({
                        url: $('legal_letter_submit_link_id').getUrl(),
                        para: {
                            letter_hd_id: '${/parameter/@letter_hd_id}'
                        },
                        success: function(res) {
                            window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                            Leaf.SideBar.show({
                                msg: '${l:HLS.SUBMIT_SUCCESS}',
                                duration: 2000
                            });
            
                            con610d_window_close();
            
                        },
                        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
                    });
              		}
                  });    
            }
            
            //提交审批
            window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function() {
            
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'leg_legal_letter_tmp');
                var info = '';
                if (ds_id) {
                    if (!$(ds_id).validate(true)) {
                        return;
                    }
                    var records = $(ds_id).getAll();
                    for (var i = 0;i < records.length;i++) {
                        if (records[i].dirty == true) {
                            Leaf.showMessage('提示', '请先保存！', null, 350);
                            return;
                        }
                        if (records[i].get('send_count') >= 1) {
                            info = '合同号为' + records[i].get('search_term_1') + '发函次数为' + records[i].get('send_count') + ',';
                        }
            
            
                    }
                    if (info.length > 1) {
                        Leaf.showConfirm('${l:PROMPT}', info, function okFun() {
                            Leaf.showConfirm('${l:PROMPT}', '是否确认地址信息？', function okFun() {
                                con610_submit();
                            });
                        });
                    } else {
            
                        Leaf.showConfirm('${l:PROMPT}', '是否确认地址信息？', function okFun() {
                            con610_submit();
            
                        });
                    }
                }
            
            };
            
            //提交审批
            /*  window['${/parameter/@layout_code}_submit_approval_layout_dynamic_click'] = function() {
             window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
             Leaf.request({
             url: $('legal_letter_submit_link_id').getUrl(),
             para:  {
             letter_hd_id: '${/parameter/@letter_hd_id}'
             },
             success: function(res) {
             window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
             Leaf.SideBar.show({
             msg: '${l:HLS.SUBMIT_SUCCESS}',
             duration: 2000
             });
             con610d_window_close();
             },
             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
             });
             }; */
            
            //撤销
            window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function() {
            
            
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
                Leaf.request({
                    url: $('legal_letter_cancel_link_id').getUrl(),
                    para: {
                        letter_hd_id: '${/parameter/@letter_hd_id}'
                    },
                    success: function(res) {
                        window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        Leaf.SideBar.show({
                            msg: '${l:HLS.SUBMIT_SUCCESS}',
                            duration: 2000
                        });
            
                        con610d_window_close();
                    },
                    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
                });
            
            
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
