yylib-quick-mobile
Version:
yylib-quick-mobile
124 lines (111 loc) • 4.43 kB
JavaScript
var _require = require('./api.all'),
TableApi = _require.TableApi,
FormApi = _require.FormApi;
var _ = require('lodash');
var _require2 = require('../../index'),
YYToast = _require2.YYToast;
var formatUtils = require('../../utils/formatUtils');
var ajax = require('../../utils/ajax');
var CURDHandler = {
"icop.select": {
"onClick": function onClick() {
var page = this.getPage();
var table = this.findUI('icop.table');
if (table) {
if (table.uitype == 'YYTable') {
TableApi.loadData({ page: page, table: table });
} else if (table.api && table.uitype == 'TableWidget') {
table.api.queryData();
} else if (table.api && table.uitype == 'CPListTable') {
table.api.queryData();
}
}
}
},
"icop.delete": {
"onClick": function onClick() {
var page = this.getPage();
var table = this.findUI('icop.table');
if (table) {
if (table.uitype == 'YYTable') {
TableApi.batchDelete({ page: page, table: table });
} else if (table.api && table.uitype == 'TableWidget') {
table.api.deleteData();
} else if (table.api && table.uitype == 'CPListTable') {
table.api.deleteData();
}
}
}
},
"icop.goback": {
"onClick": function onClick() {
this.goBack();
}
},
"icop.table": {
onViewWillMount: function onViewWillMount(options) {
var page = this.getPage();
var table = this.findUI('icop.table');
if (table && table.uitype == 'YYTable') {
TableApi.init({ page: page, table: table });
}
},
onViewDidMount: function onViewDidMount(options) {
var page = this.getPage();
var table = this.findUI('icop.table');
if (table && table.uitype == 'YYTable') {
TableApi.loadData({ page: page, table: table });
}
}
},
"icop.save": {
"onClick": function onClick() {
var that = this;
var allForms = this.findUIByType('FormWidget');
if (!_.isArray(allForms) || allForms.length == 0) return;
var _getBaseUrl = function _getBaseUrl(dataprops) {
if (dataprops && dataprops.system && dataprops.system.baseUrl && dataprops.system.systemName) {
return dataprops.system.baseUrl + dataprops.system.systemName;
}
};
var _getEntityName = function _getEntityName(dataprops) {
if (dataprops && dataprops.entity && dataprops.entity.entityFullName) {
return dataprops.entity.entityFullName;
}
};
var formKeys = [];
var _url;
var _entityName;
_.forEach(allForms, function (form, index) {
formKeys.push(form.uikey);
if (!_url) {
_url = _getBaseUrl(form.dataprops) ? _getBaseUrl(form.dataprops) + "/commons/jpa/update" : null;
}
if (!_entityName) {
_entityName = _getEntityName(form.dataprops);
}
});
FormApi.validateForms(this, { formKeys: formKeys, success: function success(options) {
var allFormValues = options.formValues;
var formValues = {};
_.forEach(allFormValues, function (values, key) {
formValues = _.assign(formValues, values);
});
var _parentEntity = {
"entityName": _entityName,
"entityJson": formValues
};
ajax.postJSON(_url, _parentEntity, function (result) {
if (result && result.success) {
YYToast.success('保存成功');
that.goBack();
} else {
YYToast.error(result.backMsg);
}
});
} });
}
}
};
module.exports = CURDHandler;
;