import { Ajax, AjaxUploadFile, AjaxFormData } from "./request";
import Taro from "@tarojs/taro";

// params转换url参数
const paramsToUrlQueryString = (data) => {
  return "?" + new URLSearchParams(Object.entries(data)).toString();
};

// 用户相关
export const WCUserLogin = (data) => {
  //登录
  return Ajax({
    // url: "/wx/user/login",
    url: "/user/login?code=" + data.code,
    data,
    method: "POST",
  });
};
export const MpSplashDetail = (data) => {
  return Ajax({
    // url: "/api/MpSplashDetail",
    url: "/firing/list" + paramsToUrlQueryString(data),
    method: "get",
  });
};
export const getUserAgreement = (data) => {
  //用户协议获取
  return Ajax({
    url: "/setting/getUserAgreement",
    data,
  });
};
export const GetAboutUs = (data) => {
  //获取用户信息接口
  return Ajax({
    url: "/setting/getAboutUs",
    data,
    method: "get",
  });
};
export const UpdateUser = (data) => {
  // 更新用户信息
  return AjaxFormData({
    url: "/user/updateUser",
    data,
    method: "post",
  });
};
export const UpdateUserUploadFile = (formData) => {
  // 更新用户信息且上传头像文件
  return AjaxUploadFile(
    {
      url: "/user/updateUser",
      filePath: formData.file,
      name: "file",
    },
    formData
  );
};
export const RefreshWxUserInfo = (data) => {
  // 刷新用户信息
  return Ajax({
    url: "/user/refreshWxUserInfo",
    data,
    method: "get",
  });
};
export const GetProvince = (data) => {
  // 获取全部省份
  return Ajax({
    url: "/region/getProvince",
    data,
    method: "get",
  });
};
export const GetAreaListByPid = (data) => {
  // 获取全部省份 ?pid=xxx
  return Ajax({
    url: "/region/getAreaListByPid" + paramsToUrlQueryString(data),
    data,
    method: "get",
  });
};
export const GetUserMobile = (data = { code: "" }) => {
  if (!data.code) {
    data.code = Taro.getStorageSync("token") || "";
  }
  //获取用户手机号码
  return Ajax({
    url: "/user/upgradeMember" + paramsToUrlQueryString(data),
    data,
    method: "post",
  });
};

// 获取平台设置
export const getAboutUs = (data) => {
  //关于我们
  return Ajax({
    url: "/setting/getAboutUs",
    data,
  });
};
export const getPrivacyAgreement = (data) => {
  //用户隐私协议获取
  return Ajax({
    url: "/setting/getPrivacyAgreement",
    data,
    method: "get",
  });
};
export const GetOtherSetting = (data) => {
  // 获取其他设置
  return Ajax({
    url: "/setting/getOtherSetting",
    data,
    method: "get",
  });
};
export const getContactWorker = (data) => {
  // 联系客服
  return Ajax({
    url: "/setting/getContactWorker",
    data,
    method: "get",
  });
};
export const SaveMessage = (data) => {
  // 联系客服-保存信息
  return Ajax({
    url: "/api/leaveMessage/saveMessage",
    data,
    method: "post",
  });
};

// 消息页
export const GetNoReadMessageNum = (data) => {
  // 查询是否有消息未读
  return Ajax({
    url: "/userScriptLog/getNoReadMessageNum",
    data,
    method: "get",
  });
};

export const GetHasBeenRead = (data) => {
  // 将消息设置为已读
  return Ajax({
    url: "/userScriptLog/hasBeenRead",
    data,
    method: "get",
  });
};

export const GetMessageList = (data) => {
  // 分页获取消息
  return Ajax({
    url: "/userScriptLog/list" + paramsToUrlQueryString(data),
    data,
    method: "get",
  });
};

// 积分页面
export const GetObtainUserIntegral = (data) => {
  // 分页获取用户积分列表
  return Ajax({
    url: "/integralLog/obtainUserIntegral" + paramsToUrlQueryString(data),
    data,
    method: "get",
  });
};
export const GetIntegralRule = (data) => {
  // 获取积分规则
  return Ajax({
    url: "/setting/getIntegralRule",
    data,
    method: "get",
  });
};
export const GetIsAttentionOfficialAccount = (data) => {
  // 查询用户是否关注公众号
  return Ajax({
    url: "/noRemind/isAttentionOfficialAccount",
    data,
    method: "get",
  });
};
export const GetOfficialAccount = (data) => {
  // 查询用户是否关闭提醒关注公众号
  return Ajax({
    url: "/noRemind/getOfficialAccount",
    data,
    method: "get",
  });
};
export const GetCloseOfficialAccount = (data) => {
  // 查询关闭提醒关注公众号
  return Ajax({
    url: "/noRemind/closeOfficialAccount",
    data,
    method: "get",
  });
};

export const GetSitePopupList = (data) => {
  // 站点管理-弹窗列表 1-首页 2-发现模块 3-活动模块
  return Ajax({
    url: "/siteInfo/popup/" + data,
    data,
    method: "get",
  });
};
export const GetSiteCarousel = (data) => {
  // 站点管理-轮播图
  return Ajax({
    url: "/siteInfo/carousel",
    data,
    method: "get",
  });
};
export const GetSiteAddTag = (data) => {
  // 站点管理-轮播图-添加标签  传值是id
  return Ajax({
    url: "/siteInfo/addTag/" + data,
    data,
    method: "get",
  });
};

