import { connect } from 'herculex';

Component(connect({
  mapStateToProps: {
    userInfo: state => state.$global.userInfo,
  },
})({
  data: {
    extInfo: {},
    created: false,
    containerStyle: '',
    serviceList: [],
  },
  props: {
    componentData: {},
  },
  didMount() {
    this.onInitData();
  },
  methods: {
    onInitData() {
      const {
        componentData,
      } = this.props;

      const {
        serviceList = [],
        componentExtInfo,
      } = componentData;
      const containerStyles = [];

      const {
        paddingHorizontal,
      } = componentExtInfo;
      /*
      * 设置按钮组的左右边距
      * */
      if (+paddingHorizontal) {
        containerStyles.push(`padding: 0 ${paddingHorizontal / 50}rem`);
      }

      this.setData({
        serviceList,
        created: true,
        extInfo: componentExtInfo,
        containerStyle: containerStyles.join(';'),
      });
    },
  },
}));
