<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2017年8月18日 下午4:10:52  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" trace="true">
    <a:view>
        <a:link id="do_csh_write_off_link" model="ccb.CCB503.ds_abc_transaction_query" modelaction="batch_update"/>
        <script type="text/javascript"><![CDATA[

        function ccb503_confirm_query() {
            $('ds_abc_confirm_ds').query();
        }

        function ccb503_confirm_reset() {
            $('ds_abc_confirm_query_ds').reset();
        }

        function ccb503_confirm_exit() {
            $('ds_abc_transaction_detail_link_winId').close();

        }

        //手工下账
        function ccb503_write_off() {
            var records = $('ds_abc_confirm_ds').getSelected();
            if (records.length == 0) {
                Leaf.showMessage('提示', '请至少选择一条数据');
                return;
            }
            var datas = [];
            for (var i = 0; i < records.length; i++) {
                if (records[i].get('deal_flag') == 'Y' ||  records[i].get('deal_flag') == null ) {
                    Leaf.showMessage('提示', '所选数据中存在已核销或回盘失败的数据,请检查!');
                    return;
                } else {
                    var obj = {};
                    obj['head_id'] = records[i].get('head_id');
                    obj['line_id'] = records[i].get('line_id');
                    obj['_status'] = 'update';
                    datas[i] = obj;

                }

            }

            Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            Leaf.request({
                url: $('do_csh_write_off_link').getUrl(),
                para: datas,
                success: function () {
                    $('ds_abc_confirm_ds').query();
                    Leaf.Masker.unmask(Ext.getBody());
                    Leaf.showMessage('提示', '核销成功!');
                },
                failure: function () {
                    Leaf.Masker.unmask(Ext.getBody());

                },
                error: function () {
                    Leaf.Masker.unmask(Ext.getBody());

                },
                scope: this
            });

        }

        ]]></script>
        <a:dataSets>
            <a:dataSet id="line_withhold_status_ds" lookupCode="DS_ABC_BACK_STATUS"/>
            <a:dataSet id="deal_flag_ds">
                <a:datas>
                    <a:record name="已处理" value="Y"/>
                    <a:record name="未处理" value="N"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="ds_abc_confirm_query_ds" autoCreate="true">
                <a:fields>
                    <a:field name="contract_number" autoComplete="true" lovGridHeight="300" lovHeight="450"
                             lovService="cont.CON500.con_contract_number_lov" lovWidth="500"
                             title="HLS.CONTRACT_NUMBER">
                        <a:mapping>
                            <a:map from="contract_number" to="contract_number"/>
                            <a:map from="contract_id" to="contract_id"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="bp_name" autoComplete="true" lovGridHeight="350" lovHeight="500" lovLabelWidth="100"
                             lovService="cont.CON541.hls_bp_master_v_for_lov?bp_category=TENANT" lovWidth="520"
                             title="HLS.BP_TITLE">
                        <a:mapping>
                            <a:map from="bp_name" to="bp_name"/>
                            <a:map from="bp_id" to="bp_id_tenant"/>
                        </a:mapping>
                    </a:field>
                    <a:field name="withhold_status"/>
                    <a:field name="withhold_status_desc" displayField="code_value_name"
                             options="line_withhold_status_ds" returnField="withhold_status" valueField="code_value"/>

                    <a:field name="deal_flag"/>
                    <a:field name="deal_flag_n" displayField="name" options="deal_flag_ds"
                             returnField="deal_flag" valueField="value"/>
                </a:fields>
            </a:dataSet>
            <a:dataSet id="ds_abc_confirm_ds" autoPageSize="true" autoQuery="true"
                       model="ccb.CCB503.ds_abc_trans_confirm" queryDataSet="ds_abc_confirm_query_ds"
                       queryUrl="${/request/@context_path}/autocrud/ccb.CCB503.ds_abc_trans_confirm/query?head_id=${/parameter/@head_id}"
                       selectable="true"/>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="ccb503_confirm_exit" text="HLS.EXIT"/>
                <a:gridButton click="ccb503_confirm_reset" text="HLS.RESET"/>
                <a:gridButton click="ccb503_confirm_query" text="HLS.QUERY"/>
                <a:gridButton click="ccb503_write_off" text="核销下账"/>
            </a:screenTopToolbar>
            <a:form title="HAP_QUERY_TITLE">
                <a:hBox labelWidth="100">
                    <a:lov name="contract_number" bindTarget="ds_abc_confirm_query_ds" prompt="合同编号"/>
                    <a:lov name="bp_name" bindTarget="ds_abc_confirm_query_ds" prompt="商业伙伴"/>
                    <a:comboBox name="withhold_status_desc" bindTarget="ds_abc_confirm_query_ds" prompt="代扣状态"/>
                    <a:comboBox name="deal_flag_n" bindTarget="ds_abc_confirm_query_ds" prompt="下账处理标志"/>
                </a:hBox>
            </a:form>
            <a:grid bindTarget="ds_abc_confirm_ds" marginHeight="250" marginWidth="40" navBar="true">
                <a:toolBar>
                    <a:button type="excel"/>
                </a:toolBar>
                <a:columns>
                    <a:column name="contract_number" prompt="合同" width="100"/>
                    <a:column name="bp_name" align="left" prompt="客户名" width="150"/>
                    <!--   <a:column name="times" align="center" prompt="期数" width="60"/>
                       <a:column name="cf_item_n" align="center" prompt="代扣项目" width="80"/>
                       <a:column name="due_date" align="center" prompt="应收日期"/>-->
                    <a:column name="bank_account_num" align="left" prompt="银行账号" width="150"/>
                    <a:column name="bank_account_name" align="left" prompt="账号名称" width="150"/>
                    <a:column name="agent_name" align="left" prompt="代理商简称" width="150"/>
                    <a:column name="due_amount" align="right" prompt="应收金额" renderer="Leaf.formatMoney" width="110"/>
                    <a:column name="received_amount" align="right" prompt="代扣成功金额" renderer="Leaf.formatMoney"
                              width="110"/>
                    <!-- <a:column name="write_off_amount" align="right" prompt="自动核销金额" renderer="Leaf.formatMoney" width="110"/>-->
                    <a:column name="withhold_status_desc" align="center" prompt="代扣状态" width="110"/>
                    <a:column name="withhold_note" editor="textAreaEd" prompt="接口返回信息" width="130"/>
                    <a:column name="deal_flag_n"  prompt="下账处理标志" align="center" width="80"/>
                    <a:column name="deal_msg"  editor="textAreaEd" prompt="核销错误信息" width="280"/>
                    <!-- <a:column name="write_off_error" editor="textAreaEd" prompt="核销错误信息" width="130"/>-->
                </a:columns>
                <a:editors>
                    <a:textArea id="textAreaEd" height="50" width="130"/>
                </a:editors>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>