import urlAlias from '../url'; import request from '../request'; const { category, shopList, search, } = urlAlias; const state = { categoryList: [], list: [], }; const mutations = { LIST: (state, list) => { state.list = list; }, CATEGORY: (state, categoryList) => { state.categoryList = categoryList; }, }; 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); }, }) } }; export default { namespaced: true, state, mutations, actions, };