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

<!--
    $Author:
    $Date: 2018/8/2
    $Revision: 1.0
    最近成交合同
-->
<a:screen xmlns:a="http://www.leaf-framework.org/application">
    <a:init-procedure/>
    <a:view template="default" package="leaf.ui.std">
        <a:link id="widget_cont_recent_910_project_get_layout_code_link_id" model="cont.CON500.con_contract_get_layout_code" modelaction="update"/>
        <a:link id="count_recent_con_contract_info_link" url="${/request/@context_path}/modules/prj/PRJ506/virtual_contract_query.lview"/>
        <style>
            html,body{
            width:264px;
            height:360px;
            margin: 0;
            padding: 0;
            }
        </style>
        <script><![CDATA[
        function cont_recent_grid_renderer(record,index){
            var html='';
            html+='<div class="listRow1">'
                +'<span class="bp_name" title="'+ record.data['bp_name'] +'">' + record.data['bp_name'] + '</span>';
            var con_date=new Date(record.data['year'],record.data['month']-1,record.data['day']);
            <!--测试用var con_date=new Date(2018,5,24);-->
            var today=new Date();
            var days=Math.floor(Math.abs(today-con_date)/1000/60/60/24);
            var dateStr=''
            if(days == 0){
                dateStr='今天';
            }else if(days == 1){
                dateStr='昨天';
            }else if(today.getFullYear()==record.data['year']){
                dateStr=record.data['month']+'月'+record.data['day']+'日';
            }else{
                dateStr=record.data['year']+'年'+record.data['month']+'月'+record.data['day']+'日';
            }
            html+='<span class="date">' + dateStr + '</span>'
                +'<span class="clearFloat"></span></div>'
                +'<div class="listRow2">'
                +'<span class="amount"><img src="${/request/@context_path}/leafresource/images/widget/fileOk.png"/>' + $L.formatMoney(record.data['contract_amount'],2) + '</span>'
                +'<img class="goDetail" src="${/request/@context_path}/leafresource/images/widget/rightSquare.png" onclick="open_vir_con_win(\'' + record.ds.id + '\',' + record.id + ')"/>'
                +'<span class="clearFloat"></span></div>';
            return html;
        }
        function open_vir_con_win(ds_id, record_id){
            var record = $(ds_id).findById(record_id);
            var param = record.data;
            param['function_code'] = 'C0N301D_CON';
            param['function_usage'] = 'QUERY';
            param['maintain_type'] = 'READONLY';
            param['cond_para2'] = record.get('hn_industry_classification');
            param['url_title'] = '合同明细';
            param['winid'] = 'con301_virtual_contract_query_detail_link_id';

            Leaf.Masker.mask(Ext.getBody(), '${l:HLS.EXECUTING}');
            Leaf.request({
                url: $('widget_cont_recent_910_project_get_layout_code_link_id').getUrl(),
                para: param,
                success: function(res) {
                    Leaf.Masker.unmask(Ext.getBody());
                    if (!res.result.layout_code) {
                        Leaf.showMessage('${l:PROMPT}', '${l:HLS.LAYOUT_CODE_IS_NULL}');
                        return;
                    }
                    param['layout_code'] = res.result.layout_code;
                    param['usage_type'] = res.result.usage_type;
                    var winid = 'hls_doc_get_layout_code_winid';
                    param['winid'] = winid;
                    param['calc_type'] = res.result.cond_para1;
                    var win;
                    win = new Leaf.Window({
                        id: winid,
                        params: param,
                        url: $('count_recent_con_contract_info_link').getUrl(),
                        title: param['url_title'] + '(' + res.result.layout_code + ')',
                        fullScreen: true,
                        draggable: true
                    });
                },
                failure: function() {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                error: function() {
                    Leaf.Masker.unmask(Ext.getBody());
                },
                scope: this
            });
        }
            ]]></script>
        <a:dataSets>
            <a:dataSet id="cont_recent_ds" autoQuery="true" pageSize="5" model="cont.CON1003.cont_recent">
                <a:fields>
                    <a:field name="contract_id"/>
                    <a:field name="project_id"/>
                    <a:field name="bp_name"/>
                    <a:field name="CONTRACT_AMOUNT"/>
                    <a:field name="hn_industry_classification"/>
                    <a:field name="year"/>
                    <a:field name="month"/>
                    <a:field name="day"/>
                    <a:field name="con_date"/>
                </a:fields>
            </a:dataSet>
        </a:dataSets>
        <a:recentList id="widget_cont_recent" title="最近成交" width="264" height="360"
                       bindTarget="cont_recent_ds" titleField="bp_name" dateField="con_date"
                       descField="contract_amount" descIcon="/leafresource/images/widget/fileOk.png"
                       goDetailFn="open_vir_con_win" goDetailIcon="/leafresource/images/widget/rightSquare.png"/>
        <a:screenBody style="display:none"> </a:screenBody>
    </a:view>
</a:screen>