<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: lingfeng.chen
    $Date: 2017-7-14 上午10:06:32
    $Revision: 1.0
    $Purpose: 潜在客户管理
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" trace="true">
    <a:init-procedure>
        <a:model-query fetchAll="true" model="basic.hls_sys_time_default_value" rootPath="default_value_path"/>
        <a:model-query model="basic.sys_session_info" rootPath="mainPage_session_record"/>
        <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:init-procedure>
    <a:view>
        <a:link id="hls210_hn_chance_bp_interviews_link" url="${/request/@context_path}/modules/hls/HLS210/hn_chance_bp_interviews.lview"/>
        <a:screen-include screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=CHANCE_BP&amp;function_code=HLS210"/>
        <script type="text/javascript"><![CDATA[
            function hls210_grid_editorFunction(record, name) {
                if (name == 'chance_bp_name') {
                    return 'hls210_grid_textField';
                }
                if (name == 'bp_class_desc') {
                    return 'hls210_grid_comboBox';
                }
                if (name == 'chance_source_desc') {
                    return 'hls210_grid_comboBox';
                }
                if (name == 'orgcrdno') {
                    if (record.get('bp_class') == 'ORG') {
                        return 'hls210_grid_textField_18';
                    }
                }
                if (name == 'id_card_no') {
                    if (record.get('bp_class') == 'NP') {
                        return 'hls210_grid_textField';
                    }
            
                }
                if (name == 'contact_person') {
                    if (record.get('bp_class') == 'ORG') {
                        return 'hls210_grid_textField';
                    }
            
                }
                if (name == 'cell_phone') {
                    return 'hls210_grid_textField';
                }
                if (name == 'enabled_flag') {
                    return 'hls210_grid_checkBox';
                }
            
                return '';
            }
            
            function hls210_query() {
                $("hls210_hn_chance_bp_result_ds").query();
            }
            
            function hls210_reset() {
                $('hls210_hn_chance_bp_query_ds').reset();
            }
            
            function hls210_ds_update_handler(ds, record, name, value, oldvalue) {
                if (name == 'bp_class') {
                    if (value == 'ORG') {
                        record.getField('contact_person').setRequired(true);
                        record.getField('orgcrdno').setRequired(true);
                    }
                    if (value == "NP") {
                        record.getField('contact_person').setRequired(false);
                        record.getField('orgcrdno').setRequired(false);
                    }
                }
            }
            
            function hls210_open_win(id) {
                var record = $('hls210_hn_chance_bp_result_ds').findById(id);
                var url = $('hls210_hn_chance_bp_interviews_link').getUrl();
                var win = new Leaf.Window({
                    id: 'hls210_hn_chance_bp_interviews_winid',
                    url: url,
                    params: {
                        chance_bp_id: record.get('chance_bp_id'),
                        chance_bp_name: record.get('chance_bp_name'),
                        winid: 'hls210_hn_chance_bp_interviews_winid'
                    },
                    title: '访谈信息',
                    fullScreen: true
                });
            
            }
            
            function hls210_detail_renderer(value, record, name) {
            
                if (!record.isNew) {
                    return "<a href='javascript:hls210_open_win(" + record.id + ")'>访谈信息</a>";
                }
            }
            
            function orgcrdno_validator(record, name, value) {
                if (value  ) {
                    var reg = /^[a-zA-Z0-9]+$/;
                    if (reg.test(value)) {
                        return true;
                    }
                    return '只能包含字母数字';
                }
                return true;
            }
        ]]></script>
        <a:dataSets>
            <a:dataSet id="hls211_bp_class_ds" lookupCode="HLS211_BP_CLASS"/>
            <a:dataSet id="lch501_chance_source_ds" lookupCode="LCH501_CHANCE_SOURCE"/>
            <a:dataSet id="hls210_hn_chance_bp_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="chance_bp_name"/>
                    <a:field name="bp_class_desc" displayField="code_value_name" options="hls211_bp_class_ds" returnField="bp_class" valueField="code_value"/>
                    <a:field name="bp_class"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="hls210_hn_chance_bp_result_ds" autoPageSize="true" autoQuery="true" model="hls.HLS210.hn_chance_bp" queryDataSet="hls210_hn_chance_bp_query_ds">
                <a:fields>
                    <a:field name="bp_class_desc" displayField="code_value_name" options="hls211_bp_class_ds" required="true" returnField="bp_class" valueField="code_value"/>
                    <!--       <a:field name="chance_source_desc" displayField="code_value_name" options="lch501_chance_source_ds" required="true" returnField="chance_source" valueField="code_value"/>
        -->
                    <a:field name="unit_id" defaultValue="${/model/hls_default_parameter_path/record/@unit_id}"/>
                    <a:field name="unit_id_n" defaultValue="${/model/hls_default_parameter_path/record/@unit_name}"/>
                    <a:field name="owner_user_id_n" defaultValue="${/model/mainPage_session_record/record/@user_desc}"/>
                    <a:field name="enabled_flag" checkedValue="Y" defaultValue="Y" uncheckedValue="N"/>
                    <a:field name="chance_bp_name" required="true"/>
                    <a:field name="cell_phone" required="true"/>
                    <a:field name="id_card_no" validator="orgcrdno_validator"/>
                    <a:field name="orgcrdno" validator="orgcrdno_validator"/>
                    <a:field name="creation_date_desc" defaultValue="${/model/default_value_path/record/@now_time}"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="hls210_ds_update_handler"/>
                    <a:event name="query" handler="aut_authority_list_validate_query"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="hls210_query" text="HLS.QUERY"/>
                <a:gridButton click="hls210_reset" text="HLS.RESET"/>
                <a:gridButton bind="hls210_hn_chance_bp_result_grid" text="新增" type="add"/>
                <a:gridButton bind="hls210_hn_chance_bp_result_grid" text="HLS.SAVE" type="save"/>
            </a:screenTopToolbar>
            <a:form column="2" title="查询条件">
                <a:textField name="chance_bp_name" bindTarget="hls210_hn_chance_bp_query_ds" prompt="客户名称"/>
                <a:comboBox name="bp_class_desc" bindTarget="hls210_hn_chance_bp_query_ds" prompt="客户类型"/>
            </a:form>
            <a:grid id="hls210_hn_chance_bp_result_grid" bindTarget="hls210_hn_chance_bp_result_ds" marginHeight="200" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="chance_bp_name" editorFunction="hls210_grid_editorFunction" prompt="客户名称" width="200"/>
                    <a:column name="bp_class_desc" editorFunction="hls210_grid_editorFunction" prompt="客户类型"/>
                    <!-- <a:column name="chance_source_desc" editorFunction="hls210_grid_editorFunction" prompt="客户来源"/> -->
                    <a:column name="orgcrdno" editorFunction="hls210_grid_editorFunction" prompt="社会统一信用证代码" width="200"/>
                    <a:column name="id_card_no" editorFunction="hls210_grid_editorFunction" prompt="身份证号码" width="150"/>
                    <a:column name="contact_person" editorFunction="hls210_grid_editorFunction" prompt="联系人"/>
                    <a:column name="cell_phone" editorFunction="hls210_grid_editorFunction" prompt="联系方式"/>
                    <a:column name="unit_id_n" prompt="业务部"/>
                    <a:column name="owner_user_id_n" prompt="创建人"/>
                    <a:column name="creation_date_desc" prompt="创建时间" renderer="Leaf.formatDate"/>
                    <a:column name="hls210_detail_renderer" align="center" prompt="访谈记录" renderer="hls210_detail_renderer"/>
                    <!--  <a:column name="is_bp" prompt="客户状态"   /> -->
                    <!-- <a:column name="enabled_flag" editorFunction="hls210_grid_editorFunction" prompt="启用"/> -->
                </a:columns>
                <a:editors>
                    <a:comboBox id="hls210_grid_comboBox"/>
                    <a:checkBox id="hls210_grid_checkBox" checkedValue="Y" uncheckedValue="N"/>
                    <a:datePicker id="hls210_grid_datePicker"/>
                    <a:lov id="hls210_grid_lov"/>
                    <a:textField id="hls210_grid_textField_18" maxLength="18"/>
                    <a:textField id="hls210_grid_textField"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>
