<?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" customizationEnabled="true" dynamiccreateenabled="true">
    <a:init-procedure>
        <a:model-query model="cont.CON707.con_archive_import_batch_id" rootPath="batch_id"/>
    </a:init-procedure>
    <a:view>
        <a:link id="con_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code"
                modelaction="update"/>
        <a:link id="con_archive_upload_link"
                url="${/request/@context_path}/modules/cont/CON707/con707_archive_import.lview"/>
        <a:link id="contract_archive_modify_link"
                url="${/request/@context_path}/modules/cont/CON707/con707_document_detail.lview"/>
        <!--    <a:link id="lend_document_return_modify_link"
                 url="${/request/@context_path}/modules/cont/CON556/document_lend_record_return.lview"/>
         <a:link id="lend_submit_link_id" model="cont.CON556.lend_record_number" modelaction="update"/>-->
        <a:link id="con_archive_atm_link"
                url="${/request/@context_path}/modules/cont/CON707/con707_contract_atm_detail.lview"/>
        <a:link id="con_archive_lend_link"
                url="${/request/@context_path}/modules/cont/CON707/con707_contract_lend_detail.lview"/>
        <a:link id="con_contract_file_save_link" model="cont.CON707.con_contract_file" modelaction="batch_update"/>
        <a:link id="con_contract_get_file_link" model="cont.CON707.con_contract_file" modelaction="execute"/>
        <a:link id="con_model_excel_detail_link"
                url="${/request/@context_path}/modules/cont/CON707/con_model_excel_sheets.lsc"/>

        <script src="${/request/@context_path}/javascripts/hap/dynamicStopAutoQuery.js" type="text/javascript"/>

        <script type="text/javascript"><![CDATA[
        stopDymanicAutoQuery('${/parameter/@layout_code}', 'G_MODIFY', 'con_contract_archive');

        window['${/parameter/@layout_code}_user_button1_layout_dynamic_click'] = function () {
            var con_ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_archive');
            var win = new Leaf.Window({
                id: 'con_archive_upload_link_winId',
                url: $('con_archive_upload_link').getUrl(),
                params: {
                    batch_id: '${/model/batch_id/record/@batch_id}',
                    winId: 'con_archive_upload_link_winId'
                },
                title: '归档数据',
                fullScreen: true,
                draggable: true
            });
            win.on('close', function () {
                $(con_ds_id).query();
            });
        }

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

        //借阅记录
        function open_lend_history_win(contract_id, record_id, ds_id) {

            var win = new Leaf.Window({
                id: 'con_archive_lend_link_winId',
                url: $('con_archive_lend_link').getUrl(),
                params: {
                    contract_id: contract_id,
                    winId: 'con_archive_lend_link_winId'
                },
                title: '借阅记录',
                fullScreen: true,
                draggable: true
            });
            win.on('close', function () {
                $(ds_id).query();
            });

        }

        //档案维护
        function open_doc_modify_win(contract_id, record_id, ds_id) {
            /* var record = $(ds_id).findById(record_id);
             var param = record.data;
             Leaf.request({
             url: $('con_contract_get_file_link').getUrl(),
             para: param,
             success: function () {*/
            window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
            var win = new Leaf.Window({
                id: 'con_archive_atm_link_winId',
                url: $('con_archive_atm_link').getUrl(),
                params: {
                    contract_id: contract_id,
                    winId: 'con_archive_atm_link_winId'
                },
                title: '归档附件',
                fullScreen: true,
                draggable: true
            });
            win.on('close', function () {
                $(ds_id).query();
            });
            /* }, failure: function () {
             window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
             },
             error: function () {
             window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();

             },
             scope: this
             });*/

        }

        /*
         function open_doc_modify_win() {
         var param = {};
         param['function_code'] = 'CON707N';
         param['function_usage'] = 'MODIFY';
         param['maintain_type'] = 'UPDATE';
         param['winid'] = 'contract_archive_cdd_win_id';
         //param['ds_id'] = ds_id;
         param['url_title'] = '资料归档';
         hls_doc_get_layout_code('con_get_layout_code_link_id', param, 'contract_archive_modify_link', null);
         }*/

        //导出
        window['${/parameter/@layout_code}_user_button2_layout_dynamic_click'] = function () {
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_archive');
            var con_ds_id = ds_id.replace('ds', 'layout_grid_id');
            $(con_ds_id)._export(null,'档案归档');
        }


        //保存submitsuccess调用
        /* window['${/parameter/@layout_code}_on_layout_dynamic_submitsuccess'] = function (ds, record, res, bp_seq) {

         var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_archive');
         var records = $(ds_id).getSelected();
         if (records.lenth == 0) {
         Leaf.showMessage('${l:PROMPT}', '请至少选择一台数据进行保存!');
         return;
         }
         var post_data = [];
         for (var i = 0; i < records.length; i++) {
         post_data.push({
         'contract_id': records[i].get('contract_id'),
         'cdd_list_id': records[i].get('cdd_list_id'),
         '_status': 'update'
         });
         }
         Leaf.request({
         url: $('con_contract_file_save_link').getUrl(),
         para: post_data,
         success: function () {
         $(ds_id).query();
         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
         Leaf.showMessage('${l:PROMPT}', '保存成功!');
         }, failure: function () {
         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
         },
         error: function () {
         window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();

         },
         scope: this
         });
         };*/

        //保存
        window['${/parameter/@layout_code}_user_button3_layout_dynamic_click'] = function () {

            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_archive');
            var records = $(ds_id).getSelected();
            if (records.length == 0) {
                Leaf.showMessage('${l:PROMPT}', '请至少选择一条数据进行保存!');
                return;
            }
            var post_data = [];
            for (var i = 0; i < records.length; i++) {
                post_data.push({
                    'contract_id': records[i].get('contract_id'),
                    'cdd_list_id': records[i].get('cdd_list_id'),
                    'ele_doc_archive_flag': records[i].get('ele_doc_archive_flag'),
                    'archive_flag': records[i].get('archive_flag'),
                    'archive_date' :records[i].get('archive_date'),
                    'complete_flag': records[i].get('complete_flag'),
                    'note': records[i].get('note'),
                    'cert_receive_flag': records[i].get('cert_receive_flag'),
                    'doc_warehouse': records[i].get('doc_warehouse'),
                    'doc_cabinet': records[i].get('doc_cabinet'),
                    'doc_layers': records[i].get('doc_layers'),
                    'doc_order': records[i].get('doc_order'),
                    'res_doc_cabinet': records[i].get('res_doc_cabinet'),
                    'res_doc_layers': records[i].get('res_doc_layers'),
                    'res_doc_order': records[i].get('res_doc_order'),
                    '_status': 'update'
                });
            }
            window['${/parameter/@layout_code}_lock_layout_dynamic_window']();
            Leaf.request({
                url: $('con_contract_file_save_link').getUrl(),
                para: post_data,
                success: function () {
                    $(ds_id).query();
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                }, failure: function () {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                error: function () {
                    window['${/parameter/@layout_code}_unlock_layout_dynamic_window']();
                },
                scope: this
            });
        }

        //模板导出
        window['${/parameter/@layout_code}_user_button4_layout_dynamic_click'] = function () {
            //防止数据过多,重复点击导出
            $('CONTRACT_ARCHIVE_MODIFY_user_button4').disable();
            var ds_id = get_dsid_by_basetable(window['${/parameter/@layout_code}_layoutDataSetList'], 'con_contract_archive');
            var cols = [{
                name: 'contract_id_n',
                prompt: '合同编号'
            }, {
                name: 'archive_flag_n',
                prompt: '归档是否完成'
            }, {
                name: 'complete_flag_n',
                prompt: '资料是否齐全'
            }, {
                name: 'note',
                prompt: '备注'
            }, {
                name: 'archive_date',
                prompt: '归档日期'
            }, {
                name: 'cert_receive_flag_n',
                prompt: '合格证是否收到'
            }, {
                name: 'doc_warehouse',
                prompt: '资料库'
            }, {
                name: 'doc_cabinet',
                prompt: '柜号'
            }, {
                name: 'doc_layers',
                prompt: '层数'
            }, {
                name: 'doc_order',
                prompt: '顺序'
            }, {
                name: 'res_doc_cabinet',
                prompt: '烟台预留柜号'
            }, {
                name: 'res_doc_layers',
                prompt: '烟台预留层数'
            }, {
                name: 'res_doc_order',
                prompt: '烟台预留顺序'
            }];


            var colsExcel = [];
            for (var k = 0; k < cols.length; k++) {
                var col = cols[k];
                colsExcel.add({
                    name: col.name,
                    prompt: col.prompt
                });
            }
            $L.doExport($(ds_id), colsExcel);
            //恢复按钮
             window.setTimeout(function () {
                 $('CONTRACT_ARCHIVE_MODIFY_user_button4').enable();
             }, 7000);


        }

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