Blame view

src/store/modules/index.js 1.92 KB
c300654f9   范牧   首页部分功能
1
2
3
4
5
6
7
8
9
10
11
   import urlAlias from '../url';
   import request from '../request';
  
   const {
    category,
    shopList,
    search,
   } = urlAlias;
  
  const state = {
    categoryList: [],
93e6a2650   喻鹏   首页懒加载
12
    list: []
c300654f9   范牧   首页部分功能
13
14
15
16
17
18
19
20
  };
  
  const mutations = {
    LIST: (state, list) => {
      state.list = list;
    },
    CATEGORY: (state, categoryList) => {
      state.categoryList = categoryList;
93e6a2650   喻鹏   首页懒加载
21
    }
c300654f9   范牧   首页部分功能
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  };
  
  const actions = {
    category({ commit }, param) {
      request({
        url: category,
        success: (res) => {
          console.log('category', res);
          let data = res.data.data;
          for(let i = 0; i<=data.length; i++) {
            if(data[i] && data[i].type !== 'filter'){
              data[i].type = 'hierarchy';
            } 
          }
          data.unshift({
            type: "hierarchy",
            name: "全部",
            value: "all",
            isNoPull: true,
          });
          commit('CATEGORY', data);
        },
        fail: (res) => {
          console.log("fail status === > ", res);
        },
        complete: (res) => {
          console.log("complete status === > ", res);
        },
      })
    },
    list({ commit }, param) {
      request({
        url: shopList,
        success: (res) => {
          commit('LIST', res.data.data)
        },
        fail: (res) => {
          console.log("fail status === > ", res);
        },
        complete: (res) => {
          console.log("complete status === > ", res);
        },
      })
    },
    search({ commit }, { params, keyword }) {
      const uid = uni.getStorageSync('uid');
      console.log("params",params, keyword);
      request({
        url: search,
        data: {
          params: JSON.stringify(params),
          uid,
          way: 1,
          keyword,
        },
        success: (res) => {
          commit('LIST', res.data.data);
        },
        fail: (res) => {
          console.log("fail status === > ", res);
        },
        complete: (res) => {
          console.log("complete status === > ", res);
        },
      })
93e6a2650   喻鹏   首页懒加载
87
    },
c300654f9   范牧   首页部分功能
88
89
90
91
92
93
94
95
  };
  
  export default {
    namespaced: true,
    state,
    mutations,
    actions,
  };