import Vuex from "vuex";
import Vue from "vue";
import * as types from "./types";
import url from "../components/axios/url";
import { doFetch } from "../components/axios/api";

Vue.use(Vuex);
export default new Vuex.Store({
  state: {
    showEditClique: false,
    title: "",
    isShowFoot: true,
    slideShow: false,
    forzenList: false,
    storeImageUrl: "",
    uniqueId: '',
    isAdmin: false,
    layoutTips: '',
    // showHandleScoreBtn: true, // 是否显示积分相关的操作按钮 true:显示 false：不显示 【废弃】
  },
  mutations: {
    [types.TITLE]: (state, data) => {
      state.title = data;
    },
    isShowFoot(state, data) {
      state.showfoot = data;
    },
    ["mutations-slide"](state, data) {
      state.slideShow = data;
    },
    ["forzen-list"](state, visible) {
      state.forzenList = visible;
    },
    ["saveStoreImage"](state, url) {
      state.storeImageUrl = url;
    },
    ['changeUniqueId'](state, id) {
      state.uniqueId = id || '';
    },
    checkAdmin(state, data) {
      const { superAdmin } = data;
      state.isAdmin = superAdmin === 1 ? true : false;
    },
    mutations_layoutTips(state, val) {
      state.layoutTips = val;
    },
    ['setEditClique'](state, val) {
      state.showEditClique = val;
    },
    // 废弃 巴拉定制需求 子账号不显示积分相关
    // showHandleScoreBtn(state, data) {
    //   state.showHandleScoreBtn = data;
    // }
  },
  actions: {
    getStorePicture({ commit }) {
      doFetch(url.getStorePicture).then(res => {
        let ret;
        if (res.data.errorCode === 0) {
          ret = res.data.result;
          commit("saveStoreImage", ret.enterpriseInfo.enterpriseUrl);
        }
      });
    }
  }
});
