condition.js 2.84 KB
import dateInstance from '../../common/date.js'
import fetch from '../../api/fetch.js'
import { CONDITIONS } from '../mutation-types.js'

const state = {
	// 门店
	storeMallList: [],	// 门店/商场列表
	checkedMallId: null,	// 单选门店
	multiCheckedMallId: [],	// 多选门店
	// 监控点
	storeGateList: [],	// 监控点/出入口列表
	checkedGateId: null,	// 单选监控点
	multiCheckedGateId: [],	// 多选监控点
	// 时间
	dateData: [],	// 基本时间数据	年月日
	// 天级日期
	selectedDayTime: '',	// 选中天级日期字符串
	dayAnchor: [],	// 选中天级日期picker下标
	// 开始结束日期
	selectedStartDayTime: '',	// 选中开始日期时间字符串
	startDayAnchor: [],	// 选中开始日期时间picker下标
	selectedEndDayTime: '',	// 选中结束日期时间字符串
	endDayAnchor: [],	// 选中结束日期时间picker下标
}

const getter = {};

const mutations = {
	// 门店/商场
	[CONDITIONS.SET_MALLS] (state, mallList) {
		state.mallList = mallList;
	},
	[CONDITIONS.CHECKED_MALL_ID] (state, mallId) {
		state.checkedMallId = mallId;
	},
	[CONDITIONS.CHECKED_MULTI_MALL_ID] (state, multiMallId) {
		state.multiCheckedMallId = multiMallId;
	},
}

const actions = {
	getMalls({ commit }, { data, header }) {
		fetch.loadAccountList('get', data, header)
			.then(res => {
				console.log('actions fetch mallList-=-=-=-=-=->', res)
				let result = res.data;
				let buildMallData = result.data.map(item => {
					item._selected = false;	// 结合数据展现新增属性
					return item;
				})
				commit(CONDITIONS.SET_MALLS, buildMallData)
				let mallId = null
					, multiMallId = [];
					multiMallId = buildMallData.map((item, index) => {
						if(index == 0) {
							mallId = {
								id: item.id,
								name: item.name
							};
						}
						return {
							id: item.id,
							name: item.name
						};
					});
				commit(CONDITIONS.CHECKED_MALL_ID, mallId)
				commit(CONDITIONS.CHECKED_MULTI_MALL_ID, multiMallId)
			})
	},
	getGates({ commit }, { data, header }) {
		fetch.loadGateList({
			data, header
		})
			.then(res => {
				console.log('actions fetch gateList-=-=-=-=-=->', res)
				let result = res.data;
				let buildGateData = result.data.map(item => {
					item._selected = false;	// 结合数据展现新增属性
					return item;
				})
				commit(CONDITIONS.SET_GATES, buildGateData)
				let gateId = null
					, multiGateId = [];
					multiGateId = buildGateData.map((item, index) => {
						if(index == 0) {
							gateId = {
								id: item.id,
								name: item.name
							};
						}
						return {
							id: item.id,
							name: item.name
						};
					});
				commit(CONDITIONS.CHECKED_GATE_ID, gateId)
				commit(CONDITIONS.CHECKED_MULTI_GATE_ID, multiGateId)
			})
	},
}

const conditionList = {
	state: state,
	getters: getter,
	mutations: mutations,
	actions: actions
}

export default conditionList;