<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: chenlingfeng
    $Date: 2018-11-09 15:49:11
    $Revision: 1.0  
    $Purpose: 向app修改商务条件，暂定为静态页面
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
    <a:view>
        <a:link id="con311_con_product_info_link" model="cont.CON311.con_product_info" modelaction="execute"/>
        <script src="${/request/@context_path}/javascripts/calculate.js" type="text/javascript"/>
        <script type="text/javascript"><![CDATA[

        function con311_change_close() {
            $('${/parameter/@winid}').close();
        }


        function lock_con311edit_window() {
            Leaf.Masker.mask($('${/parameter/@winid}').wrap, '${l:HLS.EXECUTING}');
        }

        function unlock_con311edit_window() {
            Leaf.Masker.unmask($('${/parameter/@winid}').wrap);
        }

        function con311_change_product() {
            var ds = $('con311_con_product_info_result_ds');
            var record = ds.getCurrentRecord();
            lock_con311edit_window();
            Leaf.request({
                url: $('con311_con_product_info_link').getUrl(),
                para: {
                    contract_id: record.get('contract_id'),
                    down_payment_ratio: record.get('down_payment_ratio'),
                    down_payment: record.get('down_payment'),
                    lease_times: record.get('lease_times'),
                    product_name: record.get('product_name')
                },
                success: function (res) {
                    Leaf.showMessage('提示','操作成功');
                    unlock_con311edit_window();
                },
                failure: function () {
                    unlock_con311edit_window();
                },
                error: function () {
                    unlock_con311edit_window();
                },
                scope: this
            });

        }

        function con311_product_update_handler(ds, record, name, value, oldvalue) {
            if (name == 'down_payment') {
                var other_fee = record.get('other_fee');
                var down_payment_ratio = div(value, other_fee) || 0;
                record.set('down_payment_ratio', down_payment_ratio);
            }
        }

        ]]></script>
        <a:dataSets>
            <a:dataSet id="con311_con_product_info_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="contract_id" defaultValue="${/parameter/@contract_id}"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="con311_con_product_info_result_ds" queryDataSet="con311_con_product_info_query_ds" model="cont.CON311.con_product_info" autoQuery="true">
                <a:fields>
                    <a:field name="chance_no" readOnly="true"/>
                    <a:field name="bp_id_agent_level1_n" readOnly="true"/>
                    <a:field name="other_fee" readOnly="true"/>
                    <a:field name="finance_amount" readOnly="true"/>
                    <a:field name="product_type" readOnly="true"/>
                    <a:field name="down_payment" required="true"/>
                    <a:field name="down_payment_ratio" readOnly="true"/>
                    <a:field name="product_name" readOnly="true"/>
                    <a:field name="lease_term_month" readOnly="true"/>
                    <a:field name="lease_times" required="true"/>
                </a:fields>
                <a:events>
                    <a:event name="update" handler="con311_product_update_handler"/>
                </a:events>
            </a:dataSet>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:gridButton click="con311_change_close" text="HLS.EXIT"/>
                <a:gridButton click="con311_change_product" text="更新融资商品"/>
            </a:screenTopToolbar>
            <a:form column="3" title="融资信息">
                <a:textField prompt="商机号" name="chance_no" bindTarget="con311_con_product_info_result_ds"/>
                <a:textField prompt="代理商" name="bp_id_agent_level1_n" bindTarget="con311_con_product_info_result_ds"/>
                <a:numberField allowDecimals="true" allowFormat="true" decimalPrecision="2" prompt="设备价款" name="other_fee" bindTarget="con311_con_product_info_result_ds"/>
                <a:textField prompt="融资金额" allowDecimals="true" allowFormat="true" decimalPrecision="2" name="finance_amount" bindTarget="con311_con_product_info_result_ds"/>
                <a:textField prompt="商品大类" name="product_type" bindTarget="con311_con_product_info_result_ds"/>
                <a:textField prompt="首付款" allowDecimals="true" allowFormat="true" decimalPrecision="2" name="down_payment" bindTarget="con311_con_product_info_result_ds"/>
                <a:percentField prompt="首付比例" name="down_payment_ratio" bindTarget="con311_con_product_info_result_ds"/>
                <a:textField prompt="期次" name="lease_times" bindTarget="con311_con_product_info_result_ds"/>
                <a:textField prompt="商品名称" name="product_name" bindTarget="con311_con_product_info_result_ds"/>
            </a:form>
           <a:fieldSet title="注意"  style="margin-top:10px;margin-left:10px;">
              <label style="color:red"><![CDATA[该页面只能修改正常月付的首付款项和融资期限。如需修改设备价款，请撤销商机重新申请，另修改的首付款项和融资期限只能适用于当下最新的融资商品，请参考。]]></label>
           </a:fieldSet>
        </a:screenBody>
    </a:view>
</a:screen>
