
<div class="current-location">
    <ul>
        <li class="left"><i class="glyphicon glyphicon-home"></i><a href="javascript:void(0)" onclick="location.href=location.href">签收信息</a></li>
        <li class="right"><a href="javascript:void(0)" onclick="LoadData()" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a></li>
    </ul>
</div>
<div class="head-tab" id="head_tab">
    <ul>
        @*<li data-state="" class="current">所有签收</li>*@
        <li data-state="0" class="current">未签收</li>
        <li data-state="1">已签收</li>
    </ul>
</div>
<div class="main no-top-border">
        <table class="tb-head" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td class="left">
                    <div class="btn-group btn-group-sm">
                        <button type="button" class="btn btn-default ui-selectInvert">反选</button>
                        <button type="button" class="btn btn-default ui-setMultiple"  data-custom-params="setName:'pSign',beforeExecute:'BeforeExecuting'">批量签收</button>
                    </div>
                </td>
                <td class="right form-inline form-group-sm">
                    <input type="hidden" id="state" name="state" value="0" class="ui-queryString"/>
                    <select id="s_field" name="s_field" class="btn-xs ui-queryString ui-setName form-control">
                        <option value="publisher" valueType="nvarchar" searchtype="fuzzy">按发布用户</option>
                        <option value="thedate" valueType="date" searchType="range">按提交日期</option>
                        <option value="sign_date" valueType="date" searchType="range">按签收日期</option>
                    </select>
                    <input type="text" id="title" name="title" class="ui-queryString ui-keyword  form-control" placeholder="输入标题关键词">
                    <input type="button" value="确定" class="btn btn-default btn-sm ui-queryString-search">
                </td>
            </tr>
        </table>
    <table border=0 cellpadding=0 cellspacing=0 class="table table-bordered" id="tb_list">
        <thead><tr>
            <td align="center" style="width:30px"><input type="checkbox" title="选择" class="ui-selectInvert" data-custom-params="isReverse:false"></td>
            <td align="left">标题</td>
            <td align="left">截止日期</td>
            <td align="center">签收状态</td>
            <td align="center">是否签收</td>
            <td align="center">操作</td>
        </tr>
        <tr class="item template-item">
            <td align="center"><input type="checkbox" id="id" name="id" value="{id}"></td>
            <td align=left><span class="lb_title" data-custom-params="url:'@Url.Action("GetFieldByIds","InfoData")?table={table}',textField:'title'">{detail_id}</span></td>
            <td align="center">开始日期：{start_date}<br />结束日期：{end_date}</td>
            <td align="center"><span class="lb_sign_state" date-end-date="{end_date}"></span></td>
            <td align="center"><span class="lb_state is-{state}"></span></td>
            <td align="center">
                <div class="btn-group btn-group-sm">
                    <a href="javascript:void(0)" class="btn btn-default btn-sm ui-dialog" data-custom-params="title:'签收详情',url:'@Url.Action("Detail")?table={table}&detail_id={detail_id}&id={id}',width:'80%',height:'90%'">详情</a>
                    <a href="javascript:void(0)" class="btn btn-default btn-sm ui-dialog btn_sign" data-custom-params="title:'签收信息',url:'@Url.Action("Sign")?id={id}',width:'600px',height:'250px'">签收</a>
                </div>
            </td>
        </tr>
    </table>
</div>
<script type="text/javascript">

    var $state = $("#state");
    var $btsearch = $(".ui-queryString-search");
    var $head_tab_item = $("#head_tab").children("ul").children("li");
    $head_tab_item.click(function () {
        var $this = $(this);
        var state = $this.attr("data-state");
        $state.val(state);
        $this.addClass("current").siblings().removeClass("current");
        $btsearch.click();
    })

    var nowDate = "@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")";

    function LoadData() {
        var param = { callBack: "Init" };
        var url = "@Url.Action("PageListData")"
        $("#tb_list").ListBind(url,param);
    }

    function Init() {
        var $lb_sign_state = $(".lb_sign_state");
        var $btn_sign = $(".btn_sign");
        $lb_sign_state.each(function (index) {
            var $this = $(this);
            var endDate = $this.attr("date-end-date");
            if (IsExpire(endDate, nowDate)) {
                $this.html("签收中");
            }
            else {
                $this.html("<span style=\"color:#999\">已结束</span>");
                $btn_sign.eq(index).text("结束");;
            }
        });

        ConvertText($(".lb_title"));
    }
    LoadData();

    function IsExpire(endDate,nowDate)
    {
        endDate = new Date(endDate.replace(/-/g, '/'));
        nowDate = new Date(nowDate.replace(/-/g, '/'));
        return endDate>=nowDate;
    }

    //设置前检测
    function BeforeExecuting(ids, setName) {
        var Aids = ids.split(",");
        var currentObj, guid, childObj;
        switch (setName) {
            case "pSign":
                var params = { title: '批量签收', url: '@Url.Action("PSign")?ids='+ids, width: '600px', height: '180px' };
                IDialog(params);
                return false;
                break;
        }
        return true;
    }
</script>