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

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

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