<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang 
    $Date: 2015-4-13 上午10:15:31  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" xmlns:t="http://www.leaf-framework.org/touch" customizationEnabled="true" trace="true">
    <a:view template="touch">
        <script src="${/request/@context_path}/resource/leaf.ui.touch/default/base/iscroll.js" type="text/javascript"/>
        <script type="text/javascript"><![CDATA[
            function lock_current_window() {
                Touch.Masker.mask($('#all'), '正在执行...');
            }
            
            function unlock_current_window() {
                Touch.Masker.unmask($('#all'));
            }
            
            function next_step() {
                lock_current_window();
                var bool = check();
                if (bool) {
                    alert(bool);
                    unlock_current_window();
                } else {
                    Touch.get('chance_create').request(function(data) {
                        if (data.success) {
                            var chance_id = data.result.chance_id;
                            var document_type = data.result.document_type;
                            if (document_type == 'OPPL') {
                                document_type = 'LEASE';
                            } else {
                                document_type = 'LEASEBACK';
                            }
                            var company_id = data.result.company_id;
                            location.href = '${/request/@context_path}/modules/app/calculate2.lview?chance_id=' + chance_id + '&document_type=' + document_type + '&company_id=' + company_id;
                        } else {
                            alert('跳转失败');
                            unlock_current_window();
                        }
                    }, function() {
                        alert('跳转失败');
                        unlock_current_window();
                    });
                }
            }
            
            //var sc = new iScroll('wrapper');
            
            function callback() {
                if (!sc) {
                    sc = new iScroll('wrapper');
                } else {
                    sc.refresh();
                }
            }
            
            
            //初始化数据
            
            function init_data() {
                Touch.get('combo_brand_request').request(
            
                function(data) {
                    var record = data.result.record;
                    if (record instanceof Array) {
                        init_brand(record);
                    } else {
                        var records = new Array();
                        records[0] = record;
                        init_brand(records);
                    }
            
                    Touch.get('combo_series_request').request(
            
                    function(data) {
                        var record = data.result.record;
                        if (record instanceof Array) {
                            init_series(record);
                        } else {
                            var records = new Array();
                            records[0] = record;
                            init_series(records);
                        }
            
                        Touch.get('combo_model_request').request(
            
                        function(data) {
                            var record = data.result.record;
                            if (record instanceof Array) {
                                init_model(record);
                            } else {
                                var records = new Array();
                                records[0] = record;
                                init_model(records);
                            }
                        });
            
                    });
            
                });
            
                Touch.get('company_request').request(
            
                function(data) {
                    var record = data.result.record;
                    if (record instanceof Array) {
                        init_company_id(record);
                    } else {
                        var records = Array();
                        records[0] = record;
                        init_company_id(records);
                    }
            
                });
            }
            
            //设置下拉框对象列表
            //para:
            //select下拉框对象
            //records数据集合
            //allow_null是否添加一条默认空记录,bool值
            
            function set_combo_list(select, records, allow_null, type) {
                var html;
                if (allow_null) {
                    html = ['<option value="">' + type + '</option>'];
                } else {
                    html = [];
                }
                for (var i = 0,
                    l = records.length;i < l;i++) {
                    var r = records[i];
                    if (r) {
                        var display = r['name'],
                            v = r['value'];
            
                        html.push('<option value="', v, '">', display, '</option>');
                    }
            
                }
                select[0].innerHTML = html.join('');
            
            }
            
            function init_brand(records) {
                var select = $('#brand');
                set_combo_list(select, records, true, '品牌');
            }
            
            function init_series(records) {
                var select = $('#series');
                set_combo_list(select, records, true, '车系');
            }
            
            function init_model(records) {
                var select = $('#model');
                set_combo_list(select, records, true, '车型');
            }
            
            function init_company_id(records) {
                var select = $('#company_id');
                set_combo_list(select, records, true, '公司');
            }
            
            function brand_list_change() {
                var html = [];
                var brand = $('#brand')[0];
                var series = $('#series')[0];
                var model = $('#model')[0];
                var value = brand.value;
                if (value == '') {
                    html.push('<option SELECTED="true" value="">车系</option>');
                    series.innerHTML = html.join('');
                    series.disabled = true;
                    html = [];
                    html.push('<option SELECTED="true" value="">车型</option>');
                    model.innerHTML = html.join('');
                    model.disabled = true;
                    return;
                } else {
                    Touch.get('combo_series_request').request(
            
                    function(data) {
                        var record = data.result.record;
                        if (record instanceof Array) {
                            init_series(record);
                        } else {
                            var records = new Array();
                            records[0] = record;
                            init_series(records);
                        }
                        series.disabled = false;
                    });
                }
            }
            
            function series_list_change() {
                var html = [];
                var series = $('#series')[0];
                var model = $('#model')[0];
                var value = series.value;
                if (value == '') {
                    html.push('<option SELECTED="true" value="">车型</option>');
                    model.innerHTML = html.join('');
                    model.disabled = true;
                } else {
                    Touch.get('combo_model_request').request(
            
                    function(data) {
                        var record = data.result.record;
                        if (record instanceof Array) {
                            init_model(record);
                        } else {
                            var records = new Array();
                            records[0] = record;
                            init_model(records);
                        }
                        model.disabled = false;
                    });
                }
            
            }
            
            function check() {
                var select = $('#tenant_name');
                var value = select[0].value;
                if (value != '') {} else {
                    return '客户名称没有输入,请重新输入!';
                }
            
                var cellphone = /^([\d-+]*)$/;
                select = $('#tenant_phone');
                value = select[0].value;
                if (cellphone.test(value) && value != '') {} else {
                    return '联系电话输入有误,请重新输入!';
                }
            
                select = $('#bp_type');
                value = select[0].value;
                if (value != '') {} else {
                    return '客户类型没有选择,请选择!';
                }
            
                select = $('#brand');
                value = select[0].value;
                if (value != '') {} else {
                    return '品牌没有选择,请选择!';
                }
            
                select = $('#series');
                value = select[0].value;
                if (value != '') {} else {
                    return '车系没有选择,请选择!';
                }
            
                select = $('#model');
                value = select[0].value;
                if (value != '') {} else {
                    return '车型没有选择,请选择!';
                }
            
                select = $('#document_type');
                value = select[0].value;
                if (value != '') {} else {
                    return '租赁模式没有选择,请选择!';
                }
            
                select = $('#company_id');
                value = select[0].value;
                if (value != '') {} else {
                    return '公司没有选择,请选择!';
                }
            
                return false;
            }
            
            // function tenant_name_check() {
            // var select = $('#tenant_name');
            // var value = select[0].value;
            // if (value != '') {
            // return true;
            // } else {
            // return false;
            // }
            // }
            
            // function tenant_phone_check() {
            // var cellphone = /^([\d-+]*)$/;
            // var select = $('#tenant_phone');
            // var value = select[0].value;
            // if (cellphone.test(value) && value != '') {
            // return true;
            // } else {
            // return false;
            // }
            // }
            
            // function bp_type_check() {
            // var select = $('#bp_type');
            // var value = select[0].value;
            // if (value != '') {
            // return true;
            // } else {
            // return false;
            // }
            // }
            
            // function brand_check() {
            // var select = $('#brand');
            // var value = select[0].value;
            // if (value != '') {
            // return true;
            // } else {
            // return false;
            // }
            // }
            
            // function series_check() {
            // var select = $('#series');
            // var value = select[0].value;
            // if (value != '') {
            // return true;
            // } else {
            // return false;
            // }
            // }
            
            // function model_check() {
            // var select = $('#model');
            // var value = select[0].value;
            // if (value != '') {
            // return true;
            // } else {
            // return false;
            // }
            // }
            
            // function document_type_check() {
            // var select = $('#document_type');
            // var value = select[0].value;
            // if (value != '') {
            // return true;
            // } else {
            // return false;
            // }
            // }
            
            function company_id_check() {
                var select = $('#company_id');
                var value = select[0].value;
                if (value != '') {
                    return true;
                } else {
                    return false;
                }
            }
            
            
            
            
            
            document.addEventListener('touchmove', function(e) {
                e.preventDefault();
            }, false);
        ]]></script>
        <style media="all" type="text/css"><![CDATA[
            body,ul,li {
                padding:0;
                margin:0;
                border:0;
                background-color:#fff;
            }
            ul,li {
                list-style: none;
            }
            li {
                position: relative;
                border-bottom: #DBD7D2 1px solid;
                border-top: 1px solid #FCFAF9;
            }
            .cd tr {
                height:24px;
            }
            body {
                font-size:12px;
                -webkit-user-select:none;
                -webkit-text-size-adjust:none;
                font-family:helvetica;
            }
            a:link,a:visited{
                text-decoration:none;
                color:black;                    
            } 
            .ei{
                text-align:left;
                font-size:14px;
            }
            .name {
                font-size:20px;
                font-weight:700;
            }
            #header {
                position:absolute; z-index:0;
                top:0; left:0;
                width:100%;
                height:40px;
                background-color:#d51875;
                background:url(${/request/@context_path}/images/touch/bgtop.gif) repeat-x;
                padding:0;
                color:#eee;
                font-size:20px;
                text-align:center;
            }
            #wrapper {
                padding:2px;
                margin-top:38px;
            }
            #scroller {
                position:absolute; z-index:1;
            /*  -webkit-touch-callout:none;*/
                -webkit-tap-highlight-color:rgba(0,0,0,0);
                width:100%;
                padding:0;
            }
            .label  {
                line-height:2em;
                font-size:1.5em;
                height:2em;
            }
            .info {
                line-height:2em;
                font-size:1.5em;
                height:2em;
            }
                
        ]]></style>
        <center>
            <t:ajax id="chance_create" url="${/request/@context_path}/autocrud/app.app_quote.hls_app_quote_create_chance/insert">
                <t:parameters>
                    <t:parameter name="tenant_name" bind="tenant_name" dataType="java.lang.String"/>
                    <t:parameter name="tenant_phone" bind="tenant_phone" dataType="java.lang.String"/>
                    <t:parameter name="bp_type" bind="bp_type" dataType="java.lang.String"/>
                    <t:parameter name="brand_id" bind="brand" dataType="java.lang.Long"/>
                    <t:parameter name="series_id" bind="series" dataType="java.lang.Long"/>
                    <t:parameter name="model_id" bind="model" dataType="java.lang.Long"/>
                    <t:parameter name="document_type" bind="document_type" dataType="java.lang.String"/>
                    <t:parameter name="company_id" bind="company_id" dataType="java.lang.Long"/>
                </t:parameters>
            </t:ajax>
            <t:ajax id="combo_brand_request" url="${/request/@context_path}/autocrud/app.app_quote.hls_app_quote_choose_car_brand/query"/>
            <t:ajax id="combo_series_request" url="${/request/@context_path}/autocrud/app.app_quote.hls_app_quote_choose_car_series/query">
                <t:parameters>
                    <t:parameter name="brand_id" bind="brand" dataType="java.lang.String"/>
                </t:parameters>
            </t:ajax>
            <t:ajax id="combo_model_request" url="${/request/@context_path}/autocrud/app.app_quote.hls_app_quote_choose_car_model/query">
                <t:parameters>
                    <t:parameter name="brand_id" bind="brand" dataType="java.lang.String"/>
                    <t:parameter name="series_id" bind="series" dataType="java.lang.String"/>
                </t:parameters>
            </t:ajax>
            <t:ajax id="company_request" url="${/request/@context_path}/autocrud/app.app_quote.hls_app_quote_choose_company/query">
                <t:parameters>
                    <t:parameter name="user_id" dataType="java.lang.Long" value="${/session/@user_id}"/>
                </t:parameters>
            </t:ajax>
            <div id="all">
                <div id="header">
                    <span style="margin-top:2px;float:left;margin-top:5px;font-size:16px;height:30px;width:70px;margin-right:5px;"/>
                    <span style="line-height:40px;font-size:20px;font-weight:700"><![CDATA[商机报价]]></span>
                    <t:button className="gray" style="margin-top:2px;float:right;margin-top:5px;font-size:16px;height:30px;width:70px;margin-right:5px;" text="下一步">
                        <t:events>
                            <t:event name="click" handler="next_step"/>
                        </t:events>
                    </t:button>
                </div>
                <div id="wrapper">
                    <div style="width:100%;background:#fff;min-height:100%;">
                        <table cellspacing="10" style="width:100%">
                            <tr>
                                <td colspan="2">
                                    <div style="background-color:    #e8e8e8;    padding:    0px   8px;-webkit-border-radius:    4px;border:1px    solid                #333;font-size:1.5em;height:1.5em;line-height:1.5em;">
                                        <div style="float:left;width:35%;">
                                            <span><![CDATA[客户名称]]></span>
                                        </div>
                                        <input name="tenant_name" id="tenant_name" required="true" style="float:right;border:0px;outline:0px;margin:0px;padding:0px;height:100%;font-size:1em;line-height:1em;background:none;width:65%;text-align:center" type="text"/>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <div style="background-color: #e8e8e8; padding: 0px 8px;-webkit-border-radius: 4px;border:1px solid #333;font-size:1.5em;height:1.5em;line-height:1.5em;">
                                        <div style="float: left;width:35%;">
                                            <span><![CDATA[联系电话]]></span>
                                        </div>
                                        <input name="tenant_phone" id="tenant_phone" required="" style="float:right;border:0px;outline:0px;margin:0px;padding:0px;height:100%;font-size:1em;line-height:1em;background:none;width:65%;text-align:center" type="number"/>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <select id="bp_type" class="info" style="width:100%;height:30px;-webkit-border-radius: 4px;font-size:1.5em">
                                        <option SELECTED="true" value=""><![CDATA[客户类型]]></option>
                                        <option value="ORG"><![CDATA[法人]]></option>
                                        <option value="NP"><![CDATA[个人]]></option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <select id="brand" class="info" onchange="brand_list_change()" style="width:100%;height:30px;-webkit-border-radius: 4px;font-size:1.5em">
                                        <option SELECTED="true" value=""><![CDATA[品牌]]></option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <select id="series" class="info" disabled="disabled" onchange="series_list_change()" style="width:100%;height:30px;-webkit-border-radius:4px;font-size:1.5em;">
                                        <option SELECTED="true" value=""><![CDATA[车系]]></option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <select id="model" class="info" disabled="disabled" style="width:100%;height:30px;-webkit-border-radius: 4px;font-size:1.5em">
                                        <option SELECTED="true" value=""><![CDATA[车型]]></option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <select id="document_type" class="info" style="width:100%;height:30px;-webkit-border-radius: 4px;font-size:1.5em">
                                        <option SELECTED="true" value=""><![CDATA[租赁模式]]></option>
                                        <option value="OPPL"><![CDATA[直租商机]]></option>
                                        <option value="OPPLB"><![CDATA[回租商机]]></option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <select id="company_id" class="info" style="width:100%;height:30px;-webkit-border-radius: 4px;font-size:1.5em"><![CDATA[
                                                                            
                                ]]></select>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </center>
        <script type="text/javascript"><![CDATA[
            init_data();
        ]]></script>
    </a:view>
</a:screen>