import axios from 'axios'
import { Base64 } from 'js-base64'

// let base = 'https://szzf.songyang.gov.cn:8081';
let base = 'https://lsszzf.lishui.gov.cn:18082/common/login/getuserinfo.php';
let requestHead = {
  headers: {
    'Authorization': 'Basic ' + Base64.encode('98b8c111526e4b1eba5cde7669ab2228:y916a7f471944898ab68c8b256e0c1f2'),
    'content-type': 'application/x-www-form-urlencoded',
  }
};

function get(url) {
  return axios.get(base + url, requestHead)
    .then(res => {
      if (res.status !== 200) return null;
      return res.data;
    }).catch(err => {
      console.error(err);
      return err;
    });
};

function post(url, data) {
  return axios.post(base + url, data, requestHead)
    .then(res => {
      if (res.status !== 200) return null;
      return res;
    }).catch(err => {
      console.error(err); //输出日志
      return null;
    })
};

function del(url) {
  return axios.delete(base + url, requestHead)
    .then(res => {
      if (res.status !== 200) return null;
      return res.data.data;
    }).catch(err => {
      console.error(err);
      return null;
    });
}

function put(url, data) {
  return axios.put(base + url, data, requestHead)
    .then(res => {
      if (res.status !== 200) return null;
      return res.data;
    }).catch(err => {
      console.error(err);
      return null;
    })
}

function getMyCityName()
{
  return "青田县";
}

function getMyCity()
{
  return "青田县";
}

// 获取搜索内容
export const getSearchCon = (a, b,c=1,d=10) => {
  return get('/common/search/'+b+'/query?&searchKey=' + a + '&pageNum='+c+'&pageSize='+d);
};
//获取扫码登录后用户信息
export const getPortalUserinfo = (a) => {
  return get('/api/portal/userinfo?area=sy&code=' + a);
};
// //获取扫码登录后用户信息
// export const postUserInfo = (a) => {
//   return post('/api/portal/qrinfo?area=sy&code=' + a);
// };
//获取免登后用户信息和权限信息
export const getUserInfo = (a) => {
  return get('/api/portal/qrinfo?area=sy&code=' + a);
}
//获取扫码登录后用户权限
export const getPortal2 = (a) => {
  return get('/api/portal/qrinfo2?area=sy&account=' + a);
}
//获取任务项
export const getTask = () => {
  return get('/api/Data/list?level=1');
}
