hjg
2024-10-30 8cf23534166c07e711aac2a25911ada317ba01f0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
 * exam:data-bind="datepicker:stime,datepickerOptions:{dateFmt:'yyyy-MM-dd'}" 
 *
 * 
 */
 
ko.bindingHandlers.datepicker = {
    init: function(element, valueAccessor, allBindingsAccessor) {
        //initialize datepicker with some optional options
        var options = allBindingsAccessor().datepickerOptions || {},
            $el = $(element);
        $el.click(function(event) {
            /* Act on the event */
            var fmt="yyyy-MM-dd";
            if(options.dateFmt!=null&&options.dateFmt!='')
                fmt=options.dateFmt;
            WdatePicker({dateFmt:fmt,onpicked:function(fp){
                var value=fp.cal.getNewDateStr();
                var observable = valueAccessor();
                observable(value);
                return true;   
            }});
        });
        $el.blur(function(){
            var $this=$(this);
            var str=$this.val();
            if(str==null||str==='')
            {
                var observable = valueAccessor();
                observable(undefined);
            }
             return true; 
        });
        // //handle the field changing
        // ko.utils.registerEventHandler(element, "change", function () {
        //     var observable = valueAccessor();
        //     observable($el.val());
        // });
    },
    update: function(element, valueAccessor) {
        var value = ko.utils.unwrapObservable(valueAccessor()),
            $el = $(element);
 
        //handle date data coming via json from Microsoft
        if (String(value).indexOf('/Date(') == 0) {
            value = new Date(parseInt(value.replace(/\/Date\((.*?)\)\//gi, "$1")));
        }
 
        var current = $el.val();
 
        if (value != current) {
            $el.val(value);
        }
    }
};
 
/*
    2015-01-03,mengly:添加了三个关于时间转换和有效期判断的方法,getdate,cpm_jinxq,isjinxiao,
     同时修改getlist里面,近效期的只有重点养护,锁定的只能有锁定养护
 */
 
 function getdate(date_str)
{
    try{
    if(date_str==undefined)
        return null;
    var ds=date_str.split('-');
    if(ds.length<3)
        return null;
    var y=parseInt(ds[0]);
    var m=parseInt(ds[1])-1;
    var d=parseInt(ds[2]);
    var date1=new Date(y,m,d);
    return date1;
    }catch(e){
        return undefined;
    }
}
//false:非近效期,true:近效期
function cpm_jinxq(nowdate,validdate)
{
    try{
    if(nowdate==undefined||validdate==undefined)
        return true;
    nowdate.setDate(nowdate.getDate()+30);
    if(nowdate>=validdate)
        return true;
    }catch(e){
    }
    return false;
}
function isjinxiao(datestr)
{
    var date=getdate(datestr);
    if(date==undefined)
        return true;
    return  cpm_jinxq(new Date(),date);
}