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

<!--
    :Think
    : 1.0
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure/>
    <a:view template="default" package="leaf.ui.std">
        <!--<meta name="_csrf" content="${/session/@_csrf.token}"/>-->
        <!--<meta name="_csrf_header" content="X-CSRF-TOKEN" />-->
        <a:link id="widget_csh_payment_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>
        <a:link id="widget_csh_payment_req_link_id"
                url="${/request/@context_path}/modules/csh/CSH501/csh_payment_req.lview"/>
        <a:link id="widget_csh_receipt_return_maintain_link"
                url="${/request/@context_path}/modules/csh/CSH301/csh_transaction_receipt_detail_query.lview"/>
        <a:link id="widget_csh_transaction_returned_detail_link"
                url="${/request/@context_path}/modules/csh/CSH301/csh_transaction_returned_detail_query.lview"/>
        <a:link id="widget_csh_transaction_payment_detail_link"
                url="${/request/@context_path}/modules/csh/CSH301/csh_payment_req_pay_detail.lview"/>
        <style>
            html, body {
                width: 1128px;
                height: 589px;
                margin: 0;
                padding: 0;
            }

            .widget-csh-payment {
                width: 1126px;
                height: 587px;
                background: #FFFFFF;
                border: 1px solid #F0F0F3;
            }

            .widget-csh-payment .widget_label {
                position: absolute;
                width: 40px;
                height: 4px;
                top: 0;
                left: 16px;
                background-color: #5A7FFF;
            }

            .widget-csh-payment .row1 {
                position: relative;
                padding: 16px 0 12px 16px;
                font-size: 14px;
                color: rgba(75, 80, 90, 0.85);
                letter-spacing: 0;
                border-bottom: 1px solid #F0F0F3;
            }

            .widget-csh-payment .row2 {
                box-sizing: border-box;
                height: 109px;
                padding: 26px 40px 22px 16px;
                border-bottom: 1px solid #F0F0F3;
            }

            .widget-csh-payment .asset_query_form div {
                height: 24px;
                line-height: 24px;
            }

            .widget-csh-payment .asset_query_form div:first-child {
                margin-bottom: 18px;
            }

            .widget-csh-payment .asset_query_form .label {
                display: inline-block;
                font-size: 14px;
                color: #4B505A;
                min-width: 60px;
                width: 60px;
            }

            .widget-csh-payment .asset_query_form .clickable {
                box-sizing: border-box;
                width: 88px;
                height: 26px;
                line-height: 26px;
                display: inline-block;
                padding: 0 5px;
                margin: 0 13px;
                border-radius: 2px;
                cursor: pointer;
                text-align: center;
            }

            .widget-csh-payment .asset_query_form input {
                box-sizing: border-box;
                width: 200px;
                height: 24px;
                margin: 0 30px 0 16px;
                padding-left: 8px;
                display: inline-block;
                border: 1px solid rgba(83, 93, 127, 0.60);
                border-radius: 2px;
                font-size: 12px;
                color: rgba(75, 80, 90, 0.85);
            }

            .widget-csh-payment .asset_query_form #submit {
                background: #5A7FFF;
                color: #fff;
            }

            .widget-csh-payment .asset_query_form .asset_query_currency {
                border: 1px solid rgba(83, 93, 127, 0.50);
                color: #535D7F;
            }

            .widget-csh-payment .asset_query_form .asset_query_currency_active {
                border-color: #5A7FFF;
                color: #5A7FFF;
            }

            .widget-csh-payment .hls-pagging-grid {
                width: 100%;
                height: 382px;
                -webkit-box-shadow: none;
                box-shadow: none;
            }

            .widget-csh-payment .hls-pagging-grid .grid-title {
                display: none;
            }

            .widget-csh-payment .hls-pagging-grid .grid-body {
                padding: 0 0px;
            }

            .widget-csh-payment .hls-pagging-grid .hls-table tr td {
                text-align: center;
            }

            /*表头*/
            .widget-csh-payment .hls-pagging-grid .grid-body table > tr {
                height: 45px;
                border-bottom: 1px solid #F0F0F3;
                font-size: 14px;
                color: rgba(83, 93, 127, 1);
            }

            .widget-csh-payment .hls-pagging-grid .hls-table tr td:nth-child(1),
            .widget-csh-payment .hls-pagging-grid .hls-table tr td:nth-child(5) {
                text-align: left;
            }

            .widget-csh-payment .hls-pagging-grid .grid-body table > tr > td:first-child span {
                margin-left: 16px;
            }

            .widget-csh-payment .hls-pagging-grid .grid-body table > tr > td:last-child span {
                margin-right: 16px;
            }

            .widget-csh-payment .hls-pagging-grid .hls-table tbody tr {
                height: 48px;
                font-size: 12px;
                color: rgba(0, 0, 0, 0.65);
                letter-spacing: 0;
                border-bottom: 1px solid #F0F0F3;
            }

            .widget-csh-payment .hls-pagging-grid .grid-body table tbody tr:first-child {
                height: 48px;
            }

            .widget-csh-payment .hls-pagging-grid .hls-table tbody td {
                max-width: 13em;
                text-align: center;
            }

            .widget-csh-payment .hls-pagging-grid .hls-table tbody td:first-child div {
                margin-left: 16px;
            }

            .widget-csh-payment .hls-pagging-grid .hls-table tbody td:last-child div {
                margin-right: 16px;
            }

            .widget-csh-payment .hls-pagging-grid .hls-table tbody td div p {
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
            }

            .widget-csh-payment .hls-pagging-grid .hls-table tbody tr:hover {
                background: rgba(90, 127, 255, 0.08);
            }

            .widget-csh-payment .hls-table-active {
                background-color: rgba(90, 127, 255, 0.08);
            }

            .widget-csh-payment .hls-pagging-grid .icon {
                cursor: pointer;
                width: 16px;
                height: 16px;
            }

            .widget-csh-payment .switch {
                width: 100%;
                height: 26px;
                cursor: pointer;
                padding-bottom: 11px;
                margin-top: 11px;
                border-bottom: 1px solid #F0F0F3;
            }

            .widget-csh-payment .switch .switch_approve {
                display: block;
                width: 88px;
                float: left;
                font-size: 12px;
                text-align: center;
                border: 1px solid rgba(75, 80, 90, 0.15);
                line-height: 22px;
                color: rgba(75, 80, 90, 0.75);

            }

            .widget-csh-payment .switch #widget_switch_unapprove_id {
                border-bottom-left-radius: 3px;
                border-top-left-radius: 3px;
                margin-left: 16px;
            }

            .widget-csh-payment .switch #widget_switch_approved_id {
                border-top-right-radius: 3px;
                border-bottom-right-radius: 3px;
                margin-left: -1px;
            }

            .widget-csh-payment #widget_csh_payment_grid-wraper {
                display: block;
            }

            .widget-csh-payment #widget_csh_transaction_grid-wraper {
                display: none;
            }

            .widget-csh-payment #widget_csh_transaction_grid tbody {
                text-align: center !important;
            }

            .widget-csh-payment #widget_csh_transaction_grid tbody .grid_no_date {
                margin-left: 0 !important;
                position: relative !important;
            }

        </style>
        <script><![CDATA[
        function csh_payment_detail_renderer(record, index) {
            return "<img onclick='winOpen_req_pay(\"" + record.id + "\")' class='icon' src='${/request/@context_path}/leafresource/images/menu-details@2x.png'/>";
        }

        function winOpen_req_pay(record_id) {
            var record = $('widget_csh_payment_ds').findById(record_id);
            var param = {};
            param['function_usage'] = 'UPDATE';
            param['payment_req_id'] = record.get('payment_req_id');
            param['document_category'] = record.get('document_category');
            param['business_type'] = record.get('business_type');
            if (record.get('business_type') == 'PAYMENT') {
                param['function_code'] = 'CSH501D';
            } else if (record.get('business_type') == 'PREPAYMENT') {
                param['function_code'] = 'CSH501_PRE_D';
            }
            param['winid'] = 'csh_payment_update_window';
            param['url_title'] = '付款申请';
            hls_doc_get_layout_code('widget_csh_payment_get_layout_code_link_id', param, 'widget_csh_payment_req_link_id', 'widget_csh_payment_ds');
        }

        function csh_transaction_detail_renderer(record, index) {
            if (record.get('transaction_id')) {
                var url;
                if (record.get('transaction_type') == 'RECEIPT' && record.get('returned_flag') != 'RETURN') {
                    url = $('widget_csh_receipt_return_maintain_link').getUrl() + '?transaction_id=' + record.get('transaction_id');
                    return "<img onclick='openWindow(\"" + url + "\")' class='icon' src='${/request/@context_path}/leafresource/images/menu-details@2x.png'/>";
                } else if (record.get('transaction_type') == 'RECEIPT' && record.get('returned_flag') == 'RETURN') {
                    url = $('widget_csh_transaction_returned_detail_link').getUrl() + '?transaction_id=' + record.get('transaction_id');
                    //return '<a href="javascript:RETURN_openWindow(\'' + url + '\');">' + value + '</a>';
                    return "<img onclick='RETURN_openWindow(\"" + url + "\")' class='icon' src='${/request/@context_path}/leafresource/images/menu-details@2x.png'/>";
                } else if (record.get('transaction_type') == 'PAYMENT') {
                    url = $('widget_csh_transaction_payment_detail_link').getUrl() + '?transaction_id=' + record.get('transaction_id');
                    //return '<a href="javascript:payment_openWindow(\'' + url + '\');">' + value + '</a>';
                    return "<img onclick='payment_openWindow(\"" + url + "\")' class='icon' src='${/request/@context_path}/leafresource/images/menu-details@2x.png'/>";
                } else if (record.get('transaction_type') == 'PREPAYMENT' || record.get('transaction_type') == 'DEDUCTION') {
                    url = $('widget_csh_transaction_payment_detail_link').getUrl() + '?transaction_id=' + record.get('transaction_id');
                    //return '<a href="javascript:payment_openWindow(\'' + url + '\');">' + value + '</a>';
                    return "<img onclick='payment_openWindow(\"" + url + "\")' class='icon' src='${/request/@context_path}/leafresource/images/menu-details@2x.png'/>";
                } else if (record.get('transaction_type') == 'ADVANCE_RECEIPT') {
                    url = $('widget_csh_receipt_return_maintain_link').getUrl() + '?transaction_id=' + record.get('transaction_id');
                    //return '<a href="javascript:openWindow(\'' + url + '\');">' + value + '</a>';
                    return "<img onclick='openWindow(\"" + url + "\")' class='icon' src='${/request/@context_path}/leafresource/images/menu-details@2x.png'/>";
                } else {
                    //return value;
                    return "<img  class='icon' src='${/request/@context_path}/leafresource/images/menu-details@2x.png'/>";
                }

            }


        }
        function csh_format_money(record, index) {
            var html;
            if (record.get('apply_amount')) {
                var money = Leaf.formatMoney(record.get('apply_amount'))
                html = '<div>' + money + '</div>';
            } else {
                var money = Leaf.formatMoney(record.get('transaction_amount'))
                html = '<div>' + money + '</div>';
            }
            return html;
        }

        function openWindow(url) {
            new Leaf.Window({
                id: 'csh_transaction_receipt_link_winid',
                params: {
                    winId: 'csh_transaction_receipt_link_winid'
                },
                url: url,
                title: '${l:CSH510.CSH_RECEIPT_UPDATE}',
                fullScreen: true
            });
        }
        function RETURN_openWindow(url) {
            new Leaf.Window({
                id: 'widget_csh_transaction_returned_detail_link_winid',
                params: {
                    winId: 'widget_csh_transaction_returned_detail_link_winid'
                },
                url: url,
                title: '${l:CSH515.CSH_REFUND_DETAILS}',
                fullScreen: true
            });
        }

        function payment_openWindow(url) {
            new Leaf.Window({
                id: 'csh_transaction_payment_link_winid',
                params: {
                    winId: 'csh_transaction_payment_link_winid'
                },
                url: url,
                title: '付款明细',
                fullScreen: true
            });
        }


        function clickCshPayment() {
            document.getElementById('widget_switch_unapprove_id').style.border = '1px solid #5A7FFF';
            document.getElementById('widget_switch_unapprove_id').style.color = '#5A7FFF';
            document.getElementById('widget_csh_payment_grid-wraper').style.display = "block";


            document.getElementById('widget_switch_approved_id').style.border = "1px solid #D9D9D9";
            document.getElementById('widget_switch_approved_id').style.color = "rgba(0,0,0,0.65)";
            document.getElementById('widget_csh_transaction_grid-wraper').style.display = "none";
        }
        function clickCshTransaction() {
            //已办grid等
            document.getElementById('widget_switch_approved_id').style.border = "1px solid #5A7FFF";
            document.getElementById('widget_switch_approved_id').style.color = "rgba(90,127,255,1)";
            document.getElementById('widget_csh_transaction_grid-wraper').style.display = "block";

            document.getElementById('widget_switch_unapprove_id').style.border = "1px solid #D9D9D9";
            document.getElementById('widget_switch_unapprove_id').style.color = "rgba(0,0,0,0.65)";
            document.getElementById('widget_csh_payment_grid-wraper').style.display = "none";
        }

        function cshQuery() {
            var csh_payment_req_number = $jq('[name="csh_payment_req_number"]').val();
            var csh_bp_code = $jq('[name="csh_bp_code"]').val();
            var csh_bp_name = $jq('[name="csh_bp_name"]').val();
            var csh_apply_amount = $jq('[name="csh_apply_amount"]').val();
            var cshparams = {
                'payment_req_number': csh_payment_req_number,
                "ln_bp_code": csh_bp_code,
                "ln_bp_name": csh_bp_name,
                "apply_amount": csh_apply_amount
            }
            var traprams = {
                'transaction_num': csh_payment_req_number,
                "bp_code": csh_bp_code,
                "bp_name": csh_bp_name,
                "transaction_amount": csh_apply_amount
            }

            $("widget_csh_payment_ds").qpara = cshparams;
            $("widget_csh_payment_ds").query();

            $("csh_transaction_result_ds").qpara = traprams;
            $("csh_transaction_result_ds").query();
        }
        ]]>

        </script>
        <a:dataSets>
            <a:dataSet id="widget_csh_payment_ds" autoQuery="true" pageSize="5"
                       model="csh.CSH504.csh_payment_maintain_query">
                <a:fields>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="csh_transaction_result_ds" autoQuery="true" pageSize="5"
                       queryUrl="${/request/@context_path}/autocrud/csh.CSH510.csh_transaction_query/query?transaction_category=BUSINESS">
                <a:fields>
                </a:fields>
            </a:dataSet>
        </a:dataSets>

        <div class="widget-csh-payment">
            <span class="widget_label"> </span>
            <div class="row1">付款查询</div>
            <div class="row2 asset_query_form">
                <div>
                    <span class="label">申请单号</span>
                    <input type="text" id="csh_payment_req_number" name="csh_payment_req_number"
                           placeholder="申请单号/交易单号"/>
                    <span class="label">付款对象</span>
                    <input type="text" id="csh_bp_code" name="csh_bp_code" placeholder="付款对象/交易对象"/>
                    <span class="label">对象名称</span>
                    <input type="text" id="csh_bp_name" name="csh_bp_name" placeholder="对象名称"/>
                    <span class="clickable" id="submit" onclick="cshQuery()">查询</span>
                </div>
                <div>
                    <span class="label">申请金额</span>
                    <input type="number" id="csh_apply_amount" name="csh_apply_amount" placeholder="申请金额/交易金额"/>
                </div>
            </div>
            <div class="switch">
                <div class="switch_approve" id="widget_switch_unapprove_id" onclick="clickCshPayment()">待支付清单</div>
                <div class="switch_approve" id="widget_switch_approved_id" onclick="clickCshTransaction()">已支付清单</div>
            </div>
            <a:hapGrid id="widget_csh_payment_grid" bindTarget="widget_csh_payment_ds" canWheel="true">
                <a:columns>
                    <a:column name="payment_req_number" prompt="申请单号"/>
                    <a:column name="req_date" prompt="申请日期"/>
                    <a:column name="document_type_dis" prompt="申请类型"/>
                    <a:column name="ln_bp_code" prompt="付款对象"/>
                    <a:column name="ln_bp_name" prompt="对象名称"/>
                    <a:column name="ln_bp_category_name" prompt="对象类别"/>
                    <a:column template="csh_format_money" prompt="申请总金额"/>
                    <a:column name="currency_name" prompt="币种"/>
                    <a:column template="csh_payment_detail_renderer" prompt="明细"/>
                </a:columns>
            </a:hapGrid>

            <a:hapGrid id="widget_csh_transaction_grid" bindTarget="csh_transaction_result_ds" canWheel="true">
                <a:columns>
                    <a:column name="transaction_num" prompt="交易编号"/>
                    <a:column name="transaction_date" prompt="交易日期"/>
                    <a:column name="transaction_type_desc" prompt="交易类型"/>
                    <a:column name="bp_code" prompt="交易对象"/>
                    <a:column name="bp_name" prompt="对象名称"/>
                    <a:column name="bank_account_num" prompt="银行账号"/>
                    <a:column name="bank_account_name" prompt="账户名"/>
                    <a:column template="csh_format_money" prompt="交易金额"/>
                    <a:column name="currency_name" prompt="币种"/>
                    <a:column template="csh_transaction_detail_renderer" prompt="明细"/>
                </a:columns>
            </a:hapGrid>
        </div>
        <a:screenBody style="display:none">
        </a:screenBody>
        <!--<a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>-->
        <a:screen-include
                screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=PAYMENT_REQ&amp;function_code=CSH504&amp;custom_code=CSH504"/>

        <script>
            Leaf.onReady(function () {
                document.getElementById('widget_switch_unapprove_id').style.border = '1px solid #5A7FFF';
                document.getElementById('widget_switch_unapprove_id').style.color = '#5A7FFF';
            })
        </script>
    </a:view>
</a:screen>