<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: wangwei5743 
    $Date: 2014-10-8 下午1:13:25  
    $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.role_id=${/session/@role_id} and t1.company_id=${/session/@company_id}"
                       fetchAll="true" model="hls.HLS109.hls_default_parameter" rootPath="hls_default_parameter_path"/>
        <a:model-query fetchAll="true" model="prj.PRJ500D.prj_project_get_4s" rootPath="4s_root_path"/>
        <a:model-query fetchAll="true" model="prj.PRJ500D.prj_project_invoice_agent_id_dafault_value"
                       rootPath="prj_project_invoice_agent_id_dafault_value_path"/>
        <a:model-query defaultWhereClause="t1.company_id=${/session/@company_id}" fetchAll="true"
                       model="prj.PRJ500D.get_company_info" rootPath="company_info_path"/>
        <a:model-query fetchAll="true" model="prj.PRJ500D.user_agent_description" rootPath="user_agent_description"/>
		<a:model-query defaultWhereClause="t.user_id=${/session/@user_id}" model="hls.HLS214N.sys_division" rootPath="user_division"/>
    </a:init-procedure>
    <a:view>
        <a:link id="prj_chance_create_link"
                url="${/request/@context_path}/modules/prj/PRJ500N/prj_project_create.lview"/>
        <a:link id="prj_chance_constru_create_link"
                        url="${/request/@context_path}/modules/prj/PRJ500N/prj_project_create_constru.lview"/>
        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>
        <a:link id="prj500n_create_project_interface_link" model="prj.PRJ500N.ds_project_interface_query" modelaction="execute" />
		<a:link id="prj_chance_operat_create_link"
                                url="${/request/@context_path}/modules/prj/PRJ500N/prj_project_create_operat.lview"/>
        <script type="text/javascript"><![CDATA[
        //确定
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project');
            var record = $(ds_id).getCurrentRecord();
            if(record.data.division=='70'&&record.data.business_type!='LEASEBACK'){
                debugger;
                // $L.showErrorMessage("提示", '租赁物为铁甲业务的业务类型只能是售后回租!');
                $L.showErrorMessage("提示", '租赁物为二手机业务的业务类型只能是售后回租!');
                return false;
            }
            if(record.data.division=='92'&&record.data.business_type!='LEASEBACK'){
                debugger;
                $L.showErrorMessage("提示", '租赁物为北京心诚的业务类型只能是售后回租!');
                return false;
            }
			if(record.data.division=='95'&&record.data.business_type!='LEASEOPERAT'){
                $L.showErrorMessage("提示", '租赁物为经租设备的业务类型只能是经营性租赁!');
                return false;
            }
			if(record.data.division!='95'&&record.data.business_type=='LEASEOPERAT'){
                $L.showErrorMessage("提示", '业务类型为经营性租赁只能选择经租设备!');
                return false;
            }
            if ($(ds_id).validate()) {
                 var url;
                if(record.data.is_constru_unit == 'Y' || '${/model/user_agent_description/record/@is_constru_unit}' == 'Y'){
                    record.set('function_code', 'PRJ500D_CONSTRU');
                    url = "prj_chance_constru_create_link";
			     }else if(record.data.division=='95'){
                  record.set('function_code', 'PRJ500D_OPERAT');
                  url = "prj_chance_operat_create_link";
                }else{
                    record.set('function_code', 'PRJ500D');
                    url = "prj_chance_create_link";
                }
                record.data['url_title'] = '报价申请创建';
                record.set('function_usage', 'CREATE');
                record.set('document_category', 'PROJECT');
                record.set('default_value_dsid', ds_id);
                var param = record.data;
                record.set('winid', 'prj_porject_create_win_id');

                hls_doc_get_layout_code('con_contract_get_layout_code_link_id', param, url);

            }
        };

        Leaf.onReady(function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'prj_project');
            var head_record = $(ds_id).getAt(0);
            head_record.getField('invoice_agent_id_n').setRequired(true);
            var invoice_agent_id =  '${/model/user_agent_description/record/@bp_id}';
            var invoice_agent_id_n = '${/model/user_agent_description/record/@bp_name}';

            head_record.set('unit_id', '${/model/4s_root_path/record/@value_code}');
            head_record.set('unit_id_n', '${/model/4s_root_path/record/@value_name}');
            head_record.set('company_id', '${/model/company_info_path/record/@company_id}');
            head_record.set('company_id_n', '${/model/company_info_path/record/@company_short_name}');
            //head_record.set('invoice_agent_id', '${/model/prj_project_invoice_agent_id_dafault_value_path/record/@bp_id}');
            // head_record.set('invoice_agent_id', '${/model/prj_project_invoice_agent_id_dafault_value_path/record/@bp_id}');
            // head_record.set('invoice_agent_id_n', '${/model/prj_project_invoice_agent_id_dafault_value_path/record/@bp_id_n}');
            head_record.set('invoice_agent_id', invoice_agent_id);
            head_record.set('invoice_agent_id_n', invoice_agent_id_n);
			//经营性租赁改造  18083 2023/8/24
            if("${/model/user_division/record/@division}"==95){
              head_record.set('business_type','LEASEOPERAT');
              head_record.set('business_type_n','经营性租赁');
              head_record.set('division','95');
              head_record.set('division_n','经租设备');
              head_record.getField('division').setReadOnly(true);
              head_record.getField('division_n').setReadOnly(true);
              head_record.set('bp_class','bp_class');
              head_record.set('bp_class_n','法人');
            }

            if(!invoice_agent_id){
                head_record.getField('invoice_agent_id_n').setReadOnly(false);
                // head_record.getField('invoice_agent_id_n').setRequired(false);

            }



            // alert('${/session/@user_id}');
        });


        //更新时调用
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_update'] = function (ds, record, name, value, old_value, bp_seq) {
            //
            if (name == 'division') {

                // record.set('bp_class_n', '');

                // record.set('invoice_agent_id_n', '');
                record.getField('bp_class_n').setReadOnly(false);
                // record.getField('invoice_agent_id_n').setRequired(true);

            } else if (name == 'lease_channel') {
                record.set('division', '');
                record.set('division_n', '');
                record.set('first_flag', '');
                record.set('first_flag_n', '');
                record.set('ka_prj_id', '');
                record.set('ka_prj_id_n', '');

                record.getField('first_flag_n').setReadOnly(true);
                record.getField('first_flag_n').setRequired(false);

            }

        };




        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>