<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Spencer 3893
    $Date: 2019-9-19
    $Revision: 1.0  
    $Purpose: 提前结清维护入口
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="basic.hls_division_for_lov" rootPath="hls_division_path"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con_et_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="con_et_change_link" url="${/request/@context_path}/modules/cont/CON_ET001/con_early_termination_et_detail.lview"/>
        <a:link id="con_et_create_change_link" model="cont.CON_ET001.create_change_req" modelaction="execute"/>
        <!--<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_grant_deduct_print_link" url="${/request/@context_path}/modules/cont/CON732/hls_crr_query_print_word_detail.lview"/>
        <script type="text/javascript"><![CDATA[
            function contractQueryScreen_query() {
                $('contractQueryScreen_mainDs').query();
            }

            function contractQueryScreen_reset() {
                $('contractQueryScreen_paraDs').reset();
            }
        function open_change_req(value,record,name){
            if(name=='change_req_number'){
                var req_status = record.get('req_status');
                var change_req_id = record.get('change_req_id');
                var contract_id=record.get('contract_id');
                var simulation_flag=record.get('simulation_flag');
                if('NEW' == req_status){
                    return '<a href="javascript:open_change_req_detail(' + change_req_id + ',' + contract_id + ',' + record.id + ')">'+value+'</a>';
                }else{
                    return '<a href="javascript:open_change_req_readonly_detail(' + change_req_id + ',' + contract_id + ',' + record.id + ')">'+value+'</a>';
                }
            }
            return value;
        }

        //提前结清文本打印
        function con_gur_np_pint() {
            var prj_project_result_ds = $('contractQueryScreen_mainDs');
            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];
            //update by xsh35973 增加回购提前结清合同文本生成
            var ccr_document_type;
            if (record.get('contract_status') == 'REPURING'){
                ccr_document_type = 'REPUR_CHAG'
            }else{
                ccr_document_type = 'ET';
            };
            //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_grant_deduct_print_link').getUrl(),
                title: '合同文本打印',
                width: 1000,
                height: 450
            });

            /*var contract_id = record.get('contract_id');
            var templet_code = 'CON_GUR_NP';
            var url = $('con_grant_deduct_print_link').getUrl() + '?contract_id=' + contract_id + '&templet_code=' + templet_code;
            window.open(url, '_self');*/
        }

        function open_change_req_detail(change_req_id,contract_id,id) {
            var current_record = $('contractQueryScreen_mainDs').findById(id);
            var param = {};
            param['change_req_id'] = change_req_id;
            param['contract_id'] = change_req_id;
            param['source_contract_id'] = contract_id;
            //param['layout_debugger_flag'] = 'Y';
            param['function_code'] = 'CON_ET002';
            param['url_title'] = '提前结清维护';
            param['function_usage'] = 'MODIFY';
            param['maintain_type'] = 'UPDATE';
            param['document_type'] = 'ET_CHAG';
            param['winid'] = 'con_et003_detail_winid';
            param['simulation_flag'] =current_record.get('simulation_flag');
            hls_doc_get_layout_code('con_et_get_layout_code_link_id', param, 'con_et_change_link', 'contractQueryScreen_mainDs');
        }
        function open_change_req_readonly_detail(change_req_id,contract_id,id) {
                debugger;
            var current_record = $('contractQueryScreen_mainDs').findById(id);
            var param = {};
            param['change_req_id'] = change_req_id;
            param['contract_id'] = change_req_id;
            param['source_contract_id'] = contract_id;
            //param['layout_debugger_flag'] = 'Y';
            param['function_code'] = 'CON_ET002_Q';
            param['url_title'] = '提前结清明细';
            param['function_usage'] = 'QUERY';
            param['maintain_type'] = 'QUERY';
            param['document_type'] = 'ET_CHAG';
            param['winid'] = 'con_et003_detail_winid';
            param['simulation_flag'] =current_record.get('simulation_flag');
            hls_doc_get_layout_code('con_et_get_layout_code_link_id', param, 'con_et_change_link', 'contractQueryScreen_mainDs');
        }

        function on_grid_select(ds, record, bp_seq) {
            if(record.get('req_status') != 'APPROVED'){
                document.getElementById("con_gur_np_pint_id").style.display = "none";
            }else{
                document.getElementById("con_gur_np_pint_id").style.display = "";
            }
        }
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=CONTRACT&amp;function_code=CON_ET001"/>
        <a:dataSets>
            <a:dataSet id="yes_or_no_ds" lookupCode="YES_NO"/>
            <a:dataSet id="contract_status_ds" lookupCode="CON500_CONTRACT_STATUS"/>
            <a:dataSet id="contract_chage_req_status_ds" lookupCode="CON_CHANGE_REQ_STATUS"/>
            <a:dataSet id="hls_division_ds">
                <a:datas dataSource="/model/hls_division_path"/>
            </a:dataSet>
            <a:dataSet id="contractQueryScreen_paraDs">
                <a:fields>
                    <a:field name="contract_number" typeCase="upper"/>
                    <a:field name="contract_name"/>
                    <a:field name="date_from"/>
                    <a:field name="date_to"/>
                    <a:field name="bp_id_tenant"/>
                    <a:field name="bp_name" lovGridHeight="330" lovHeight="470" lovLabelWidth="120" lovService="cont.CON701.hls_bp_master_v_all_lov?bp_category=TENANT" lovWidth="700" title="承租人">
                        <a:mapping>
                            <a:map from="bp_id" to="bp_id_tenant"/>
                            <a:map from="bp_name" to="bp_name"/>
                        </a:mapping>
                    </a:field>
                    <!--代理商-->
                    <a:field name="bp_id_agent_level1"/>
                    <a:field name="bp_agent" lovGridHeight="330" lovHeight="470" lovLabelWidth="120" lovService="cont.CON701.hls_bp_master_v_all_lov?bp_category=AGENT" lovWidth="700" title="代理商">
                        <a:mapping>
                            <a:map from="bp_id" to="bp_id_agent_level1"/>
                            <a:map from="bp_name" to="bp_agent"/>
                        </a:mapping>
                    </a:field>
                    <!--产品线-->
                    <a:field name="division_n" displayField="description" options="hls_division_ds" returnField="division" valueField="division"/>
                    <a:field name="contract_status"/>
                    <a:field name="contract_status_desc" displayField="code_value_name" options="contract_status_ds" returnField="contract_status" valueField="code_value"/>
                    <a:field name="req_employee_n"/>
                    <a:field name="req_status"/>
                    <a:field name="req_status_n" displayField="code_value_name" options="contract_chage_req_status_ds" returnField="req_status" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="contractQueryScreen_mainDs" autoQuery="true" fetchAll="false" model="cont.CON_ET003.con_early_termination_modify_query" pageSize="14" queryDataSet="contractQueryScreen_paraDs" selectable="true" selectionModel="single">
                <a:fields>
                    <a:field name="et_type_dis" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="cont.CON701.hls_document_type_for_et_lov" lovWidth="500" prompt="提前结清类型" readOnly="true" required="true">
                        <a:mapping>
                            <a:map from="document_type" to="et_type"/>
                            <a:map from="document_type_desc" to="et_type_dis"/>
                        </a:mapping>
                    </a:field>
