import { getGroupInfo } from "@/api/system/dept";
import store from '@/store'
/**
 * 油品，根据油品名查类型
 */
export async function queryPageStatus(allowJiBieArr=[], type) { // 1 积分 2 电子卡 3 优惠券
  //返回值  0 页面初始状态 1 此页面不对此用户不开放 2 权限不在此页面 3 发生错误 4 正常显示
  const currentJiBie = store.state.user.jiBie
  if(!allowJiBieArr.includes(currentJiBie)){
    return 1;
  }
  if(!type){
    return 4
  }
  const getGroupInfoRes = await getGroupInfo()
  if(getGroupInfoRes.code != 200){
    return 3
  }
  if(getGroupInfoRes.data == null){
    return 1
  }
  const integralRuleFlag = getGroupInfoRes.data.integralRuleFlag; // 0 不共享 1 共享
  const cardRuleFlag = getGroupInfoRes.data.cardRuleFlag;
  const couponFlag = getGroupInfoRes.data.couponFlag;
  if(type == 1){
    if(integralRuleFlag == 0){
      if(currentJiBie == 1){
        return 2
      }else if(currentJiBie == 2){
        return 4
      }else if(currentJiBie == 0){
        return 1
      }
    }else if(integralRuleFlag == 1){
      if(currentJiBie == 1){
        return 4
      }else if(currentJiBie == 2){
        return 2
      }else if(currentJiBie == 0){
        return 1
      }
    }

  } else if(type == 2){
    if(cardRuleFlag == 0){
      if(currentJiBie == 1){
        return 2
      }else if(currentJiBie == 2){
        return 4
      }else if(currentJiBie == 0){
        return 1
      }
    }else if(cardRuleFlag == 1){
      if(currentJiBie == 1){
        return 4
      }else if(currentJiBie == 2){
        return 2
      }else if(currentJiBie == 0){
        return 1
      }
    }
  }else if(type == 3){
    if(couponFlag == 0){
      if(currentJiBie == 1){
        return 2
      }else if(currentJiBie == 2){
        return 4
      }else if(currentJiBie == 0){
        return 1
      }
    }else if(couponFlag == 1){
      if(currentJiBie == 1){
        return 4
      }else if(currentJiBie == 2){
        return 2
      }else if(currentJiBie == 0){
        return 1
      }
    }
  }
  return 3
}