import React from 'react';
import { Button, Icon, Tabs, Modal } from 'antd';
import { WeaTools, WeaLocaleProvider, WeaDialog, WeaNewScroll } from 'ecCom';
const TabPane = Tabs.TabPane;
const getLabel = WeaLocaleProvider.getLabel;
const E8_SYS_COLORS = ['#0070c1', '#cc3432', '#5c64c2', '#50833b', '#874d19', '#f46f43', '#22c9b2', '#b24079', '#83686c', '#666f81', '#627f7e'];
import './style/';
class WeaThemeCenter extends React.Component {
state = { visible: false, loading: false, tabKey: '', tabKey2: '', themes: [], curTheme: {}, hasRight: false };
constructor(props) {
super(props);
this.getButtons = this.getButtons.bind(this);
this.onOk = this.onOk.bind(this);
this.onCancel = this.onCancel.bind(this);
this.onSetting = this.onSetting.bind(this);
this.onThemeChange = this.onThemeChange.bind(this);
this.onColorChange = this.onColorChange.bind(this);
}
render() {
const { visible, loading, tabKey, tabKey2, themes = [], curTheme = {}, hasRight } = this.state;
const { type: type_cur, templateid: templateid_cur, templatetype: templatetype_cur, skin: skin_cur, color: color_cur, layout: layout_cur } = curTheme;
const themeTabPaneComp = (
this.setState({ tabKey2: key })}>
{
themes.map((themeType) => {
const { key, name, data = [] } = themeType;
return (
{
data.map((theme, index) => {
const { type, templateid, templatetype, skin, layout } = theme;
let previewComp = '';
if (key == 'ecology8') {
previewComp =
;
} else {
previewComp =
;
}
let selectedComp = '';
if (type == type_cur && ((templateid == templateid_cur && templatetype == templatetype_cur && skin == skin_cur) || (layout == '5' && layout == layout_cur))) {
selectedComp =

;
}
return (
this.onThemeChange(theme)}>
{previewComp}
{theme.name}
{selectedComp}
);
})
}
);
})
}
);
let tabComp =
;
const operationComp = hasRight ? : '';
if (templatetype_cur == 'ecology8') {
let colorImg = '';
let colorSelectedStyle = {};
if (color_cur) {
const _color = color_cur.replace(/[^0-9]/ig, '');
const _index = _color == '' ? 0 : parseInt(_color);
colorImg = `/wui/theme/ecology8/page/images/skin/color${_color}_wev8.png`;
colorSelectedStyle = { display: 'block', left: 50 * _index + 41, backgroundColor: E8_SYS_COLORS[_index] };
}
const colorTabPaneComp = (
{
E8_SYS_COLORS.map((item, index) => (
))
}
);
tabComp = (
this.setState({ tabKey: key })} tabBarExtraContent={operationComp}>
{themeTabPaneComp}
{colorTabPaneComp}
);
} else {
tabComp = (
this.setState({ tabKey: key })} tabBarExtraContent={operationComp}>
{themeTabPaneComp}
);
}
return (
{tabComp}
);
}
onShow() {
this.setState({ visible: true, loading: true });
WeaTools.callApi('/api/portal/themeCenter/getAllThemes', 'GET', {}).then((result) => {
const { data = {} } = result;
const { curTheme = {} } = data;
const { templatetype, color, layout } = curTheme;
this.setState({ loading: false, tabKey: templatetype == 'ecology8' && color ? '2' : '1', tabKey2: layout == '5' ? 'ts' : templatetype, ...data });
});
}
getButtons() {
let buttons = [];
buttons.push();
return buttons;
}
onOk() {
this.setState({ visible: false });
}
onCancel() {
this.setState({ visible: false });
}
onSetting() {
window.open('/spa/portal/engine.html#/portalengine/portalmaintenance/mainportal', '_blank');
}
onThemeChange(theme) {
const { type, templatetype } = theme;
if (type == 'preview') {
let redirectUrl = theme.url;
let width = screen.availWidth - 10;
let height = screen.availHeight - 60;
let szFeatures = 'top=0,';
szFeatures += 'left=0,';
szFeatures += `width=${width},`;
szFeatures += `height=${height},`;
szFeatures += 'directories=no,';
szFeatures += 'status=yes,';
szFeatures += 'menubar=no,';
szFeatures += 'scrollbars=yes,';
szFeatures += 'resizable=yes';
window.open(redirectUrl, '', szFeatures);
} else if (type == 'layout') {
this.setState({ loading: true });
doThemeAction('onLayoutChange', { type: theme.layout }, () => this.setState({ loading: false }));
} else if (templatetype == 'ecology8' || templatetype == 'ecology9') {
this.setState({ loading: true });
doThemeAction('onThemeChange', theme, () => this.setState({ loading: false, curTheme: theme }));
}
}
onColorChange(e) {
const $obj = jQuery(e.target);
const index = $obj.attr('data-index');
jQuery('.wea-theme-center-color-img').css('background', `url(/wui/theme/ecology8/page/images/skin/color${index}_wev8.png)`);
jQuery('.wea-theme-center-color-selected').css({ display: 'block', 'background-color': $obj.css('background-color') }).animate({ left: $obj.position().left - 5 });
this.setState({ loading: true });
doThemeAction('onColorChange', { color: `left${index}` }, () => this.setState({ loading: false }));
}
}
export default WeaThemeCenter;