<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: hand  
    $Date: 2013-1-8 上午09:42:18  
    $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="fnd.fnd_uom_codes_vl" rootPath="uom_codes"/>
        <a:model-query fetchAll="true" model="gld.gld_currency_vl" rootPath="currency"/>
        <a:model-query defaultWhereClause="code=&apos;HLS_PAWN_FILE&apos;" model="sys.sys_code_values_v" rootPath="sys_list"/>
    </a:init-procedure>
    <a:view>
        <script type="text/javascript"><![CDATA[
        function back(){
            history.go(-1);
        }
        function update_pawn(){
            $('pawn_ds').submit();
        }
            function attachment_link(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;
            
                }
            }
            var wd;
            
            function saveFile() {
                $('file_result_ds').submit();
            }
            
            function reload() {
                $('hls_pawn_upload_ds').query();
            }
            
            function submitMSG(dataSet, datas, res) {
                Leaf.showMessage('提示信息', '保存成功！');
            }
            
            function attachmentLink(value, record, name) {
                //var pkvalue = record.get('cus_upload_id');
                //var url = '<img src="../../images/upload.png" alt="附件上传" onclick="url_link('+pkvalue+')"/>&nbsp;&nbsp;&nbsp;';
            
                if (typeof(value) == 'undefined' && Ext.isEmpty(value)) {
                    //return url;
                    return '';
                } else {
                    //return url + value;
                    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;
                }
            }
            
            function url_link(pkvalue) {
                var url = '${/request/@context_path}/hls_upload_for_attachment_view.lview?sourcetype=hls_pawn_upload&pkvalue=' + pkvalue;
                wd = new Leaf.Window({
                    id: 'attachment_up_window',
                    url: url,
                    title: '附件上传',
                    height: 350,
                    width: 850
                });
            }
            
            function attachmentUpload(value, record, name) {
                var p_pkvalue = record.get('pawn_upload_id');
                return "<A href='javascript:url_link(" + p_pkvalue + ")'>附件上传</A>";
            }
            
                     function dateValidator(record, name, value){ 
                if(name == 'start_date' || name == 'end_date'){
                    var start_date = record.get('start_date');
                    var end_date = record.get('end_date');            
                    if(typeof(end_date) != 'undefined' && !Ext.isEmpty(end_date)){
                        if(!compareDate(start_date, end_date)){
                            return '开始时间不能大于结束时间';
                        }
                    }
                    return true;
                }
            }
                        function compareDate(start, end) {
                if (start.getTime() > end.getTime()) {
                    return false;
                }
                return true;
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="pawn_stat_ds" lookupCode="HLS_PAWN_STATUS"><![CDATA[
            ]]></a:dataSet>
            <a:dataSet id="file_result_ds" autoQuery="true" fetchAll="true" model="hls.HLS209.hls_pawn_upload" queryUrl="${/request/@context_path}/autocrud/hls.HLS209.hls_pawn_upload/query?pawn_id=${/parameter/@pawn_id}&amp;_queryorderby=file_code asc">
                <a:fields>
                    <a:field name="submit_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                </a:fields>
                <a:events>
                    <a:event name="submitSuccess" handler="submitMSG"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="uom_codes_ds">
                <a:datas dataSource="/model/uom_codes"/>
            </a:dataSet>
            <a:dataSet id="currency_ds">
                <a:datas dataSource="/model/currency"/>
            </a:dataSet>
            <a:dataSet id="pawn_ds" autoCreate="true" autoQuery="true" model="hls.HLS209.hls_pawns" queryUrl="${/request/@context_path}/autocrud/hls.HLS209.hls_pawns/query?pawn_id=${/parameter/@pawn_id}" submitUrl="${/request/@context_path}/modules/fnd/HLS201/hls_pawn.lsc?update">
                <a:fields>
                    <a:field name="uom_name" displayField="description_text" options="uom_codes_ds" returnField="uom" valueField="uom_code"/>
                    <a:field name="customer_id"/>
                    <a:field name="currency_name" displayField="currency_name" options="currency_ds" returnField="currency" valueField="currency_code"/>
                    <a:field name="pawn_status_des" displayField="code_value_name" options="pawn_stat_ds" returnField="pawn_status" valueField="code_value"/>
                    <a:field name="customer_name" lovHeight="600" lovService="hls.HLS209.hls_partner_lov" lovWidth="500">
                        <a:mapping>
                            <a:map from="customer_id" to="customer_id"/>
                            <a:map from="customer_name" to="customer_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="start_date" validator="dateValidator"/>
                    <a:field name="end_date" validator="dateValidator"/>
                    <a:field name="area_uom" defaultValue="平方米" readOnly="true"/>
                    <a:field name="lease_contract_id"/>
                    <a:field name="lease_contract_code" lovHeight="600" lovService="hls_prj.hls_prj_contract_hds_for_lov" lovWidth="500">
                        <a:mapping>
                            <a:map from="contract_hds_id" to="lease_contract_id"/>
                            <a:map from="contract_number" to="lease_contract_code"/>
                        </a:mapping>
                    </a:field>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="hls_pawn_upload_ds" autoQuery="true" fetchAll="true" model="hls.HLS209.hls_pawn_upload" queryUrl="${/request/@context_path}/autocrud/hls.HLS209.hls_pawn_upload/query?ORDER_FIELD=file_code&amp;pawn_id=${/parameter/@pawn_id}">
                <a:fields>
                    <a:field name="submit_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                </a:fields>
                <a:events>
                    <a:event name="submitSuccess" handler="submitMSG"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:tabPanel id="main_tab" height="600" width="1000">
                <a:tabs id="main_tab" width="990">
                    <a:tab prompt="抵押物信息" width="110">
                        <a:form title="基本信息" width="990">
                            <a:hBox labelWidth="100">
                                <a:textField name="pawn_name" bindTarget="pawn_ds" prompt="抵押物名称"/>
                                <a:textField name="pawn_contract_no" bindTarget="pawn_ds" prompt="抵押合同编号"/>
                                <a:lov name="lease_contract_code" bindTarget="pawn_ds" prompt="租赁合同编号"/>
                            </a:hBox>
                            <a:hBox labelWidth="100">
                                <a:lov name="customer_name" bindTarget="pawn_ds" fetchRemote="false" prompt="抵押人"/>
                                <a:textField name="pawn_register_no" bindTarget="pawn_ds" prompt="抵押登记证号"/>
                                <a:textField name="pawn_registed_dept" bindTarget="pawn_ds" prompt="登记部门"/>
                            </a:hBox>
                            <a:hBox labelWidth="100">
                                <a:numberField name="quantity" allowDecimals="false" bindTarget="pawn_ds" prompt="抵押物数量"/>
                                <a:comboBox name="uom_name" bindTarget="pawn_ds" prompt="单位"/>
                            </a:hBox>
                            <a:hBox labelWidth="100">
                                <a:numberField name="pawn_value" allowFormat="true" bindTarget="pawn_ds" prompt="价值"/>
                                <a:comboBox name="currency_name" bindTarget="pawn_ds" prompt="币种"/>
                            </a:hBox>
                            <a:hBox labelWidth="100">
                                <a:textField name="estate_license_code" bindTarget="pawn_ds" prompt="房产证号"/>
                                <a:hBox labelWidth="97">
                                    <a:numberField name="housing_area" bindTarget="pawn_ds" prompt="房屋面积" width="100"/>
                                    <span><![CDATA[平方米]]></span>
                                </a:hBox>
                            </a:hBox>
                            <a:hBox labelWidth="100">
                                <a:textField name="land_certificate_code" bindTarget="pawn_ds" prompt="土地证号"/>
                                <a:hBox labelWidth="97">
                                    <a:numberField name="land_area" bindTarget="pawn_ds" prompt="土地面积" width="100"/>
                                    <span><![CDATA[平方米]]></span>
                                </a:hBox>
                            </a:hBox>
                            <a:hBox labelWidth="100">
                                <a:datePicker name="start_date" bindTarget="pawn_ds" prompt="抵押日期从"/>
                                <a:datePicker name="end_date" bindTarget="pawn_ds" prompt="抵押日期到"/>
                                <a:comboBox name="pawn_status_des" bindTarget="pawn_ds" prompt="抵押物状态"/>
                            </a:hBox>
                            <a:hBox labelWidth="100">
                                <a:textField name="pawn_location" bindTarget="pawn_ds" prompt="房屋坐落" width="410"/>
                            </a:hBox>
                            <a:hBox labelWidth="100">
                                <a:textField name="pawn_ownership" bindTarget="pawn_ds" prompt="物权所属" width="410"/>
                            </a:hBox>
                            <a:hBox labelWidth="100">
                                <a:textField name="pawn_occupied" bindTarget="pawn_ds" prompt="占管状况" width="410"/>
                            </a:hBox>
                            <a:hBox labelWidth="100">
                                <a:textField name="note" bindTarget="pawn_ds" prompt="备注" width="410"/>
                            </a:hBox>
                        </a:form>
                        <a:hBox>
                            <a:button click="update_pawn" text="保存"/>
                            <a:button click="back" text="返回"/>
                        </a:hBox>
                    </a:tab>
                    <a:tab prompt="附件" ref="" width="110">
                        <a:form title="附件信息" width="990">
                            <a:grid id="grid_id" bindTarget="hls_pawn_upload_ds" height="300" model="hls_fnd.hls_pawn_upload" queryUrl="${/request/@context_path}/autocrud/hls_fnd.hls_pawn_upload/query?pawn_id=${/parameter/@pawn_id}&amp;_queryorderby=file_code asc" style="margin-left:42px" width="900">
                                <a:columns>
                                    <a:column name="file_name" prompt="文件类型" width="320"/>
                                    <a:column name="pawn_upload_id" align="center" prompt="附件上传" renderer="attachmentUpload" width="80"/>
                                    <a:column name="atm_file" prompt="HLS_CUSTOMER_UPLOAD.UPLOADFILE" renderer="attachmentLink" width="382"/>
                                </a:columns>
                                <a:editors>
                                    <a:checkBox id="file_checkBok"/>
                                </a:editors>
                            </a:grid>
                            <a:form labelWidth="100" style="margin-left:42px" title="其他附件上传" width="900">
                                <a:upload buttonWidth="75" deleteUrl="" fileType="*.*" pkvalue="${/parameter/@pawn_id}" sourcetype="hls_pawn" text="上传文件"/>
                            </a:form>
                        </a:form>
                    </a:tab>
                </a:tabs>
            </a:tabPanel>
        </a:screenBody>
    </a:view>
</a:screen>
