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

export default {
  namespaced: true,
  state: {
    ordersList: [],
    recordOrders: [],
  },
  mutations: {
    updateList (state, payload) {
      state.ordersList = payload || []
    },
    updateRecordList (state, payload) {
      state.recordOrders = payload || []
    },
  },
  actions: {
    GetOrdersList ({ commit }, payload) {
      ajax(api.goodsOrder.getOnlineOrder.url, {
        method: api.goodsOrder.getOnlineOrder.method,
        queryData: {
          ...payload,
        }
      }).then(res => {
        commit('updateList', res)
      })
    },
    GetOrdersByRecord ({ commit }, { id, callback }) {
      ajax(api.goodsOrder.getOrdersByRecord.url, {
        method: api.goodsOrder.getOrdersByRecord.method,
        urlData: {
          id
        }
      }).then(res => {
        commit('updateRecordList', res)
        if (callback) {
          callback()
        }
      })
    }
  }
}
