<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: lpc 9874
    $Date: 2017/11/20 14:35:56 $
    $Revision: 1.0 $
    $Purpose: 抵押登记备案创建
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure><![CDATA[     
    ]]></a:init-procedure>
    <a:view>
        <a:link id="acp_invoice_attachment_uploadFile_id" url="${/request/@context_path}/uploadFile.lview"/>
        <a:link id="acp_invoice_attachment_downloadFile_id" url="${/request/@context_path}/downloadFile.lview"/>
        <a:link id="mor_register_delete_id" model="mor.mor100.mor_register_query" modelaction="batch_update"/>
        <a:screen-include screen="modules/hls/hls_common_javascript.lview"/>
        <script type="text/javascript"><![CDATA[
            function con303N_exit() {
                $('contract_houdu_query_window').close();
            }
            
            function detail_upload_window(check_id, file_name, record_id) {
                var record = $('file_result_ds').getCurrentRecord();
                var oldvalue = file_name ? file_name : null;
                var contract_id = ${/parameter/@contract_id};
                paras = {
                    'contract_id': contract_id
                };
                var url = $('acp_invoice_attachment_downloadFile_id').getUrl() + '?table_name=PRJ_CDD_ITEM_CHECK&header_id=' + check_id;
                var win = new Leaf.Window({
                    url: url,
                    title: '${l:HLS.SUPPORTING_DOCUMENT}',
                    id: 'insurance_records_uploadFile_id',
                    width: 850,
                    height: 400
                });
                // win.on('close', function() {
                    // $('file_result_ds').query();
                // });
            
            }
            //附件上传
            
            function attachment_upload(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:detail_upload_window(\'' + record.get('check_id') + '\',\'' + file_name + '\',\'' + record_id + '\')">附件上传</a>';
                }
            }
            
            function con303n_attachment(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_suffix = temp[0].substr(temp[0].lastIndexOf('.') + 1).toUpperCase();
                            if (file_suffix == 'BMP' || file_suffix == 'JPG' || file_suffix == 'JPEG' || file_suffix == 'PNG' || file_suffix == 'GIF') {
                                url = url + '<a ref="img" href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            } else {
                                url = url + '<a href=' + link + temp[1] + '>' + temp[0] + '</a>' + ',';
                            }
                        }
                    }
                    return url;
                }
            }
            
            function check_raise_status(ds) {
                var records = ds.getAll();
                for (var i = 0;i < records.length;i++) {
                    var raise_status = records[i].get('raise_status');
                    if (raise_status != 'INCEPT') {
                        records[i].getField('condition_req').setReadOnly(true);
                        records[i].getField('department_desc').setReadOnly(true);
                        records[i].getField('req_status_desc').setReadOnly(true);
                        records[i].getField('expiration_date').setReadOnly(true);
                        records[i].getField('req_description').setReadOnly(true);
                    }
                }
            }
            
            function check_delete(ds, records) {
                for (var i = 0;i < records.length;i++) {
                    if (records[i].get('raise_status') != 'INCEPT') {
                        Leaf.showMessage( '${l:HLS.PROMPT}', '非付款阶段不能删除!');
                        return false;
                    }
                }
            }
        ]]></script>
        <a:dataSet id="doc_require_ds" lookupCode="DOC_REQUIRE"/>
        <a:dataSet id="req_status_ds" lookupCode="REQ_STATUS"/>
        <a:dataSet id="raise_status_ds" lookupCode="RAISE_STATUS"/>
        <a:dataSets>
            <a:dataSet id="file_result_ds" autoQuery="true" fetchAll="false" model="cont.CON303N.con303n_file_query" pageSize="15" queryUrl="${/request/@context_path}/autocrud/cont.CON303N.con303n_file_query/query?contract_id=${/parameter/@contract_id}" selectable="true">
                <a:fields>
                    <a:field name="contract_id" defaultValue="${/parameter/@contract_id}"/>
                    <a:field name="cdd_list_id" defaultValue="${/parameter/@cdd_list_id}"/>
                    <a:field name="note" readOnly="true"/>
                    <a:field name="doc_require_n" displayField="code_value_name" options="doc_require_ds" readOnly="true" returnField="doc_require" valueField="code_value"/>
                    <a:field name="doc_require" readOnly="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con_file_result_ds" autoQuery="true" fetchAll="false" model="cont.CON303N.con_file_query" pageSize="15" queryUrl="${/request/@context_path}/autocrud/cont.CON303N.con_file_query/query?contract_id=${/parameter/@contract_id}" selectable="true">
                <a:fields>
                    <a:field name="file_info_id"/>
                    <a:field name="contract_id" defaultValue="${/parameter/@contract_id}"/>
                    <a:field name="condition_req" readOnly="true"/>
                    <a:field name="department_id" readOnly="true"/>
                    <a:field name="raise_status_desc" defaultValue="付款阶段" displayField="code_value_name" options="raise_status_ds" readOnly="true" returnField="raise_status" valueField="code_value"/>
                    <a:field name="raise_status" defaultValue="INCEPT" readOnly="true"/>
                    <a:field name="req_status_desc" displayField="code_value_name" options="req_status_ds" readOnly="true" returnField="req_status" valueField="code_value"/>
                    <a:field name="req_status" readOnly="true"/>
                    <a:field name="department_desc" autoComplete="true" lovGridHeight="300" lovHeight="450" lovService="cont.CON303N.exp_org_unit_for_lov" lovWidth="650" readOnly="true" title="部门">
                        <a:mapping>
                            <a:map from="unit_id" to="department_id"/>
                            <a:map from="description" to="department_desc"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="expiration_date" readOnly="true"/>
                    <a:field name="req_description" readOnly="true"/>
                    <a:field name="req_flag" checkedValue="Y" defaultValue="N" readOnly="true" uncheckedValue="N"/>
                    <a:field name="req_date" readOnly="true"/>
                </a:fields>
                <!-- <a:events>
                    <a:event name="load" handler="check_raise_status"/>
                    <a:event name="beforeremove" handler="check_delete"/>
                </a:events> -->
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="con303N_exit" text="HLS.EXIT"/>
            </a:screenTopToolbar>
            <a:grid id="file_grid" bindTarget="file_result_ds" marginHeight="180" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="description" prompt="文件名称" width="120"/>
                    <a:column name="attachment" align="center" prompt="附件上传" renderer="attachment_upload" width="85"/>
                    <a:column name="file_name" prompt="附件名称" renderer="con303n_attachment" width="120"/>
                    <a:column name="doc_require_n" prompt="文件要求" width="120"/>
                    <a:column name="note" prompt="备注" width="120"/>
                </a:columns>
                <!-- <a:editors>
                    <a:textField id="fileDs_tf"/>
                    <a:comboBox id="doc_type_n_cb_id"/>
                </a:editors> -->
            </a:grid>
            <a:grid id="con_file_grid" bindTarget="con_file_result_ds" marginHeight="180" marginWidth="30" navBar="true">
                <!-- <a:toolBar>
                    <a:button type="add"/>
                    <a:button type="delete"/>
                    <a:button type="save"/>
                </a:toolBar> -->
                <a:columns>
                    <a:column name="condition_req" editor="conFileDs_tf" prompt="条件要求" width="120"/>
                    <a:column name="department_desc" editor="departmentDs_lov" prompt="部门" width="120"/>
                    <a:column name="req_status_desc" editor="statusDs_box" prompt="要求完成时点" width="120"/>
                    <a:column name="raise_status_desc" editor="statusDs_box" prompt="提出时点" width="120"/>
                    <a:datePicker name="expiration_date" editor="dateDs_picker" prompt="到期时间" renderer="Leaf.formatDate" width="110"/>
                    <a:column name="req_description" editor="conFileDs_tf" prompt="备注" width="120"/>
                    <a:column name="req_flag" editor="isNo_check" prompt="是否已完成" width="120"/>
                    <a:column name="req_date" editor="dateDs_picker" prompt="完成 时间" renderer="Leaf.formatDate" width="120"/>
                </a:columns>
                <!-- <a:editors>
                    <a:textField id="conFileDs_tf"/>
                    <a:lov id="departmentDs_lov"/>
                    <a:datePicker id="dateDs_picker"/>
                    <a:checkBox id="isNo_check"/>
                    <a:comboBox id="statusDs_box"/>
                </a:editors> -->
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
