import { getQualityData, getQuesData } from "@/api/dataManagement/qualityCheck"
  const getDefaultState = () => {
    return {
      pageType: 1,// 页面类型 1.未入库主页面 2.质检列表 3.质检-检查 4.质检-问题记录
      entity: {}, // 实体
      batchRow: {}, // 质检表格-检查,点击的行
      // 质检表格相关
      tableLoading: false,
      tableData: [],
      pagination: {
        pageSize: 10,
        pageNum: 1,
        total: 0,
      },
      // 问题记录表格
      quesLoading: false,
      quesData: [], 
    }
  }
  const state = getDefaultState()
  const mutations = {
    SET_PAGE_TYPE(state, data) {
      state.pageType = data;
    },
    SET_ENTITY(state, data) {
      state.entity = data;
    },
    SET_BATCH_ROW(state, data) {
      state.batchRow = data;
    },
    GET_DATA(state, data) {
      state.tableData = data.list
      state.pagination.total = data.total
      state.tableLoading = false
    },
    GET_QUES_DATA(state, data) {
      state.quesData = data.resultList
      state.quesLoading = false
    },
  }
  const actions = {
    async getData({
      commit,
      dispatch
    }, data) {
      await getQualityData(data).then(res => {
        try {
          commit('GET_DATA', res.body)
        } catch (err) {
          throw new Error(err)
        }
      })
    },
    async getQuesData({
      commit,
      dispatch
    }, data) {
      await getQuesData(data).then(res => {
        try {
          commit('GET_QUES_DATA', res.body)
        } catch (err) {
          throw new Error(err)
        }
      })
    },
  }
  export default {
    namespaced: true,
    state,
    mutations,
    actions
  }
  