import oldRequest from "../../../core/utils/request";
import { idCardNoFn, mobileFn } from './../utils/rsa';
export const request = async ({
  url,
  data,
  headers,
  showToast = true
}) => {
  const [err, result] = await oldRequest({
    url,
    data,
    headers
  });

  if (err && Number(err.code) !== 200 && showToast) {
    my.showToast({
      type: 'fail',
      content: err.msg || '操作失败'
    });
  }

  return [err, result];
}; // 获取我的订单列表

export function scenicOrderList(data) {
  return request({
    url: 'api/v1/proxy/scenic/order/list',
    data
  });
} // 获取我的订单详情

export function scenicOrderDetail(data) {
  return request({
    url: 'api/v1/proxy/scenic/order/detail',
    data
  });
} // 取消订单

export function scenicOrderCancel(data) {
  return request({
    url: 'api/v1/proxy/scenic/order/cancel',
    data
  });
} // 退款申请

export function scenicOrderRefundApply(data) {
  return request({
    url: 'api/v1/proxy/scenic/order/refund/apply',
    data
  });
} // 申请退款

export function scenicOrderRefundDo(data) {
  return request({
    url: 'api/v1/proxy/scenic/order/refund/do',
    data
  });
} // 申请退款

export function scenicOrderGetPayment(data) {
  return request({
    url: 'api/v1/proxy/scenic/order/getPayment',
    data
  });
}
/*
* 获取景区详情
* */

export function scenicInfo(data) {
  return request({
    url: 'api/v1/proxy/scenic/info',
    data
  });
}
/*
* 获取景区列表
* */

export function scenicSpotList(data) {
  return request({
    url: 'api/v1/proxy/scenic/list',
    data
  });
}
/*
* 获取景区购买需知
* */

export function purchaseInfo(data) {
  return request({
    url: 'api/v1/proxy/scenic/purchase/info',
    data
  });
}
/*
* 门票预定查询
* @params { productId:String , date: String}
* */

export function scenicTicketReserve(params) {
  return request({
    url: 'api/v1/proxy/scenic/ticket/reserve',
    data: params
  });
}
/*
* 预定须知查询
* @params {id: String}
* */

export function scenicPurchaseInfo(params) {
  return request({
    url: 'api/v1/proxy/scenic/purchase/info',
    data: params
  });
}
/*
* 获取联系人列表
* */

export function scenicTouristList() {
  return request({
    url: 'api/v1/proxy/scenic/tourists/list'
  });
}
/*
* 获取联系人列表
* */

export function touristsList(data) {
  return request({
    url: 'api/v1/proxy/scenic/tourists/list',
    data
  });
}
/*
* 联系人操作
* */

export async function touristsOperate(params) {
  const item = {
    actionType: params.actionType,
    certType: params.certType,
    name: params.name,
    id: params.id || ''
  };
  let idCardNo = '';
  let mobile = '';
  let dataParams = {};

  if (params.idCardNo) {
    idCardNo = await idCardNoFn(params);
  }

  if (params.mobile) {
    mobile = await mobileFn(params);
  }

  if (idCardNo && mobile) {
    dataParams = { ...item,
      idCardNo,
      mobile
    };
  }

  if (idCardNo && !mobile) {
    dataParams = { ...item,
      idCardNo
    };
  }

  if (!idCardNo && mobile) {
    dataParams = { ...item,
      mobile
    };
  }

  if (!idCardNo && !mobile) {
    dataParams = { ...item
    };
  }

  return request({
    url: 'api/v1/proxy/scenic/tourists/operate',
    data: dataParams
  });
}
/*
* 请求下单
* */

export function scenicOrderPay(params) {
  return request({
    url: 'api/v1/proxy/scenic/order/pay',
    data: params,
    showToast: false
  });
}
/*
* 景点简介
* */

export function scenicIntroduction(data) {
  return request({
    url: 'api/v1/proxy/scenic/introduction',
    data
  });
}