UNPKG

yyuap-template

Version:

template project which is based on tinper

307 lines (284 loc) 14.4 kB
(function (global, factory) { if (typeof define === "function" && define.amd) { define(['module', 'exports', 'react', 'bee-panel', 'bee-layout', '../TableLayout/TableLayout', 'moment'], factory); } else if (typeof exports !== "undefined") { factory(module, exports, require('react'), require('bee-panel'), require('bee-layout'), require('../TableLayout/TableLayout'), require('moment')); } else { var mod = { exports: {} }; factory(mod, mod.exports, global.react, global.beePanel, global.beeLayout, global.TableLayout, global.moment); global.RowContent = mod.exports; } })(this, function (module, exports, _react, _beePanel, _beeLayout, _TableLayout, _moment) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _react2 = _interopRequireDefault(_react); var _TableLayout2 = _interopRequireDefault(_TableLayout); var _moment2 = _interopRequireDefault(_moment); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var values = {}; var RowContent = function (_Component) { _inherits(RowContent, _Component); function RowContent(props) { _classCallCheck(this, RowContent); var _this = _possibleConstructorReturn(this, (RowContent.__proto__ || Object.getPrototypeOf(RowContent)).call(this, props)); _this.formatDate = function (date, type) { if (new Date(date)) { return (0, _moment2.default)(new Date(date)).format(type); } else { return date; } }; _this.state = { isEdit: false, checkFormNow: false, expanded: false, viewModel: _this.props.viewModel, dataModel: JSON.parse(JSON.stringify(_this.props.dataModel || {})) }; return _this; } _createClass(RowContent, [{ key: 'createRow', value: function createRow(type, rowData) { var self = this; switch (type) { case 'add': var title = []; var content = []; var total = 1; this.props.viewModel.layoutDetail.map(function (layout, index) { if (layout.isDisplay && total < 6) { content.push(_react2.default.createElement( 'span', { className: 'row-title-col' }, 'rowData[layout.fieldId]' )); total++; } }); break; case 'rollback': var content = []; var total = 1; var contentTotal = 0; this.props.viewModel.layoutDetail.map(function (layout, index) { if (layout.islist && total < self.props.titleListTotal) { total++; } }); this.props.viewModel.layoutDetail.map(function (layout, index) { if (layout.islist && contentTotal < self.props.titleListTotal && rowData.rowData[layout.fieldId]) { if (layout.componentKey == "DateComponent" && rowData.rowData[layout.fieldId].value) { content.push(_react2.default.createElement( 'span', { key: "content_" + index, title: self.formatDate(rowData.rowData[layout.fieldId].value, layout.format), className: 'row-content-col uit-col-' + total }, self.formatDate(rowData.rowData[layout.fieldId].value, layout.format) )); } else { content.push(_react2.default.createElement( 'span', { key: "content_" + index, title: rowData.rowData[layout.fieldId].value, className: 'row-content-col uit-col-' + total }, rowData.rowData[layout.fieldId].name )); } contentTotal++; } }); return { rowContent: content }; break; } } }, { key: 'componentWillMount', value: function componentWillMount() {} }, { key: 'rowClick', value: function rowClick() { this.setState({ expanded: !this.state.expanded }); } }, { key: 'rowEditBtnClick', value: function rowEditBtnClick() { this.setState({ isEdit: true }); this.props.handleIsEdit(true); this.props.setEditRowIndex(this.props.currentRowIndex); } }, { key: 'rowDeleteBtnClick', value: function rowDeleteBtnClick(e) { this.props.deleteRow(e, this.props.currentRowIndex); } }, { key: 'rowSaveBtnClick', value: function rowSaveBtnClick(e) { var _this2 = this; this.props.saveRow(e, this.props.currentRowIndex, function () { _this2.setState({ isEdit: false, dataModel: JSON.parse(JSON.stringify(_this2.props.dataModel || {})) }); _this2.props.handleIsEdit(false); }); } }, { key: 'rowCancelBtnClick', value: function rowCancelBtnClick() { this.setState({ isEdit: false }); this.props.handleIsEdit(false); } }, { key: 'handleIsEdit', value: function handleIsEdit() { this.setState({ isEdit: false }); this.props.handleIsEdit(false); } }, { key: 'render', value: function render() { var _this3 = this; return _react2.default.createElement( 'div', null, _react2.default.createElement( 'div', { className: this.createRow('rollback', { rowData: this.state.dataModel }).rowContent && this.createRow('rollback', { rowData: this.state.dataModel }).rowContent.length > 0 ? 'border row-content' : 'row-content', onClick: function onClick() { _this3.rowClick(); } }, this.createRow('rollback', { rowData: this.state.dataModel }).rowContent ), _react2.default.createElement( 'div', { className: 'row-whole-content' }, _react2.default.createElement( _beePanel.Panel, { collapsible: true, clsPrefix: 'uit-panel', expanded: this.state.expanded }, _react2.default.createElement(_TableLayout2.default, { allExpand: true, form: this.props.form, typeId: this.props.typeId, config: this.props.config, isEdit: this.state.isEdit, viewModel: this.props.viewModel, dataModel: this.state.dataModel, showLabel: this.props.showLabel, typeIndex: this.props.typeIndex, headFormExpand: this.state.expanded, handleValue: this.props.handleValue, handleIsEdit: this.handleIsEdit.bind(this), handleComponentCallback: this.props.handleComponentCallback }) ), _react2.default.createElement( 'div', null, this.state.expanded && !this.state.isEdit && !this.props.editStatus && !this.props.isAddRow ? _react2.default.createElement( 'div', { style: { display: "inline-block", margin: "10px" } }, _react2.default.createElement( 'button', { className: "uit-button", onClick: function onClick(e) { _this3.rowEditBtnClick(e); }, style: { marginRight: "10px" }, id: 'bodyform_edit' }, uiTemplateMultilingual.template('edit') ) ) : null, this.state.expanded && !this.state.isEdit && !this.props.editStatus && !this.props.isAddRow ? _react2.default.createElement( 'div', { style: { display: "inline-block", margin: "10px" } }, _react2.default.createElement( 'button', { className: "uit-button", onClick: function onClick(e) { _this3.rowDeleteBtnClick(e); }, style: { marginRight: "10px" }, id: 'bodyform_delete' }, uiTemplateMultilingual.template('delete') ) ) : null ), _react2.default.createElement( 'div', { style: { position: "absolute", right: "10px", bottom: "10px" } }, this.state.expanded && this.state.isEdit && this.props.editStatus && !this.props.isAddRow ? _react2.default.createElement( 'div', { style: { display: "inline-block" } }, _react2.default.createElement( 'button', { className: "uit-button", onClick: function onClick(e) { _this3.rowSaveBtnClick(e); }, style: { marginRight: "10px" }, id: 'headform_save' }, uiTemplateMultilingual.template('save') ) ) : null, this.state.expanded && this.state.isEdit && this.props.editStatus && !this.props.isAddRow ? _react2.default.createElement( 'div', { style: { display: "inline-block" } }, _react2.default.createElement( 'button', { className: "uit-button", onClick: function onClick(e) { _this3.rowCancelBtnClick(e); }, style: { marginRight: "10px" }, id: 'headform_cancel' }, uiTemplateMultilingual.template('cancel') ) ) : null ) ) ); } }]); return RowContent; }(_react.Component); exports.default = RowContent; module.exports = exports['default']; });