<?xml version="1.0" encoding="UTF-8"?>
<!--
    2019-9-6  Spencer 3893  合同回购申请创建
 -->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="con_contract_repo_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="con_contract_modify_link" url="${/request/@context_path}/modules/cont/CON505/con_contract_modify.lview"/>
        <a:link id="con_contract_change_link" url="${/request/@context_path}/modules/cont/CON_REPO001/con_contract_change_repo_detail.lview"/>
        <a:link id="con731_create_change_link" model="cont.CON_REPO001.create_change_req" modelaction="execute"/>
        <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'] = 'CON301';
            param['function_usage'] = 'QUERY';
            param['download'] = 'Y';
            param['maintain_type'] = 'QUERY';
            param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
            hls_doc_get_layout_code('con_contract_repo_get_layout_code_link_id', param, 'con_contract_modify_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 () {
            $('${/parameter/@layout_code}_user_button1').disable(); //按钮不可用

            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) {
                $('${/parameter/@layout_code}_user_button1').enable(); //按钮启用
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                return;
            }
            Leaf.showConfirm('特别注意', '<span style="color: #ff0000; ">该操作将导致合同在回购期间无法进行后续操作，请谨慎操作！！！如果需要取消回购，请一定点击取消按钮！！！</span>', function () {
                var record = records[0];

                    var contract = record.get('contract_id');
                    var ccr_document_type = 'REPUR';
                    Leaf.Masker.mask(Ext.getBody());
                    Leaf.request({
                        url: $('con731_create_change_link').getUrl(),
                        para: {
                            simulation_flag: 'N',
                            contract_id: record.get('contract_id'),
                            req_type: ccr_document_type
                        },
                        success: function (res) {
                            $('${/parameter/@layout_code}_user_button1').enable(); //按钮启用
                            var param = record.data;
                            param['change_req_id'] = res.result.change_req_id;
                            param['contract_id'] = res.result.change_req_id;
                            //param['layout_debugger_flag'] = 'Y';
                            param['function_code'] = 'CON_REPO001D';
                            param['url_title'] = '合同回购';
                            param['function_usage'] = 'MODIFY';
                            param['maintain_type'] = 'UPDATE';
                            param['document_type'] = ccr_document_type;
                            param['winid'] = 'con_repo001d_detail_winid';
                            hls_doc_get_layout_code('con_contract_repo_get_layout_code_link_id', param, 'con_contract_change_link', ds_id);
                        },
                        failure: function () {
                            Leaf.Masker.unmask(Ext.getBody());
                            $('${/parameter/@layout_code}_user_button1').enable(); //按钮启用
                        },
                        error: function () {
                            Leaf.Masker.unmask(Ext.getBody());
                            $('${/parameter/@layout_code}_user_button1').enable(); //按钮启用
                        },
                        scope: this
                    });
            }, function () {
                $('${/parameter/@layout_code}_user_button1').enable(); //按钮启用
            }, 300, 150);
        };

        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_authority_list_validate.lview?document_category=CONTRACT&amp;function_code=CON501"/>-->
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>