<?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();
                if (!price_list()) {
                    alert("产品方案没有选择,请选择!");
                    unlock_current_window();
                    return;
                }
                if (!money_check('transaction_price')) {
                    alert("成交车价有误,请重新输入!");
                    unlock_current_window();
                    return;
                }
                if (!money_check('purchase_tax')) {
                    alert("购置税有误,请重新输入!");
                    unlock_current_window();
                    return;
                }
                if (!money_check('insurance_fee')) {
                    alert("保险费有误,请重新输入!");
                    unlock_current_window();
                    return;
                }
                if (!money_check('licence_fee')) {
                    alert("牌照费有误,请重新输入!");
                    return;
                }
                if (!money_check('other_fee')) {
                    alert("其它费用有误,请重新输入!");
                    unlock_current_window();
                    return;
                }
                if (!money_check('down_payment')) {
                    alert("首付款有误,请重新输入!");
                    unlock_current_window();
                    return;
                }
                if (!money_check('deposit')) {
                    alert("保证金有误,请重新输入!");
                    unlock_current_window();
                    return;
                }
                if (!money_check('fee')) {
                    alert("手续费有误,请重新输入!");
                    unlock_current_window();
                    return;
                }
                if (!lease_times_check()) {
                    alert("租赁期限有误,请重新输入!");
                    unlock_current_window();
                    return;
                }
            
                Touch.get('quotation_create').request(function(data) {
                    if (data.success) {
                        var calc_session_id = data.result.calc_session_id;
                        location.href = '${/request/@context_path}/modules/app/calculate3.lview?chance_id=${/parameter/@chance_id}&calc_session_id=' + calc_session_id;
                    } else {
                        alert('租金计算失败');
                        unlock_current_window();
                    }
                }, function() {
                    alert('租金计算失败');
                    unlock_current_window();
                });
            }
            
            function pre_step() {
                location.href = '${/request/@context_path}/modules/app/calculate.lview';
            }
            
            var sc = new iScroll('wrapper');
            
            function callback() {
                if (!sc) {
                    sc = new iScroll('wrapper');
                } else {
                    sc.refresh();
                }
            }
            
            //初始化数据
            
            function init_data() {
                Touch.get('price_list_request').request(
            
                function(data) {
                    var record = data.result.record;
                    if (record instanceof Array) {
                        init_price_list(record);
                    } else {
                        var records = Array();
                        records[0] = record;
                        init_price_list(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],
                        display = r['name'],
                        v = r['value'];
            
                    html.push('<option value="', v, '">', display, '</option>');
            
                }
                select[0].innerHTML = html.join('');
            
            }
            
            // function init_company_id(records) {
            // var select = $('#company_id');
            // set_combo_list(select, records, true, '公司');
            // }
            
            function init_price_list(records) {
                var select = $('#price_list');
                set_combo_list(select, records, true, '产品方案');
            }
            
            // function company_change() {
            // var html = [];
            // var company_id = $('#company_id')[0];
            // var price_list = $('#price_list')[0];
            // var value = company_id.value;
            // if (value == '') {
            // html.push('<option SELECTED="true" value="">产品方案</option>');
            // price_list.innerHTML = html.join('');
            // price_list.disabled = true;
            // } else {
            // Touch.get('price_list_request').request(
            
            // function(data) {
            // var record = data.result.record;
            // if (record instanceof Array) {
            // init_price_list(record);
            // } else {
            // var records = Array();
            // records[0] = record;
            // init_price_list(records);
            // }
            // price_list.disabled = false;
            // });
            
            // }
            
            // }
            
            function price_list() {
                var select = $('#price_list');
                var value = select[0].value;
                if (value != '') {
                    return true;
                } else {
                    return false;
                }
            }
            
            function money_check(id) {
                var re = /^\d+(\.\d+)?$/;
                var id = '#' + id;
                var select = $(id);
                var value = select[0].value;
                if (re.test(value) && value != '') {
                    return true;
                } else {
                    return false;
                }
            }
            
            function lease_times_check() {
                var re = /^[0-9]*[1-9][0-9]*$/;
                var select = $('#lease_times');
                var value = select[0].value;
                if (re.test(value) && value != '') {
                    return true;
                } else {
                    return false;
                }
            }
            
            function mousedown(event) {
                // var targ
                // if (!e) var e = window.event
                // if (e.target) targ = e.target
                // else if (e.srcElement) targ = e.srcElement
                // if (targ.nodeType == 3) // defeat Safari bug
                // targ = targ.parentNode
                // var tname
                // tname = targ.tagName
                // alert("You clicked on a " + tname + " element.")
                var target = event.currentTarget;
                //target.defaultValue = '';
                //target.value = '';
            }
            
            
            
            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:#F4EEE9;
            }
            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="quotation_create" url="${/request/@context_path}/autocrud/app.app_quote.hls_app_quote_create_quotation/insert">
                <t:parameters>
                    <t:parameter name="company_id" dataType="java.lang.Long" value="${/parameter/@company_id}"/>
                    <t:parameter name="price_list" bind="price_list" dataType="java.lang.Double"/>
                    <t:parameter name="transaction_price" bind="transaction_price" dataType="java.lang.Double"/>
                    <t:parameter name="purchase_tax" bind="purchase_tax" dataType="java.lang.Double"/>
                    <t:parameter name="insurance_fee" bind="insurance_fee" dataType="java.lang.Double"/>
                    <t:parameter name="licence_fee" bind="licence_fee" dataType="java.lang.Double"/>
                    <t:parameter name="other_fee" bind="other_fee" dataType="java.lang.Double"/>
                    <t:parameter name="lease_times" bind="lease_times" dataType="java.lang.Double"/>
                    <t:parameter name="down_payment" bind="down_payment" dataType="java.lang.Double"/>
                    <t:parameter name="deposit" bind="deposit" dataType="java.lang.Double"/>
                    <t:parameter name="fee" bind="fee" dataType="java.lang.Double"/>
                    <t:parameter name="residual_value" bind="residual_value" dataType="java.lang.Double"/>
                    <t:parameter name="chance_id" dataType="java.lang.Long" value="${/parameter/@chance_id}"/>
                </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>
            <t:ajax id="price_list_request" url="${/request/@context_path}/autocrud/app.app_quote.hls_app_quote_choose_price_list/query">
                <t:parameters>
                    <t:parameter name="company_id" dataType="java.lang.String" value="${/parameter/@company_id}"/>
                    <t:parameter name="business_type" dataType="java.lang.String" value="${/parameter/@document_type}"/>
                </t:parameters>
            </t:ajax>
            <div id="all">
                <div id="header">
                    <span style="line-height:40px;font-size:20px;font-weight:700"><![CDATA[商机报价]]></span>
                    <t:button className="gray" style="margin-top:2px;float:left;margin-top:5px;font-size:16px;height:30px;width:70px;margin-right:5px;margin-left:2px;" text="重新报价">
                        <t:events>
                            <t:event name="click" handler="pre_step"/>
                        </t:events>
                    </t:button>
                    <t:button className="gray" style="margin-top:2px;float:right;margin-top:5px;font-size:16px;height:30px;width:70px;margin-right:3px;" 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%;font-size:12px;">
                        <table cellspacing="0" style="width:100%">
                            <tr>
                                <td colspan="2">
                                    <select id="price_list" class="info" 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">
                                    <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="transaction_price" id="transaction_price" onmousedown="mousedown(event)" 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" value="0"/>
                                    </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="purchase_tax" id="purchase_tax" onmousedown="mousedown(event)" 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" value="0"/>
                                    </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="insurance_fee" id="insurance_fee" onmousedown="mousedown(event)" 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" value="0"/>
                                    </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="licence_fee" id="licence_fee" onmousedown="mousedown(event)" 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" value="0"/>
                                    </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="other_fee" id="other_fee" onmousedown="mousedown(event)" 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" value="0"/>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <select id="lease_times" class="info" style="width:100%;height:30px;-webkit-border-radius: 4px;font-size:1.5em">
                                        <option SELECTED="true" value=""><![CDATA[租赁期限(月)]]></option>
                                        <option value="12"><![CDATA[12月]]></option>
                                        <option value="24"><![CDATA[24月]]></option>
                                        <option value="36"><![CDATA[36月]]></option>
                                        <option value="48"><![CDATA[48月]]></option>
                                        <option value="60"><![CDATA[60月]]></option>
                                    </select>
                                </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="down_payment" id="down_payment" onmousedown="mousedown(event)" required="" style="float:center;border:0px;outline:0px;margin:0px;padding:0px;height:100%;font-size:1em;line-height:1em;background:none;width:60%;text-align:right" type="number"/>
                                        <div style="float:right;width:5%;">
                                            <span><![CDATA[%]]></span>
                                        </div>
                                    </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="deposit" id="deposit" onmousedown="mousedown(event)" required="" style="float:center;border:0px;outline:0px;margin:0px;padding:0px;height:100%;font-size:1em;line-height:1em;background:none;width:60%;text-align:right" type="number"/>
                                        <div style="float:right;width:5%;">
                                            <span><![CDATA[%]]></span>
                                        </div>
                                    </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="fee" id="fee" onmousedown="mousedown(event)" required="" style="float:center;border:0px;outline:0px;margin:0px;padding:0px;height:100%;font-size:1em;line-height:1em;background:none;width:60%;text-align:right" type="number"/>
                                        <div style="float:right;width:5%;">
                                            <span><![CDATA[%]]></span>
                                        </div>
                                    </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="residual_value" id="residual_value" onmousedown="mousedown(event)" 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" value="0"/>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </center>
        <script type="text/javascript"><![CDATA[
            init_data();
        ]]></script>
    </a:view>
</a:screen>