import { navigateTo, toUrl } from '../../utils';
import { connect } from 'herculex';

Component(connect({
  mapStateToProps: {
    templateUUID: state => state.$global.templateUUID,
  },
})({
  props: {
    className: '',
    componentData: {},
    imgSrcPrefix: '',
    iconSize: '12',
    hasBorder: true,
    hasMoreIcon: true, // 是否显示更多
    defaultText: '项服务',
    // length: 4, // 控制title右侧更多等文案展示
  },
  methods: {
    jumpToServiceDetail(e) {
      // TODO: 跳转服务
      const { item = {} } = e.target.dataset;
      // eslint-disable-next-line max-len
      const { componentType, componentExtInfo, componentTitle, componentUUID, whetherSetDynamicDatasource } = item;
      const { backgroundUrl = '' } = componentExtInfo || {};
      const params = {
        title: componentTitle,
        componentType,
        componentUUID,
        backgroundUrl,
        templateUUID: this.data.templateUUID,
        whetherSetDynamicDatasource,
      };
      switch (componentType) {
        case 'contentComponent':
        case 'noticeComponent': {
        // 跳转咨询组件的页面
          navigateTo({
            url: `../../pages/consult-detail/index${toUrl(params)}`,
          });
          break;
        }
        case 'divide4NpartsComponent':
        case 'activityAdComponent':
        case 'textlistComponent':
        case 'navigationbarsComponent':
        case 'fourpicComponent': {
          //  跳转活动或者文字列表页面或者四联图片
          navigateTo({
            url: `../../pages/service-detail/index${toUrl(params)}`,
          });
          break;
        }
        case 'twopicComponent': {
          navigateTo({
            url: `../../pages/list-detail-two/index${toUrl(params)}`,
          });
          break;
        }
        case 'piclistComponent': {
          navigateTo({
            url: `../../pages/list-detail-one/index${toUrl(params)}`,
          });
          break;
        }
        default:
      }
    },
  },
}));
