import request from '../js/request';
import config from '../js/config';

/**
 * 添加反馈
 * @param {*} params  {description: '', files: '', title: 1，type: 1，user_id:12}
 * @returns
 */
export function addFeedBack(params) {
    let files = params.files;
    console.log(files.length);
    let data = JSON.parse(JSON.stringify(params));
    delete data.files
    console.log("🚀 ~ addFeedBack ~ files.length:", files.length)
    if (files.length) {
        return uni.uploadFile({
            url: config.domain + '/cs-system-boot/feedback/addFeedBack', //仅为示例，非真实的接口地址
            files: files,
            header: {
                Authorization: uni.getStorageSync('access_token'),
            },
            formData: data,
        });
    } else {
        return request({
            url: '/cs-system-boot/feedback/addFeedBack',
            method: 'post',
            data: data,
        });
    }
}

/**
 * 问题详情
 * @param {*} id
 * @returns
 */
export function queryFeedBackDetail(id) {
    return request({
        url: '/cs-system-boot/feedback/queryFeedBackDetail',
        method: 'post',
        data: {
            id,
        },
    });
}

// 问题列表
export function queryFeedBackPage(params) {
    return request({
        url: '/cs-system-boot/feedback/queryFeedBackPage',
        method: 'post',
        data: {
            pageNum: 1,
            pageSize: 20,
            status: '',
            type: '',
            userId: uni.getStorageSync('userInfo').id,
        },
    });
}

/**
 * 添加反馈聊天
 *
 * @param {*} params {chatContent: '', id: 12, userId: 1}
 * @returns
 */
export function AddFeedbackChat(params) {
    return request({
        url: '/cs-system-boot/feedbackChat/AddFeedbackChat',
        method: 'post',
        data: params,
        header: {
            'Content-Type': 'application/json',
        },
    });
}

/**
 * 更新反馈聊天状态
 * @param {*} params  {
  "id": "2e47078c0f59a4a612655bb3bbaed617",
  "userId": "12"
}
 * @returns
 */
export function updateChatStatus(params) {
    return request({
        url: '/cs-system-boot/feedbackChat/updateChatStatus',
        method: 'post',
        data: params,
        header: {
            'Content-Type': 'application/json',
        },
    });
}

/**
 * 更新反馈状态
 */

export function updateFeedBackStatus(params) {
    console.log(params);
    return request({
        url: '/cs-system-boot/feedback/auditFeedBack',
        method: 'post',
        data: params,
    });
}
