FHidden_wev8.js
2.47 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
define(['mUtil', "Component", "Form"],function(mUtil, Component, Form) {
var FHidden = function(options) {
var $field;
Component.super(this, options);
this.type = "FHidden";
this.tpl = this.type + "_html";
this.dataload = true;
var vm = this.viewModel = {
form : "",
field : {
name : "",
id : "",
value : "",
defaultValue: ""
},
detailtable: {
isA: false //是否是明细表字段
}
};
this.dbValueHasSet = false; //是否已设置表单数据值,调用this.setValueByDB()方法后修改此状态
this.beforeMount = function () {
//主表或明细新增,并且值为空 但默认值不为空时,使用默认值代替赋值
Form.utils.setDefaultValue(this.pageid, vm);
};
this.mounted = function(){
var that = this;
$field = this.$el.find("input");
if(vm.field.needParseSqlValue){
//解析默认值,默认值sql
return Form.utils.parseDefaultSqlValue(vm.field.defaultValue, this.pageid, function(result){
vm.field.value = result;
//设置默认值
that.setValue(vm.field.value);
});
}
};
this.getData = function(){
return mUtil.parseJSON("fieldname_" + vm.field.name, $field.val());
};
this.getShowData = function(){
return mUtil.parseJSON(vm.field.name, $field.val());
};
this.bindTrigger = function(triggers, isTrigger){
var that = this,
fieldid = vm.field.id;
if(fieldid && mUtil.isObject(triggers) && triggers["field" + fieldid]){
var trigger = triggers["field" + fieldid];
$field.bind("change", function(){
Mobile_NS.readyToTrigger(trigger, $field, that.$container);
});
//默认值触发字段联动,主表新建或者是明细表添加数据时触发
if (vm.field.value && ((vm.form.indexOf("detailtable") == -1 && !$p("billid")) || isTrigger)) {
Mobile_NS.readyToTrigger(trigger, $field, that.$container);
}
}
};
this.setValueByDB = function(value){
this.dbValueHasSet = true;
if(value || !vm.field.value){
vm.field.value = value;
this.setValue(value);
}
};
this.setValue = function(value){
$field.val(value).triggerHandler("change");
this.dbValueHasSet && mUtil.trigger('dataload', this.pageid, this.id);
};
this.reset = function(){
this.setValue(vm.field.value);
};
this.checkRequired = function(){};
};
return Component.init(FHidden);
});