// 仪器管理
export const InstrumentInfo = {
  /**根据序列号获取仪器信息 serial 序列号*/
  getInstrumentInfoBySerial: (data) => {
    return Ajax({
      url:
        "/instrument/getInstrumentInfoBySerial" + paramsToUrlQueryString(data),
      data,
      method: "get",
    });
  },
  /**根据序列号获取仪器信息*/
  isBindingSerial: (data) => {
    return Ajax({
      url: "/instrument/isBindingSerial" + paramsToUrlQueryString(data),
      data,
      method: "get",
    });
  },

  /**绑定仪器*/
  binding: (data) => {
    return Ajax({
      url: "/instrument/binding" + paramsToUrlQueryString(data),
      data,
      method: "get",
    });
  },
  /**更换绑定仪器*/
  exchangeBinding: (data) => {
    return Ajax({
      url: "/instrument/exchangeBinding" + paramsToUrlQueryString(data),
      data,
      method: "get",
    });
  },
  /**获取当前用户：已绑定仪器列表*/
  bindingInstrumentList: () => {
    return Ajax({
      url: "/instrument/bindingInstrumentList",
      data,
      method: "get",
    });
  },

  /**获取当前用户：未绑定仪器列表*/
  unbindingInstrumentInfoList: () => {
    return Ajax({
      url: "/instrument/unbindingInstrumentInfoList",
      data,
      method: "get",
    });
  },

  /**获取当前用户：绑定记录 instrumentId*/
  bindingInstrumentInfo: (data) => {
    return Ajax({
      url: "/instrument/bindingInstrumentInfo" + paramsToUrlQueryString(data),
      data,
      method: "get",
    });
  },

  /**用户手动绑定仪器 file 图片文件*/
  manualCodeBinding: (formData) => {
    return AjaxUploadFile(
      {
        url: "/instrument/manualCodeBinding",
        filePath: formData.serialImage,
        name: "serialImage",
      },
      formData
    );
  },

  /**用户扫码绑定仪器 serial instrumentId*/
  scanCodeBinding: (data) => {
    return Ajax({
      url: "/instrument/scanCodeBinding" + paramsToUrlQueryString(data),
      data,
      method: "get",
    });
  },
  /**根据仪器ID：获取仪器介绍信息 instrumentId*/
  instructionInfo: (data) => {
    return Ajax({
      url: "/instrument/instructionInfo" + paramsToUrlQueryString(data),
      data,
      method: "get",
    });
  },
  /**根据仪器ID：获取仪器的初次护理信息*/
  firstNurseInfo: (data) => {
    return Ajax({
      url: "/instrument/firstNurseInfo" + paramsToUrlQueryString(data),
      data,
      method: "get",
    });
  },
  /**根据仪器ID：获取仪器模式列表*/
  modeInfoList: (data) => {
    return Ajax({
      url: "/instrument/modeInfoList" + paramsToUrlQueryString(data),
      data,
      method: "get",
    });
  },
  /**获取设备升级数据 instrumentId*/
  getUpgrade: (data) => {
    return Ajax({
      url: "/instrument/upgrade" + paramsToUrlQueryString(data),
      data,
      method: "get",
    });
  },

  /**打卡相关*/
  clock: {
    /**添加用户使用仪器记录 instrumentId*/
    addClockInstrument: (data) => {
      return Ajax({
        url: "/clock/addClockInstrument" + paramsToUrlQueryString(data),
        data,
        method: "get",
      });
    },
    /**用户打卡*/
    postInsertClockLog: (data) => {
      return Ajax({
        url: "/clock/insertClockLog",
        data,
        method: "post",
      });
    },
    /**查询用户当天最新的一条打卡记录*/
    getLatestClockRecord: (data) => {
      return Ajax({
        url: "/clock/latestClockRecord",
        data,
        method: "get",
      });
    },
    /**分页获取用户的打卡记录 page size*/
    getList: (data) => {
      return Ajax({
        url: "/clock/list" + paramsToUrlQueryString(data),
        data,
        method: "get",
      });
    },
    /**分页获取打卡统计*/
    getClockStatistics: (data) => {
      return Ajax({
        url: "/clock/clockStatistics",
        data,
        method: "get",
      });
    },
  },
  /**护理相关*/
  nursingLog: {
    /**新增用户护理日志*/
    addLog: (data) => {
      return Ajax({
        url: "/nursingLog/add",
        data,
        method: "post",
      });
    },
    /**查询用户护理记录*/
    getRecord: (data) => {
      return Ajax({
        url: "/nursingLog/record" + paramsToUrlQueryString(data),
        data,
        method: "get",
      });
    },
    /**查询用户护理记录的当月统计信息*/
    getStatistics: (data) => {
      return Ajax({
        url: "/nursingLog/statistics" + paramsToUrlQueryString(data),
        data,
        method: "get",
      });
    },
  },
};
//localhost:9204/instrument/getInstrumentInfoBySerial

///////////
///////////
