<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: zhuxianfei
    $Date: 2018-07-12 下午2:20:47
    $Revision: 1.0
    $Purpose:
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query model="acr.ACR519.acr_delivery_import_batch_id" rootPath="batch_id"/>
        <a:model-delete model="acr.ACR519.modify_interface"/>
    </a:init-procedure>
    <a:view>
        <a:link id="import_upload_link"
                url="${/request/@context_path}/modules/acr/ACR519/acr_invoice_delivery_import_upload.lview"/>
        <a:link id="acr519_import_check_link" model="acr.ACR519.check_data" modelaction="update"/>
        <a:link id="import_save_link" model="acr.ACR519.acr_invoice_delivery_temp" modelaction="update"/>
        <a:link id="con_contract_return_link"
                url="${/request/@context_path}/modules/acr/ACR519/acr_invoice_delivery.lview"/>

        <script type="text/javascript"><![CDATA[
        var flag;
        var check_flag = 'N';

        //导入数据

        function loadData() {
            new Leaf.Window({
                id: 'upload_window',
                url: $('import_upload_link').getUrl() + '?batch_id=${/model/batch_id/record/@batch_id}&group_code=${/parameter/@group_code}',
                title: '导入实例',
                width: 420,
                height: 300
            });
        }

        //校验数据

        function checkData() {
            var allData = $('acr_deliery_ds').getAll();
            if (allData.length == 0) {
                Leaf.showMessage('${l:PROMPT}', '请导入数据!');
            } else {
                var param = {};
                param['batch_id'] = '${/model/batch_id/record/@batch_id}';
                param['group_code'] = '${/parameter/@group_code}';
                Leaf.request({
                    url: $('acr519_import_check_link').getUrl(),
                    para: param,
                    success: function (res) {
                        check_flag = 'Y';
                        flag = res.result.return_id;
                        if (res.result.return_id == 0) {
                            Leaf.showMessage('${l:PROMPT}', '数据有错误,请核对!');
                            $('acr_deliery_ds').query();
                        } else {
                            Leaf.SideBar.show({
                                msg: '核对操作成功!',
                                duration: 2000
                            });
                            $('acr_deliery_ds').query();
                        }
                    },
                    scope: this
                });
            }
        }

        //提交数据

        function submitData() {
            //
            if (check_flag == 'N') {
                Leaf.showMessage('${l:PROMPT}', '请先核对通过再提交,谢谢!');
                return;
            } else {
                if (flag == 0) {
                    Leaf.showMessage('${l:PROMPT}', '导入的数据有错误,请重新导入,谢谢!');
                    return;
                } else {
                    $('submitData_btn_id').disable(); //让按钮失效
                    var param = {};
                    param['batch_id'] = '${/model/batch_id/record/@batch_id}';
                    param['group_code'] = '${/parameter/@group_code}';
                    Leaf.request({
                        url: $('import_save_link').getUrl(),
                        para: param,
                        success: function () {
                            Leaf.SideBar.show({
                                msg: '提交操作成功!',
                                duration: 2000
                            });
                            acr519_quit();
                        },
                        scope: this
                    });
                }
            }
        }

        function acr519_quit() {
            window.location.href = $('con_contract_return_link').getUrl();
        }

        ]]></script>
        <a:dataSets>
            <a:dataSet id="acr_deliery_ds" autoQuery="true" model="acr.ACR519.acr_invoice_delivery_temp"
                       queryUrl="${/request/@context_path}/autocrud/acr.ACR519.acr_invoice_delivery_temp/query?batch_id=${/model/batch_id/record/@batch_id}"/>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:toolbarButton click="acr519_quit" text="HLS.EXIT"/>
                <a:toolbarButton click="loadData" text="PROMPT.LOADDATA" width="80"/>
                <a:toolbarButton click="checkData" text="PROMPT.CHECK"/>
                <a:toolbarButton id="submitData_btn_id" click="submitData" text="PROMPT.SUBMIT" width="80"/>
            </a:screenTopToolbar>
            <a:grid bindTarget="acr_deliery_ds" marginHeight="200" marginWidth="30" navBar="true">
                <a:columns>
                    <a:column name="contract_number" prompt="合同编号" width="150" align="center"/>
                    <a:column name="invoice_number" prompt="ACR.INVOICE_NUMBER" align="center" width="150"/>
                    <a:column name="invoice_code" prompt="发票代码" align="center" width="150"/>
                    <a:column name="transfer_time" renderer="Leaf.formatDate" editor="datePicker_e" align="center"
                              prompt="已转交时间" width="100"/>
                    <a:column name="recipient" editor="textField_e" align="center" prompt="已签收人" width="100"/>
                    <a:column name="express_date" renderer="Leaf.formatDate" editor="datePicker_e" align="center"
                              prompt="已邮寄时间" width="100"/>
                    <a:column name="express_num" editor="textField_e" align="center" prompt="邮寄快递单号" width="100"/>
                    <a:column name="express_to" editor="textField_e" align="center" prompt="接收人" width="100"/>
                    <a:column name="status_n" align="center" prompt="发票状态" width="100"/>
                    <a:column name="err_message" align="center" prompt="错误信息" width="180"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
    </a:view>
</a:screen>