<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: LPC  
    $Date: 
    $Revision: 1.0  
    $Purpose: 成员指派
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:view>
        <script type="text/javascript"><![CDATA[
            function allocationPersonDs_query() {
                $('allocationPersonDs').query();
            }
            
            function allocationPersonDs_grid_add() {
                $('allocationPersonDs_grid').showEditorByRecord($('allocationPersonDs').create());
            }
            
            function allocationPersonDs_grid_clear() {
                $('allocationPersonDs_grid').clear();
            }
            
            function allocationPersonDs_grid_submit() {

                var result_ds = $('allocationPersonDs');
                if (result_ds.validate()) {
                    var result_record = result_ds.getAll();
                    var next_time_count = 0;
                    for (var i = 0;i < result_record.length;i++) {
                        var next_time_flag = result_record[i].get('next_time_flag');
                        var enable_flag = result_record[i].get('enable_flag');
                        if (enable_flag == 'Y') {
                            if (next_time_flag == 'Y') {
                                next_time_count = next_time_count + 1;
                            }
                        } else if(enable_flag == 'N' && next_time_flag == 'Y'){
                            Leaf.showMessage('提示', '勾选下次分配标志的组员需要启用!');
                            return;
                        }
                    }
                    if (next_time_count > 1) {
                        Leaf.showMessage('提示', '下次分配标志只能勾选一个!');
                        return;
                    } else {
                        result_ds.submit();
                    }
            
                }
            }
            
            function allocationPersonScreen_close() {
                $('allocation_group').close();
            }
            
            function allocationPersonDs_update(ds, record, name, value, oldvalue) {
                if (name == 'next_time_flag') {
                    if (record.get('enable_flag') == 'N') {
                        if (value == 'Y') {
                            Leaf.showMessage('提示', '请先启用该组员!');
                            return;
                        }
                    }
                }
            }
            // function editorFunction_allocationPersonDs_grid(record, name) {
            // if (record.isNew) {
            // if (name == 'seq') {
            // return 'allocationPersonDs_grid_editor_tf_upper';
            // }
            // }
            // return '';
            // }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="allocationPerson_headDs" autoQuery="true" model="zjwfl.ZJWFL1111.hls_auto_allocation_group" queryUrl="${/request/@context_path}/autocrud/zjwfl.ZJWFL1111.hls_auto_allocation_group/query?group_id=${/parameter/@group_id}">
                <a:fields>
                    <a:field name="group_code" readOnly="true"/>
                    <a:field name="group_name" readOnly="true"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="para_allocationPersonDs">
                <a:fields>
                    <a:field name="user_name" lovGridHeight="300" lovHeight="450" lovService="basic.sys_user_for_lov" lovWidth="500" prompt="HLS.USER_NAME" title="AUT106.CHOOSE_USER">
                        <a:mapping>
                            <a:map from="description" to="user_name"/>
                            <a:map from="user_id" to="user_id"/>
                        </a:mapping>
                    </a:field>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="allocationPersonDs" autoPageSize="true" autoQuery="true" fetchAll="false" model="zjwfl.ZJWFL1111.hls_auto_allocation_person" queryDataSet="para_allocationPersonDs" queryUrl="${/request/@context_path}/autocrud/zjwfl.ZJWFL1111.hls_auto_allocation_person/query?group_id=${/parameter/@group_id}" selectable="true">
                <a:fields>
                    <a:field name="group_id" defaultValue="${/parameter/@group_id}"/>
                    <a:field name="seq" required="true"/>
                    <a:field name="user_id"/>
                    <a:field name="user_name" lovGridHeight="300" lovHeight="450" lovService="basic.sys_user_for_lov" lovWidth="500" prompt="HLS.USER_NAME" required="true" title="AUT106.CHOOSE_USER">
                        <a:mapping>
                            <a:map from="description" to="user_name"/>
                            <a:map from="user_id" to="user_id"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="next_time_flag" checkedValue="Y" defaultValue="N" uncheckedValue="N"/>
                    <a:field name="enable_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="allocationPersonDs_update"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="allocationPersonScreen_close" text="HLS.CLOSE"/>
                <a:gridButton click="allocationPersonDs_grid_add" text="HLS.NEW"/>
                <a:gridButton click="allocationPersonDs_grid_clear" text="HLS.CLEAR"/>
                <a:gridButton click="allocationPersonDs_grid_submit" text="HLS.SAVE"/>
                <a:gridButton click="allocationPersonDs_query" text="HLS.QUERY"/>
            </a:screenTopToolbar>
            <a:form column="4" labelWidth="120" title="HLS.QUERY_TITLE">
                <a:textField name="group_code" bindTarget="allocationPerson_headDs" prompt="分组类型"/>
                <a:textField name="group_name" bindTarget="allocationPerson_headDs" prompt="分组名称"/>
                <a:lov name="user_name" bindTarget="para_allocationPersonDs" prompt="组员"/>
            </a:form>
            <a:grid id="allocationPersonDs_grid" bindTarget="allocationPersonDs" marginHeight="200" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="seq" align="left" editor="allocationPersonDs_grid_editor_tf" prompt="顺序" sortable="true" width="120"/>
                    <a:column name="user_name" editor="allocationPersonDs_grid_editor_lov" prompt="组员" width="300"/>
                    <a:column name="next_time_flag" editor="allocationPersonDs_grid_editor_check" prompt="下次分配标志" width="80"/>
                    <a:column name="enable_flag" editor="allocationPersonDs_grid_editor_check" prompt="启用标志" width="80"/>
                </a:columns>
                <a:editors>
                    <a:textField id="allocationPersonDs_grid_editor_tf_upper" typeCase="upper"/>
                    <a:textField id="allocationPersonDs_grid_editor_tf"/>
                    <a:comboBox id="allocationPersonDs_grid_editor_comb"/>
                    <a:checkBox id="allocationPersonDs_grid_editor_check"/>
                    <a:lov id="allocationPersonDs_grid_editor_lov"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>