import request from '../../utils/request'
import apis from '../../config/api'
export default {
  namespaced: true,
  stare:{
    customers:{}
  },
  mutations:{
    updateList (state, payload) {
      state.customers = payload
    },
    updateDetail (state, payload) {
      state.detail = payload
    }
  },
  actions:{
    setDetailNull ({ commit }) {
      commit('updateDetail', {})
    },
    getCustomers ({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request({
          ...apis.customer.list,
          params: payload,
        }).then((data) => {
          window.console.log(data)
          commit('updateList', data)
          resolve(data)
        }).catch(({ message }) => {
          if (typeof message === 'string') {
            reject(message)
          }
        })
      })
    },
    getRecommendCustomers ({ commit }, payload) { // 查询推荐客户列表
      return new Promise((resolve, reject) => {
        request({
          ...apis.recommendCustomer.list,
          params: payload,
        }).then((data) => {
          resolve(data)
        }).catch(({ message }) => {
            reject(message)
        })
      })
    },
    getRecommendCustomersGetById ({ commit }, payload) { // 根据Id查询列表
      return new Promise((resolve, reject) => {
        request({
          ...apis.recommendCustomer.getById,
          urlData: { id: payload.customerId},
        }).then((data) => {
          resolve(data)
        }).catch(({ message }) => {
          reject(message)
        })
      })
    },
    getRecommendCustomersUpdate ({ commit }, payload) { // 修改
      return new Promise((resolve, reject) => {
        request({
          ...apis.recommendCustomer.update,
          urlData: { id: payload.customerId},
          data: payload
        }).then((data) => {
          resolve(data)
        }).catch(({ message }) => {
          reject(message)
        })
      })
    },
    recommendCustomerList({ commit }, payload) { // 推荐客户列表
      return new Promise((resolve, reject) => {
        request({
          ...apis.recommendCustomer.recommendCustomerList,
          urlData: { id: payload.customerId},
          params: payload
        }).then((data) => {
          resolve(data)
        }).catch(({ message }) => {
          reject(message)
        })
      })
    },
    taPointsRecords({ commit }, payload) { // 积分列表
      return new Promise((resolve, reject) => {
        request({
          ...apis.recommendCustomer.taPointsRecords,
          urlData: { id: payload.customerId},
          params: payload
        }).then((data) => {
          resolve(data)
        }).catch(({ message }) => {
          reject(message)
        })
      })
    },
    getCustomerDetail({ commit }, payload) { // 查询客户详情
      return new Promise((resolve, reject) => {
        request({
          ...apis.recommendCustomer.getCustomerDetail,
          urlData: { id: payload.customerId}
        }).then((data) => {
          resolve(data)
        }).catch(({ message }) => {
          reject(message)
        })
      })
    },
    getRecommendDrift({ commit }, payload) { // 查询推荐客户列表
      return new Promise((resolve, reject) => {
        request({
          ...apis.recommendCustomer.drift,
          params: payload,
        }).then((data) => {
          resolve(data)
        }).catch(({ message }) => {
          reject(message)
        })
      })
    },
    
  }
}