<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2018年7月25日 下午3:04:47  
    $Revision: 1.0  
    $Purpose: 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application" customizationEnabled="true" dynamiccreateenabled="true"
          trace="true">
    <a:init-procedure>
        <a:model-query model="acp.ACP518.acp_invoice_import_batch_id" rootPath="batch_id"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con_contract_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>
        <a:link id="acp_invoice_upload_link"
                url="${/request/@context_path}/modules/acp/ACP518/acp518_invoice_import.lview"/>
        <a:link id="acp_invoice_verify_link" model="acp.ACP518.acp_invoice_verify" modelaction="batch_update"/>
        <a:link id="${/parameter/@layout_code}${/parameter/@pre_layout}_invoice_cdd_uploadFile_id"
                url="${/request/@context_path}/downloadFile.lview"/>
        <script type="text/javascript"><![CDATA[
        //发票验证
        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {

            var acp_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'acp_invoice_ln');
            var records = $(acp_ds_id).getSelected();
            if (records.length == 0) {
                Leaf.showMessage('${l:PROMPT}', '请至少选择一条数据!');
                return;
            }
            var param_list = [];
            var param = {};
            for (var i = 0; i < records.length; i++) {
                param = records[i].data;
                param['_status'] = 'update';
                param_list.push(param);
            }
            window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            Leaf.request({
                url: $('acp_invoice_verify_link').getUrl(),
                para: param_list,
                success: function (res) {
                    $(acp_ds_id).query();
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();


                },
                error: function () {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                failure: function () {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                sync: true,
                scope: this
            });


        }

        //导入发票验证
        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function () {

            var acp_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'acp_invoice_ln');
            var win = new Leaf.Window({
                id: 'acp_invoice_upload_link_winId',
                url: $('acp_invoice_upload_link').getUrl(),
                params: {
                    batch_id: '${/model/batch_id/record/@batch_id}',
                    winId: 'acp_invoice_upload_link_winId'
                },
                title: '发票验证',
                fullScreen: true,
                draggable: true
            });
            win.on('close', function () {
                $(acp_ds_id).query();
            });
        }

        //导出
        window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'acp_invoice_ln');
            var ap_ds_id = ds_id.replace('ds', 'layout_grid_id');
            $(ap_ds_id)._export();
        }

        //重置
        window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function () {
            $("AP_INVOICE_CONFIRME_AP_QUERY__ds").reset();
        }

            //超链接渲染
        window['${/parameter/@bp_seq}${/parameter/@layout_code}_dynamic_link_renderer'] = function (value, record, name, config_record, bp_seq) {
            //
            var link_function = '';
            var invoice_line_id = record.get('invoice_line_id');
            window['${/parameter/@bp_seq}${/parameter/@layout_code}_hls_link_render_record'][record.id + '---' + name] = record;
            if (name == 'attachment') {
                return '<a href="javascript:attachment_window_open(\'' + invoice_line_id + '\',\'' + record.id + '\',\'' + record.ds.id + '\');">' + '上传' + '</a>';
            }
        };

        function attachment_window_open(invoice_line_id, record_id, ds_id) {
            url = $('${/parameter/@layout_code}${/parameter/@pre_layout}_invoice_cdd_uploadFile_id').getUrl() + '?table_name=ACP_INVOICE_LN&header_id=' + invoice_line_id;
            wd = new Leaf.Window({
                id: 'open_attachment_window',
                url: url,
                title: '附件上传',
                height: 350,
                width: 850
            });
        }


        ]]></script>
        <a:screen-include screen="modules/cont/CON500/con_contract_get_layout_code.lview"/>
    </a:view>
</a:screen>