import webapi from '../webapi'
import { commit } from '@ttk/app-loader'
import * as validator from '@/utils/validator'

// 初始化查询表单
export function initGoodsSearchForm(reduce, gf) {
  return async (dispatch, getState) => {
    // 更新表单数据
    reduce('goodsSearchForm', { type: 'init' })
  }
}
// 更新查询表单
export function updateGoodsSearchForm(reduce, gf, fields) {
  return async (dispatch, getState) => {
    if (!fields)
      fields = gf(['goodsSearchForm'])
    // 更新表单数据
    reduce('goodsSearchForm', { type: 'update', data: fields })
  }
}

// 客户列表
export function goodsTableData(reduce, gf, fields) {
  return async (dispatch, getState) => {
    let data = []
    let pager = {}
    let param = gf(['goodsSearchForm'])
    if (fields)
      param = { ...param, ...fields }
    let res = await webapi.goodsTableData(param)
    if (res) {
      data = res.data
      pager = res.pager
      reduce('goodsTableData', { type: 'update', data })
      reduce('goodsPagination', { type: 'update', data: pager })
    }
  }
}