import { Notification, MessageBox, Message } from 'element-ui' const attribute = { state: { attributeList: [], groupList: [], functionList: [], eventList: [], }, mutations: { SET_ATTRIBUTE_LIST: (state, list) => { // debugger state.attributeList = list }, PUSH_ATTRIBUTE: (state, item) => { state.attributeList.push(item) }, UPDATE_ATTRIBUTE: (state, {item, idx}) => { state.attributeList[idx] = item }, DELETE_ATTRIBUTE: (state, idx) => { state.attributeList.splice(idx,1); }, GET_ATTRIBUTE_ITEM: (state, idx) => { return state.attributeList[idx] }, GET_ATTRIBUTE_LIST: (state) => { return state.attributeList }, SET_GROUP_LIST: (state, list) => { state.groupList = list }, PUSH_GROUP: (state, item) => { state.groupList.push(item) }, UPDATE_GROUP: (state, {item, idx}) => { state.groupList[idx] = item }, DELETE_GROUP: (state, idx) => { state.groupList.splice(idx,1); }, GET_GROUP_ITEM: (state, idx) => { return state.groupList[idx] }, GET_GROUP_LIST: (state) => { return state.groupList }, //功能 SET_FUNCTION_LIST: (state, list) => { state.functionList = list }, PUSH_FUNCTION: (state, item) => { state.functionList.push(item) }, UPDATE_FUNCTION: (state, {item, idx}) => { state.functionList[idx] = item }, DELETE_FUNCTION: (state, idx) => { state.functionList.splice(idx,1); }, GET_FUNCTION_ITEM: (state, idx) => { return state.functionList[idx] }, GET_FUNCTION_LIST: (state) => { return state.functionList }, //功能 SET_EVENT_LIST: (state, list) => { state.eventList = list }, PUSH_EVENT: (state, item) => { state.eventList.push(item) }, UPDATE_EVENT: (state, {item, idx}) => { state.eventList[idx] = item }, DELETE_EVENT: (state, idx) => { state.eventList.splice(idx,1); }, GET_EVENT_ITEM: (state, idx) => { return state.eventList[idx] }, GET_EVENT_LIST: (state) => { return state.eventList }, }, actions: { GetAttributeList({state}) { // debugger return new Promise((resolve, reject) => { resolve(state.attributeList) }) }, GetGroupList({state}) { return new Promise((resolve, reject) => { resolve(state.groupList) }) }, GetFunctionList({state}) { return new Promise((resolve, reject) => { resolve(state.functionList) }) }, GetEventList({state}) { return new Promise((resolve, reject) => { resolve(state.eventList) }) }, setAttribute({ commit, state }, data){ commit('SET_ATTRIBUTE_LIST', data) }, // 初始化 属性和分组数据 InitAttributeAndGroup({ commit, state }, data) { commit('SET_ATTRIBUTE_LIST', data.attrList) commit('SET_GROUP_LIST', data.groupList) commit('SET_FUNCTION_LIST', data.functionList) commit('SET_EVENT_LIST', data.eventList) console.log('res:', state, data) }, // 新增 属性 AddAttribute({ commit, state }, attr) { commit('PUSH_ATTRIBUTE', attr) }, // 新增 分组 AddGroup({ commit, state }, data) { commit('PUSH_GROUP', data) }, // 新增 功能 AddFunction({ commit, state }, data) { commit('PUSH_FUNCTION', data) }, // 新增 功能 AddEvent({ commit, state }, data) { commit('PUSH_EVENT', data) }, // 获取 属性 单个信息 GetAttributeItem({ commit, state }, idx) { return new Promise((resolve, reject) => { resolve(state.attributeList[idx]) }) }, // 获取 分组 单个信息 GetGroupItem({ commit, state }, idx) { return new Promise((resolve, reject) => { resolve(state.groupList[idx]) }) }, // 获取 功能 单个信息 GetFunctionItem({ commit, state }, idx) { return new Promise((resolve, reject) => { resolve(state.functionList[idx]) }) }, // 获取 功能 单个信息 GetEventItem({ commit, state }, idx) { return new Promise((resolve, reject) => { resolve(state.eventList[idx]) }) }, // 修改 属性 EditAttribute({ commit, state }, param) { commit('UPDATE_ATTRIBUTE', param) }, // 修改 属性 EditGroup({ commit, state }, param) { commit('UPDATE_GROUP', param) }, // 修改 列表 EditFunction({ commit, state }, param) { commit('UPDATE_FUNCTION', param) }, // 修改 事件 EditEvent({ commit, state }, param) { commit('UPDATE_EVENT', param) }, // 删除分组 删除分组 判断分组是否有属性,有属性就不能删除 DeleteGroup({ commit, state }, idx) { let groupItem = state.groupList[idx]; let result = state.attributeList.filter(v => { if (v['cmdKey'] === groupItem['cmdKey']) { return true } }) if (!result) { commit('DELETE_GROUP', idx) } else { Message.error('当前分组已关联参数,无法删除!'); } }, // 删除属性 DeleteAttribute({ commit, state }, idx) { commit('DELETE_ATTRIBUTE', idx) }, // 删除方法 DeleteFunction({ commit, state }, idx) { commit('DELETE_FUNCTION', idx) }, // 删除事件 DeleteEvent({ commit, state }, idx) { commit('DELETE_EVENT', idx) }, } } export default attribute