<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: hand  
    $Date: 2016-6-20 下午1:45:57  
    $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_plan_to_district_link" url="${/request/@context_path}/modules/cont/CON630/con_plan_to_district.lview"/>
        <a:link id="con_persons__district_link" url="${/request/@context_path}/modules/cont/CON630/con_persons_district.lview"/>
        <a:link id="con_collection_way_link" url="${/request/@context_path}/modules/cont/CON630/con_collection_ways.lview"/>
        <a:link id="save_collection_hold_link_id" model="cont.CON630.con_save_collection_hold" modelaction="update"/>
        <script type="text/javascript"><![CDATA[
             function persons_district_renderer(value, record, name) {

                 var staff_id= record.get('staff_id');
                if (name == 'district') {
                    return '<a  href="javascript:persons_district_window_open(\'' +staff_id + '\',\'' + name + '\')">' + '<font color="#FF9900">区域</font>' + '</a>';
                }
            }
            function persons_district_window_open(id, name,group_id) {
                if (Ext.isEmpty(id) || id == 'undefined') {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先点击保存!');
                } else {
                    var win = new Leaf.Window({
                        id: 'con_persons_district_window',
                        url: $('con_persons__district_link').getUrl(),
                        params: {
                            winId: 'con_persons_district_window',
                            staff_id: id
                        },
                        title: '区域定义',
                        height: 550,
                        width: 400
                    });
                }
            }   
             function district_renderer(value, record, name) {
                 var group_id= record.get('group_id');
                if (name == 'district') {
                    return '<a  href="javascript:district_window_open(\'' + group_id + '\',\'' + name + '\')">' + '<font color="#FF9900">区域</font>' + '</a>';
                }
            }
            function district_window_open(id, name) {
                if (Ext.isEmpty(id) || id == 'undefined') {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先点击保存!');
                } else {
                    var win = new Leaf.Window({
                        id: 'con_district_window',
                        url: $('con_plan_to_district_link').getUrl(),
                        params: {
                            winId: 'con_district_window',
                            group_id: id
                        },
                        title: '区域定义',
                        height: 550,
                        width: 400
                    });
                }
            }
           
            function quit() {
                if ('') {
                    $('').close();
                } else {
                    location.href = '${/request/@context_path}/modules/cont/CON630/con_collection_tgp.lview';
                    parent.shMenu('show');
                }
            }
             
             function save() {

                 $('con_collection_type_result_ds').submit();
                 var records =$('con_collection_hold_result_ds').getAt(0);
                   var collection_hold = records.get('collection_hold');
               //    Leaf.showConfirm('确认', '确定保存？', function() {
              //     $('con_collection_type_result_ds').submit();
                    // var records =$('con_collection_hold_result_ds').getAt(0);
                   // var collection_hold = records.get('collection_hold');
                    Leaf.request({
                    url: $('save_collection_hold_link_id').getUrl(),
                    para: {collection_hold : collection_hold},
                    success: function(args) {
                        $('con_collection_type_result_ds').query();
                        $('con_collection_group_result_ds').query();
                        $('con_collection_persons_result_ds').query();
                    },
                    failure: function(args) {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    error: function(args) {
                        Leaf.Masker.unmask(Ext.getBody());
                    },
                    scope: this
                });   
                    
              //  });
            
            }
             function collection_renderer(value, record, name) {
                 var type_id= record.get('type_id');
                if (name == 'collection_way') {
                    return '<a  href="javascript:collection_window_open(\'' + type_id + '\',\'' + name + '\')">' + '<font color="#FF9900">催收方式</font>' + '</a>';
                }
            }
            function collection_window_open(id, name) {
                if (Ext.isEmpty(id) || id == 'undefined') {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先点击保存!');
                } else {
                    var win = new Leaf.Window({
                        id: 'con_collection_way_window',
                        url: $('con_collection_way_link').getUrl(),
                        params: {
                            winId: 'con_collection_way_window',
                            type_id: id
                        },
                        title: '催收方式定义',
                        height: 500,
                        width: 400
                    });
                }
            }
            
            function addgroupid(ds,record,index) {
                var type_record = $('con_collection_type_result_ds').getCurrentRecord();
                if (Ext.isEmpty(type_record)) {
                    return;
                } else if (type_record.isNew) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先保存刚新添加的数据');
                      var des = $('con_collection_group_result_ds');
                      var group_record = des.getCurrentRecord();
                      des.remove(group_record);
                      return;
                }
            }
            
             function addstaffid(ds,record,index) {
                var group_record = $('con_collection_group_result_ds').getCurrentRecord();
                if (Ext.isEmpty(group_record)) {
                    return;
                } else if (group_record.isNew) {
                    Leaf.showMessage('${l:HLS.PROMPT}', '请先保存刚新添加的数据');
                      var des = $('con_collection_persons_result_ds');
                      var staff_record = des.getCurrentRecord();
                      des.remove(staff_record);
                      return;
                }
            }
            
        ]]></script>
        <a:dataSets>
            <a:dataSet id="con_collection_hold_result_ds" autoCreate="true" autoQuery="true" model="cont.CON630.con_collection_hold">
                <a:fields>
                    <a:field name="collection_hold" required="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con_collection_type_result_ds" autoQuery="true" fetchAll="true" model="cont.CON630.con_collection_type" selectable="true" selectionModel="single" submitUrl="${/request/@context_path}/modules/cont/CON630/con_collection.lsc">
                <a:fields>
                    <a:field name="type_id"/>
                    <a:field name="type_code"/>
                    <a:field name="type_name"/>
                    <a:field name="start_date"/>
                    <a:field name="end_date"/>
                    <a:field name="collection_way" defaultValue="催收方式"/>
                    <a:field name="note"/>
                </a:fields>
                <!--  <a:events>
                     <a:event name="add" handler="addtypeid"/>
               </a:events> -->
            </a:dataSet>
            <a:dataSet id="con_collection_group_result_ds" bindName="con_collection_group" bindTarget="con_collection_type_result_ds" fetchAll="true" model="cont.CON630.con_collection_group" selectable="true" selectionModel="single">
                <a:fields>
                    <a:field name="group_id"/>
                    <a:field name="type_id"/>
                    <a:field name="group_code"/>
                    <a:field name="group_name"/>
                    <a:field name="district" defaultValue="区域"/>
                    <a:field name="note"/>
                </a:fields>
                <a:events>
                    <a:event name="add" handler="addgroupid"/>
                </a:events>
            </a:dataSet>
            <a:dataSet id="con_collection_persons_result_ds" bindName="con_collection_persons" bindTarget="con_collection_group_result_ds" fetchAll="true" model="cont.CON630.con_collection_persons" selectable="true" selectionModel="single">
                <a:fields>
                    <a:field name="staff_id"/>
                    <a:field name="user_id"/>
                    <a:field name="group_id"/>
                    <a:field name="staff_name" lovGridHeight="350" lovHeight="500" lovLabelWidth="100" lovService="cont.CON630.con_collection_sys_user_lov" lovWidth="520" title="用户姓名">
                        <a:mapping>
                            <a:map from="user_id" to="user_id"/>
                            <a:map from="description" to="staff_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="district" defaultValue="区域"/>
                    <a:field name="note"/>
                </a:fields>
                <a:events>
                    <a:event name="add" handler="addstaffid"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="quit" text="退出"/>
                <a:gridButton click="save" text="保存"/>
            </a:screenTopToolbar>
            <a:form column="3" title="催收阀值">
                <a:numberField name="collection_hold" allowDecimals="false" bindTarget="con_collection_hold_result_ds" prompt="催收阀值"/>
            </a:form>
            <a:grid id="grid_id" bindTarget="con_collection_type_result_ds" height="175" marginWidth="250" navBar="true">
                <a:toolBar>
                    <a:button type="add"/>
                    <a:button type="delete"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="type_code" editor="grid_id_textField_id" prompt="类型代码" width="100"/>
                    <a:column name="type_name" editor="grid_id_textField_id" prompt="类型名称" width="100"/>
                    <a:column name="start_date" editor="grid_id_textField_id" prompt="开始天数" renderer="Leaf.formatNumber" width="100"/>
                    <a:column name="end_date" editor="grid_id_textField_id" prompt="结束天数" renderer="Leaf.formatNumber" width="100"/>
                    <a:column name="collection_way" prompt="催收方式" renderer="collection_renderer" width="100"/>
                    <a:column name="note" editor="grid_id_textField_id" prompt="备注" width="300"/>
                </a:columns>
                <a:editors>
                    <a:textField id="grid_id_textField_id"/>
                </a:editors>
            </a:grid>
            <a:grid id="grid_id1" bindTarget="con_collection_group_result_ds" height="175" marginWidth="250" navBar="true">
                <a:toolBar>
                    <a:button type="add"/>
                    <a:button type="delete"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="group_code" editor="grid_id_textField_id1" prompt="组别代码" width="100"/>
                    <a:column name="group_name" editor="grid_id_textField_id1" prompt="组别名称" width="100"/>
                    <a:column name="district" prompt="区域" renderer="district_renderer" width="100"/>
                    <a:column name="note" editor="grid_id_textField_id1" prompt="备注" width="300"/>
                </a:columns>
                <a:editors>
                    <a:textField id="grid_id_textField_id1"/>
                </a:editors>
            </a:grid>
            <a:grid id="grid_id2" bindTarget="con_collection_persons_result_ds" height="175" marginWidth="250" navBar="true">
                <a:toolBar>
                    <a:button type="add"/>
                    <a:button type="delete"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="staff_name" editor="staff_lov_name" prompt="员工" width="150"/>
                    <a:column name="district" prompt="区域" renderer="persons_district_renderer" width="150"/>
                    <a:column name="note" editor="grid_id_textField_id2" prompt="备注" width="300"/>
                </a:columns>
                <a:editors>
                    <a:numberField id="grid_id_numberField_id2"/>
                    <a:textField id="grid_id_textField_id2"/>
                    <a:lov id="staff_lov_name"/>
                </a:editors>
            </a:grid>
            <!--  <a:screen-include screen="modules/cont/CON630/con_collection_group.lview"/> -->
        </a:screenBody>
    </a:view>
</a:screen>
