<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Feng  
    $Date: 2014-1-3 上午10:24:25  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
    <a:init-procedure>
        <s:server-script import="contract_print_path.js"><![CDATA[
           $ctx.parameter.file_path = con_print_path[ 'con_print_path'];
           $ctx.parameter.tomcat_source = con_print_path['tomcat_source' ];
         ]]></s:server-script>
        <a:model-execute model="db.prj_cdd_item_pkg.prj_cdd_item_extra_save"/>
        <a:model-query model="cont.CON555B.con555_get_info" rootPath="con555_get_info"/>
    </a:init-procedure>
    <a:view>
        <link href="${/request/@context_path}/css/lightbox.css" rel="stylesheet" type="text/css"/>
        <!-- <script src="${/request/@context_path}/javascripts/lightbox.js" /> -->
        <a:link id="tre503_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="tre503_cdd_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <a:link id="get_contranct_link_id" model="cont.CON555A.con_contract" modelaction="update"/>
        <a:link id="con555_cdd_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="con_contract_location_self" url="${/request/@context_path}/modules/cont/CON555B/con_contract_storage_apply.lview"/>
        <a:link id="con555_cdd_download_id" url="${/request/@context_path}/atm_download.lsc"/>
        <a:link id="con555_cdd_query_link" url="${/request/@context_path}/autocrud/cont.CON555A.con_content_query_detail/query"/>
        <a:link id="con_contract_file_link_id" model="db.con_contract_pkg.update_contract_file_date" modelaction="execute"/>
        <link href="${/request/@context_path}/css/lightbox.css" rel="stylesheet" type="text/css"/>
        <!-- <a:link id="con555B_con_contract_location_id" model="cont.CON570.contract_archive" modelaction="update"/> -->
        <a:link id="detail_ds_link_id" model="cont.CON570.con555_get_info" modelaction="update"/>
        <a:link id="con_submit_approval_link" model="cont.CON555A.contract_workflow_start" modelaction="update"/>
        <script src="${/request/@context_path}/javascripts/lightbox.js" type="text/javascript"/>
        <script type="text/javascript"><![CDATA[
            Ext.ux.Lightbox.register('a[ref=img]', true);
            
            window['con555_cdd_editorFunction'] = function(record, name) {
                if (record.get('sys_flag') == 'N') {
                    return 'con555_cdd_tf_id';
                }
                return '';
            };
            
            function con555_cdd_selectFunc(record) {
                if (record.get('sys_flag') == 'Y') {
                    return false;
                }
                return true;
            }
            
            function view_pdf(attachment_id) {
                Leaf.request({
                    url: '${/request/@context_path}/autocrud/fnd.fnd_atm_attachment/query',
                    para: {
                        attachment_id: attachment_id
                    },
                    success: function(res) {

                        var path = res.result.record.file_path;
                        path = path.substr(path.indexOf('hls_attachment'));
                        var tomcat_source = '${/parameter/@tomcat_source}';
                        var source_path = 'http://' + window.location.host + '/' + tomcat_source + '/' + path;
                        var oWin = window.open(source_path);
                    },
                    scope: this
                });
            }
            
            
            window['con555_cdd_attachment_render'] = function(value, record, name) {
                //
                var check_id = record.get('check_id');
                var file_name = record.get('file_name');
                var record_id = record.id;
                if (!record.isNew && check_id) {
                    return '<a href="javascript:window[\'con555_cdd_attachtment_upload\'](\'' + record.get('check_id') + '\',\'' + file_name + '\',\'' + record_id + '\')">${l:HLS.ATTACHMENT}</a>';
                }
            };
            
            window['con555_link_render'] = function(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])) {
                            var file_name = temp[0].toUpperCase();
                            var file_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                            if (file_name.indexOf('.PDF') >= 0) {
                                url = url + '<a href=javascript:view_pdf(\'' + temp[1] + '\')>' + temp[0] + '</a>' + ',';
                            } else if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                url = url + '<a href=' + link + temp[1] + ' ref="img">' + temp[0] + '</a>' + ',';
                            } else {
                                url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            }
                        }
                    }
                    return url;
            
                }
            
            };
            
            window['con555_cdd_attachtment_upload'] = function(check_id, file_name, record_id) {
                var url = $('tre503_cdd_downloadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + check_id;
                if ('${/parameter/@upload_atm_flag}' == 'Y') {
                    url = $('con555_cdd_uploadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + check_id;
                }
            
                var record = $('con555_detail_result_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: 'con555_cdd_uploadFile_screen_id',
                    width: 850,
                    height: 400
                });
                win.on('close', function() {
                    //
                    Leaf.request({
                        url: $('con555_cdd_query_link').getUrl(),
                        para: paras,
                        success: function(data) {
                            $('con555_detail_result_ds').query();
            
                            var newvalue = $('con555_detail_result_ds').findById(record_id).get('file_name');
                            //con555_attach_update(oldvalue,newvalue);
                        },
                        sync: true
                    });
            
                });
            
            };
            window['con555_cdd_required_render'] = function(value, record, name) {
                var project_required_flag = record.get('project_required_flag');
                if (project_required_flag == 'Y') {
                    return '<pan style="color:red">' + value + '</pan>';
                } else {
                    return value;
                }
            };
            
            function con555_con_contract_back() {
                $('con_contract_storage_apply_window').close();
            }
            
            function con555_con_contract_reset() {
                $('con555_detail_ds').reset();
            }
            
            function con555_con_contract_submit() {
                var contract_id = $('con555_detail_ds').getCurrentRecord().get('contract_id');
                var archive_status = $('con555_detail_ds').getCurrentRecord().get('archive_status');
                if (archive_status == '20' || archive_status == '30') {
                    Leaf.showMessage('提示', '未归档的支付表才能提交档案审批！');
                } else {
                    //
                    con555_detail_result_save();
                    var url = $('con_submit_approval_link').getUrl();
                    var detail_mask;
                    detail_mask = Ext.getBody();
                    Leaf.Masker.mask(detail_mask, '${l:HLS.EXECUTING}');
                    Leaf.request({
                        url: url,
                        para: {
                            contract_id: contract_id
                        },
                        success: function() {
                            $('con555_detail_ds').query();
                            Leaf.Masker.unmask(detail_mask);
                            Leaf.SideBar.show({
                                msg: '操作成功',
                                duration: 2000
                            });
                        },
                        failure: function() {
                            Leaf.Masker.unmask(detail_mask);
                        },
                        error: function() {
                            Leaf.Masker.unmask(detail_mask);
                        },
                        scope: this
                    });
                }
            
            }
            
            
            
            function con555_detail_result_save() {
                $('con555_detail_result_ds').submit();
                var contract_id = $('con555_detail_ds').getCurrentRecord().get('contract_id');
                var archive_date = $('con555_detail_ds').getCurrentRecord().get('archive_date');
                var archive_flag = $('con555_detail_ds').getCurrentRecord().get('archive_flag');
                var url = $('detail_ds_link_id').getUrl();
                Leaf.request({
                    url: url,
                    para: {
                        contract_id: contract_id,
                        archive_flag: archive_flag,
                        archive_date: archive_date
                    },
                    success: function() {
                        $('con555_detail_ds').query();
                        Leaf.SideBar.show({
                            msg: '操作成功',
                            duration: 2000
                        });
                    },
                    failure: function() {},
                    error: function() {},
                    scope: this
                });
            }
            //加载时控制字段的只读
            onLoad_LineDs = function(ds) {

                var records = ds.getAll();
                for (var i = 0;i < records.length;i++) {
                    if ('${/parameter/@edit_flag}' == 'Y') {
                        records[i].getField('paper_content_flag').setReadOnly(true);
                        records[i].getField('archive_reason').setReadOnly(true);
                        if (records[i].get('paper_content_flag') == 'Y') {
                            records[i].getField('paper_apply_flag').setReadOnly(true);
                            records[i].getField('doc_type_n').setReadOnly(true);
                            records[i].getField('amount').setReadOnly(true);
                            records[i].getField('doc_address').setReadOnly(true);
                            records[i].getField('note').setReadOnly(true);
                        }
                    } else if ('${/parameter/@edit_flag}' == 'N') {
                        if (records[i].get('paper_content_flag') == 'Y') {
                            records[i].getField('paper_apply_flag').setReadOnly(true);
                            records[i].getField('doc_type_n').setReadOnly(true);
                            records[i].getField('amount').setReadOnly(true);
                            records[i].getField('doc_address').setReadOnly(true);
                            records[i].getField('archive_reason').setReadOnly(true);
                            records[i].getField('note').setReadOnly(true);
                        }
                        records[i].getField('paper_apply_flag').setReadOnly(true);
                        records[i].getField('doc_type_n').setReadOnly(true);
                        records[i].getField('amount').setReadOnly(true);
                        records[i].getField('doc_address').setReadOnly(true);
                        // records[i].getField('archive_reason').setReadOnly(true);
                        records[i].getField('note').setReadOnly(true);
                    }
                }
            };
            
            function zjwfl5110_beforeapproveCheck(type) {
                //
                con555_detail_result_save();
                return true;
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="doc_type_ds" lookupCode="FILE_TYPE"/>
            <a:dataSet id="doc_require_ds" lookupCode="DOC_REQUIRE"/>
            <a:dataSet id="region_ds" lookupCode="HLS_SYS_REGION"/>
            <a:dataSet id="archive_flagds" lookupCode="YES_NO"/>
            <a:dataSet id="con555_detail_ds" autoCreate="true" autoQuery="true" model="cont.CON570.con555_get_info" queryUrl="${/request/@context_path}/autocrud/cont.CON570.con555_get_info/query?contract_id=${/parameter/@contract_id}">
                <a:fields>
                    <a:field name="contract_id"/>
                    <a:field name="contract_number" readOnly="true"/>
                    <a:field name="project_number" readOnly="true"/>
                    <a:field name="bp_name" readOnly="true"/>
                    <a:field name="business_type_desc" readOnly="true"/>
                    <a:field name="division_desc" readOnly="true"/>
                    <a:field name="bp_class_desc" readOnly="true"/>
                    <a:field name="invoice_agent_desc" readOnly="true"/>
                    <a:field name="contract_id" readOnly="true"/>
                    <a:field name="project_id" readOnly="true"/>
                    <a:field name="express_number" readOnly="true"/>
                    <a:field name="express_province_n" readOnly="true"/>
                    <a:field name="express_city_n" readOnly="true"/>
                    <a:field name="express_date" readOnly="true"/>
                    <a:field name="archive_status" readOnly="true"/>
                    <a:field name="reg_status" readOnly="true"/>
                    <a:field name="archive_status_n" readOnly="true"/>
                    <a:field name="reg_status_n" readOnly="true"/>
                    <a:field name="doc_type1" readOnly="true"/>
                    <a:field name="doc_type2" readOnly="true"/>
                    <a:field name="inception_of_lease" readOnly="true"/>
                    <a:field name="express_person" readOnly="true"/>
                    <a:field name="express_tel" readOnly="true"/>
                    <a:field name="express_note" readOnly="true"/>
                    <a:field name="express_address" readOnly="true"/>
                    <a:field name="region" defaultValue="${/model/con555_get_info/record/@region}" displayField="code_value_name" options="region_ds" returnField="region_n" valueField="code_value"/>
                    <a:field name="region_n"/>
                    <a:field name="hd_user_col_v02"/>
                    <a:field name="archive_date" readOnly="true"/>
                    <a:field name="archive_flag_desc" displayField="code_value_name" options="archive_flagds" readOnly="true" returnField="archive_flag" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con555_detail_result_ds" autoPageSize="true" autoQuery="true" fetchAll="true" model="cont.CON555A.con_content_query_detail" pageSize="13" queryDataSet="con555_detail_ds" queryUrl="${/request/@context_path}/autocrud/cont.CON555A.con_content_query_detail/query?contract_id=${/parameter/@contract_id}" selectFunction="con555_cdd_selectFunc" selectable="true">
                <a:fields>
                    <a:field name="cdd_item"/>
                    <a:field name="paper_required" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="not_applicable" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="paper_content_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="paper_apply_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="collection_data_flag" checkedValue="Y" defaultValue="N" readOnly="true" 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="document_table" defaultValue="CON_CONTRACT"/>
                    <a:field name="note"/>
                    <a:field name="notes"/>
                    <a:field name="doc_require" displayField="code_value_name" options="doc_require_ds" returnField="doc_require_n" valueField="code_value"/>
                    <a:field name="doc_require_n"/>
                    <a:field name="doc_type_n" displayField="code_value_name" options="doc_type_ds" returnField="doc_type" valueField="code_value"/>
                    <a:field name="amount"/>
                    <!-- <a:field name="file_type_n" displayField="code_value_name" options="file_typeds" returnField="file_type" valueField="code_value"/> -->
                    <a:field name="archive_number"/>
                    <a:field name="doc_address"/>
                    <a:field name="archive_reason"/>
                </a:fields>
                <a:events>
                    <a:event name="load" handler="onLoad_LineDs"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <!-- <a:gridButton click="con555_con_contract_back" text="HLS.BACK"/> -->
                <a:gridButton click="con555_detail_result_save" text="保存"/>
                <!-- <a:gridButton id="save1" click="con555_con_contract_submit" text="归档审批"/> -->
            </a:screenTopToolbar>
            <a:form column="4" labelWidth="120" marginWidth="30" title="基础信息">
                <a:textField name="contract_number" bindTarget="con555_detail_ds" prompt="支付表编号"/>
                <a:textField name="bp_name" bindTarget="con555_detail_ds" prompt="承租人名称"/>
                <a:textField name="project_number" bindTarget="con555_detail_ds" prompt="申请编号"/>
                <a:textField name="business_type_desc" bindTarget="con555_detail_ds" prompt="业务类型"/>
                <!-- <a:textField name="division_desc" bindTarget="con555_detail_ds" prompt="产品线"/> -->
                <a:textField name="bp_class_desc" bindTarget="con555_detail_ds" prompt="客户类别"/>
                <a:textField name="invoice_agent_desc" bindTarget="con555_detail_ds" prompt="经销商"/>
                <a:comboBox name="archive_flag_desc" bindTarget="con555_detail_ds" prompt="是否缺失资料"/>
                <a:datePicker name="archive_date" bindTarget="con555_detail_ds" prompt="归档完成日期"/>
                <!-- <a:textField name="archive_status_n" bindTarget="con555_detail_ds" prompt="合同归档"/>
                <a:comboBox name="region" bindTarget="con555_detail_ds" prompt="区域"/>
                <a:textField name="hd_user_col_v02" bindTarget="con555_detail_ds" prompt="序号"/> -->
            </a:form>
            <a:grid bindTarget="con555_detail_result_ds" height="350" marginWidth="30" navBar="true">
                <!-- <a:toolBar>
                    <a:button type="add"/>
                    <a:button type="save"/>
                    <a:button type="delete"/>
                </a:toolBar> -->
                <a:columns>
                    <a:column name="description" editorFunction="con555_cdd_editorFunction" prompt="HLS.DOCUMENT_NAME" renderer="con555_cdd_required_render" width="250"/>
                    <!--<a:column name="attachment_required" editor="con555_cdd_ck_id" prompt="HLS.DIGITAL_FILE" width="40"/>
                    <a:column name="paper_required" editor="con555_cdd_ck_id" prompt="已提交" width="40"/>-->
                    <a:column name="attachment" align="center" prompt="附件" renderer="con555_cdd_attachment_render" width="70"/>
                    <a:column name="file_name" align="center" prompt="附件名" renderer="con555_link_render" width="300"/>
                    <a:column name="paper_apply_flag" align="center" editor="con555_cdd_ck_id" prompt="纸质归档申请" width="85"/>
                    <a:column name="doc_type_n" align="center" editor="doc_type_n_cb_id" prompt="原件/复印件" width="85"/>
                    <a:column name="amount" editor="con555_cdd_tf_id" prompt="归档份数" width="85"/>
                    <a:column name="doc_address" editor="con555_cdd_tf_id" prompt="归档位置" width="85"/>
                    <!-- <a:column name="archive_reason" editor="con555_cdd_tf_id" prompt="未入库原因" width="120"/> -->
                    <a:column name="note" editor="con555_cdd_tf_id" prompt="HLS.COMMENT" width="120"/>
                    <a:column name="paper_content_flag" align="center" editor="con555_cdd_ck_id" prompt="纸质是否归档" width="85"/>
                    <a:column name="archive_reason" editor="con555_cdd_tf_id" prompt="未入库原因" width="120"/>
                    <!--<a:column name="creation_date" prompt="附件上传时期" renderer="Leaf.formatDate" width="150"/>-->
                </a:columns>
                <a:editors>
                    <a:checkBox id="con555_cdd_ck_id"/>
                    <a:comboBox id="doc_type_n_cb_id"/>
                    <a:textField id="con555_cdd_tf_id"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
