<?xml version="1.0" encoding="UTF-8"?>

<!--
    $Author: huangtianyang
    $Date: 2018/8/29 上午9:56
    $Revision: 1.0 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true"
          trace="true">
    <a:init-procedure/>
    <a:view>

        <script type="text/javascript"><![CDATA[
        var header = $jq('meta[name=_csrf_header]').attr('content');
        var token = $jq('meta[name=_csrf]').attr('content');
        $jq(document).ajaxSend(function (e, xhr, options) {
            xhr.setRequestHeader(header, token);
        });

        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'bf_pay_response');
            $(ds_id).create({});
        }

        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function () {
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'bf_pay_response');
            var records = $(ds_id).getSelected();
            if (records.length !== 1) {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                Leaf.showErrorMessage('提示', '仅能选一条记录提交');
                return;
            }
            if (!records[0].get('response_id')) {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                Leaf.showErrorMessage('提示', '请先保存');
                return;
            }
            $jq.ajax({
                url: '${/request/@context_path}/baofoo/pay/req',
                type: 'post',
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify({responseId: records[0].get('response_id')}),
                success: function (res) {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    if (res.success) {
                        Leaf.SideBar.show({
                            msg: '保存成功',
                            duration: 2000
                        });
                    } else {
                        Leaf.showErrorMessage('提示', res.message);
                    }
                    $(ds_id).query();
                },
                failure: function (res) {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    Leaf.showErrorMessage('提示', res.message);
                },
                error: function (res) {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    Leaf.showErrorMessage('提示', res.message);
                }
            })
        }

        window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function () {
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_lock_layout_dynamic_window']();
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'bf_pay_response');
            var records = $(ds_id).getSelected();
            if (records.length !== 1) {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                Leaf.showErrorMessage('提示', '仅能选一条记录提交');
                return;
            }
            if (!records[0].get('response_id')) {
                window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                Leaf.showErrorMessage('提示', '请先保存');
                return;
            }
            $jq.ajax({
                url: '${/request/@context_path}/baofoo/query/req',
                type: 'post',
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify({responseId: records[0].get('response_id')}),
                success: function (res) {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    if (res.success) {
                        Leaf.SideBar.show({
                            msg: '保存成功',
                            duration: 2000
                        });
                    } else {
                        Leaf.showErrorMessage('提示', res.message);
                    }
                    $(ds_id).query();
                },
                failure: function (res) {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    Leaf.showErrorMessage('提示', res.message);
                },
                error: function (res) {
                    window['${/parameter/@bp_seq}${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                    Leaf.showErrorMessage('提示', res.message);
                }
            })
        }
        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>