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

<!--
    $Author: zhuxianfei
    $Date: 2018/7/5 15:38
    $Revision: 1.0 
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure>
        <a:model-query model="cont.CON707.con_archive_import_batch_id" rootPath="batch_id"/>
        <a:model-query model="basic.sys_session_info" rootPath="default_value_record"/>
        <a:model-query model="cont.CON706.con_contract_status" rootPath="contract_status_list"/>
    </a:init-procedure>
    <a:view>
        <a:link id="trans_info_modify_link"
                url="${/request/@context_path}/modules/cont/CON706/con706_et_document_info.lview"/>
        <a:link id="trans_info_send_link"
                url="${/request/@context_path}/modules/cont/CON706/con706_document_send_detail.lview"/>
        <a:link id="con706_trans_book_doc_print_link"
                url="${/request/@context_path}/modules/cont/CON706/con_trans_book_doc_print.lview"/>
        <a:link id="con_et_document_upload_link"
                url="${/request/@context_path}/modules/cont/CON706/con706_et_document_import.lview"/>
        <script type="text/javascript"><![CDATA[
        function con706_query() {
            $('contract_doc_result_ds').query();
        }

        function con706_reset() {
            $('contract_doc_query_ds').reset();
        }

        function con706_trans_info_modify() {
            var records = $('contract_doc_result_ds').getSelected();
            if (records.length != 1) {
                Leaf.showMessage('${l:PROMPT}', '请选择一条单据！');
                return;
            }

            var win = new Leaf.Window({
                id: 'trans_info_modify_link_winId',
                url: $('trans_info_modify_link').getUrl(),
                params: {
                    readonly: 'N',
                    contract_id: records[0].get('contract_id'),
                    winId: 'trans_info_modify_link_winId'
                },
                title: '快递信息维护',
                fullScreen: true,
                draggable: true
            });
            win.on('close', function () {
                $('contract_doc_result_ds').query();
            });
        }

        function con706_trans_info_print() {
            var records = $('contract_doc_result_ds').getSelected();
            if (records.length === 0) {
                Leaf.showMessage('${l:PROMPT}', '请选择至少一条记录');
                return;
            }
            /* else if (!check_data(records)) {
             Leaf.showWarningMessage('提示', '仅能打印汇签单列显示为<font color="red">未打印</font>或已打印的数据！');
             return;
             }*/
            var instr = '';
            for (var i = 0; i < records.length; i++) {
                if (i == 0) {
                    instr = instr + records[i].get('contract_id');
                } else {
                    instr = instr + ',' + records[i].get('contract_id');
                }
            }
            var url = $('con706_trans_book_doc_print_link').getUrl() + '?contract_id=' + instr + '&_csrf=${/session/@_csrf.token}';
            window.open(url);
        }

        function send_detail_render(value, record, name) {
            return '<a href="javascript:open_send_info(' + record.get('contract_id') + ')">寄送明细</a>';
        }

        function open_send_info(contract_id) {
            //var url = $('trans_info_send_link').getUrl() + '?contract_id=' + contract_id;
            /* var url = $('trans_info_send_link').getUrl();
             window.open(href = url, target = "_self");*/
            // var header = $jq('meta[name=_csrf_header]').attr('content');
            // var token = $jq('meta[name=_csrf]').attr('content');
            // $jq(document).ajaxSend(function (e, xhr, options) {
            //     xhr.setRequestHeader(header, token);
            // });

            var win = new Leaf.Window({
                id: 'trans_info_send_link_winId',
                url: $('trans_info_send_link').getUrl(),
                params: {
                    skip_flag: 'Y',
                    contract_id: contract_id,
                    winId: 'trans_info_send_link_winId'
                },
                title: '寄送明细',
                fullScreen: true,
                draggable: true
            });
            win.on('close', function () {
                $('contract_doc_result_ds').query();
            });
        }

        function render_objectDs_grid(value, record, name) {
            if (name === 'trans_cert_print_flag') {
                if (value === 'Y') {
                    return '已打印';
                } else {
                    return '<font color="red">未打印</font>';
                }
            }
        }

        function con706_trans_info_export() {
            $('cont_doc_result_ds_id')._export(null,'结清资料退还');
        }


        function con706_trans_info_import() {
            var win = new Leaf.Window({
                id: 'con_et_document_upload_link_winId',
                url: $('con_et_document_upload_link').getUrl(),
                params: {
                    batch_id: '${/model/batch_id/record/@batch_id}',
                    winId: 'con_et_document_upload_link_winId'
                },
                title: '资料导入',
                fullScreen: true,
                draggable: true
            });
            win.on('close', function () {
                $('contract_doc_result_ds').query();
            });
        }

        //模板导出
        function con706_trans_model_export() {
            var cols = [
                {
                    name: 'contract_number',
                    width: 200,
                    prompt: '合同编号'
                }, {
                    name: 'cert_recipient01',
                    width: 200,
                    prompt: '合格证收件人'
                }, {
                    name: 'cert_tracknum01',
                    width: 200,
                    prompt: '合格证快递单'
                }, {
                    name: 'cert_send_date01',
                    width: 200,
                    prompt: '合格证邮寄日期'
                }, {
                    name: 'trans_recipient01',
                    width: 200,
                    prompt: '所有权转移证书收件人'
                }, {
                    name: 'trans_tracknum01',
                    width: 200,
                    prompt: '所有权转移证书快递单'
                }, {
                    name: 'trans_send_date01',
                    width: 200,
                    prompt: '所有权转移证书邮寄日期'
                }, {
                    name: 'note',
                    width: 200,
                    prompt: '备注'
                }];


            var colsExcel = [];
            for (var k = 0; k < cols.length; k++) {
                var col = cols[k];
                colsExcel.add({
                    name: col.name,
                    width: col.width,
                    prompt: col.prompt
                });
            }
            $L.doExport($('contract_doc_result_ds'), colsExcel);
        }


        ]]></script>
        <a:screen-include
                screen="modules/cont/CON500/con_contract_authority_list_validate.lview?document_category=CONTRACT&amp;function_code=CON706"/>
        <a:dataSets>
            <a:dataSet id="send_flag_ds" lookupCode="YES_NO"/>
            <a:dataSet id="doc_print_flag_ds">
                <a:datas>
                    <a:record name="已打印" value="Y"/>
                    <a:record name="未打印" value="N"/>
                </a:datas>
            </a:dataSet>
            <a:dataSet id="contract_status_options">
                <a:datas dataSource="/model/contract_status_list"/>
            </a:dataSet>
            <a:dataSet id="contract_doc_query_ds">
                <a:fields>
                    <a:field name="contract_number"/>
                    <a:field name="bp_name"/>
                    <a:field name="agent_name"/>
                    <a:field name="lease_end_date"/>
                    <a:field name="et_date"/>
                    <a:field name="send_flag_n" displayField="code_value_name" options="send_flag_ds"
                             returnField="send_flag" valueField="code_value"/>
                    <a:field name="trans_cert_print_flag"/>
                    <a:field name="trans_cert_print_flag_des" displayField="name" options="doc_print_flag_ds"
                             returnField="trans_cert_print_flag" valueField="value"/>
                    <a:field name="contract_status" />
                    <a:field name="contract_status_n" options="contract_status_options" displayField="code_value_name" returnField="contract_status" valueField="code_value" />

                </a:fields>
            </a:dataSet>
            <a:dataSet id="contract_doc_result_ds" autoPageSize="true" autoQuery="false" selectionModel="single"
                       model="cont.CON706.con_contract_et_result" queryDataSet="contract_doc_query_ds"
                       selectable="true"/>
        </a:dataSets>
        <a:screenBody>
            <a:screenTopToolbar>
                <a:screenTitle/>
                <a:gridButton click="con706_query" text="HLS.QUERY"/>
                <a:gridButton click="con706_reset" text="HLS.RESET"/>
                <a:gridButton id="con706_trans_info_print_id" click="con706_trans_info_print" text="所有权转移证书打印"/>
                <a:gridButton id="con706_trans_info_modify_id" click="con706_trans_info_modify" text="维护快递信息"/>
                <a:gridButton id="con706_trans_info_import_id" click="con706_trans_info_import" text="导入"/>
                <a:gridButton click="con706_trans_info_export" text="导出"/>
                <a:gridButton click="con706_trans_model_export" text="模板导出"/>
            </a:screenTopToolbar>
            <a:form column="4" labelWidth="150" title="HAP_QUERY_TITLE" marginWidth="40">
                <a:textField name="contract_number" bindTarget="contract_doc_query_ds" prompt="合同号"/>
                <a:textField name="bp_name" bindTarget="contract_doc_query_ds" prompt="客户姓名"/>
                <a:textField name="agent_name" bindTarget="contract_doc_query_ds" prompt="代理商姓名"/>
                <a:comboBox name="send_flag_n" bindTarget="contract_doc_query_ds" prompt="合格证是否邮寄"/>
                <a:datePicker name="et_date_from" bindTarget="contract_doc_query_ds" prompt="结清日期从"/>
                <a:datePicker name="et_date_to" bindTarget="contract_doc_query_ds" prompt="结清日期到"/>
                <a:datePicker name="lease_execution_date_from" bindTarget="contract_doc_query_ds" prompt="执行日期从"/>
                <a:datePicker name="lease_execution_date_to" bindTarget="contract_doc_query_ds" prompt="执行日期到"/>
                <a:datePicker name="cert_send_date01_from" bindTarget="contract_doc_query_ds" prompt="合格证寄送日期从"/>
                <a:datePicker  name="cert_send_date01_to" bindTarget="contract_doc_query_ds" prompt="合格证寄送日期到"/>
                <a:datePicker name="trans_send_date01_from" bindTarget="contract_doc_query_ds" prompt="所有权证书寄送日期从"/>
                <a:datePicker name="trans_send_date01_to" bindTarget="contract_doc_query_ds" prompt="所有权证书寄送日期到"/>
                <a:comboBox name="trans_cert_print_flag_des" bindTarget="contract_doc_query_ds" prompt="证书是否打印"
                            width="150"/>
                <a:comboBox name="contract_status_n" bindTarget="contract_doc_query_ds" prompt="合同状态"/>
            </a:form>
            <a:grid id="cont_doc_result_ds_id" bindTarget="contract_doc_result_ds" marginHeight="240" marginWidth="40"
                    navBar="true">
                <a:columns>
                    <a:column name="contract_number" align="center" prompt="合同号" width="130"/>
                    <a:column name="bp_name" align="center" prompt="客户姓名" width="200"/>
                    <a:column name="agent_name" align="center" prompt="代理商" width="130"/>
                    <a:column name="trans_cert_print_flag" align="center" prompt="所有权转移证书是否打印"
                              renderer="render_objectDs_grid"
                              width="200"/>
                    <a:column name="business_type_n" align="center" prompt="租赁形式" width="130"/>
                    <a:column name="lease_end_date" align="center" prompt="期满日期"
                              width="130"/>
                    <a:column name="lease_execution_date" align="center" prompt="执行日期"
                              width="130"/>
                    <a:column name="contract_status_n" prompt="合同状态" width="180" align="center"/>
                    <a:column name="et_date" align="center" prompt="结清日期" width="200"/>
                    <a:column name="send_flag_n" align="center" prompt="是否寄出" width="130"/>
                    <a:column prompt="合格证">
                        <a:column name="cert_recipient01" align="center" prompt="收件人" width="200"/>
                        <a:column name="cert_tracknum01" align="center" prompt="快递单" width="130"/>
                        <a:column name="cert_send_date01" align="center" prompt="邮寄日期" width="130"/>
                    </a:column>
                    <!-- <a:column prompt="第二次寄送合格证">
                         <a:column name="cert_recipient02" align="center" prompt="收件人2" width="200"/>
                         <a:column name="cert_tracknum02" align="center" prompt="快递单2" width="130"/>
                         <a:column name="cert_send_date02" align="center" prompt="邮寄日期2" width="130"/>
                     </a:column>-->
                    <a:column prompt="所有权转移证书">
                        <a:column name="trans_recipient01" align="center" prompt="收件人" width="200"/>
                        <a:column name="trans_tracknum01" align="center" prompt="快递单" width="130"/>
                        <a:column name="trans_send_date01" align="center" prompt="邮寄日期" width="130"/>
                    </a:column>
                    <!-- <a:column prompt="第二次寄送所有权转移证书">
                         <a:column name="trans_recipient02" align="center" prompt="收件人2" width="200"/>
                         <a:column name="trans_tracknum02" align="center" prompt="快递单2" width="130"/>
                         <a:column name="trans_send_date02" align="center" prompt="邮寄日期2" width="130"/>
                     </a:column>-->
                    <a:column name="note" align="center" prompt="备注" width="130"/>
                    <a:column align="center" prompt="发票寄送明细" renderer="send_detail_render" width="130"/>
                </a:columns>
            </a:grid>
        </a:screenBody>
        <script type="text/javascript"><![CDATA[
        if ('${/model/default_value_record/record/@bp_category}' == 'AGENT') {
            $('con706_trans_info_print_id').disable();
            $('con706_trans_info_modify_id').disable();
            $('con706_trans_info_import_id').disable();
        }
        ]]></script>
    </a:view>
</a:screen>