import { eProductType, eProductStatus } from "@/types/loanProduct"
import { PAGE_SIZE } from '@/const/config/page'
import LoanProductService from "@/service/LoanProductService/index"
import { Module } from 'vuex'
import { iListItem, iProductModuleState } from './type'

export default <Module<iProductModuleState, {}>>{
  namespaced: true,
  state: {
    list: [] as iListItem[],
    end_time:undefined,
    limit: PAGE_SIZE,
    loan_type: eProductType.all,
    offset: 0,
    product_status: eProductStatus.all,
    start_time: undefined,
    loading:false,
    total:0,
    page: 1,
    product_name:''
  },
  mutations: {
    save(state, payload) {
      Object.assign(state, payload)
    },
  },
  actions: {
    async query({ state, commit }, payload) {
      state.loading = true
      const ret = await LoanProductService.getInstance().queryDirectLoanReq({
        product_name:state.product_name,
        end_time: state.end_time as number,
        limit: state.limit,
        loan_type: state.loan_type,
        offset: state.offset as number,
        product_status: state.product_status,
        start_time: state.start_time as number,
      })
      if (ret.code === 200) {
        commit('save', {
          list:ret.data.items,
          total: ret.data.total,
        })
        state.loading = false
      }
    },
  },
}
