//issues.js
//获取应用实例
const app = getApp()
const baseUrl = app.globalData.baseUrl
// console.log("baseUrl", baseUrl)

var util = require('../../utils/util')
Page({
  data: {
    title: '',
    content: '',
    time: ''
  },

  titleInput: function (e) {
    this.setData({
      title: e.detail.value
    })
  },

  contentInput: function (e) {
    this.setData({
      content: e.detail.value
    })
  },

  submit: function () {
    var TIME = util.formatTime(new Date());
    wx.request({
      url: `${baseUrl}/notice/addNotice`,
      data: {
        title: this.data.title,
        content: this.data.content,
        time: TIME,
      },
      success: function (d) {
        if (d.data != "提交失败") {
          wx.showToast({
            title: d.data,
            icon: 'success',
            duration: 2000,
            success: function () {
              setTimeout(function () {
                wx.switchTab({
                  url: '../home/home'
                })
              }, 2000);
            }
          })
        } else {
          wx.showToast({
            title: d.data,
            icon: 'error',
            duration: 2000
          })
        }
      }
    })
  },

  onLoad: function () {

  },

});
