index.js 2.43 KB
import urlAlias from '../url';
 import request from '../request';

 const {
   category,
   shopList,
   search,
 } = urlAlias;

let initData = {"name":"志平防蓝光-防辐射电脑网课眼镜","id":"9","imgurl":"",
   "price":0,"trade_num":"102","rsSon":{"pic":"9_FDB33D.jpg","model_pic":null,"in_price":"6000","sku_value":"80_83",
   "discount":"45","kc":"0","sku_name":"1.56非球面防蓝光_黑透+蓝纹","Max_Price":158,"Min_Price":99}}
var initArr = [1,2,3,4,5,6,7,8]
let list = []
initArr.forEach(function (value) {
	list.push(initData)
});	

//初始化数据是为了显示默认骨架
 const state = {
   categoryList: [],
   list: list
 };
 
 const mutations = {
   LIST: (state, list) => {
     state.list = list;
   },
   CATEGORY: (state, categoryList) => {
     state.categoryList = categoryList;
   }
 };

 const actions = {
   category({
     commit
   }, param) {
	   return new Promise((resolve) => request({
       url: category,
       success: (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);
		 resolve(data)
		 console.log('3333')
       },
       fail: (res) => {
         console.log("fail status === > ", res);
       }
     }))
     
   },
   list({
     commit
   }, param) {
	 return new Promise((resolve) =>  request({
       url: shopList,
       success: (res) => {
         commit('LIST', res.data.data)
		  resolve(res.data)
		  console.log('3333')
       },
       fail: (res) => {
         console.log("fail status === > ", res);
       },
       complete: (res) => {
         state.isLoading = false;
       },
     }))
   },
   search({
     commit
   }, {
     params,
     keyword
   }) {
	  const uid = uni.getStorageSync('uid');
	 return new Promise((resolve) => request({
       url: search,
       data: {
         params: JSON.stringify(params),
         uid,
         way: 1,
         keyword,
       },
       success: (res) => {
         commit('LIST', res.data.data);
		 resolve(res.data)
       },
       fail: (res) => {
         console.log("fail status === > ", res);
       }
     }))
     
   },
 };

 export default {
   namespaced: true,
   state,
   mutations,
   actions,
 };