import Vue from 'vue'
import Vuex from 'vuex'
import modules from './modules'
import { getOptions } from '@/api/common'
import util from '@/utils/util'
Vue.use(Vuex)

const store = new Vuex.Store({
	modules,
	state: {
		allOptions: ''
	},
	getters: {
		allOptions: state => state.allOptions ||
		 (util.isEmpty(uni.getStorageSync('allOptions')) ? {} : JSON.parse(uni.getStorageSync('allOptions')))
	},
	mutations: {
		// 全局选项
		setAllOptions(state, data = {}) {
			  state.allOptions = data
			  uni.setStorageSync('allOptions', JSON.stringify(data))
		}
	  },
	actions: {
		getAllOptions({ commit }) {
		// sysBudgetStatus 预算   sysRenovationStatus 装修类型  sysBookingStatus 派单状态
			return getOptions({
				type: ''
			}).then((res) => {
				if (res.status === 'success') {
					commit('setAllOptions', res.data)
				} else {
					uni.showToast({
						title: res.errors.message,
						icon: 'none'
					})
				}
			})
		}
	}
})

export default store
