import http from '@/request/http.js' // 引入封装之后的http中创建的http实例
import ossConfig from '@/assets/ossConfig.js'
import store from '@/store/index.js'
// 公共api
export default {
    /**
   *  BasicData
   */
    // 获取请求用户信息
    getCurrentUserInfo () {
        return http.get('/api/SystemAdmin/BasicData/GetCurrentUserInfo')
    },
    // 获取当前时间是当前学期的第几周
    getCurrentWeekIndex () {
        return http.get('/api/SystemAdmin/BasicData/GetCurrentWeekIndex')
    },
    // 获取学期列表
    getTermInfoList () {
        return http.get('/api/SystemAdmin/TermInfo/GetList')
    },
    // 获取分部接口
    getSubCompanys () {
        return http.get('/api/SystemAdmin/BasicData/GetSubCompanys')
    },
    // 根据字典分类代码获取数据字典明细项
    getItemDetailByCode: ({ code }) => http.get(`/api/SystemAdmin/BasicData/GetItemDetailByCode/${code}`),
    // 根据字典分类代码获取数据字典递归明细项
    getItemDetailRecursionByCode: ({ code }) => http.get(`/api/SystemAdmin/BasicData/GetItemDetailRecursionByCode/${code}`),

    /**
   *  PlatBsInfo 平台基础数据接口
   */
    // 获取学期信息
    getTermList () {
        return http.post('/api/PlatBsInfo/GetTermList')
    },

    /**
   *  BSGradeClass 班级年级管理
   */
    // 获取所有年级班级
    getGradeClassList () {
        return http.get('/api/SystemAdmin/BSGradeClass/GetGradeClassList')
    },
    // 获取当前角色管理的年级班级
    getRoleGradeClass () {
        return http.get('/api/SystemAdmin/BSGradeClass/GetRoleGradeClass')
    },
    getCurrentUserClassInfo (params) {
        return http.get(`/api/SystemAdmin/BSGradeClass/GetCurrentUserClassInfo/${params.isSelectAll}/${params.isResponseTree}/${params.roleCode}`)
    },
    // 根据年级Id获取班级信息
    getClassInfosByGradeId (params) {
        return http.get('/api/SystemAdmin/BSGradeClass/GetClassInfosByGradeId', { params: params })
    },

    // 根据班级获取学生列表
    getStudentInfoByClassId (params) {
        return http.get(`/api/SystemAdmin/BSGradeClass/GetStudentInfoByClassId/${params.classId}`)
    },
    // 获取当前学校年级
    getCompanyGrades: () => http.get('/api/SystemAdmin/BSGradeClass/GetCompanyGrades'),

    /**
     * Teacher
     */
    // 获取学校教师列表
    getSchoolTeachers () {
        return http.get('/api/SystemAdmin/Teacher/GetSchoolTeachers')
    },
    // 获取教师本人信息
    getTeacherSelfInfo () {
        return http.get('/api/SystemAdmin/TeacherInfo/GetSelfInfo')
    },
    // 更新教师自己的信息
    UpdateTeacherSelfInfo (params) {
        return http.post('/api/SystemAdmin/TeacherInfo/UpdateSelfInfo', JSON.stringify(params))
    },
    // 获取教师信息
    fetchTeacherInfo (params) {
        return http.get('/api/SystemAdmin/TeacherInfo/Get', { params })
    },

    /**
   * Student
   */
    chooseStudent (params) {
        return http.post('/api/Student/ChooseStudent', JSON.stringify(params))
    },

    /**
   * Subject
   */
    // 获取当前学校的已开课科目
    getOpenSubject () {
        return http.get('/api/Subject/GetOpenSubject')
    },
    // 根据年级获取关联科目
    getGradeSubject (params) {
        return http.get('/api/Subject/GetGradeSubject', { params })
    },

    /**
   * PIPERMISSIONITEM 平台操作权限
   */
    // 获取当前用户信息
    getCurrentUser () {
        return http.get('/api/PIPERMISSIONITEM/GetCurrentUser')
    },
    // 判断用户是否是超管和是否是某个角色管理员
    getUserCheckRole (params) {
        return http.get(`/api/PIPERMISSIONITEM/UserCheckRole/${params.roleCode}`)
    },
    // 判断用户是否是超管和是否是某个角色管理员
    getUserCheckRoles (params) {
        return http.get(`/api/PIPERMISSIONITEM/UserCheckRoles/${params.roleCode}`)
    },
    // 万能的获取班级，当返回AllClassInfos对象，就用这个树状的数据，否则，用MyClassInfos普通数组数据
    getWechatGradeClassInfo (params) {
        return http.get(`/api/SystemAdmin/BSGradeClass/GetWechatGradeClassInfo/${params}`)
    },
    // 获取学校类型
    getSchoolInfo () {
        return http.get(`/api/SystemAdmin/BasicData/GetSchoolInfo`)
    },

    /**
   * UploadPlug 上传文件共用接口
   */
    getPlugInfo (params) {
        return http.get('/api/SystemAdmin/UploadPlug/GetPlugInfo', {
            params
        })
    },
    // 导入
    addPlugInfo (params) {
        return http.post('/api/SystemAdmin/UploadPlug/AddPlugInfo', JSON.stringify(params))
    },
    // 下载模板
    exportTemplate (params) {
        return http.post(params.url, JSON.stringify(params.data), {
            responseType: 'blob'
        })
    },
    // 导入表格文件
    importExcelTable (params, callback) {
        return http.post(params.url, params.data, {
            headers: {
                'Content-Type': 'multipart/form-data'
            },
            isShowLoading: false,
            onUploadProgress: (e) => {
                callback(e)
            }
        })
    },

    /**
   * PlatFormModule
   */
    getPlatFormModuleTree (params) {
        return http.get('/api/SystemAdmin/PlatFormModule/GetPlatFormModuleTree', {
            params
        })
    },
    // 获取自定义模块
    getPlatFormCustomModule () {
        return http.get('/api/SystemAdmin/PlatFormCustomModule/List')
    },
    // 删除我的应用
    deletePlatFormCustomModule (params, interfaceNamae) {
        return http.get(`/api/SystemAdmin/PlatFormCustomModule/${interfaceNamae}`, { params })
    },
    // 保存我的应用
    saveMyUsualModule (params) {
        return http.post(
            '/api/SystemAdmin/PlatFormCustomModule/SaveOrder',
            JSON.stringify(params)
        )
    },
    // 已经选择的应用
    getSelectedModules () {
        return http.get(
            '/api/SystemAdmin/PlatFormCustomModule/GetSelectedModules'
        )
    },
    createPlatFormCustomModule (params) {
        return http.post(
            '/api/SystemAdmin/PlatFormCustomModule/Create',
            JSON.stringify(params)
        )
    },
    /**
     * SystemAdmin
     */
    // 获取学期列表
    getTermsList () {
        return http.get('/api/SystemAdmin/TermInfo/GetList')
    },

    // 获取年班级列表
    getGradeClass: () => http.get('/api/SystemAdmin/BSGradeClass/GetGradeClassListByCompanyId', {
        params: { company_id: store.state.tokenPayload.CompanyId },
        isShowLoading: false
    }),
    // 获取省市区
    getPCA: () => http.get('/Assets/Administrative-divisions-of-China/dist/pca-code.json', {
        baseURL: ossConfig.staticResourcesFileBucket.domain,
        isShowLoading: false
    }),
    // 获取省市
    getPC: () => http.get('/Assets/Administrative-divisions-of-China/dist/pc-code.json', {
        baseURL: ossConfig.staticResourcesFileBucket.domain,
        isShowLoading: false
    }),
    // 获取省
    getP: () => http.get('/Assets/Administrative-divisions-of-China/dist/provinces.json', {
        baseURL: ossConfig.staticResourcesFileBucket.domain,
        isShowLoading: false
    }),

    // ---- 表单控件 ----
    // 获取控件列表
    formControlsList: params => http.post('/api/Form/FormControls/List', params),
    // 获取控件详情
    formControlsGet: params => http.get('/api/Form/FormControls/Get', { params }),
    // 创建控件
    formControlsCreate: params => http.post('/api/Form/FormControls/Create', params),
    // 修改控件
    formControlsUpdate: params => http.post('/api/Form/FormControls/Update', params),
    // 启用禁用控件
    formControlsSetEnabled: params => http.get('/api/Form/FormControls/SetEnabled', { params }),
    // 删除控件
    formControlsDelete: params => http.get('/api/Form/FormControls/Delete', { params }),
    // 控件排序
    formControlsSort: params => http.post('/api/Form/FormControls/SetSortCode', params),

    // ---- 表单详情 ----
    // 获取表单详情
    formInfoGet: params => http.get('/api/Form/FormInfo/Get', { params }),
    // 根据类别和数据源获取表单详情
    formInfoGetByCS: params => http.get('/api/Form/FormInfo/GetByCategoryAndSourceId', { params }),
    // 创建表单
    formInfoCreate: params => http.post('/api/Form/FormInfo/Create', params),
    // 修改表单
    formInfoUpdate: params => http.post('/api/Form/FormInfo/Update', params),
    // 删除表单
    formInfoDelete: params => http.get('/api/Form/FormInfo/Delete', { params }),

    /**
     * Organize
     */
    getOrganizeTree () {
        return http.post('/api/Organize/OrganizeTree')
    },

    // ---- 表单记录 ----
    // 获取记录列表
    formRecordList: params => http.get('/api/Form/FormRecord/List', { params }),
    // 获取记录详情
    formRecordGet: params => http.get('/api/Form/FormRecord/Get', { params }),
    // 创建记录
    formRecordCreate: params => http.post('/api/Form/FormRecord/Create', params),
    // 创建记录（不需要 token）
    formRecordCreateNoAuth: params => http.post('/api/Form/FormRecord/CreateNoAuthentication', params),
    // 修改记录
    formRecordUpdate: params => http.post('/api/Form/FormRecord/Update', params),
    // 删除记录
    formRecordDelete: params => http.get('/api/Form/FormRecord/Delete', { params }),

    // ---- 表单工具 ----
    // 日期区间排除休息时间
    formJudgeLeaveDay: params => http.get('/api/BsTeacherRestTime/JudgeLeaveDay', { params, isShowLoading: false }),
    // 表单控件数据唯一验证
    formRecordValidation: params => http.post('/api/Form/FormRecordValidation/UniqueValidation', params, { isShowLoading: false }),
    // 获取文件流进行下载
    formGetFile: url => http.get(url, { responseType: 'blob' }),

    /**
     * TeacherLession
     */
    getClassSubject: params => http.get('/api/SystemAdmin/GetClassSubject', { params })
}
