<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query model="cont.CON708.con_tract_lease_channel" rootPath="hls_lease_channel_list"/>
        <a:model-query model="cont.CON708.con_division" rootPath="hls_division_list"/>
        <a:model-query model="cont.CON708.con_contract_status" rootPath="contract_status_list"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con708_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>
        <a:link id="con708_contract_modify_link"
                url="${/request/@context_path}/modules/cont/CON302N/con_contract_modify.lview"/>
        <a:link id="contract_settlement_link" model="cont.CON708.contract_settlement" modelaction="update"/>
        <script type="text/javascript"><![CDATA[
        function contractQueryScreen_query() {
            $('contractQueryScreen_mainDs').query();
        }

        function contractQueryScreen_reset() {
            $('contractQueryScreen_paraDs').reset();
        }

        function contractQueryScreen_export(){
            $('contractQueryScreen_mainDs_grid')._export(null,'合同结清');
        }

        function contractQueryScreen_incept() {
            var records = $('contractQueryScreen_mainDs').getSelected();
            var contract_status = records[0].get('contract_status');
            if (contract_status != 'LOSSSHARE_TERMINATE' && contract_status != 'AGENT_TERMINATE'){
                Leaf.showMessage('${l:PROMPT}','只有损失担保结清和代理商垫款结清才能起租!');
                return;
            }
            Leaf.request({
                url: $('contract_settlement_link').getUrl(),
                para: {
                    contract_id: records[0].get('contract_id'),
                    contract_status :'INCEPT'
                },
                success: function(res) {
                    Leaf.SideBar.show({
                        msg: '${l:HLS.SUBMIT_SUCCESS}',
                        duration: 2000
                    });
                    contractQueryScreen_query();
                },
                scope: this
            });
        }

        function contractQueryScreen_loss_settlement() {
           var records = $('contractQueryScreen_mainDs').getSelected();
            Leaf.request({
                url: $('contract_settlement_link').getUrl(),
                para: {
                    contract_id: records[0].get('contract_id'),
                    contract_status :'LOSSSHARE_TERMINATE'
                },
                success: function(res) {
                    Leaf.SideBar.show({
                        msg: '${l:HLS.SUBMIT_SUCCESS}',
                        duration: 2000
                    });
                    contractQueryScreen_query();
                },
                scope: this
            });
        }

        function contractQueryScreen_normal_clearance() {
            var records = $('contractQueryScreen_mainDs').getSelected();
            Leaf.request({
                url: $('contract_settlement_link').getUrl(),
                para: {
                    contract_id: records[0].get('contract_id'),
                    contract_status :'TERMINATE'
                },
                success: function(res) {
                    Leaf.SideBar.show({
                        msg: '${l:HLS.SUBMIT_SUCCESS}',
                        duration: 2000
                    });
                    contractQueryScreen_query();
                },
                scope: this
            });
        }

        function contractQueryScreen_advance_payment() {
            var records = $('contractQueryScreen_mainDs').getSelected();
            Leaf.request({
                url: $('contract_settlement_link').getUrl(),
                para: {
                    contract_id: records[0].get('contract_id'),
                    contract_status :'AGENT_TERMINATE'
                },
                success: function(res) {
                    Leaf.SideBar.show({
                        msg: '${l:HLS.SUBMIT_SUCCESS}',
                        duration: 2000
                    });
                    contractQueryScreen_query();
                },
                scope: this
            });
        }

        function contractQueryScreen_virtual_terminate() {
            var records = $('contractQueryScreen_mainDs').getSelected();
            Leaf.request({
                url: $('contract_settlement_link').getUrl(),
                para: {
                    contract_id: records[0].get('contract_id'),
                    contract_status :'VIRTUAL_TERMINATE'
                },
                success: function(res) {
                    Leaf.SideBar.show({
                        msg: '${l:HLS.SUBMIT_SUCCESS}',
                        duration: 2000
                    });
                    contractQueryScreen_query();
                },
                scope: this
            });
        }

        function con708_detail_renderer(value, record, name) {
            return '<a href="javascript:con708_open_contract_win(' + record.id + ')">'+value+'</a>';
        }

        function con708_open_contract_win(id) {
            var ds_id = 'contractQueryScreen_mainDs';
            var record = $(ds_id).findById(id);
            var param = record.data;
            param['function_code'] = 'CON301';
            param['function_usage'] = 'QUERY';
            param['maintain_type'] = 'READONLY';
            param['bp_class'] = 'NP';
            param['winid'] = 'con_contract_modify_link_winid';
            param['url_title'] = '${l:CON301.CONTRACT_DETAIL}';
            hls_doc_get_layout_code('con708_contract_get_layout_code_link_id', param, 'con708_contract_modify_link', ds_id);

        }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="lease_channel_options">
                <a:datas dataSource="/model/hls_lease_channel_list"/>
            </a:dataSet>
            <a:dataSet id="division_options">
                <a:datas dataSource="/model/hls_division_list"/>
            </a:dataSet>
            <a:dataSet id="contract_status_options">
                <a:datas dataSource="/model/contract_status_list"/>
            </a:dataSet>
            <a:dataSet id="contractQueryScreen_paraDs">
                <a:fields>
                    <a:field name="bp_name" lovGridHeight="330" lovHeight="470" lovLabelWidth="120" lovService="cont.CON708.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.CON708.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="lease_channel" />
                    <a:field name="lease_channel_n" options="lease_channel_options" displayField="description" returnField="lease_channel" valueField="lease_channel"/>
                    <a:field name="division" />
                    <a:field name="division_n" options="division_options" displayField="description" returnField="division" valueField="division" />
                    <a:field name="contract_status" />
                    <a:field name="contract_status_n" options="contract_status_options" displayField="code_value_name" returnField="contract_status" valueField="code_value" />
                </a:fields>
            </a:dataSet>
            <a:dataSet id="contractQueryScreen_mainDs" autoQuery="false" fetchAll="false" model="cont.CON708.contract_settlement" pageSize="14" queryDataSet="contractQueryScreen_paraDs" selectable="true" selectionModel="single">
                <a:fields>
                    <a:field name="lease_execution_date" datatype="date"/>
                </a:fields>
                <a:events>
                    <a:event name="submitsuccess" handler="contractQueryScreen_query"/>
                </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="contractQueryScreen_export" text="导出"/>
                <a:gridButton click="contractQueryScreen_loss_settlement" text="损失担保结清"/>
                <a:gridButton click="contractQueryScreen_normal_clearance" text="正常结清"/>
                <a:gridButton click="contractQueryScreen_advance_payment" text="代理商垫款结清"/>
                <a:gridButton click="contractQueryScreen_virtual_terminate" text="虚拟结清"/>
                <a:gridButton click="contractQueryScreen_incept" text="起租"/>
            </a:screenTopToolbar>
            <a:form column="4" labelWidth="100" marginWidth="40" title="HLS.QUERY_TITLE">
                <a:comboBox name="lease_channel_n" bindTarget="contractQueryScreen_paraDs"  prompt="商业模式" />
                <a:textField name="contract_number" 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:comboBox name="contract_status_n" bindTarget="contractQueryScreen_paraDs" prompt="合同状态"/>
                <a:datePicker name="lease_execution_date_from" bindTarget="contractQueryScreen_paraDs" prompt="执行日期从"/>
                <a:datePicker name="lease_execution_date_to" bindTarget="contractQueryScreen_paraDs" prompt="执行日期到"/>
                <a:datePicker name="et_date_from" bindTarget="contractQueryScreen_paraDs" prompt="合同结清日期从"/>
                <a:datePicker name="et_date_to" bindTarget="contractQueryScreen_paraDs" prompt="合同结清日期到"/>
            </a:form>
            <a:grid id="contractQueryScreen_mainDs_grid" bindTarget="contractQueryScreen_mainDs" marginHeight="230" marginWidth="40" navBar="true">
                <a:columns>
                    <a:column name="contract_number"  prompt="合同编号" width="180" align="center" renderer="con708_detail_renderer"/>
                    <a:column name="bp_name" prompt="承租人名称" width="180" align="center"/>
                    <a:column name="bp_agent" prompt="代理商名称" width="180" align="center"/>
                    <a:column name="division_n" prompt="产品线" width="180" align="center"/>
                    <a:column name="lease_execution_date" prompt="执行日期" renderer="Leaf.formatDate" width="180" align="center"/>
                    <a:column name="contract_status_n" prompt="合同状态" width="180" align="center"/>
                    <a:column name="lease_channel_n" prompt="商业模式" width="180" align="center"/>
                    <a:column name="guarantor_info" prompt="损失担保标志" width="180" align="center"/>
                    <a:column name="et_date" prompt="合同结清日期" renderer="Leaf.formatDate" width="180" align="center"/>
                    <a:column name="loss_sharing_flag_n" prompt="损失分担与否"  width="180" 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>