// 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: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  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 (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),
      });
    }, 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);
        });
        that.setData({
          infoList: res.data.data.pageBean.recordList,
        });
      }
    })
    // 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,
      });
    }
  },
});
