SegControl_wev8.js
2.13 KB
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
define(['mUtil', "Component"], function (mUtil, Component) {
var SegControl = function (options) {
var _segControl = {};
Component.super(this, options);
this.type = "SegControl";
this.tpl = this.type + "_html";
this.css = this.type + "_css";
var vm = this.viewModel = {
segments: [{
text: " ",
active: false,
click: function () { }
}],
badge: null
};
this.beforeMount = function(){
vm.remindApis = [];
vm.segments.map(function(segment){
if(segment.remind && segment.remindapi && segment.remindapi.api){
segment.uuid = segment.remindapi.uuid = mUtil.UUID();
segment.apiid = segment.remindapi.api.id;
vm.remindApis.push(segment.remindapi);
delete segment.remindapi;
}
});
if(vm.badge === true){
vm.badge = mUtil.getActionUrl(this.type, {action:"getBadge", "mec_id": this.id}, this.pageid);
}
};
this.mounted = function () {
var that = this,
segments = vm.segments,
$comp = that.$el.children(".wev-comp-" + that.type);
$comp.on("click", ".wev-control-item", function (e) {
var index = $(this).index(),
segment = segments[index];
$(this).addClass("active").siblings().removeClass("active");
segment && mUtil.eval(segment.click, that.pageid);
e.stopPropagation();
});
var notActive = true;
segments.map(function (segment) {
if(segment && segment.active){
mUtil.eval(segment.click, that.pageid);
notActive = false;
}
});
if(notActive){
$comp.find(".wev-control-item").eq(0).addClass("active")
}
_segControl.loadBadge();
};
this.refreshBadge = function () {
_segControl.loadBadge();
};
_segControl.loadBadge = function () {
if(vm.badge == null){
return;
}
var $badges = $(".wev-numremind", this.$el);
require(["remindHelper"], function (helper) {
helper.renderBadge(vm.badge, $badges, vm.remindApis);
});
};
_segControl.loadBadge = _segControl.loadBadge.bind(this);
};
return Component.init(SegControl);
});