import request from '@/router/axios';
import {getToken} from '@/util/auth'
// 企业列表
export const getList =
  (current, size, params) => {
    return request({
      url: '/api/jobslink-api/tenant/company/manage/list',
      method: 'get',
      params: {
        ...params,
        current,
        size,
      }
    })
  }
// 企业列表
export const getListNew =
  (current, size, params) => {
    return request({
      url: '/api/jobslink-api/tenant/company/manage/listNew',
      method: 'get',
      params: {
        ...params,
        current,
        size,
      }
    })
  }
//暂不处理
export const getNoProcessing =
  (id, desc, status) => {
    return request({
      url: '/api/jobslink-api/tenant/company/noProcessing',
      method: 'get',
      params: {
        id,
        desc,
        status,
      }
    })
  }
// 认证企业列表菜单
export const getMenuList =
  (current, size, params) => {
    return request({
      url: '/api/jobslink-api/tenant/company/menu/list',
      method: 'get',
      params: {
        ...params,
        current,
        size,
      }
    })
  }

// 获取企业详情
export const getDetail =
  (id) => {
    return request({
      url: '/api/jobslink-api/tenant/company/detail',
      method: 'get',
      params: {id}
    })
  }

export const detailCompany =
  (params) => {
    return request({
      url: '/api/jobslink-api/tenant/company/detailCompany',
      method: 'get',
      params: params
    })
  }
// 仅保存或提交审核
export const detailNew =
  (flag, company, saveFlag) => {
    return request({
      url: '/api/jobslink-api/tenant/company/detailNew',
      method: 'post',
      data: {flag, company, saveFlag}
    })
  }
//审核接口
export const review =
  (id, status, desc) => {
    return request({
      url: '/api/jobslink-api/tenant/company/review',
      method: 'get',
      params: {id, status, desc}
    })
  }
// 企业开户
export const add =
  (row) => {
    return request({
      url: '/api/jobslink-api/tenant/company/submit',
      method: 'post',
      data: row
    })
  }

// 编辑企业
export const update =
  (row) => {
    return request({
      url: '/api/jobslink-api/tenant/company/updateCompany',
      method: 'post',
      data: row
    })
  }

// 配置详情
export const configDetail =
  (companyId, tenantId) => {
    return request({
      url: '/api/jobslink-api/tenant/base/config/detail',
      method: 'get',
      params: {companyId, tenantId}
    })
  }

//下载全部
export const downloadList =
  (urls) => {
    return `/api/jobslink-api/tenant/company/downloadList?urls=${urls}&Jobslink-Auth=${getToken()}`
  }

// 获取一堆公司信息
function getCompanyInfo(companyId) {
  return request({
    url: '/api/jobslink-api/tenant/company/examineInfo',
    method: 'get',
    params: {companyId}
  })
}

// 获取一堆公司信息
function getCompanyInfoNew(companyId) {
  return request({
    url: '/api/jobslink-api/tenant/company/examineInfoNew',
    method: 'get',
    params: {companyId}
  })
}

// 审核通过
export const examine =
  (companyId) => {
    return request({
      url: '/api/jobslink-api/tenant/company/examine',
      method: 'post',
      params: {companyId}
    })
  }

//新的审核接口
export const newExamineApi = (
  id, tenantId, tradeId, masterName, masterIdentity,
  cityId, companyAddress, authUrlId,
  identityUrl4Id, identityUrl5Id, signSrcUrl, letterOfAttorneyUrl,
  motoleyUrl) => {
  return request({
    url: '/api/jobslink-api/tenant/company/examineNew',
    method: 'post',
    data: {
      id, tenantId, tradeId, masterName, masterIdentity,
      cityId, companyAddress, authUrlId,
      identityUrl4Id, identityUrl5Id, signSrcUrl, letterOfAttorneyUrl,
      motoleyUrl
    }
  })
}
// 审核驳回
export const reject =
  (companyId, remarks) => {
    return request({
      url: '/api/jobslink-api/tenant/company/reject',
      method: 'post',
      params: {companyId, remarks}
    })
  }

function state(companyId, flag) {
  return request({
    url: '/api/jobslink-api/tenant/company/status',
    method: 'post',
    params: {companyId, flag}
  })
}

// 恢复合作
export const start = (companyId) => state(companyId, 'S')
// 终止合作
export const stop = (companyId) => state(companyId, 'O')

// 获取审核信息
export const examineInfo =
  (companyId) => {
    return new Promise(function (resolve, reject) {
      getCompanyInfo(companyId)
        .then(function (resp) {
          const data = resp.data.data
          const fee = data.fee[0] || {}
          const result = {
            data: {
              data: {
                ...data.user,
                ...data.company,
                serveCost: fee.serveCost,
                serveUnit: fee.serveUnit,
                status: data.status
              }
            }
          };
          resolve(result)
        })
        .catch(reject)
    })
  }

// 获取管理员
export const getAdmin =
  (companyId) => {
    return new Promise(function (resolve, reject) {
      getCompanyInfo(companyId)
        .then(function (resp) {
          const result = {data: {data: resp.data.data.user}};
          resolve(result)
        })
        .catch(reject)
    })
  }

// 获取配置
export const getConfig =
  (companyId) => {
    return new Promise(function (resolve, reject) {
      getCompanyInfo(companyId)
        .then(function (resp) {
          const data = resp.data.data
          const result = {
            data: {data: {config: data.config, fee: data.fee}}
          };
          resolve(result)
        })
        .catch(reject)
    })
  }
// 获取配置
export const getConfigNew =
  (companyId) => {
    return new Promise(function (resolve, reject) {
      getCompanyInfoNew(companyId)
        .then(function (resp) {
          const data = resp.data.data
          const result = {
            data: {data: {config: data.config, fee: data.fee}}
          };
          resolve(result)
        })
        .catch(reject)
    })
  }
// 设置配置
export const setConfig =
  (data) => {
    return request({
      url: '/api/jobslink-api/tenant/base/config/on',
      method: 'post',
      data
    })
  }

// 添加服务费
export const addService =
  (data) => {
    return request({
      url: '/api/jobslink-api/tenant/config/service/fee/save',
      method: 'post',
      data
    })
  }

// 启用服务费
export const serviceEnable = (id, companyId) => {
  return request({
    url: '/api/jobslink-api/tenant/config/service/fee/isEnabled',
    method: 'post',
    data: {id, companyId}
  })
}

//客服开通电子合同服务之前，先查询企业是否开通了【电子签章】
export const whetherSignService = (companyId) => {
  return request(
    {
      url: '/api/jobslink-api/doc/company/cert/sealstatus',
      method: 'get',
      params: {
        companyId
      }
    }
  )
}
