import Ajax from '../../util/ajax'
import api from '../../util/api'

export default {
  namespaced: true,
  state: {
    orders: {},
  },
  mutations: {
    setGoodsOrders (state, {res, page}) { // 获取案场下单数量信息
      if (page <= 1) {
        state.orders = res
      } else {
        state.orders = {...res, list: [...state.orders.list, ...res.list]}
      }
    },
  },
  actions: {
    getCustomerGoodsOrder ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        Ajax(api.goods.getCustOrders.url, {
          method: api.goods.getCustOrders.method,
          queryData: {
            ...payload
          },
        }).then(res => {
          commit("setGoodsOrders", {res, page: payload.page})
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    },
  }
}