const app = require('../../utils/util.js');
const tools = require('../../utils/tools.js');
Page({
  data: {
    active: 0,
    wdArr: [],
    ydArr: [],
    showNull: false,
    showNull1: false
  },
  getArr(sessionKey) {
    wx.request({
      url: app.globalData.publicUrl + '/wx/eduNoticeSee/list',
      method: "post",
      data: {
        sessionKey: sessionKey,
        isSee: 1,
         isNotice: 0
      },
      success: (res) => {
        console.log(res);
        if (res.data.code == 0) {
          if (res.data.list.length !== 0) {
            this.setData({
              showNull: false,
              wdArr: res.data.list
            })
          } else {
            this.setData({
              wdArr: res.data.list,
              showNull: true
            })
          }
        } else {
          this.setData({
            showNull: true
          })
        }
      },
      fail: () => {
        this.setData({
          showNull: true
        })
      }
    })
  },
  getArr1(sessionKey) {
    wx.request({
      url: app.globalData.publicUrl + '/wx/eduNoticeSee/list',
      method: "post",
      data: {
        sessionKey: sessionKey,
        isSee: 0,
        isNotice: 0
      },
      success: (res) => {
        if (res.data.code == 0) {
          if (res.data.list.length !== 0) {
            this.setData({
              showNull1: false,
              ydArr: res.data.list
            })
          } else {
            this.setData({
              ydArr: res.data.list,
              showNull1: true
            })
          }
        } else {
          this.setData({
            showNull1: true
          })
        }
      },
      fail: () => {
        this.setData({
          showNull1: true
        })
      }
    })
  },
  async onChange(event) {
    if (event.detail.index == 1) {
      const sessionKey = await tools.checkSessionAndLogin();
      this.getArr1(sessionKey);
    }
  },
  meRead(sessionKey, noticeId) {
    wx.request({
      url: app.globalData.publicUrl + '/wx/eduNoticeSee/edit',
      method: "post",
      data: {
        sessionKey: sessionKey,
        isSee: 0,
        noticeId: noticeId
      },
      success: () => {
        this.getArr(sessionKey)
      }
    })
  },
  async btn(e) {
    let noticeId = e.currentTarget.dataset.item.noticeId;
    const sessionKey = await tools.checkSessionAndLogin();
    this.meRead(sessionKey, noticeId);
  },
  async onLoad() {
    const sessionKey = await tools.checkSessionAndLogin();
    this.getArr(sessionKey);
  }
})