channel.js 3.63 KB
import Vue from 'vue';
import * as Types from './types';
const contentCode = 'cfcd8de156d3edc26c84091804c43e23'; //  f788335b57b67c1711f255648c744dab

export default function() {
  return {
    namespaced: true,
    state: {
      // channelData: [],
      channelList: {
        list: [], // 资源列表
        productlist: [], // 资源列表
        page: 0, // 当前页
        page_size: 20, // 每页数量
        page_total: 0, // 总共多少页
        total: 0, // 总共多少条
        scrollnavList: [], // 导航菜单
        // scrollnavidList: [], // 导航菜单
        current: 0,
      },
      contentCode: contentCode,
      defaultSearchWord: '',
      showMsg: false,
    },
    mutations: {
      [Types.FETCH_CHANNEL](state, { list }) {

        list.map((res, index) => {
          // 增加曝光参数
          let F_ID = res.template_id;
          let F_NAME = res.template_name;
          let F_INDEX = index + 1;

          res.data.map((item, i) => {
            let reportParams = {};

            reportParams.P_NAME = 'XY_UFOHome';
            reportParams.P_PARAM = contentCode;
            reportParams.F_ID = F_ID;
            reportParams.F_NAME = F_NAME;
            reportParams.F_INDEX = F_INDEX;
            reportParams.I_INDEX = i + 1;
            reportParams.ACTION_URL = item.url;
            item.reportParams = reportParams;
          });
          if (res.template_name === 'hotSeries') {
            for (let i = 0; i < res.data.length; i++) {
              state.channelList.scrollnavList.push(res.data[i].series_name);
            }
          }
        });
        state.channelList.list = list;
      },
      [Types.FETCH_PRODUCT](state, { productlist }) {
        Vue.set(state.channelList, 'productlist', state.channelList.productlist.concat(productlist.product_list));
        Vue.set(state.channelList, 'page', productlist.page);
      },
      [Types.FETCH_NEWSACTIVE](state, { list }) {
        state.showMsg = false;
        list && list.map((item) => {
          if (item.unReadCount > 0) {
            state.showMsg = true;
          }
        });
      },
      [Types.FETCH_DEFAULT_SEARCH_WORD](state, [{search_word} = {}] = []) {
        state.defaultSearchWord = search_word;
      },
    },
    actions: {
      async fetchProductList({ commit, state }, obj) {
        let page = obj && obj.isReset ? state.channelList.page = 1 : state.channelList.page + 1;
        let size = state.channelList.page_size;
        const result = await this.$api.get('/api/ufo/list/productList', {
          page,
          pageSize: size,
          ...obj,
        });

        if (result.code === 200) {
          commit(Types.FETCH_PRODUCT, {productlist: result.data});
        }
      },
      async fetchChannelList({ commit }) {
        const result = await this.$api.get('/api/ufo/channel/channelList', {
          content_code: contentCode
        });

        if (result.code === 200) {
          commit(Types.FETCH_CHANNEL, { list: result.data });
          return result.data;
        }
      },
      async getAllInboxCatInfo({ commit }) {
        const result = await this.$api.get('/api/ufo/home/listInboxTypeInfo', {});

        if (result.code === 200) {
          commit(Types.FETCH_NEWSACTIVE, { list: result.data || [] });
        }
      },

      /**
       *  ufo.product.searchWord
          word_type=2   搜索默认词
          client_type= iphone  android  h5
       */
      async fetchDefaultSearchWord({commit}) {
        const res = await this.$api.get('/api/ufo/list/searchWords', {word_type: 1});

        if (res.code === 200) {
          commit(Types.FETCH_DEFAULT_SEARCH_WORD, res.data);
        }
      }
    },
  };
}