<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhangxing5129  
    $Date: 2014-8-14 上午10:21:13  
    $Revision: 1.0  
    $Purpose: 租赁物维护入口界面
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true"
          trace="true">
    <a:init-procedure>
        <a:model-query defaultWhereClause="t1.user_id=${/session/@user_id}" model="basic.sys_session_info" rootPath="user_name_path"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con_contract_get_layout_code_link" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>
        <a:link id="get_lease_item_devision_link" model="hls.HLS203.hls_lease_item" modelaction="query"/>
        <a:link id="hls_lease_item_modify_link"
                url="${/request/@context_path}/modules/hls/HLS203N/hls_lease_item_modify.lview"/>
        <a:link id="hls_lease_item_list_link"
                url="${/request/@context_path}/modules/hls/HLS203/hls_lease_item_detail.lview"/>
        <script type="text/javascript"><![CDATA[
        function open_lease_item_win(record_id, ds_id) {
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            Leaf.request({
                url: $('get_lease_item_devision_link').getUrl(),
                para: {
                    'lease_item_id': record.get('lease_item_id')
                },
                success: function (data) {
                    Leaf.Masker.unmask(Ext.getBody());
                    if (data.result.record) {
                        param['division'] = data.result.record['division'];
                        param['function_code'] = 'HLS203D';
                        param['function_usage'] = 'MODIFY';
                        param['maintain_type'] = 'UPDATE';
                        param['url_title'] = '租赁物维护';
                        hls_doc_get_layout_code('con_contract_get_layout_code_link', param, 'hls_lease_item_modify_link', ds_id);
                    }
                },
                failure: function () {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                error: function () {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                scope: this
            });

        }

        function open_lease_item_detail_win(record_id, ds_id) {
            var record = $(ds_id).findById(record_id);
            var lease_item_id = record.get('lease_item_id');
            var li_list_type = record.get('li_list_type');
            new Leaf.Window({
                url: $('hls_lease_item_list_link').getUrl() + '?lease_item_id=' + lease_item_id + '&li_list_type=' + li_list_type,
                params: {
                    winId: 'hls_lease_item_detail_winId'
                },
                title: '${l:HLS201.HLS_LEASE_ITEM_LIST}',
                id: 'hls_lease_item_detail_winId',
                width: 900,
                height: 480
            });
        }

        window['${/parameter/@layout_code}_dynamic_link_renderer'] = function (value, record, name, config_record) {
            if (name == 'lease_item_code' && value) {
                return '<a href="javascript:open_lease_item_win(' + record.id + ',\'' + record.ds.id + '\')">' + value + '</a>';
            } else if (name == 'lease_item_detail') {
                return '<a href="javascript:open_lease_item_detail_win(' + record.id + ',\'' + record.ds.id + '\')">明细</a>';
            }
        };

        //维护按钮
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_lease_item');
            var records = $(ds_id).getSelected();
            if (records.length != 1) {
                Leaf.showMessage('${l:PROMPT}', '${l:HLS.SELECT_RECORD}');
                return;
            }
            var record = records[0];
            open_lease_item_win(record.id, ds_id);

        };

        window['${/parameter/@layout_code}_on_layout_dynamic_grid_query'] = function (ds, qpara, bp_seq) {
            // alert(111);

            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_lease_item');

            if (ds == $(ds_id)) {
                aut_authority_list_validate_query(ds, qpara);
                //   alert(1);
            }
        };

        window['${/parameter/@layout_code}_on_layout_dynamic_grid_load'] = function(ds, record) {
            //0017  宏菱管理员   HAND   HAND管理员
            var  role_code = '${/model/user_name_path/record/@role_code}';
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_lease_item');
            if (record) {
                if (role_code == '0017' || role_code == 'HAND') {
                    record.getField('ref_n01').setReadOnly(false);
                } else {
                    record.getField('ref_n01').setReadOnly(true);
                }
            }
            if(ds.id == ds_id){
                var record = $(ds_id).getAll()
                for (var i=0;i<record.length;i++){
                    if(record[i].data.division=='70' || record[i].data.division=='92'){
                        record[i].getField('pattern').setRequired(false);
                        record[i].getField('pattern').setReadOnly(true);
                        record[i].getField('equipments').setReadOnly(true);
                        record[i].getField('detention').setReadOnly(true);
                        record[i].getField('detention').setRequired(false);
                        record[i].getField('machine_model_class').setReadOnly(true);
                        record[i].getField('machine_model_class_n').setReadOnly(true);
                        record[i].getField('ref_n01').setReadOnly(true);
                        record[i].getField('created_by_n').setReadOnly(true);
                        record[i].getField('vender_id').setReadOnly(true);
                        record[i].getField('vender_id').setRequired(false);
                        record[i].getField('vender_id_n').setReadOnly(true);
                        record[i].getField('vender_id_n').setRequired(false);
                    }
                }
            }
        };
        //新增时调用(grid,table,gridBox)
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_grid_add'] = function(ds, record, config_records, bp_seq) {
            record.set("created_by_n",'${/model/user_name_path/record/@user_name}');
            record.set("created_by",'${/session/@user_id}');
            record.getField('ref_n01').setReadOnly(false);
        };

        //更新时调用
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function(ds, record, name, value, old_value, bp_seq) {
            debugger;
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_lease_item');
            if(ds.id == ds_id){
                if(name == 'division'){
                    if(value == '70' || value == '92'){
                        record.getField('pattern').setReadOnly(true);
                        record.getField('pattern').setRequired(false);
                        record.getField('equipments').setReadOnly(true);
                        record.getField('detention').setReadOnly(true);
                        record.getField('detention').setRequired(false);
                        record.set('machine_model_class',' ');
                        record.set('machine_model_class_n',' ');
                        record.getField('machine_model_class').setReadOnly(true);
                        record.getField('machine_model_class_n').setReadOnly(true);
                        record.getField('ref_n01').setReadOnly(true);
                        record.getField('created_by_n').setReadOnly(true);
                        record.getField('vender_id').setReadOnly(true);
                        record.getField('vender_id').setRequired(false);
                        record.getField('vender_id_n').setReadOnly(true);
                        record.getField('vender_id_n').setRequired(false);
                    }else {
                        record.getField('pattern').setReadOnly(false);
                        record.getField('pattern').setRequired(true);
                        record.getField('equipments').setReadOnly(false);
                        record.getField('detention').setReadOnly(false);
                        record.getField('detention').setRequired(true);
                        record.set('machine_model_class','LARGE');
                        record.set('machine_model_class_n','大型');
                        record.getField('machine_model_class').setReadOnly(false);
                        record.getField('machine_model_class_n').setReadOnly(false);
                        record.getField('ref_n01').setReadOnly(false);
                        record.getField('vender_id').setReadOnly(false);
                        record.getField('vender_id').setRequired(true);
                        record.getField('vender_id_n').setReadOnly(false);
                        record.getField('vender_id_n').setRequired(true);
                    }
                }
            }
        }

        //更新机型信息
        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'hls_lease_item');

            Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            Leaf.request({
                url: '${/request/@context_path}/autocrud/hls.HLS203.hls_lease_item/update',
                para: {
                    'user_id': '${/session/@user_id}'
                },
                success: function (res) {
                    Leaf.Masker.unmask(Ext.getBody());
                    Leaf.SideBar.show({
                        msg: '操作成功',
                        duration: 2000
                    });
                    $(ds_id).query();
                },
                error: function () {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                failure: function () {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                sync: true,
                scope: this
            })
            ;

        };
        ]]></script>
        <a:screen-include
                screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=LEASE_ITEM&amp;function_code=HLS203"/>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>
