FCheckItem_wev8.js
3.68 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
define(['mUtil', "Component", "Form"],function(mUtil, Component, Form) {
var FCheckItem = function(options) {
Component.super(this, options);
this.type = "FCheckItem";
this.tpl = this.type + "_html";
this.css = this.type + "_css";
var vm = this.viewModel = {
form: "",
field: {
label: "", //显示名
name: "", //字段名
id: "", //字段id
value: "" //字段值
},
detailtable: {
isA: false //是否是明细表字段
},
readonly: false,
required: false
};
var successClass = "wev-check-success",
errorClass = "wev-check-error",
blankClass = "wev-check-blank",
$wevField, $checkItem, $checkEdit, $field;
this.mounted = function(){
var that = this, $el = this.$el;
$wevField = this.$el.find(".wev-field");
$checkItem = $el.find(".wev-check-item");
$checkEdit = $el.find(".wev-check-item .wev-check-edit");
$field = $el.find("input[name='fieldname_" + vm.field.name + "']");
if (!vm.readonly) {
that.$comp.on("click", function (e) {
var currValue = $field.val(), nextValue = "";
switch (currValue) {
case "1":
nextValue = "0";
break;
case "0":
nextValue = "";
break;
default:
nextValue = "1";
break;
}
that.setValue(nextValue);
e.stopPropagation();
});
}
$checkEdit.on("click", function (e) {
mUtil.trigger("oncheckedit", that.pageid, vm.form.replace("form_", ""), [that, vm.field.id]);
e.stopPropagation();
});
if(vm.field.value){
this.setValue(vm.field.value);
}
};
this.getData = function(){
return mUtil.parseJSON("fieldname_" + vm.field.name, $field.val());
};
this.getShowData = function(){
var val = $field.val(), showData = mUtil.parseJSON(vm.field.name, val);
showData[vm.field.name + "_showvalue"] = val;
return showData;
};
this.reset = function(){
this.setValue(vm.field.value);
};
this.checkRequired = function () {
var required = vm.required && !$field.val();
$wevField.toggleClass("wev-required-remind", required);
return required && vm.field.label;
};
this.setValueByDB = function(value){
value = value || '';
vm.field.value = value;
this.setValue(value);
};
this.setValue = function(v){
var activeClass = blankClass;
switch (v) {
case "1":
activeClass = successClass;
break;
case "0":
activeClass = errorClass;
break;
default:
v = "";
activeClass = blankClass;
break;
}
$checkItem.removeClass(successClass).removeClass(errorClass)
.removeClass(blankClass).addClass(activeClass);
$field.val(v);
};
};
return Component.init(FCheckItem);
});