import store from './store';

Page(store.register({
  data: {
    defaultUrl: 'https://gw.alipayobjects.com/mdn/rms_a0c592/afts/img/A*sivLQ7HSVNsAAAAAAAAAAABkARQnAQ',
  },
  onLoad(options) {
    this.onResetStore();
    // 根据传过来的options动态设置标题 动态加载样式
    const { backgroundUrl, title, componentUUID, componentType, templateUUID } = options;
    const { imgSrcPrefix } = this.data;
    my.setNavigationBar({
      // reset: true,
      title,
    });
    this.commit({
      componentType,
      componentUUID,
      templateUUID,
      // eslint-disable-next-line no-nested-ternary
      backgroundUrl: backgroundUrl ? (backgroundUrl.length == 32 ? imgSrcPrefix + backgroundUrl : backgroundUrl) : this.data.defaultUrl,
    });
    this.dispatch('getListTwoData');
  },
  onReloadHandle() {
    this.onResetStore();
    this.dispatch('getListTwoData');
  },
  onResetStore() {
    this.commit({
      errorType: '',
      serviceList: [],
    });
  },
}));