<!--                    <a:field name="termination_date" datatype="date" required="true"/>-->
                    <a:field name="overdue_status" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="trial" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="lease_execution_date" datatype="date"/>
                </a:fields>
                <a:events>
                    <a:event name="query" handler="aut_authority_list_validate_query"/>
                    <!--<a:event name="select" handler="on_grid_select"/>-->
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="contractQueryScreen_query" text="HLS.QUERY"/>
                <a:gridButton click="contractQueryScreen_reset" text="HLS.RESET"/>
                <a:gridButton click="con_gur_np_pint" text="合同文本打印" id="con_gur_np_pint_id"/>
            </a:screenTopToolbar>
            <a:form column="4" labelWidth="100" marginWidth="40" title="HLS.QUERY_TITLE">
                <a:textField name="change_req_number" bindTarget="contractQueryScreen_paraDs" prompt="变更申请编号"/>
                <a:textField name="contract_number" bindTarget="contractQueryScreen_paraDs" prompt="合同编号"/>
                <a:textField name="contract_name" bindTarget="contractQueryScreen_paraDs" prompt="合同名称"/>
                <a:lov name="bp_name" bindTarget="contractQueryScreen_paraDs" prompt="承租人名称"/>
<!--                <a:lov name="bp_agent" bindTarget="contractQueryScreen_paraDs" prompt="代理店"/>-->
                <a:comboBox name="division_n" bindTarget="contractQueryScreen_paraDs" prompt="租赁物"/>
                <a:textField name="req_employee_n" bindTarget="contractQueryScreen_paraDs" prompt="申请人"/>
                <a:datePicker name="termination_date_from" bindTarget="contractQueryScreen_paraDs" prompt="提前结清日从"/>
                <a:datePicker name="termination_date_to" bindTarget="contractQueryScreen_paraDs" prompt="提前结清日到"/>
                <a:comboBox name="req_status_n" bindTarget="contractQueryScreen_paraDs" prompt="变更审批状态"/>
            </a:form>
            <a:grid id="contractQueryScreen_mainDs_grid" bindTarget="contractQueryScreen_mainDs" marginHeight="200" marginWidth="40" navBar="true">
                <a:columns>
                    <a:column name="change_req_number" prompt="变更申请编号" width="120" align="left" renderer="open_change_req"/>
                    <a:column name="contract_number" prompt="合同编号" width="120" align="left"/>
                    <a:column name="contract_name" prompt="合同名称" width="120" align="left"/>
                    <a:column name="bp_name" prompt="承租人名称" width="200" align="left"/>
                    <a:column name="bp_agent" prompt="代理店" width="200" align="left"/>
                    <a:column name="division_n" prompt="租赁物" width="120" align="left"/>
                    <a:column name="req_employee_n" prompt="申请人" width="80" align="right"/>
                    <a:column name="termination_date" prompt="提前结清日" width="100" align="center"/>
                    <a:column name="req_status_n" prompt="变更审批状态" width="100" align="center"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
