<?xml version="1.0" encoding="UTF-8"?>
<!--
    2019-09-17 回购 维护
    
 -->
<a:screen xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <!--<a:link id="con_contract_repo_modify_link" url="${/request/@context_path}/modules/cont/CON501N/con_contract_modify.lview"/>-->
	  <a:link id="con_contract_repo_modify_link" url="${/request/@context_path}/modules/cont/CON3200/con_re_incept_modify.lview"/>
     <a:link id="con_contract_repo_change_link" url="${/request/@context_path}/modules/cont/CON_REPO001/con_contract_change_repo_detail.lview"/>
        <a:link id="con_grant_deduct_print_link" url="${/request/@context_path}/modules/cont/CON732/hls_ccr_modify_assignment_agreement_print.lsc"/>
        <a:link id="con_crr_query_print_link_id" url="${/request/@context_path}/modules/cont/CON732/hls_crr_query_print_word_detail.lview"/>
        <script type="text/javascript"><![CDATA[
            function open_contract_win(ds_id, record_id) {
                var record = $(ds_id).findById(record_id);
                var param = record.data;
                param['function_code'] = 'CON3200Q';
                param['function_usage'] = 'QUERY';
                param['contract_id'] = record.get('normal_contract_id');
                param['download'] = 'Y';
               /* param['maintain_type'] = 'UPDATE';*/
                param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_repo_modify_link', ds_id);
            }

            function open_change_detail(ds_id, record_id) {
                var record = $(ds_id).findById(record_id);
                var param = record.data;
                param['change_req_id'] = record.get('contract_id');
                param['contract_id'] = record.get('contract_id');
                param['function_usage'] = 'MODIFY';
                param['maintain_type'] = 'UPDATE';
                param['function_code'] = 'CON732D_BASIC';
                param['url_title'] = '合同回购';
                param['document_type'] = record.get('ccr_document_type');
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_repo_change_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');
                var prj_project_result_ds = $(ds_id);
                var records = prj_project_result_ds.getSelected();

                if (records.length != 1) {
                    Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                    return;
                }
                var record = records[0];

                var req_status = record.get('req_status');
                var param = record.data;
                var req_status = record.get('req_status');
                param['change_req_id'] = record.get('contract_id');
                param['contract_id'] = record.get('contract_id');

                param['req_status'] = req_status;
                param['url_title'] = '合同回购';
                if (req_status == 'APPROVED' || req_status == 'APPROVING' || req_status == 'CANCEL') {
                    param['maintain_type'] = 'READONLY';
                    param['function_code'] = 'CON_REPO001D_Q';
                } else {
                    param['maintain_type'] = 'UPDATE';
                    param['function_code'] = 'CON_REPO001D';
                }
                param['document_type'] = record.get('ccr_document_type');
                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, 'con_contract_repo_change_link', ds_id);
            };

            //回购解除协议打印
        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 prj_project_result_ds = $(ds_id);
            var records = prj_project_result_ds.getSelected();
            if (records.length != 1) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                return false;
            }
            var record = records[0];
            var contract_id = record.get('contract_id');
            var templet_code = 'CON_GRANT_DEDUCT';
            var url = $('con_grant_deduct_print_link').getUrl() + '?contract_id=' + contract_id + '&templet_code=' + templet_code;
            window.open(url, '_self');*/

            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var prj_project_result_ds = $(ds_id);
            var records = prj_project_result_ds.getSelected();
            if (records.length != 1) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                return false;
            }
            var record = records[0];
            var ccr_document_type = 'REPURCHASE';
            //var req_status = record.get('req_status');
            var contract_id = record.get('change_req_id');

            new Leaf.Window({
                id: 'open_print_detail_win',
                params: {
                    contract_id: contract_id,
                    ccr_document_type: ccr_document_type,
                    document_category: record.get('document_category'),
                    business_type : record.get('business_type'),
                    content_type : 'NORMAL',
                    winid: 'open_print_detail_win'
                },
                url: $('con_crr_query_print_link_id').getUrl(),
                title: '合同文本打印',
                width: 1000,
                height: 450
            });
        };


            window['${/parameter/@layout_code}_on_layout_dynamic_grid_query'] = function(ds, qpara, bp_seq) { //查询权限
                var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
                // if (ds == $(ds_id)) {
                //     aut_authority_list_validate_query(ds, qpara);
                // }
            };
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
<!--        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=CHANGE_REQUEST&amp;function_code=CON732"/>-->
    </a:view>
</a:screen>
