<?xml version="1.0" encoding="UTF-8"?>
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true" trace="true">
    <a:init-procedure>
        <a:model-query model="cont.CON620.get_sys_role" rootPath="role_info"/>
        <a:model-query fetchAll="true" model="cont.CON2000.login_user" rootPath="login_user"/>
    </a:init-procedure>
    <a:view>
        <a:link id="prj_approval_link_id" model="cont.CON2000.contract_phone_approval" modelaction="update"/>
        <a:link id="${/parameter/@layout_code}_prj500_cdd_downloadFile_id"
                url="${/request/@context_path}/downloadFile.lview"/>
        <!--        <a:link id="prj_approval_link_id" model="classes/cont/CON2000/contract_phone_approval.lwm" modelaction="update"/>-->
        <script ><![CDATA[

        //新增和加载时调用(form)
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_on_layout_dynamic_form_add_and_load'] = function (ds, record, config_records, bp_seq) {
            var user_name = '${/model/login_user/record/@user_name}';
            var tenant_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASIC_1', 'con_contract');
            if(user_name!='ZHOUYICONG'&&"${/model/role_info/record/@role_code}" !="0019" ){
                if (tenant_ds_id == ds.id) {
                    record.getField('ht_send_message_n').setReadOnly(true);
                    record.getField('ht_cell_phone').setReadOnly(true);

                }

            }else{
                if (tenant_ds_id == ds.id) {
                    if (Leaf.isEmpty(record.get('ht_send_message'))) {
                        record.set('ht_send_message', 'YES');
                        record.set('ht_send_message_n', '是');
                        record.getField('ht_cell_phone').setRequired(true);
                    } else if (record.get('ht_send_message') == 'YES') {
                        record.getField('ht_cell_phone').setRequired(true);
                    }

                    if (Leaf.isEmpty(record.get('phone_status'))){
                        record.set('phone_status', 'NEW');
                    }
                    if(record.get('phone_status')=='APPROVING'){
                        record.getField('ht_send_message_n').setReadOnly(true);
                        record.getField('ht_cell_phone').setReadOnly(true);
                    }


                }
            }
        }
        //只有代理店下级和周一聪才会显示按钮
        if("${/model/role_info/record/@role_code}"!="0019" && '${/model/login_user/record/@user_name}'!='ZHOUYICONG'){
            if(document.getElementById('${/parameter/@layout_code}_user_button1')){
                document.getElementById('${/parameter/@layout_code}_user_button1').style.display = "none";
            }
            if(document.getElementById('${/parameter/@layout_code}_save')){
                document.getElementById('${/parameter/@layout_code}_save').style.display = "none";
            }
        }

        if('${/parameter/@phone_status}'=='APPROVING'){
            document.getElementById('${/parameter/@layout_code}_user_button1').style.display = "none";
            document.getElementById('${/parameter/@layout_code}_save').style.display = "none";
        }


        var submit_wfl_flag = 'N';

        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {


            Leaf.showConfirm('${HLS.PROMPT}', '确认要提交工作流吗?', function () {
                submit_wfl_flag = 'Y';
                window['${/parameter/@layout_code}_SAVE_LAYOUT_DYNAMIC_CLICK']();

            });

        }

        //保存submitsuccess调用
        window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function (ds, record, res) {
            window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract');
            var current_record = $(ds_id).getCurrentRecord();
            var contract_id = current_record.get('contract_id');

            if (submit_wfl_flag == 'Y') {
                submit_wfl_flag = 'N';
                Leaf.request({
                    url: $('prj_approval_link_id').getUrl(),
                    para: {
                        contract_id: contract_id
                    },
                    scope: this,
                    success: function () {
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                        $('${/parameter/@winid}').close();
                        Aurora.SideBar.show({
                            msg: '操作成功',
                            duration: 2000
                        });
                    },
                    failure: function () {
                        submit_wfl_flag = 'N';
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    },
                    error: function () {
                        submit_wfl_flag = 'N';
                        window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    }
                });
            }else{
                window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            }
        }

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

            var tenant_ds_id = get_dsid_by_tabcode_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'F_BASIC_1', 'con_contract');

            if (tenant_ds_id == ds.id && tenant_ds_id) {

                if (name == 'ht_send_message') {
                    if (value == 'YES') {
                        record.getField('ht_cell_phone').setRequired(true);
                    } else if (value == 'NO') {
                        record.getField('ht_cell_phone').setRequired(false);
                    }
                }

            }
        }


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