import { defineStore } from 'pinia';
import type { queryParams } from './types';
import { getQueryList } from '@/api/common';
import {  ElMessage } from 'element-plus'

// interface SelectObj {
//   RECEIVEACTNO: string
// }

interface QueryListState {
  list: any[],
  // dataArr: SelectObj[],
  dataArr: any[],
  dataArr2: any[],
  detailList: any[],
  total?: number | string
}

const queryListStore = defineStore({
  id: 'QueryList',
  state: (): QueryListState => ({
    list: [],//列表
    dataArr: [],//下拉框查询
    dataArr2: [],//下拉框查询
    detailList: [],//详情
    total: 0
  }),
  actions: {
    async getQueryList(queryParams: queryParams) {
      //@ts-ignore  
      const {code, data, total, message} = await getQueryList(queryParams)
       //@ts-ignore  
      if(code == 0) {
        switch(queryParams.listCode) {
          case 'select': //下拉框查询
            this.dataArr = data
            break;
          case 'list':  //列表
            this.list = data
            this.total = total || 0
            break;
          case 'detail':  //详情
            this.detailList = data
            break;
          default:
            this.list = data
            this.total = total || 0
        }
      }else {
        ElMessage.error(message);
      }
    },
    async getSlectyList(queryParams: queryParams) {
      //@ts-ignore  
      const {code, data, message} = await getQueryList(queryParams)
       //@ts-ignore  
      if(code == 0) {
        this.dataArr2 = data
      }else {
        ElMessage.error(message);
      }
    }
  },
});

export default queryListStore;
