<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129  
    $Date: 2014-11-24 下午02:31:19  
    $Revision: 1.0  
    $Purpose: 合同文档借阅新增
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:view>
        <a:link id="yonda_document_lend_record_save_link" url="${/request/@context_path}/modules/cont/CON556/yonda_document_lend_record_save.lsc"/>
        <script type="text/javascript"><![CDATA[
            function con_contract_query_ds_update(ds, record, name, value, oldvalue) {
                if (name == 'contract_id') {
                    $('yonda_document_lend_record_ln_query_ds').setQueryParameter('contract_id', value);
                    $('yonda_document_lend_record_ln_query_ds').query();
                }
            }
            
            function yonda_document_lend_record_add_close() {
                $('${/parameter/@winid}').close();
            }
            
            
            function lend_record_save() {
                if ($('yonda_document_lend_record_hd_create_ds').validate()) {
                    Leaf.Masker.mask($('${/parameter/@winid}').wrap, '${l:HLS.EXECUTING}');
                    var saveData = [];
                    var header_record = $('yonda_document_lend_record_hd_create_ds').getCurrentRecord();
                    var params = header_record.data;
                    var contract_records = $('con_contract_ds').getAll();
                    if (contract_records.length > 0) {
                        for (var i = 0;i < contract_records.length;i++) {
                            var line_record = contract_records[i].data['record_ln'].data;
                            for (var j = 0;j < line_record.length;j++) {
                                if (line_record[j].get('lend_flag') == 'Y') {
                                    line_record[j].set('_status', 'insert');
                                    line_record[j].set('contract_id', contract_records[i].get('contract_id'));
                                    saveData.push(line_record[j].data);
                                }
                            }
                        }
                    }
            
                    if (saveData.length == 0) {
                        Leaf.showMessage('提示', '请至少选择文档一条记录');
                        Leaf.Masker.unmask($('${/parameter/@winid}').wrap);
                        return;
                    }
            
                    params['line_records'] = saveData;
                    Leaf.request({
                        url: $('yonda_document_lend_record_save_link').getUrl(),
                        para: params,
                        success: function() {
                            Leaf.Masker.unmask($('${/parameter/@winid}').wrap);
                            $('${/parameter/@winid}').close();
                        },
                        error: function() {
                            Leaf.Masker.unmask($('${/parameter/@winid}').wrap);
                        },
                        failure: function() {
                            Leaf.Masker.unmask($('${/parameter/@winid}').wrap);
                        }
                    });
            
                }
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="yonda_document_lend_record_hd_create_ds" autoCreate="true">
                <a:fields>
                    <a:field name="status" defaultValue="NEW"/>
                    <a:field name="borrower_name" required="true"/>
                    <a:field name="borrower_phone" required="true"/>
                    <a:field name="borrower_date" required="true"/>
                    <a:field name="lender_name" required="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con_contract_ds" selectable="true">
                <a:fields>
                    <a:field name="contract_id"/>
                    <a:field name="contract_number" lovHeight="500" lovService="cont.CON556.con_contract_v_for_lov_lend" lovWidth="450">
                        <a:mapping>
                            <a:map from="contract_id" to="contract_id"/>
                            <a:map from="contract_number" to="contract_number"/>
                            <a:map from="contract_name" to="contract_name"/>
                            <a:map from="bp_name" to="bp_name"/>
                            <a:map from="bp_type_desc" to="bp_type_desc"/>
                            <a:map from="hls_lease_channel_desc" to="hls_lease_channel_desc"/>
                        </a:mapping>
                    </a:field>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="con_contract_query_ds_update"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="yonda_document_lend_record_ln_query_ds" bindName="record_ln" bindTarget="con_contract_ds" fetchAll="true" model="cont.CON556.yonda_document_lend_record_query">
                <a:fields>
                    <a:field name="lend_flag" checkedValue="Y" uncheckedValue="N"/>
                    <a:field name="document_id"/>
                    <a:field name="cdd_item_id"/>
                    <a:field name="description"/>
                    <a:field name="return_date"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="yonda_document_lend_record_add_close" text="HLS.BACK"/>
                <a:gridButton click="lend_record_save" text="提交"/>
            </a:screenTopToolbar>
            <a:form column="3" labelWidth="120" marginWidth="60" title="借阅人信息">
                <a:textField name="borrower_name" bindTarget="yonda_document_lend_record_hd_create_ds" prompt="借阅人名称"/>
                <a:textField name="borrower_phone" bindTarget="yonda_document_lend_record_hd_create_ds" prompt="借阅人电话"/>
                <a:datePicker name="borrower_date" bindTarget="yonda_document_lend_record_hd_create_ds" prompt="借出日期"/>
                <a:textField name="lender_name" bindTarget="yonda_document_lend_record_hd_create_ds" prompt="出借人"/>
                <a:textField name="ref_v01" bindTarget="yonda_document_lend_record_hd_create_ds" colspan="5" prompt="出借理由" width="600"/>
            </a:form>
            <a:grid id="con_contract_query_grid" bindTarget="con_contract_ds" height="200" marginWidth="60" navBar="true">
                <a:toolBar>
                    <a:button type="add"/>
                    <a:button type="clear"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="contract_number" editor="con_contract_query_lov" prompt="合同编号" width="120"/>
                    <a:column name="contract_name" prompt="合同名称" width="200"/>
                    <a:column name="bp_name" prompt="承租人名称" width="200"/>
                    <a:column name="bp_type_desc" prompt="承租人类型" width="120"/>
                    <a:column name="hls_lease_channel_desc" prompt="商业模式" width="120"/>
                </a:columns>
                <a:editors>
                    <a:lov id="con_contract_query_lov"/>
                </a:editors>
            </a:grid>
            <a:grid bindTarget="yonda_document_lend_record_ln_query_ds" marginHeight="400" marginWidth="60" navBar="true">
                <a:columns>
                    <a:column name="description" prompt="文档名称" width="600"/>
                    <a:column name="lend_flag" editor="yonda_document_lend_record_add_cb" prompt="是否借出" width="80"/>
                    <a:column name="return_date" editor="yonda_document_lend_record_add_dp" prompt="归还时间" renderer="Leaf.formatDate" width="120"/>
                </a:columns>
                <a:editors>
                    <a:checkBox id="yonda_document_lend_record_add_cb"/>
                    <a:datePicker id="yonda_document_lend_record_add_dp"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
