userRecommand.js 2.02 KB
import urlAlias from '../url';
 import request from '../request';

 const {
  recommandList
 } = urlAlias;

const state = {
  recommandList: [],
};

const data = {
    "code": 1,
    "msg": "请求成功",
    "data": {
			// list 表示商品数据列表
            "list": [
				{
					model_pic: null,
					p_name: "1.61防蓝光镜片 非球面_枪色款镜架商务男士防蓝光眼镜",
					p_root_index: "1", //对应goodType
					pic: "http://localhost/sys-glass/image/picture.png",
					pid: "96",
					real_price: "17800",
					sk_id: "1448",
					sku_name: "1.61防蓝光镜片 非球面_枪色款镜架",
					trade_num: "0",
                },
				{
                    "sk_id": "39",
                    "pic": "/static/img/goods/p1.jpg",
                    "p_name": "1.56防蓝光镜片非球面_黑银色镜架防蓝光眼镜超轻不压鼻",
                    "old_price": "18000",
                    "real_price": "9900",
                    "trade_num": 123,	// 对应购买人数
                    "p_root_index": 2,		// 对应跳转的详情页
					"pid":4, // 产品id
                },
            ],
			pagesnum:1, // 懒加载要用到的页数
			pagessize:10,// 每次请求返回的list长度
        }
    
}

const mutations = {
  INIT: (state, list) => {
    state.recommandList = list;
  },
};

let goodsList=[];

const actions = {
  getRecommandList({ commit }, param) {
    request({
      url: recommandList,
      success: (res) => {
		  console.log('userRecommand-parm',param)
		  console.log(res.data.data)
		  // const Res={...res.data.data.list,...data.data.list}
		  goodsList=[...goodsList,...res.data.data]
		  // console.log(res.data)
        commit('INIT', goodsList)
      },
      fail: (res) => {
		  uni.showToast({
			  title:"数据加载完了",
			  icon:"none"
		  })
        console.log("fail status === > ", res);
      },
      complete: (res) => {
        console.log("complete status === > ", res);
      },
    })
  },
};

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