details.js 1.13 KB
import urlAlias from '../url'
import request from '../request'

const {
  read,
} = urlAlias

const state = {
  // 轮播图
  carousel: [
    '/static/img/detail/d9.png',
  ],
  // 商品基本信息
  goodsInfo: {
    name: '暂无名称',
    price: '暂无价格',
    discountPrice: undefined,
    tradeNumber: undefined,
  },
}

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

const actions = {
  details({ commit }, param) {
    return new Promise((resolve, reject) => request({
      url: read,
      data: param,
      success: ({ data: { data } }) => {
        commit('INIT', {
          carousel: data.pics,
          goodsInfo: {
            name: data.p_name,
            price: data.priceArea.Min_Price,
            discountPrice: data.priceArea.Min_Price - Number(data.priceArea.discount),
            tradeNumber: data.trade_num,
          },
        })
        resolve(data)
      },
      fail: (res) => {
        console.log('fail status ===>', res)
      },
    }))
  },
}

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