import request from '@/utils/request'
import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE } from '@/config/serviceSettings.js'
import Vue from 'vue'

export default {
  state: {
    // 通知列表
    remindData:null,
    count: {
      A: 0,
      B:0
    }

  },

  mutations: {
    // 写入通知数量
    SET_REMIND: (state, remindList) => {
      state.remindData = remindList
    },

  },
  actions: {
    getCountMessage({ commit,state }) {
      let p = {
        A:{
        noticeType: "A",
        whetherRead: "N"
      },
       B: {
          noticeType: "B",
          whetherRead: "N"
        }
      }
      for (let key in p) {
       request({
          url: UPCLOUD_RDC_TMS_MAINDATA_SERVICE + '/message/countMessage',
          method: 'post',
          data:p[key],
        }).then((response) => {
          if (response.success) {
            state.count[key]=response.data
          }
        })
      }
    },
    resetRemind({ commit }, data) {

     return request.post(UPCLOUD_RDC_TMS_MAINDATA_SERVICE + '/message/page', data).then(res => {
        if (res.success) {


          commit('SET_REMIND', res.data)
        } else {
          console.log(this)
          commit('SET_REMIND', null)
          Vue.prototype.$exception(res)
        }
      })
    }
  }
}
