<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangyu  
    $Date: 2015-12-06 下午14:57:33  
    $Revision: 1.0  
    $Purpose: 批量借款合同调息
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:init-procedure/>
    <a:view>
        <a:link id="con_batch_adjust_add_check_link" model="tre.TRE112.tre_loan_con_batch_hd_check" modelaction="update"/>
        <a:link id="con_batch_submit" model="cont.CON801.con_visit_report_batch_submit" modelaction="execute"/>
        <a:link id="batch_adjust_detail_link" url="${/request/@context_path}/modules/cont/CON801/con_visit_report_hds.lview"/>
        <a:link id="con801_attach_upload_link" url="${/request/@context_path}/uploadFile.lview"/>
        <script type="text/javascript"><![CDATA[
            function query_bacth_adjust_hd() {
                $('bacth_adjust_hd_ds').query();
            }
            
            function submitsuccess(ds, res) {
                ds.query();
            }
            
            function open_detail(value, record, name) {
                if (record.isNew) {
                    return '';
                } else {
                    var batch_id = record.get('batch_id');
                    if(name == 'detail'){
                        return '<a href="javascript:showDetail(' + value + ', '+batch_id+' );">' + '明细'+ '</a>';
                    }
                    
                    
                }
            
            }
            
            function showDetail(batch_hd_id ,batch_id) {
                new Leaf.Window({
                    id: 'batch_adjust_detail_winid',
                    url: $('batch_adjust_detail_link').getUrl(),
                    params: {
                        batch_hd_id: batch_hd_id,
                        batch_id :batch_id ,
                        win_id: 'batch_adjust_detail_winid'
                    },
                    title: '资产检查',
                    fullScreen: true
                }).on('close', function() {
                    $('bacth_adjust_hd_ds').query();
                });
            }
            
            function batch_adjust_grid_add() {
                Leaf.request({
                    url: $('con_batch_adjust_add_check_link').getUrl(),
                    success: function(res) {
                        var add_flag = res.result.add_flag;
                        if (add_flag == 'N') {
                            Leaf.showMessage('${l:PROMPT}', '请先提交已创建的调息申请（或其他用户可能创建了调息申请，但未提交）！');
                        } else {
                            $('bacth_adjust_hd_ds').create();
                        }
                    },
                    scope: this,
                    sync: true
                });
            
            }
            
            function delete_batch_req() {
                Leaf.showConfirm('提示', '是否确认删除', function() {
                    var records = $('bacth_adjust_hd_ds').getSelected();
                    var approval_status = records[0].get('approval_status');
                    if (approval_status != 'NEW') {
                        Leaf.showMessage('${l:PROMPT}', '新建的申请才允许删除！');
                        return;
                    }
                    $('bacth_adjust_hd_ds').remove(records[0]);
                });
            }
            function columnEditor(record,name){
                if(name == 'visit_date' && record.isNew){
                        return 'bacth_dateP';
                }
                if(name == 'batch_name' && record.isNew){
                        return 'bacth_txt';
                }
                if(name == 'batch_description' && record.isNew){
                        return 'bacth_txt';
                }
                if(name == 'status_n' && record.isNew){
                        return 'bacth_com';
                }
                
                
                
                
                return null;
            }
            function batch_adjust_grid_query(){
                $('bacth_adjust_hd_ds').query();
            }
            
           
            
            function batch_submit_approval(){
                var records = $('bacth_adjust_hd_ds').getSelected();
                if(records.length == 0){
                    Leaf.showMessage('${l:PROMPT}', '未选择！');
                    return ;
                }else if(records.length > 1){
                    Leaf.showMessage('${l:PROMPT}', '只能选择单项！');
                    return ;
                }
                rec = records[0];
                var v_status = rec.get('status_n');
                if(v_status == '审批中'  || v_status == '审批通过' ){
                    Leaf.showMessage('${l:PROMPT}', '只有新建或审批拒绝的报告才能提交审批！');
                    return ;
                }
                batch_id  = rec.get('batch_id');
                
                Leaf.showConfirm('提示', '是否确认提交审批', function() {
                    var url = $('con_batch_submit').getUrl() + '?batch_id='+batch_id;
                    Leaf.request({
                    url: url,
	                    success: function() {
	                        $('bacth_adjust_hd_ds').query();
	                    },
	                    failure: function() {
		                    Leaf.showMessage('${l:PROMPT}', '审批失败！');
		                },
		                error: function() {
		                    Leaf.showMessage('${l:PROMPT}', '审批出错！');
		                },
	                    scope: this,
	                    sync: true
	                });
                });
            }
            
            function attach_upload_win(batch_id){
                var url = $('con801_attach_upload_link').getUrl() + '?table_name=SDIC_CON_VISIT_REPORT_BATCH&header_id='+batch_id;
                new Leaf.Window({
                    url: url,
                    title: '附件上传',
                    id: 'con_visit_hd_win',
                    width: 850,
                    height: 400
                });
	      }
            
            function open_attach(value,record,name){
                if(!Ext.isEmpty(record.get('batch_id'))||!record.isNew){
	              return '<a href="javascript:attach_upload_win('+record.get('batch_id')+')">'+'附件上传'+'</a>';
	          }
            }
            
            function bacth_adjust_hd_ds_add(){
                var ds = $( 'bacth_adjust_hd_ds');
                var record = ds.create(ds.currentIndex);
                $( 'batch_adjust_grid').showEditorByRecord(record);
                
            }
            
            function bacth_adjust_hd_ds_save(){
                  var ds = $( 'bacth_adjust_hd_ds');
                if (ds.validate()) {
                    ds.submit();
                }
                
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="approval_status_ds" lookupCode="CON801_WFL_STATUS"/>
            <a:dataSet id="bacth_adjust_hd_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="batch_number"/>
                    <a:field name="status"/>
                    <a:field name="status_n" displayField="code_value_name" options="approval_status_ds" returnField="status" valueField="code_value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="bacth_adjust_hd_ds" PageSize="15" autoQuery="true" model="cont.CON801.sdic_con_visit_report_batch" queryDataSet="bacth_adjust_hd_query_ds" selectable="true" selectionModel="single">
                <a:fields>
                    <a:field name="batch_id"/>
                    <a:field name="batch_name" required="true"/>
                    <a:field name="batch_number"/>
                    <a:field name="batch_description" required="true"/>
                    <a:field name="visit_date" required="true"/>
                    <a:field name="status" defaultValue="NEW" required="true"/>
                    <a:field name="status_n" defaultValue="新建" displayField="code_value_name" options="approval_status_ds" returnField="status" valueField="code_value"/>
                </a:fields>
                <a:events>
                    <a:event name="submitsuccess" handler="submitsuccess"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <!--  <a:gridButton click="batch_adjust_grid_add" text="HLS.NEW"/>
                <a:gridButton click="delete_batch_req" text="删除"/>
                <a:gridButton click="query_bacth_adjust_hd" text="HLS.QUERY"/> -->
                <a:gridButton click="batch_adjust_grid_query" text="查询"/>
                <!-- <a:gridButton bind="batch_adjust_grid" type="add"/> -->
                <a:gridButton click="bacth_adjust_hd_ds_add" text="新增"/>
                <!-- <a:gridButton bind="batch_adjust_grid" type="save"/> -->
                <a:gridButton click="bacth_adjust_hd_ds_save" text="保存"/>
                <a:gridButton click="batch_submit_approval" text="提交审批"/>
                <!-- <a:gridButton bind="batch_adjust_grid" type="clear"/> -->
            </a:screenTopToolbar>
            <a:form column="2" labelWidth="100" marginWidth="200" title="查询">
                <a:textField name="batch_number" bindTarget="bacth_adjust_hd_query_ds" prompt="编号"/>
                <a:comboBox name="status_n" bindTarget="bacth_adjust_hd_query_ds" prompt="审批状态"/>
            </a:form>
            <a:grid id="batch_adjust_grid" Height="425" bindTarget="bacth_adjust_hd_ds" marginWidth="200" navBar="true">
                <a:toolBar>
                    <!-- <a:button  type="add"/>
	            	<a:button  type="delete"/>
	            	<a:button  type="save"/>
	            	<a:button   type="clear" /> --><![CDATA[
                    
                    
                    
                    
	            	
	            ]]></a:toolBar>
                <a:columns>
                    <a:column name="batch_number" align="center" prompt="编号" width="170"/>
                    <a:column name="batch_name" editorFunction="columnEditor" prompt="名称" width="250"/>
                    <a:column name="batch_description" editorFunction="columnEditor" prompt="描述"/>
                    <a:column name="status_n" align="center" editorFunction="columnEditor" prompt="审批状态"/>
                    <a:column name="visit_date" align="center" editorFunction="columnEditor" prompt="检查日期" renderer="Leaf.formatDate"/>
                    <a:column name="detail" align="center" prompt="明细" renderer="open_detail" width="170"/>
                    <a:column name="batch_attach" align="center" prompt="检查报告" renderer="open_attach" width="100"/>
                </a:columns>
                <a:editors>
                    <a:textArea id="bacth_ta"/>
                    <a:comboBox id="bacth_com"/>
                    <a:datePicker id="bacth_dateP"/>
                    <a:textField id="bacth_txt"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
