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

// 请求数据
export default {
  namespaced: true,
  state: {
    remarkList: []
  },
  mutations: {
    setRemark (state, data) {
      state.remarkList = data.list || []
    }
  },
  actions: {
    getRemark (context, data) {
      return new Promise((resolve, reject) => {
        Ajax({
          ...api.remark.getRemark,
          urlData: { ...data },
          queryData: {
            page: 1,
            pagesize: 10000
          }
        }).then(res => {
          context.commit('setRemark', res)
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    },
    setRemark (context, data) {
      return new Promise((resolve, reject) => {
        Ajax({
          ...api.remark.setRemark,
          data: {
            SalesId: data.salesId,
            CustomerId: data.customerId,
            Remark: data.remark
          }
        }).then(res => {
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    }
  }
}
