
import Api from '../../util/Api/index'
import ToolClass from '../../util/PublicMethod/index'

export default {
  namespaced: true,
  state: {
    IndexBanner: [], // 首页banner
    ActivityList: [], // 活动列表
    PhotoList: [], // 照片墙列表
    QuanYiBanner: [], // 荟权益banner
    YeZhuZiXunList: [], // 业主资讯列表
    HuiAiXinBanner: [], // 荟爱心banner
    MingXingYeZhuList: [], // 明星业主列表
    ZhengNengLiangShiJiList: [], // 正能量事迹列表
    HuoDongNavList: [], // 活动类型列表
    UserActivityList: [] // 我的活动列表
  },
  mutations: {
    UpdateIndexBanner (state, data) { // 更新首页banner
      state.IndexBanner = state.IndexBanner.concat(data || [])
    },
    EmptyIndexBanner (state) { // 清空首页banner
      state.IndexBanner = []
    },
    UpdatePhotoList (state, data) { // 更新照片墙列表
      state.PhotoList = state.PhotoList.concat(data || [])
    },
    EmptyPhotoList (state) { // 清空照片墙列表
      state.PhotoList = []
    },
    UpdateActivityList (state, data) { // 更新活动列表
      state.ActivityList = state.ActivityList.concat(data || [])
    },
    EmptyActivityList (state) { // 清空活动列表
      state.ActivityList = []
    },
    UpdateQuanYiBanner (state, data) { // 更新荟权益banner
      state.QuanYiBanner = state.QuanYiBanner.concat(data || [])
    },
    EmptyQuanYiBanner (state) { // 清空荟权益banner
      state.QuanYiBanner = []
    },
    UpdateYeZhuZiXunList (state, data) { // 更新业主资讯列表
      state.YeZhuZiXunList = state.YeZhuZiXunList.concat(data || [])
    },
    EmptyYeZhuZiXunList (state) { // 清空业主资讯列表
      state.YeZhuZiXunList = []
    },
    UpdateHuiAiXinBanner (state, data) { // 更新荟爱心banner
      state.HuiAiXinBanner = state.HuiAiXinBanner.concat(data || [])
    },
    EmptyHuiAiXinBanner (state) { // 清空荟爱心banner
      state.HuiAiXinBanner = []
    },
    UpdateMingXingYeZhuList (state, data) { // 更新明星业主列表
      state.MingXingYeZhuList = state.MingXingYeZhuList.concat(data || [])
    },
    EmptyMingXingYeZhuList (state) { // 清空明星业主列表
      state.MingXingYeZhuList = []
    },
    UpdateZhengNengLiangShiJiList (state, data) { // 更新正能量事迹列表
      state.ZhengNengLiangShiJiList = state.ZhengNengLiangShiJiList.concat(data || [])
    },
    EmptyZhengNengLiangShiJiList (state) { // 清空正能量事迹列表
      state.ZhengNengLiangShiJiList = []
    },
    UpdateHuoDongNavList (state, data) { // 更新活动类型列表
      state.HuoDongNavList = data || []
    },
    EmptyHuoDongNavList (state) { // 清空活动类型列表
      state.HuoDongNavList = []
    },
    UpdateUserActivityList (state, data) { // 更新我的活动列表
      state.UserActivityList = state.UserActivityList.concat(data || [])
    },
    EmptyUserActivityList (state) { // 清空我的活动列表
      state.UserActivityList = []
    }
  },
  actions: {
    GetNewsDetail (context, payload) { // 获取资讯详情
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.GetNewsDetail.url,
          method: Api.GetNewsDetail.method,
          ...payload,
          success (res) {
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    GetUserActivityList (context, payload) { // 获取我的活动列表
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.GetUserActivityList.url,
          method: Api.GetUserActivityList.method,
          ...payload,
          success (res) {
            context.commit('UpdateUserActivityList', res.data.data.records)
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    GetHuoDongNavList (context, payload) { // 获取活动类型列表
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.GetHuoDongNavList.url,
          method: Api.GetHuoDongNavList.method,
          ...payload,
          success (res) {
            context.commit('UpdateHuoDongNavList', res.data.data.records)
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    GetZhengNengLiangShiJiList (context, payload) { // 获取正能量事迹列表
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.GetZhengNengLiangShiJiList.url,
          method: Api.GetZhengNengLiangShiJiList.method,
          ...payload,
          success (res) {
            context.commit('UpdateZhengNengLiangShiJiList', res.data.data.records)
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    GetMingXingYeZhuList (context, payload) { // 获取明星业主列表
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.GetMingXingYeZhuList.url,
          method: Api.GetMingXingYeZhuList.method,
          ...payload,
          success (res) {
            context.commit('UpdateMingXingYeZhuList', res.data.data.records)
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    GetHuiAiXinBanner (context, payload) { // 获取荟爱心banner
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.GetHuiAiXinBanner.url,
          method: Api.GetHuiAiXinBanner.method,
          ...payload,
          success (res) {
            context.commit('UpdateHuiAiXinBanner', res.data.data.records)
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    GetYeZhuZiXunList (context, payload) { // 获取业主资讯列表
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.GetYeZhuZiXunList.url,
          method: Api.GetYeZhuZiXunList.method,
          ...payload,
          success (res) {
            context.commit('UpdateYeZhuZiXunList', res.data.data.records)
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    GetHuiQuanYiBanner (context, payload) { // 获取荟权益banner
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.GetHuiQuanYiBanner.url,
          method: Api.GetHuiQuanYiBanner.method,
          ...payload,
          success (res) {
            context.commit('UpdateQuanYiBanner', res.data.data.records)
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    GetIndexBanner (context, payload) { // 获取首页banner
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.GetIndexBanner.url,
          method: Api.GetIndexBanner.method,
          ...payload,
          success (res) {
            context.commit('UpdateIndexBanner', res.data.data.records)
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    GetPhotoList (context, payload) { // 获取照片墙列表
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.GetPhotoList.url,
          method: Api.GetPhotoList.method,
          ...payload,
          success (res) {
            context.commit('UpdatePhotoList', res.data.data.records)
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    GetActivityDetail (context, payload) { // 获取活动详情
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.GetActivityDetail.url,
          method: Api.GetActivityDetail.method,
          ...payload,
          success (res) {
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    },
    GetActivityList (context, payload) { // 获取活动列表
      return new Promise((resolve, reject) => {
        ToolClass.WxRequest({
          url: Api.GetActivityList.url,
          method: Api.GetActivityList.method,
          ...payload,
          success (res) {
            context.commit('UpdateActivityList', res.data.data.records)
            resolve(res)
          },
          error (res) {
            reject(res)
          }
        })
      })
    }
  }
}
