import Vue from "vue";
import {getPromiseVerifyList, templateDetails} from "@/api/commitment";
import { myFetch} from "@/utils/fetch";

const state = {
    templateJson: {
        components:[]
    },
    indicatorList: []
}

const mutations = {
    setTemplateComponents(state, data) {
        Vue.set(state,'templateJson',data)
    },
    setIndicatorList(state, data) {
        Vue.set(state, 'indicatorList', data)
    },

}

const actions = {
    async getPromiseDetail({ commit }, uuid) {
        try {
            let result = await getPromiseVerifyList({
                uuid
            })
            if (result.data && result.data.promiseBody) {
                let promiseBody = JSON.parse(result.data.promiseBody)
                commit('setTemplateComponents',promiseBody )
            } else {
                commit('setTemplateComponents', {})
            }
            if(result.data && result.data.list) {
                commit('setIndicatorList', result.data.list.records)
            }else {
                commit('setIndicatorList', [])
            }
        }
        catch (e) {
            console.log(e)
        }
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions,
}