<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129  
    $Date: 2015-11-6 下午01:38:37  
    $Revision: 1.0  
    $Purpose: 价目表层次定义
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:view>
        <script type="text/javascript"><![CDATA[
            function level_define_back() {
                $('${/parameter/@winId}').close();
            }
            
            function level_define_add_level() {
                var record = $('hls_price_list_level_define_ds').getSelected()[0];
                var record1;
                if (Ext.isEmpty(record)) {
                    record1 = new Leaf.Record({
                        enabled_flag: 'Y',
                        doc_flag: 'Y'
                    });
                    $('hls_price_list_level_define_ds').add(record1);
            
                } else {
                    if (Ext.isEmpty(record.get('level_id'))) {
                        Leaf.showMessage('提示', '请先保存！');
                        return;
                    }
            
                    if (record.get('doc_flag') != 'Y') {
                        Leaf.showMessage('提示', '该节点下面不可以添加分类！');
                        return;
                    }
            
                    record1 = new Leaf.Record({
                        parent_level_id: record.get('level_id'),
                        enabled_flag: 'Y',
                        doc_flag: 'Y'
                    });
                    $('hls_price_list_level_define_ds').add(record1);
            
                }
            }
            
            function level_define_add_price() {
                var record = $('hls_price_list_level_define_ds').getSelected()[0];
            
                if (Ext.isEmpty(record)) {
                    return;
                }
            
                if (Ext.isEmpty(record.get('level_id'))) {
                    Leaf.showMessage('提示', '请先保存！');
                    return;
                }
            
                if (record.get('doc_flag') != 'Y') {
                    Leaf.showMessage('提示', '该节点下面不可以添加价目表！');
                    return;
                }
            
                var record1 = new Leaf.Record({
                    parent_level_id: record.get('level_id'),
                    enabled_flag: 'Y',
                    doc_flag: 'N'
                });
            
                $('hls_price_list_level_define_ds').add(record1);
            }
            
            function level_define_delete() {
                $('hls_price_list_level_define_treegrid').remove();
            }
            
            function level_define_save() {
                $('hls_price_list_level_define_ds').submit();
            }
            
            function level_define_treegrid_ef(record, name) {
                if (name == 'level_name') {
                    if (record.get('doc_flag') == 'Y') {
                        return 'level_define_treegrid_tf';
                    }
                } else if (name == 'price_list') {
                    if (record.get('doc_flag') != 'Y') {
                        return 'level_define_treegrid_lov';
                    }
                }
                return '';
            }
            
            function level_define_treegrid_render(value, record, name) {
                if (name == 'level_name') {
                    if (record.get('doc_flag') == 'Y') {
                        record.getField(name).setReadOnly(false);
                        record.getField(name).setRequired(true);
                    } else {
                        record.getField(name).setReadOnly(true);
                        record.getField(name).setRequired(false);
                    }
                } else if (name == 'price_list') {
                    if (record.get('doc_flag') == 'Y') {
                        record.getField(name).setReadOnly(true);
                        record.getField(name).setRequired(false);
                    } else {
                        record.getField(name).setReadOnly(false);
                        record.getField(name).setRequired(true);
                    }
                }
                return value;
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="hls_price_list_level_define_ds" autoQuery="true" fetchAll="true" model="hls.HLS050.hls_price_list_level_define" selectable="true">
                <a:fields>
                    <a:field name="level_id"/>
                    <a:field name="level_name"/>
                    <a:field name="price_list_name"/>
                    <a:field name="parent_level_id"/>
                    <a:field name="doc_flag"/>
                    <a:field name="price_list" lovGridHeight="320" lovHeight="450" lovService="hls.HLS050.hls_price_list_for_lov" lovWidth="500">
                        <a:mapping>
                            <a:map from="price_list" to="price_list"/>
                            <a:map from="description" to="price_list_name"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="seq"/>
                    <a:field name="enabled_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="level_define_back" text="返回"/>
                <a:gridButton click="level_define_add_level" text="新增分类"/>
                <a:gridButton click="level_define_add_price" text="添加价目表"/>
                <a:gridButton click="level_define_delete" text="删除"/>
                <a:gridButton click="level_define_save" text="保存"/>
            </a:screenTopToolbar>
            <a:treeGrid id="hls_price_list_level_define_treegrid" bindTarget="hls_price_list_level_define_ds" expandField="expand_flag" height="410" idField="level_id" navBar="true" parentField="parent_level_id" sequenceField="seq" width="670">
                <a:columns>
                    <a:column name="level_name" editorFunction="level_define_treegrid_ef" prompt="分类名称" renderer="level_define_treegrid_render" width="150"/>
                    <a:column name="price_list" editorFunction="level_define_treegrid_ef" prompt="价目表" renderer="level_define_treegrid_render" width="180"/>
                    <a:column name="price_list_name" prompt="价目表名称" width="200"/>
                    <a:column name="seq" editor="level_define_treegrid_nf" prompt="序号" width="50"/>
                    <a:column name="enabled_flag" editor="level_define_treegrid_cb" prompt="是否启用" width="60"/>
                </a:columns>
                <a:editors>
                    <a:lov id="level_define_treegrid_lov"/>
                    <a:checkBox id="level_define_treegrid_cb"/>
                    <a:textField id="level_define_treegrid_tf"/>
                    <a:numberField id="level_define_treegrid_nf" allowDecimals="false" allowNegative="false"/>
                </a:editors>
            </a:treeGrid>
        </a:screenBody>
    </a:view>
</a:screen>
