import { action, makeObservable, observable, runInAction } from "mobx";
// 档案分类
import BaseStore from "./baseStore";
import { TagDataType } from "@/model/userModel";
import baseHttp from "@/service/base";

class TrainingConfig {
    static LIST: string = "/v1/training/list"
    static ADD: string = "/v1/training"
    static DELETE: string = "/v1/training"
    static EDIT: string = "/v1/training"
    static ACCESS: string = "/v1/training/accept"
    static tran_user: string = "/v1/training/user"
    static addScores: string = "/v1/scoreMgmt/scores"
    static addAchives: string = "/v1/training/archives"
    static back: string = "/v1/supplies/suppliesBack"
    static fish: string = "/v1/training/taskFish"
}
class TrainingStore extends BaseStore<TagDataType> {
    constructor() {
        super(TrainingConfig)
        makeObservable(this, {
            access: action,
            id: observable,
            userList: observable,
            getUserListByTraning: action,
            setUserScore: action,
            fish:action,
        })
    }
    async setUserScore(ids: Array<any>) {
        let res = await baseHttp.post(TrainingConfig.addScores, { "list": ids })
        if (res.data === "ok") {
            this.getUserListByTraning();
            return true
        }
    }
    async access(id: number, param: any) {
        await baseHttp.put(TrainingConfig.ACCESS + "/" + id, param)
        this.getlist()
    }
    async fish(id: string) {
        await baseHttp.put(TrainingConfig.fish + "/" + id, {})
        this.getlist()
    }
    
    // 添加档案到培训
    async addAcieves(param: any) {
        return await baseHttp.post(TrainingConfig.addAchives, param)
    }
    // 添加档案到培训
    async back(id: string,task_type:number) {
        return await baseHttp.put(TrainingConfig.back + "/" + id, {task_type})
    }
    async getUserListByTraning() {
        let res = await baseHttp.get(TrainingConfig.tran_user + "/" + this.id, null)
        let data: Array<any> = []
        if (!res?.data?.record) {
            runInAction(() => {
                this.userList = data;
            })
            return;
        }
        for (let i = 0; i < res.data.record.length; i++) {
            data.push({
                key: res.data.record[i].identity,
                ...res.data.record[i]
            })
        }
        this.userList = data;
    }
    id!: string
    userList!: Array<any>
}
export const trainingStore = new TrainingStore()

