import { apiurl } from './apiurl.js';

// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
const install = (Vue, vm) => {
  // 反馈提交
  let feedbackAdd = (params = {}) => vm.$u.post(apiurl.feedbackAddUrl, params);

  let getuseinfo = (params = {}) => vm.$u.get(apiurl.getuseinfourl + '/' + params);

  let createOrder = (params = {}) => vm.$u.post(apiurl.createOrderurl, params);

  let bindphone = (params = {}) => vm.$u.post(apiurl.bindphoneurl, params);

  let getPhoneLoginCode = (params = {}) => vm.$u.post(apiurl.phoneLoginCodeUrl, params);

  let phoneLoginAuth = (params = {}) =>
    vm.$u.post(
      apiurl.phoneLoginAuthUrl,
      {
        code: params.code
      },
      {
        Authorization: `Bearer ${params.accessToken}`,
        user_id: params.userId
      }
    );

  let getWXInfo = (params = {}) => vm.$u.get(apiurl.getWXInfoUrl + params);

  let wxPay = (params = {}) => vm.$u.post(apiurl.wxPayUrl, params);

  let getIndexData = (params = {}) => vm.$u.post(apiurl.getIndexDataUrl, params);

  let roadInfoById = (params = {}) => vm.$u.get(apiurl.roadInfoById + params.id);

  let getMycars = (params = {}) => vm.$u.get(apiurl.mycarsUrl, params);
  let addCar = (params = {}) => vm.$u.post(apiurl.mycarsUrl, params);
  let delCar = (params = {}) => vm.$u.delete(apiurl.mycarsUrl + '/' + params);
  let setDefaultCar = (params = {}) => vm.$u.put(apiurl.setDefaultCarUrl + params.id);

  let getOrderList = (params = {}) => vm.$u.get(apiurl.getOrderListUrl, params);
  //室内停车订单列表api
  let getRoomParkingApi = (params = {}) => vm.$u.get(apiurl.getRoomparkingList, params);
  let getOrderinfo = (params = {}) => vm.$u.get(apiurl.getOrderinfoUrl + params.id);
  let getRoomOrderDetail = (params = {}) =>
    vm.$u.get(apiurl.getRoomOrderDetailUrl + params.id, {
      showLoading: false
    });
  let getOrderDetail = (params = {}) =>
    vm.$u.get(apiurl.getOrderDetailUrl + params.id, {
      showLoading: false
    });

  let getMessageList = (params = {}) => vm.$u.get(apiurl.getMessageListUrl, params);
  let messageRead = (params = {}) => vm.$u.put(apiurl.messageReadUrl + params.newId);

  let nearRoadsl = (params = {}) => vm.$u.post(apiurl.nearRoadslUrl, params);
  let roadChargeRule = (params = {}) => vm.$u.get(apiurl.roadsChargeRuleUrl + params.roadNo);

  let nearParkingLot = (params = {}) => vm.$u.get(apiurl.nearParkingLotUrl, params);
  let parkingLotChargeRule = (params = {}) => vm.$u.get(apiurl.parkingLotChargeRuleUrl + params.parkNo, params);

  let monthInfo = (params = {}) => vm.$u.get(apiurl.monthInfoUrl, params);
  let createMonth = (params = {}) => vm.$u.post(apiurl.createMonthUrl, params);
  let monthPay = (params = {}) => vm.$u.post(apiurl.monthPayUrl, params);
  let getMonthPay = (params = {}) => vm.$u.get(apiurl.getMonthPayUrl + params.id);
  let getMonthList = (params = {}) => vm.$u.get(apiurl.getMonthListUrl, params);
  // 停车场包月列表
  let getParkMonthList = (params = {}) => vm.$u.get(apiurl.getParkMonthListUrl, params);
  let cancelMonth = (params = {}) => vm.$u.put(apiurl.cancelMonthUrl + params.monthId);

  let feePay = (params = {}) => vm.$u.put(apiurl.feePayUrl + params.vehicleId);
  let payGzbank = (params = {}) => vm.$u.post(apiurl.payGzbankUrl, params);

  let bindVehicleNo = (params = {}) => vm.$u.post(apiurl.bindVehicleNoApi, params);

  //贵州银行支付
  let gzbank = (params = {}) => vm.$u.post(apiurl.gzbankurl, params);
  // 订单查询
  let getOrderInfo = (params = {}) => vm.$u.get(apiurl.getOrderInfoApi + params.orderId);
  // 设备状态查询
  let getEquomentInfo = (params = {}) => vm.$u.get(apiurl.getEqupmentStatusApi + params.orderNo);
  // 订单退款操作
  let updateOrderRefund = (params = {}) => vm.$u.post(apiurl.updateOrderRefundApi, params);
  // 获取订单退款详情
  let getOrderRefundDetails = (params = {}) => vm.$u.get(apiurl.getOrderRefundDetailsApi + params.orderId);
  // 普通微信支付
  let ordinaryWxPay = (params = {}) => vm.$u.post(apiurl.ordinaryWxPayApi, params);
  // 包月微信支付
  let monthlyWxPay = (params = {}) => vm.$u.post(apiurl.monthlyWxPayApi, params);
  // 获取自定义富文本内容: 0-包月须知 1-用户服务条款 2-隐私权政策信息 3-收费标准 4-退款温馨提示
  let getSysterms = (params = {}) => vm.$u.get(apiurl.getSystermsApi + params.termsType);
  // 通过微信登录获取openid
  let codeV2Api = {
    // 发送验证码V2
    sendSmsCodeV2api: (params = {}) => vm.$u.post(apiurl.codeV2Url.sendSmsCodeV2Url, params),
    // 验证短信验证码V2
    verifyCodeV2Api: (params = {}) => vm.$u.post(apiurl.codeV2Url.verifyCodeV2Url, params),
    // 登出
    logoutApi: (params = {}) => vm.$u.post(apiurl.codeV2Url.logoutUrl, params)
  };
  let userLoginApi = {
    openidLoginApi: (params = {}) => vm.$u.post(apiurl.userLoginUrl.openidLoginUrl, params),
    sendSmsCodeApi: (params = {}) => vm.$u.post(apiurl.userLoginUrl.sendSmsCodeUrl, params),
    mobileLoginApi: (params = {}) => vm.$u.post(apiurl.userLoginUrl.mobileLoginUrl, params)
  };
  let geomaLockDetailsApi = (params = {}) => vm.$u.post(apiurl.geomaLockDetailsUrl, params);
  let getDetailEntranceApi = (params = {}) => vm.$u.post(apiurl.getDetailEntrance, params);
  let getDetailAdvanceApi = (params = {}) => vm.$u.post(apiurl.getDetailAdvance, params);
  let getDetailExportApi = (params = {}) => vm.$u.post(apiurl.getDetailExport, params);
  let entranceByNoVehicleApi = (params = {}) => vm.$u.post(apiurl.entranceByNoVehicle, params);
  let getAdvanceInfoApi = (params = {}) => vm.$u.post(apiurl.getAdvanceInfo, params);
  let getExportInfoApi = (params = {}) => vm.$u.post(apiurl.getExportInfo, params);
  let getOrderStateExportApi = (params = {}) => vm.$u.post(apiurl.getOrderStateExportUrl, params);
  let quickPayExportApi = (params = {}) => vm.$u.post(apiurl.quickPayExportUrl, params);
  let polyPayExportApi = (params = {}) => vm.$u.post(apiurl.polyPayExportUrl, params);
  let getDictApi = (params = {}) => vm.$u.get(apiurl.getDictUrl + params.type);
  let wechatPayApi = (params = {}) => vm.$u.post(apiurl.wechatPayUrl, params);
  let parkingWechatPayApi = (params = {}) => vm.$u.post(apiurl.parkingWechatPayUrl, params);
  let getParamsApi = (params = {}) => vm.$u.get(apiurl.getParamsUrl + params.key);
  let wechatMonthlyPayapi = (params = {}) => vm.$u.post(apiurl.wechatMonthlyPayUrl, params);
  let monthlyRuleDetailsApi = (params = {}) => vm.$u.get(apiurl.monthlyRuleDetailsUrl, params);
  let couponListApi = (params = {}) => vm.$u.get(apiurl.couponListUrl, params);
  let exchangeCouponApi = (params = {}) => vm.$u.put(apiurl.exchangeCouponUrl, params);
  let updateCouponStatusApi = (params = {}) => vm.$u.post(apiurl.updateCouponStatusUrl, params);
  let getCouponByOrderIdApi = (params = {}) => vm.$u.get(apiurl.getCouponByOrderIdUrl, params);
  let getVehicleInquiryListApi = (params = {}) => vm.$u.post(apiurl.getVehicleInquiryListUrl, params);
  let getOrderInfoByParknoApi = (params = {}) => vm.$u.post(apiurl.getOrderInfoByParknoUrl, params);
  let indoorPaymentApi = (params = {}) => vm.$u.post(apiurl.indoorPaymentUrl, params);
  // 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
  vm.$u.api = {
    feedbackAdd,
    getuseinfo,
    createOrder,
    bindphone,
    getPhoneLoginCode,
    phoneLoginAuth,
    getWXInfo,
    wxPay,
    getIndexData,
    getMycars,
    addCar,
    delCar,
    setDefaultCar,
    roadInfoById,
    getOrderinfo,
    getOrderList,
    getOrderDetail,
    gzbank,
    nearRoadsl,
    roadChargeRule,
    nearParkingLot,
    parkingLotChargeRule,
    getMessageList,
    payGzbank,
    monthInfo,
    createMonth,
    monthPay,
    getMonthPay,
    getMonthList,
    getParkMonthList,
    cancelMonth,
    messageRead,
    feePay,
    getOrderInfo,
    getEquomentInfo,
    updateOrderRefund,
    getOrderRefundDetails,
    ordinaryWxPay,
    monthlyWxPay,
    getSysterms,
    bindVehicleNo,
    codeV2Api,
    userLoginApi,
    geomaLockDetailsApi,
    getDetailEntranceApi,
    getDetailAdvanceApi,
    getDetailExportApi,
    entranceByNoVehicleApi,
    getAdvanceInfoApi,
    getExportInfoApi,
    getOrderStateExportApi,
    quickPayExportApi,
    polyPayExportApi,
    getRoomParkingApi,
    getRoomOrderDetail,
    getDictApi,
    wechatPayApi,
    parkingWechatPayApi,
    getParamsApi,
    wechatMonthlyPayapi,
    monthlyRuleDetailsApi,
    couponListApi,
    exchangeCouponApi,
    updateCouponStatusApi,
    getCouponByOrderIdApi,
    getVehicleInquiryListApi,
    getOrderInfoByParknoApi,
    indoorPaymentApi
  };
};

export default {
  install
};
