let app = getApp();
Page({
  data: {
    isSubmit: false,
    name: "",
    type: 1,
    content: ""
  },
  formSubmit: function (e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value);
    let { name, type, content } = e.detail.value;
    wx.request({  
      url: 'http://192.168.251.13:8091/api/saveorupdate', // 上传接口地址
      method:'POST',
      data:{
        name:name,
        type:type,
        content:content,
        status:1
      },
      header: {
        'content-type': 'application/json' // 设置请求头为json格式
      },
      success(res) {
        const data = res.data;
        console.log(data)
        // 根据实际返回的数据格式处理返回结果
        if (data.successful === true) {
          wx.showToast({
            title: '数据获取成功',
            icon: 'success',
            duration: 2000
          });
          wx.redirectTo({
            url: `/pages/record/record`,
          });
        } else {
          wx.showToast({
            title: '上传失败，请重试！',
            icon: 'none',
            duration: 2000
          });
        }
      },
      fail(err) {
        console.error('上传失败：', err);
        wx.showToast({
          title: '上传失败，请重试！',
          icon: 'none',
          duration: 2000
        });
      }
    });
    this.setData({
      name: "",
      type: 1,
      content: ""
    })
  },
  formReset: function () {
    console.log('form发生了reset事件')
  }
})