channel.js 2.17 KB
import Vue from 'vue';
import * as Types from './types';

export default function() {
  return {
    namespaced: true,
    state: {
      // channelData: [],
      channelList: {
        list: [], // 资源列表
        productlist: [], // 资源列表
        page: 0, // 当前页
        page_size: 20, // 每页数量
        page_total: 0, // 总共多少页
        total: 0, // 总共多少条
        scrollnavList: [], // 导航菜单
        // scrollnavidList: [], // 导航菜单
      },
    },
    mutations: {
      [Types.FETCH_CHANNEL](state, { list }) {
        state.channelList.list = list;
        state.channelList.list.map(res => {
          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.scrollnavidList.push(res.data[i].series_id);
            }
          }
        });
      },
      [Types.FETCH_PRODUCT](state, { productlist }) {
        // state.channelList.productlist = productlist;
        Vue.set(state.channelList, 'productlist', state.channelList.productlist.concat(productlist.product_list));
        Vue.set(state.channelList, 'page', productlist.page);
      },
    },
    actions: {
      async fetchProductList({ commit, state }, obj) {
        console.log(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', {
          order: obj && obj.isReset ? 'sale_desc' : 'st_desc',
          type: 6,
          page,
          pageSize: size,
        });

        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: 'c07b807110b342a09bd65d13aeb118f6',
          // uid: '64668089',
          uid: '500031170',
        });
        if (result.code === 200) {
          commit(Types.FETCH_CHANNEL, { list: result.data });
        }
      }
    },
  };
}