<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: wangwei  
    $Date: 2014-11-17 下午6:42:33  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:view>
        <a:link id="attachment_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="insurance_endorse_link_id" url="${/request/@context_path}/modules/cont/CON762/con_insurance_endorse_change.lview"/>
        <a:link id="update_contract_status_id" model="cont.CON762.con_contract_finish" modelaction="update"/>
        <script type="text/javascript"><![CDATA[
            function attachment_upload(val, rec, name) {
                return '<a href=javascript:open_upload_window(' + rec.get('ast_car_license_id') + ')>附件上传</a>';
            }
            
            function open_upload_window(record_id) {
                if (Leaf.isEmpty(record_id)) {
                    Leaf.showMessage('提示', '请先保存再上传附件！');
                    return;
                }
                var url = $('attachment_uploadFile_id').getUrl() + '?table_name=AST_CAR_LICENSE&header_id=' + record_id;
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'license_uploadFile_id',
                    width: 850,
                    height: 400
                });
                win.on('close', function() {});
            }
            
            function receipt_attachment_upload(val, rec, name) {
                return '<a href=javascript:open_upload_insurance_window(' + rec.get('ast_car_insurance_id') + ')>附件上传</a>';
            }
            
            function open_upload_insurance_window(record_id){
                 if (Leaf.isEmpty(record_id)) {
                    Leaf.showMessage('提示', '请先保存再上传附件！');
                    return;
                }
                var url = $('attachment_uploadFile_id').getUrl() + '?table_name=AST_CAR_INSURANCE&header_id=' + record_id;
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'insurance_uploadFile_id',
                    width: 850,
                    height: 400
                });
       
            }
            
            function insurance_endorse(val, rec, name){
                 return '<a href=javascript:open_insurance_endorse_window(' + rec.get('ast_car_insurance_id') + ')>批单更改</a>';
            }
            
            function open_insurance_endorse_window(record_id){
                  var url = $('insurance_endorse_link_id').getUrl();
                    var win = new Leaf.Window({
                        id: 'con_insurance_endorse_win',
                        url: url,
                        params: {
                            ast_car_insurance_id: record_id,
                            winId: 'con_insurance_endorse_win'
                        },
                    width: 720,
                    height: 400
                    });
             
            }
            
            function item_attachment_upload(val, rec, name){
                 return '<a href=javascript:open_upload_item_window(' + rec.get('item_detail_id') + ')>附件上传</a>';
            }
            
            function open_upload_item_window(record_id){
                  if (Leaf.isEmpty(record_id)) {
                    Leaf.showMessage('提示', '请先保存再上传附件！');
                    return;
                }
                var url = $('attachment_uploadFile_id').getUrl() + '?table_name=CON_CONTRACT_ITEM_DETAIL&header_id=' + record_id;
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'insurance_uploadFile_id',
                    width: 850,
                    height: 400
                });
            }
            
            function con762_exit(){
                $('${/parameter/@winId}').close();
            }
            
            function con762_save(){
                $('con_car_license_ds').submit();
                $('con_item_detail_ds').submit();
                
            }
            
            function con762_finish_trans(){
                   Leaf.showConfirm('${l:HLS.PROMPT}', '确认完成所有权转移？', function() {
                        Leaf.request({
                            url: $('update_contract_status_id').getUrl(),
                            para: {
                                contract_id: '${/parameter/@contract_id}'
                            },
                            success: function() {
                                $('${/parameter/@winId}').close();
                                Leaf.SideBar.show({
                                    msg: '操作成功',
                                    duration: 2000
                                });
            
                            },
                            scope: this
                        });
                       
                   });
            }
            
             function con762_cdd_attachment_render(value, record, name){
         
                 var check_id = record.get('check_id');
                var file_name = record.get('file_name');
                var record_id = record.id;
                if(check_id){
                    return '<a href="javascript:con762_cdd_attachtment_upload(\'' + record.get('check_id') + '\',\'' + file_name + '\',\'' + record_id + '\')">${l:HLS.ATTACHMENT}</a>';
                }
            }
            
            function con762_cdd_attachtment_upload(check_id, file_name, record_id) {
                //
               
                var url = $('attachment_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + check_id;
                var record = $('con762_detail_result1_ds').getCurrentRecord();
                var oldvalue = file_name ? file_name : null;
                var contract_id = '${/parameter/@contract_id}';
                paras = {
                    'contract_id': contract_id
                };
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'con762_cdd_uploadFile_screen_id',
                    width: 850,
                    height: 400
                });
                win.on('close',function(){
                    $('con762_detail_result1_ds').query();
                });
            };
            
         function con762_link_render(value, record, name){
                if (value != null) {
                    var link = '${/request/@context_path}/atm_download.lsc?attachment_id=';
                    var str = value.split(';;');
                    var url = '';
                    for (var i = 0;i < str.length;i++) {
                        var temp = str[i].split('--');
                        if (!Leaf.isEmpty(temp[0])) {
                            url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                        }
                    }
                    return url; 
                }
            }       
        ]]></script>
        <a:dataSets>
            <a:dataSet id="con_contract_detail_head_ds" autoQuery="true" queryUrl="${/request/@context_path}/autocrud/cont.CON761.con_contract_v/query?contract_id=${/parameter/@contract_id}">
                <a:fields>
                    <a:field name="inception_of_lease" datatype="java.util.Date"/>
                    <a:field name="lease_end_date" datatype="java.util.Date"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con_car_license_ds" autoQuery="true" model="cont.CON762.con_car_license" queryUrl="${/request/@context_path}/autocrud/cont.CON762.con_car_license/query?contract_id=${/parameter/@contract_id}">
                <a:fields>
                    <a:field name="mortgage_flag" checkedValue="Y" readOnly="true" uncheckedValue="N"/>
                    <a:field name="mortgage_date" datatype="java.util.Date"/>
                    <a:field name="relieve_mortgage_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="relieve_mortgage_date" datatype="java.util.Date"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con_car_insurance_ds" autoQuery="true" model="cont.CON762.con_car_insurance" queryUrl="${/request/@context_path}/autocrud/cont.CON762.con_car_insurance/query?contract_id=${/parameter/@contract_id}"><![CDATA[
            ]]></a:dataSet>
            <a:dataSet id="con_item_detail_ds" autoQuery="true" model="cont.CON762.con_contract_item_detail" queryUrl="${/request/@context_path}/autocrud/cont.CON762.con_contract_item_detail/query?contract_id=${/parameter/@contract_id}">
                <a:fields>
                    <a:field name="ownership_transfer_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="transfer_date" datatype="java.util.Date"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con762_detail_result1_ds" autoQuery="true" model="cont.CON762.con_content_query_detail_1" pageSize="8" queryUrl="${/request/@context_path}/autocrud/cont.CON762.con_content_query_detail_1/query?contract_id=${/parameter/@contract_id}" selectable="true">
                <a:fields>
                    <a:field name="document_table" defaultValue="CON_CONTRACT_CREDIT"/>
                    <a:field name="paper_required" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="sign_required_flag" checkedValue="Y" readOnly="true" uncheckedValue="N"/>
                    <a:field name="paper_required" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="attachment_required" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="sys_flag" defaultValue="N"/>
                    <a:field name="document_id" defaultValue="${/parameter/@contract_id}"/>
                    <a:field name="cdd_list_id" defaultValue="${/parameter/@cdd_list_id}"/>
                    <a:field name="note"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="con762_exit" text="退出"/>
                <a:gridButton click="con762_save" text="保存"/>
                <a:gridButton click="con762_finish_trans" text="完成转移"/>
            </a:screenTopToolbar>
            <a:form column="4" labelWidth="120" marginWidth="60" title="基础信息">
                <a:textField name="contract_number" bindTarget="con_contract_detail_head_ds" prompt="合同编号" readOnly="true"/>
                <a:textField name="bp_name" bindTarget="con_contract_detail_head_ds" prompt="承租人名称" readOnly="true"/>
                <a:datePicker name="inception_of_lease" bindTarget="con_contract_detail_head_ds" prompt="起租日" readOnly="true"/>
                <a:datePicker name="lease_end_date" bindTarget="con_contract_detail_head_ds" prompt="到期日" readOnly="true"/>
            </a:form>
            <a:tabPanel marginWidth="56">
                <a:tabs>
                    <a:tab prompt="基础信息" width="200">
                        <a:grid bindTarget="con_car_license_ds" height="120" marginWidth="60" navBar="true">
                            <a:columns>
                                <a:column name="mortgage_flag" editor="check_e" prompt="是否办理抵押" width="100"/>
                                <a:column name="mortgage_date" prompt="办理日期" renderer="Leaf.formatDate" width="150"/>
                                <a:column name="mortgage_by" prompt="抵押权人" width="200"/>
                                <a:column name="relieve_mortgage_flag" editor="check_e" prompt="是否解除抵押" width="100"/>
                                <a:column name="relieve_mortgage_date" editor="date_e" prompt="办理日期" renderer="Leaf.formatDate" width="150"/>
                                <a:column align="center" prompt="附件" renderer="attachment_upload" width="100"/>
                            </a:columns>
                            <a:editors>
                                <a:checkBox id="check_e"/>
                                <a:datePicker id="date_e"/>
                            </a:editors>
                        </a:grid>
                        <a:grid bindTarget="con_item_detail_ds" height="140" marginWidth="60" navBar="true">
                            <a:columns>
                                <a:column name="brands_des" prompt="品牌" width="100"/>
                                <a:column name="series_des" prompt="车系" width="200"/>
                                <a:column name="model_des" prompt="车型" width="200"/>
                                <a:column name="item_frame_number" prompt="车架号" width="150"/>
                                <a:column name="item_engine_number" prompt="发动机号" width="120"/>
                                <a:column name="ownership_transfer_flag" editor="check_ed" prompt="是否办理过户" width="100"/>
                                <a:column name="transfer_date" editor="date_ed" prompt="办理时间" renderer="Leaf.formatDate" width="100"/>
                                <a:column align="center" prompt="附件" renderer="item_attachment_upload" width="100"/>
                            </a:columns>
                            <a:editors>
                                <a:checkBox id="check_ed"/>
                                <a:datePicker id="date_ed"/>
                            </a:editors>
                        </a:grid>
                        <a:grid bindTarget="con_car_insurance_ds" height="140" marginWidth="60" navBar="true">
                            <a:columns>
                                <a:column name="insurer_dis" prompt="保险公司" width="100"/>
                                <a:column name="insurance_number" prompt="保单号" width="100"/>
                                <a:column name="insurance_type_des" prompt="保险类型" width="100"/>
                                <a:column name="document_status_des" align="center" prompt="单据状态" width="100"/>
                                <a:column name="insure_date" prompt="投保日" renderer="Leaf.formatDate" width="100"/>
                                <a:column name="insure_name" prompt="投保人" width="100"/>
                                <a:column name="insurance_date_from" prompt="保险起始日" renderer="Leaf.formatDate" width="80"/>
                                <a:column name="insurance_date_to" prompt="保险终止日" renderer="Leaf.formatDate" width="80"/>
                                <a:column name="insure_place" editor="ast_car_insurance_tf" prompt="投保地点" width="100"/>
                                <a:column name="first_beneficiary" editor="ast_car_insurance_tf" prompt="第一受益人" width="100"/>
                                <a:column align="center" prompt="附件" renderer="receipt_attachment_upload" width="100"/>
                                <a:column align="center" prompt="批单更改" renderer="insurance_endorse" width="100"/>
                            </a:columns>
                        </a:grid>
                    </a:tab>
                    <a:tab prompt="附件上传" width="200">
                        <a:grid bindTarget="con762_detail_result1_ds" height="280" marginWidth="60" navBar="true">
                            <a:toolBar>
                                <a:button type="add"/>
                                <a:button type="save"/>
                                <a:button type="delete"/>
                            </a:toolBar>
                            <a:columns>
                                <a:column name="description" editor="con555_cdd_tf_id1" lock="true" prompt="HLS.DOCUMENT_NAME" width="200"/>
                                <a:column name="attachment" align="center" lock="true" prompt="附件" renderer="con762_cdd_attachment_render" width="60"/>
                                <a:column name="file_name" align="center" lock="true" prompt="附件名" renderer="con762_link_render" width="400"/>
                                <a:column name="note" editor="con555_cdd_tf_id1" prompt="备注" width="200"/>
                            </a:columns>
                            <a:editors>
                                <a:textField id="con555_cdd_tf_id1"/>
                            </a:editors>
                        </a:grid>
                    </a:tab>
                </a:tabs>
            </a:tabPanel>
        </a:screenBody>
    </a:view>
</a:screen>
