import { useMessage } from '/@/hooks/web/useMessage';
import { useUserStore } from '/@/store/modules/user';
import { check } from '/@/api/common/api'
import { decryptData } from '/@/api/common/api';
import { getZbmgxx } from '/@/api/dkgl.api';
import { Modal } from 'ant-design-vue';

const { createMessage } = useMessage();
// 是否锁定的提示
export const tip = (params) => {
    if (params?.dksdzt&&params?.dksdzt == 1) {
        createMessage.info('地块已经被锁定不能此执行操作');
        return true
    }else return false
}
// 点击抽查的时候已经锁定的不能再抽查
export const chTip = (params) => {
  let flg = true;
  for (let i = 0; i < params.length; i++) {
    if (tip(params[i])) {
      flg = false;
      break;
    }
  }
  return flg
}
// 确认锁定的提示
export const spotCheck=(params,handleSuccess)=>{
 Modal.confirm({
        title: '确认抽查',
        content: '请确认选中的地块是否开始进入抽查阶段！',
        centered: true,
        okText: '确认',
        cancelText: '取消',
        onOk: async () => {
          // 走接口
          await check(params);
          handleSuccess()
        },
      });
}

// 不是选择一条数据的提示
export const oneTip = (params) => {
    if (params.length > 1) {
        createMessage.info('每次只能选择一条数据');
        return true
    } else if (params.length == 0) {
        createMessage.info('请选择需要处理的内容');
        return true
    }
    else return false  
}    
// 土地使用权人需要判断市级是否填报
const userStore= useUserStore();
export const checkZbmgxx = async (params)=>{
    if (userStore?.userInfo?.userIdentity == '4') {
        const res = await getZbmgxx(params);
        if (!res) {
          createMessage.info('市级生态环境部门没有填写周边敏感信息排查，不能填报');
          return true
    }
    return false
      }
}

// 校验是不是纯数字或者电话号码
export function isNumeric(input) {
    let flg = true;
    // 纯数字校验
    const rule = /^[0-9]+$/.test(input);
    if (rule) {
      flg = true;
    } else {
      // 电话号码校验
      const regex = /0\d{2,3}-\d{7,8}/.test(input);
      if (regex) {
        flg = true;
      } else flg = false;
    }
    return flg;
}
//  给电话 身份证 银行卡 手机号 加*
export async function decrypts(v,isRead=true) {
    if (!v) return;
    let res;
    if (isNumeric(v)) {
      res = v;
    } else if (v=='/') {
      res = v;
    }
    else {
      res = await decryptData({ str: v });
    }

    let str;
    if (isRead) {
        if (res.length == 11) {
            str = res.replace(res.substring(3, 7), '****');
          } else if (res.length > 11 && res.length < 18) {
            if (/0\d{2,3}-\d{7,8}/.test(res)) {
              str = res.replace(/\d(?=\d{3,}$)/g, '*');
            } else str = res.replace(/\d{4}(\d{10}|\d{8})(\d{4})/, '****$1****');
          } else if (res.length == 18) {
            str = res.replace(/(\d{6})\d+(\d{4})/, '$1******$2');
          } else str = res.replace(/^(.{4})(?:\d+)(.{4})$/, '$1 **** **** $2');
        console.log(str, 'str');
    }else str=res
    return str;
  }

