// pages/message/index.js
const app = getApp();
import dateUtil from "../../utils/dateUtil";
import { customRequest } from '../../utils/request.js';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isLogin: app.globalData.isLogin,
    serviceInfo: {},
    iosDialog: false,
    isLoading: true,
    messageClick: false,
    infoList: [],
    list: [
      {
        title: '平台消息',
        url: '/subPage/systemMessage/index',
        img: '../../assets/images/ptxx.svg',
        content: '新春祝福与品牌升级...',
        time: '下午 2:30',
      },
      {
        title: '每日发单',
        url: '/subPage/todayBill/index',
        img: '../../assets/images/mrfd.svg',
        content: '按偏好订阅每日接收推送',
        time: '下午 1:30',
      },
      // {
      //   title: '发单助手',
      //   url: '/subPage/todayBill/index',
      //   img: '../../assets/images/fadan.svg',
      //   content: '按偏好订阅每日接收推送',
      //   time: '下午 1:30',
      // },
      // {
      //   title: '报名助手',
      //   url: '/subPage/todayBill/index',
      //   img: '../../assets/images/baoming.svg',
      //   content: '按偏好订阅每日接收推送',
      //   time: '下午 1:30',
      // },
      // {
      //   title: '账单助手',
      //   url: '/subPage/todayBill/index',
      //   img: '../../assets/images/zhangdan.svg',
      //   content: '按偏好订阅每日接收推送',
      //   time: '下午 1:30',
      // },
      // {
      //   title: '智能匹配助手', 
      //   url: '/subPage/chat/index?title=智能匹配助手',
      //   img: '../../assets/images/chat.svg',
      //   content: 'AI大模型智能匹配',
      //   time: '下午 1:30',
      // },

    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    this.setData({
      messageClick: wx.getStorageSync("messageClick" + app.globalData.loginUserInfo.id),
    });
    console.log(this.data.messageClick);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady () { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {
    // let serviceInfo =  wx.getStorageSync('ServiceInfo')
    this.getInfoList();
    console.log('messageTab' + typeof this.getTabBar);
    if (app.globalData.appId == 'wxe431e0b3abd9ae0b') {
      this.data.list = [{
        title: '平台消息',
        url: '/subPage/systemMessage/index',
        img: '../../assets/images/ptxx.svg',
        content: '新春祝福与品牌升级',
        time: '下午 2:30',
      },
      {
        title: '每日发单',
        url: '/subPage/todayBill/index',
        img: '../../assets/images/mrfd.svg',
        content: '按偏好订阅每日接收推送',
        time: '下午 1:30',
      },
      {
        title: '发单助手',
        url: '/subPage/todayBill/index',
        img: '../../assets/images/fadan.svg',
        content: '按偏好订阅每日接收推送',
        time: '下午 1:30',
      },
      {
        title: '报名助手',
        url: '/subPage/todayBill/index',
        img: '../../assets/images/baoming.svg',
        content: '按偏好订阅每日接收推送',
        time: '下午 1:30',
      },
      {
        title: '账单助手',
        url: '/subPage/todayBill/index',
        img: '../../assets/images/zhangdan.svg',
        content: '按偏好订阅每日接收推送',
        time: '下午 1:30',
      },
      {
        title: '智能匹配助手',
        url: '/subPage/chat/index?title=智能匹配助手',
        img: '../../assets/images/chat.svg',
        content: 'AI大模型智能匹配',
        time: '下午 1:30',
      }]
    } else if (app.globalData.appId == 'wxb0dea4d11428c6a5') {
      this.data.list = [
        {
          title: '平台消息',
          url: '/subPage/systemMessage/index',
          img: '../../assets/images/ptxx.svg',
          content: '新春祝福与品牌升级',
          time: '下午 2:30',
        },
        {
          title: '每日发单',
          url: '/subPage/todayBill/index',
          img: '../../assets/images/mrfd.svg',
          content: '按偏好订阅每日接收推送',
          time: '下午 1:30',
        },
      ]
    }
    if (typeof this.getTabBar === "function" && this.getTabBar()) {
      this.getTabBar().setData({
        isShow: true,
        selected: 2,
      });
    }
    setTimeout(() => {
      this.setData({
        serviceInfo: app.globalData.serviceInfo,
        isLoading: true,
        messageClick: wx.getStorageSync("messageClick" + app.globalData.loginUserInfo.id),
        list: this.data.list
      });
    }, 10);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide () {
    this.setData({
      iosDialog: false,
    });
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload () { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh () { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom () { },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage () {
    return app.sharePageImage()
  },

  makePhoneCall () {
    console.log(1);
    var that = this;
    wx.makePhoneCall({
      // number: that.data.jobDetail.assistantUserTel + ""
      phoneNumber: that.data.serviceInfo.workPhone || "0371-6611 3723",
    });
  },

  showdialog () {
    this.setData({
      iosDialog: true,
      loading: true,
    });
  },
  closeDialog () {
    this.setData({
      iosDialog: false,
    });
  },
  imageLoad () {
    this.setData({
      isLoading: false,
    });
  },
  getInfoList () {
    let that = this;
    customRequest("/bocai/cms/list", { header: 'headers', method: 'post', data: { pageSize: 100, pageNum: 1, keys: "" } }).then((res) => {
      if (res.data.status == 200) {
        res.data.data.pageBean.recordList.forEach(item => {
          item['pubTime'] = dateUtil.timeShow(item.publishTime);
          console.log(item);
        });
        this.data.list[0].content = res.data.data.pageBean.recordList[0].title;
        that.setData({
          infoList: res.data.data.pageBean.recordList,
          list: this.data.list
        });
      }
    })
    // wx.request({
    //   url: app.globalData.ip + "/bocai/cms/list",
    //   data: { pageSize: 100, pageNum: 1, keys: "" },
    //   header: app.globalData.headers,
    //   method: "post",
    //   success: function (res) {
    //     console.log(res);
    //     if (res.data.status == 200) {
    //       res.data.data.pageBean.recordList.forEach(item => {
    //         item['pubTime'] = dateUtil.timeShow(item.publishTime);
    //         console.log(item);
    //       });
    //       that.setData({
    //         infoList: res.data.data.pageBean.recordList,
    //       });
    //     }
    //   },
    // });
  },
  /**
   * 阻止滑动穿透
   *
   *
   */
  modalMove () {
    return false;
  },
  goDetail (e) {
    console.log(e);
    if (e.currentTarget.dataset.type == "wellcome") {
      wx.setStorageSync("messageClick" + app.globalData.loginUserInfo.id, true);
      wx.navigateTo({
        url: "/pages/messageDetail/index?type=1",
      });
    } else {
      wx.navigateTo({
        url: "/pages/messageDetail/index?id=" + e.currentTarget.dataset.id,
      });
    }
  },
});
