UNPKG

4 kBJavaScriptView Raw
1/**
2 * Module : kero dataTable row ref
3 * Author : liuyk(liuyk@yonyou.com)
4 * Date : 2016-08-08 13:54:01
5 */
6import {getJSObject} from 'tinper-sparrow/src/util';
7import {date} from 'tinper-sparrow/src/util/dateUtils';
8import {_getField} from './row-util';
9
10const ref = function (fieldName) {
11 this.parent.createField(fieldName);
12 if (!this.valueChange[fieldName])
13 this.valueChange[fieldName] = ko.observable(1);
14 return ko.pureComputed({
15 read: function () {
16 this.valueChange[fieldName]();
17 this.currentRowChange();
18 return this.getChildValue(fieldName)
19 //var value = this._getField(fieldName)['value'];
20 //return value;
21 },
22 write: function (value) {
23 this.setChildValue(fieldName, value);
24 //this.setValue(fieldName, value)
25 },
26 owner: this
27 })
28}
29
30
31
32const refMeta = function (fieldName, key) {
33 if (!this.metaChange[fieldName + '.' + key])
34 this.metaChange[fieldName + '.' + key] = ko.observable(1);
35 return ko.pureComputed({
36 read: function () {
37 this.metaChange[fieldName + '.' + key]()
38 return this.getMeta(fieldName, key)
39 },
40 write: function (value) {
41 this.setMeta(fieldName, key, value)
42 },
43 owner: this
44 })
45}
46const refCombo = function (fieldName, datasource) {
47 if (!this.valueChange[fieldName])
48 this.valueChange[fieldName] = ko.observable(1);
49 return ko.pureComputed({
50 read: function () {
51 this.valueChange[fieldName]();
52 this.currentRowChange();
53 var ds = getJSObject(this.parent.parent, datasource)
54 if (_getField(this, fieldName)['value'] === undefined || _getField(this, fieldName)['value'] === "") return "";
55 var v = _getField(this, fieldName)['value'];
56 var valArr = typeof v === 'string' ? v.split(',') : [v];
57
58 var nameArr = []
59
60 for (var i = 0, length = ds.length; i < length; i++) {
61 for (var j = 0; j < valArr.length; j++) {
62 var value = ds[i]['pk'] || ds[i]['value'] || '';
63 if (value == valArr[j]) {
64 nameArr.push(ds[i].name)
65 }
66 }
67 }
68
69 return nameArr.toString();
70 },
71 write: function (value) {
72
73 this.setValue(fieldName, value)
74 },
75 owner: this
76 })
77}
78const refDate = function (fieldName, format) {
79 if (!this.valueChange[fieldName])
80 this.valueChange[fieldName] = ko.observable(1);
81 return ko.pureComputed({
82 read: function () {
83 this.valueChange[fieldName]();
84 this.currentRowChange();
85 if (!_getField(this, fieldName)['value']) return "";
86 var valArr = _getField(this, fieldName)['value']
87 if (!valArr) return "";
88 valArr = date.format(valArr, format); //moment(valArr).format(format)
89 return valArr;
90 },
91 write: function (value) {
92
93 this.setValue(fieldName, value)
94 },
95 owner: this
96 })
97}
98
99// 刘云燕提交
100const refEnum = function (fieldName) {
101 this.parent.createField(fieldName);
102 if (!this.valueChange[fieldName])
103 this.valueChange[fieldName] = ko.observable(1);
104 return ko.pureComputed({
105 read: function () {
106 this.valueChange[fieldName]();
107 this.currentRowChange();
108 if (!_getField(this, fieldName)['value']) return "";
109 var valArr = _getField(this, fieldName)['value']
110 if (!valArr) return "";
111 if(valArr == "N")
112 valArr = "否";
113 else if(valArr == "Y")
114 valArr = "是";
115 return valArr;
116 },
117 write: function (value) {
118
119 this.setValue(fieldName, value)
120 },
121 owner: this
122 })
123}
124
125export {
126 ref,
127 refMeta,
128 refCombo,
129 refDate,
130 refEnum
131}