read.js 1.35 KB
import urlAlias from '../url'
import request from '../request'

const {
  read,
} = urlAlias

const state = {
  goodInfo: {},
}

const mutations = {
  INIT: (state, goodInfo) => {
    state.goodInfo = goodInfo
  },
}

const actions = {
  fetch({ commit }, param) {
    // 由于购物车和用户推荐的价格要根据sk_id来获取
    const arg = Object.assign({}, param)
    delete param.sk_id
    return new Promise((resolve, reject) => request({
      url: read,
      data: param,
      success: (res) => {
        // console.log('readParm====>', arg)
        // console.log('read====>', res.data.data)
        // 用一个新的对象来接收sk_id找的值
        const Res = Object.assign({}, res.data.data)
        if (arg.sk_id !== undefined) {
          for (let i = 0; i < res.data.data.sku.length; i++) {
            if (res.data.data.sku[i].sk_id === arg.sk_id) {
              Res.p_sale_price = res.data.data.sku[i].real_price
              console.log('.......购物车和用户推荐的价格.........')
            }
          }
        }
        commit('INIT', Res)
        resolve(res.data)
      },
      fail: (res) => {
        console.log('fail status === > ', res)
      },
      complete: (res) => {
        console.log('complete status === > ', res)
      },
    }))
  },
}

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