import {
    request
} from '@/untils/AxiosUtils.js';
/* 任务邀请列表 */
export const inviteList = (current, size) => {
    return request({
        url: '/api/jobslink-api/desk/user/notice/list',
        method: 'get',
        params: {
            current,
            size
        }
    })
}

/* 获取任务邀请未读数量 */
export const inviteCount = () => {
    return new Promise(function(resolve, reject) {
        request({
                url: '/api/jobslink-api/desk/user/notice/count',
                method: 'get'
            })
            .then((resp) => {
                const result = resp.data.data;
                resolve(result);
            })
            .catch(reject)
    })
}

/* 任务邀请设置已读 */
export const inviteRead = (id) => {
    return request({
        url: '/api/jobslink-api/desk/user/notice/update',
        method: 'post',
        data: {
            id
        }
    })
}

/* 任务邀请删除 */
export const inviteRemove = (ids) => {
    return request({
        url: '/api/jobslink-api/desk/notice/missions/remove',
        method: 'post',
        params: {
            ids
        }
    })
}

function getDesc(desc) {
    let re = desc.replace(/<\/?.+?\/?>/g, '')
    return re.substring(0, 50)
}

/* 通知列表 */
export const noticeList = (current, size) => {
    return new Promise(function(resolve, reject) {
        request({
            url: '/api/jobslink-api/desk/notice/user/list',
            method: 'get',
            params: {
                current,
                size
            }
        }).then(resp => {
            resp.data.data.records.forEach(item => {
                item.desc = getDesc(item.content)
            })

            resolve(resp)
        }).catch(reject)
    })
}

/* 获取通知未读数量 */
export const noticeCount = () => {
    return new Promise(function(resolve, reject) {
        request({
                url: '/api/jobslink-api/desk/notice/user/read',
                method: 'get'
            })
            .then((resp) => {
                const result = resp.data.data;
                resolve(result);
            })
            .catch(reject)
    })
}

/* 通知列表设置已读 */
export const noticeRead =
    (ids) => {
        return request({
            url: '/api/jobslink-api/desk/notice/status/read',
            method: 'post',
            params: {
                ids
            }
        })
    }

/* 通知列表删除 */
export const noticeRemove = (ids) => {
    return request({
        url: '/api/jobslink-api/desk/notice/status/remove',
        method: 'post',
        params: {
            ids
        }
    })
}


export const noticeStatus1 = () => new Promise((resolve, reject) => {
    return request({
            url: '/api/jobslink-api/desk/notice/noticeStatus',
            method: 'get',
            params: {
                type: 1
            }
        }).then((resp) => {
            const result = resp.data.data;
            resolve(result);
        })
        .catch(reject)
})
export const noticeStatus2 = () => new Promise((resolve, reject) => {
    return request({
            url: '/api/jobslink-api/desk/notice/noticeStatus',
            method: 'get',
            params: {
                type: 2
            }
        }).then((resp) => {
            const result = resp.data.data;
            resolve(result);
        })
        .catch(reject)
})
export const noticeStatus3 = () => new Promise((resolve, reject) => {
    return request({
            url: '/api/jobslink-api/desk/notice/noticeStatus',
            method: 'get',
            params: {
                type: 3
            }
        }).then((resp) => {
            const result = resp.data.data;
            resolve(result);
        })
        .catch(reject)
})

export const settingRead1 = (data) => {
    return request({
        url: '/api/jobslink-api/desk/notice/status/read',
        method: 'post',
        params: {
            stype: 1,
            ...data
        }
    })
}
export const settingRead2 = (data) => {
    return request({
        url: '/api/jobslink-api/desk/notice/status/read',
        method: 'post',
        params: {
            stype: 2,
            ...data
        }
    })
}
export const settingRead3 = (data) => {
    return request({
        url: '/api/jobslink-api/desk/notice/status/read',
        method: 'post',
        params: {
            stype: 3,
            ...data
        }
    })
}

export const updataEmployedNew = (params) => {
    return request({
        url: '/api/jobslink-api/missions/mission/apply/employed/new',
        method: 'post',
        params
    })
}
export const cancelEmployed = (params) => {
    return request({
        url: '/api/jobslink-api/missions/mission/apply/cancelEmployed',
        method: 'post',
        params
    })
}