// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作
const install = (Vue, vm) => {
  /**
   * 单图片上传
   */
  // 使用 uni.uploadFile 以 file 类型上传（multipart/form-data），避免 H5 plus 依赖
  // params: { filePath: string, name?: string, formData?: object }
  let UploadSingleImage = (params = {}) => {
    const { filePath, name = "file", formData = {} } = params;
    return new Promise((resolve, reject) => {
      if (!filePath) return reject(new Error("filePath 不能为空"));
      uni.uploadFile({
        url: vm.$u.http.config.baseUrl + "/api/UploadFiles/SingleImageUpload",
        filePath,
        name,
        formData,
        header: {
          Authorization: "Bearer " + vm.vuex_token,
        },
        success: (res) => {
          // uni.uploadFile 的 res.data 可能是字符串，需要手动解析
          let data = res.data;
          try {
            data =
              typeof res.data === "string" ? JSON.parse(res.data) : res.data;
          } catch (e) {
            // 保持原始数据
          }
          resolve(data);
        },
        fail: (err) => reject(err),
      });
    });
  };

  // ********
  // 获取教师信息
  let getTeacherInfo = (params = {}) =>
    vm.$u.get("api/BasicDataMaintenance/GetTeacher", params);

  let updateTeacherInfo = (params = {}) =>
    vm.$u.post("api/BasicDataMaintenance/UpdateTeacher", params);

  let getData = (params = {}) =>
    vm.$u.get("api/BasicDataMaintenance/GetData", params);
  // 获取排班数据
  let getShiftSchedulingData = (params = {}) =>
    vm.$u.get("api/BasicDataMaintenance/GetShiftSchedulingData", params);

  // 登录
  let LoginApp = (params = {}) => vm.$u.post("api/Token/LoginApp", params);
  // 注册
  let RegisterUser = (params = {}) =>
    vm.$u.post("api/Token/RegisterUser", params);
  // 基础资料以及保存用户头像
  let saveUserInfo = (params = {}) =>
    vm.$u.post("app/User/UploadingFormFileHead", params);
  // 更新用户定位信息
  let upPosition = (params = {}) =>
    vm.$u.post("app/Position/InsertPosition", params);
  // 获取用户当前定位信息
  let getPosition = (params = {}) =>
    vm.$u.get("app/Position/GetPositionByUser", {
      userId: vm.vuex_user.id,
    });
  // 获取所有学校
  let GetAllSchool = (params = {}) =>
    vm.$u.get("app/User/GetSchoolList", params);
  //获取首页地图信息
  let HomeMap = (params = {}) => vm.$u.get("/app/User/HomeMap", params);
  //修改密码
  let ChangePassword = (params = {}) =>
    vm.$u.post("app/User/ChangePassword", params);
  //修改密码
  let myChangePassword = (params = {}) =>
    vm.$u.post("app/My/ChangePassword", params);
  // 获取搜索页面相关信息
  let SearchInfo = (params = {}) =>
    vm.$u.get("app/User/SearchRelevant", params);
  //获取搜索结果页面
  let getSearch = (params = {}) => vm.$u.get("app/User/GetSearchList", params);
  // 获取用户信息
  let getUserInfo = (params = {}) => vm.$u.get("app/User/HomePage", params);
  // 获取校友帮帮列表
  let GetHelpList = (params = {}) =>
    vm.$u.get("app/HelpArticle/GetHelpArticleListByKey", params);
  // 获取学校资讯
  let GetSchoolList = (params = {}) =>
    vm.$u.get("app/AlumnRange/AlumnRangeSchool", params);
  //获取最新的用户信息（更新用户数据）
  // let getUser = (params = {}) =>
  //   vm.$u.get("app/User/GetUser", { userId: vm.vuex_user.id }).then((res) => {
  //     vm.$u.get("/app/User/GetUserSchool").then((ress) => {
  //       // res.isAttestationGLY = ress.isAttestationGLY
  //       // res.isAttestationJZG = ress.isAttestationJZG
  //       // res.isAttestationQY = ress.isAttestationQY
  //       // res.isAttestationXY = res.isAttestationXY
  //       // res.isAttestationZXS = ress.isAttestationZXS
  //       res.schoolId = ress.items.schoolId;
  //       vm.$u.vuex("vuex_user", { ...res.user, ...res.userExtension });
  //       vm.$u.vuex("vuex_user_hobby", res.lableList);
  //     });
  //   });
  //获取用户消息列表
  let getcharList = (params = {}) =>
    vm.$u.get("app/Chat/GetUserMessageList", params);
  //获取用户获取关注列表
  let getFollowList = (params = {}) =>
    vm.$u.get("app/Chat/GetFollowList", { id: vm.vuex_user.id });
  //	获取系统消息列表
  let getSysList = (params = {}) =>
    vm.$u.get("app/Chat/GetSystemMessageList", { id: vm.vuex_user.id });
  //获取管理消息列表
  let getAdminList = (params = {}) =>
    vm.$u.get("app/Chat/GetManageMessageList", { schoolId: vm.vuex_user.id });
  //获取互动信息列表
  let getinteractionList = (params) =>
    vm.$u.get("app/Chat/GetInterMessageList", {
      id: vm.vuex_user.id,
      type: params,
    });
  //校友找找推荐列表
  let getAlumnSearch = (params = {}) =>
    vm.$u.get("app/AlumnRange/AlumnSearch", params);
  //获取聊天记录
  let getChatRecord = (params = {}) =>
    vm.$u.get("app/Chat/GetChatRecord", params);
  //校友找找列表
  let AlumnSearchList = (params = {}) =>
    vm.$u.get("app/AlumnRange/AlumnSearchList", params);
  // 初始化的数据调用微信接口返回参数
  let GetInfoMation = (params = {}) =>
    vm.$u.get("api/Token/GetInfoMation", params);
  // 回复绑定
  let toBind = (params = {}) => vm.$u.get("app/Chat/ReplyBind", params);
  //我的资讯
  let MyAlumnRange = (params = {}) => vm.$u.get("app/My/MyAlumnRange", params);
  // 解除绑定
  let colseBind = (params = {}) => vm.$u.get("app/Chat/UnbindReply", params);
  // 删除评论
  let DelateComment = (params = {}) =>
    vm.$u.get("app/AlumnRange/DelateComment", params);
  let userVerify = (params = {}) =>
    vm.$u.post("api/Token/IsIdentityCard", params);

  // 获取人脸验证token
  let getAPIToken = (params = {}) =>
    vm.$u.post("app/My/GetVerifyToken", params);
  // 查询人脸核验结果
  let getVerifyInfo = (params = {}) =>
    vm.$u.post("app/My/GetDetailInfo?VerifyToken=" + params);
  // 根据身份证获取信息
  let getInfoByCard = (params = {}) =>
    vm.$u.get("app/User/GetCardByPreConfiguredUser", params);
  // 更新身份信息
  let updateCard = (params = {}) => vm.$u.post("api/Token/UpdateCard", params);

  //【手机端】添加心愿
  let PushWishDan = (params = {}) => vm.$u.post("app/My/PushWishDan", params);

  //【手机端】获取个人心愿列表
  let GetWishListAsync_mobile = (params = {}) =>
    vm.$u.get("app/My/GetWishListAsync_mobile", params);
  //【手机端】删除心愿 删除=失效
  let DeleteWish = (params = {}) => vm.$u.post("app/My/DeleteWish", params);
  //【管理端】获取当前是否开启匿名 开启true 关闭false
  let CheckNM = (params = {}) => vm.$u.get("/app/My/CheckNM", params);

  /** 首页ai对话 */
  // 发送消息(创建对话)
  let SendMessageApi = (params = {}) =>
    vm.$u.post("api/ChatAI/CreateChat", params, { showLoading: false });
  // 获取对话详情
  let GetConversationDetail = (params = {}) =>
    vm.$u.get("api/ChatAI/GetHistoricalConversations", params);
  // 获取历史对话列表
  let GetConversationPage = (params = {}) =>
    vm.$u.get("/api/ChatAI/GetConversationPage", params);
  // 新-当前回复是否有帮助
  let ModifyStatus = (params = {}) =>
    vm.$u.post("api/ChatAI/ModifyStatus", params);
  // 新-获取热门问题
  let GetHotQuestions = (params = {}) =>
    vm.$u.get("api/ChatAI/GetHotQuestions", params);
  // 新-获取热门问题详情对话
  let GetHotQuestionsFromId = (params = {}) =>
    vm.$u.post("api/ChatAI/GetHotQuestionsFromId", params);
  // 新-删除对话
  let DeleteDialogueManagement = (params = {}) =>
    vm.$u.post("api/ChatAI/DeleteDialogueManagement", params);

  /** 登录 */
  // 获取图形验证码
  let GetCaptcha = (params = {}) => vm.$u.get("api/Login/GetCaptcha", params);
  // 发送验证码-学生
  let GetStuVerifyCode = (params = {}) =>
    vm.$u.post("api/Login/GetSMSCodeAccountRegister", params);
  // 登录-学生
  let StuLogin = (params = {}) =>
    vm.$u.post("api/Login/PhoneLoginExpertUser", params);

  // 发送验证码-教师
  let GetTeacherVerifyCode = (params = {}) =>
    vm.$u.post("api/Login/RequestLoginSMSCode", params);
  // 密码登录-教师
  let TeacherLogin = (params = {}) =>
    vm.$u.post("api/Login/LoginManagementEnd", params);
  // 验证码登录-教师
  let TeacherLoginByCode = (params = {}) =>
    vm.$u.post("api/Login/PhoneLoginManagementEnd", params);
  // 忘记密码-获取短信验证码
  let RequestForgotPasswordSMSCode = (params = {}) =>
    vm.$u.post("api/Login/RequestForgotPasswordSMSCode", params);
  // 忘记密码-修改密码
  let ForgotPasswordChangePassword = (params = {}) =>
    vm.$u.post("api/Login/ForgotPasswordChangePassword", params);

  /** 用户-个人中心 */
  // 获取用户信息
  let GetUserApi = (params = {}) =>
    vm.$u.get("api/BasicDataMaintenance/GetUser", params);
  // 更新用户信息
  let UpdateUserApi = (params = {}) =>
    vm.$u.post("api/BasicDataMaintenance/UpdateUser", params);

  /** 会话 */
  // 获取教师列表(学生端-招办在线)
  let GetTeacherListApi = (params = {}) =>
    vm.$u.get("api/Dialogue/GetTeacherList", params);
  // 获取会话列表-教师
  let GetDialogueListApi = (params = {}) =>
    vm.$u.get("api/Dialogue/GetDialogueList", params);
  // 获取会话列表-用户
  let GetDialogueList_UserApi = (params = {}) =>
    vm.$u.get("api/Dialogue/GetDialogueList_User", params);
  // 创建会话
  let AddDialogueApi = (params = {}) =>
    vm.$u.post("api/Dialogue/AddDialogue", params);
  // 发送私聊消息
  let SendMessage_PrivateApi = (params = {}) =>
    vm.$u.post("api/Dialogue/SendAPrivateChatMessage", params);
  // 获取会话聊天记录
  let GetChatHistoryDataApi = (params = {}) =>
    vm.$u.get("api/Dialogue/GetChatHistoryData", params);
  // 获取消息接收方用户信息
  let GetReceiverUserInfoApi = (params = {}) =>
    vm.$u.get("api/Dialogue/GetReceiverUserInfo", params);
  // 置顶一个会话
  let OverheadOneDialogueApi = (params = {}) =>
    vm.$u.post("api/Dialogue/OverheadOneDialogue", params);
  // 将会话消息标记为已读
  let ReadMessageApi = (params = {}) =>
    vm.$u.post("api/Dialogue/ReadMessage", params);
  // 删除会话
  let DeleteDialogueApi = (params = {}) =>
    vm.$u.post("api/Dialogue/DeleteDialogue", params);
  // 转人工服务
  let TransferToALiveAgentApi = (params = {}) =>
    vm.$u.post("api/Dialogue/TransferToALiveAgent", params);
  // 结束人工服务
  let EndLiveAgentApi = (params = {}) =>
    vm.$u.post("api/Dialogue/EndLiveAgent", params);

  // 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
  vm.$u.api = {
    UploadSingleImage,
    getTeacherInfo,
    getData,
    getShiftSchedulingData,
    updateTeacherInfo,
    LoginApp,
    RegisterUser,
    saveUserInfo,
    upPosition,
    getPosition,
    GetAllSchool,
    HomeMap,
    ChangePassword,
    myChangePassword,
    SearchInfo,
    getSearch,
    getUserInfo,
    GetHelpList,
    GetSchoolList,
    // getUser,
    getcharList,
    getFollowList,
    getSysList,
    getAdminList,
    getinteractionList,
    getAlumnSearch,
    getChatRecord,
    AlumnSearchList,
    GetInfoMation,
    toBind,
    colseBind,
    MyAlumnRange,
    DelateComment,
    userVerify,
    GetWishListAsync_mobile,
    DeleteWish,
    CheckNM,
    PushWishDan,
    getAPIToken,
    getVerifyInfo,
    getInfoByCard,
    updateCard,
    SendMessageApi,
    GetCaptcha,
    GetStuVerifyCode,
    StuLogin,
    GetConversationPage,
    GetConversationDetail,
    ModifyStatus,
    GetHotQuestions,
    GetHotQuestionsFromId,
    DeleteDialogueManagement,
    GetTeacherVerifyCode,
    TeacherLogin,
    TeacherLoginByCode,
    RequestForgotPasswordSMSCode,
    ForgotPasswordChangePassword,
    GetUserApi,
    UpdateUserApi,
    GetTeacherListApi,
    GetDialogueListApi,
    GetDialogueList_UserApi,
    AddDialogueApi,
    SendMessage_PrivateApi,
    GetChatHistoryDataApi,
    GetReceiverUserInfoApi,
    OverheadOneDialogueApi,
    ReadMessageApi,
    DeleteDialogueApi,
    TransferToALiveAgentApi,
    EndLiveAgentApi,
  };
};

export default {
  install,
};
