//index.js
//获取应用实例
const app = getApp()
import fetch from '../../../utils/http'
const $api = require('../../../config/api.js').$api;

Component({
  behaviors: [],
  properties: {},
  banner: [],
  data: {
    UserInfo: app.globalData.UserInfo,
    TopNavList: [{
      value: '楼盘展示',
      icon: '/assets/images/icon5.png',
      remark: '银城在售全部楼盘'
    }, {
      value: '购房工具',
      icon: '/assets/images/icon6.png',
      remark: '查公积金、算房贷、看政策'
    }, {
      value: '电话咨询',
      icon: '/assets/images/icon7.png',
      remark: '24小时电话客服热线：025-12345678'
    }],
    EstateList: []
  },
  lifetimes: {},
  ready: function() {
    wx.setNavigationBarTitle({
      title: '银城地产·江北公司'
    })
    const _that = this
    fetch({
      url: $api.banner.list.url,
      method: $api.banner.list.method,
      data: {
        imgLocation: 'firstPage'
      }
    }).then((imgs) => {
      _that.setData({
        banner: imgs.data
      })
    })

    fetch({
      url: $api.dynamic.list.url,
      method: $api.dynamic.list.method,
      data: {
        pageNum: 1,
        pageSize: 10
      }
    }).then((dynamics) => {
      const records = dynamics.data.records.map(x => {
        return {
          ...x,
          createDate: x.createDate.slice(2,10)
        }
      })
      _that.setData({
        EstateList: records
      })
    })
  },
  pageLifetimes: {
    show: function() {},
  },
  methods: {
    TopNavTap(e) { // topnav点击事件
      if (e.target.dataset.type === 0) { // 楼盘展示
        this.triggerEvent('myevent', {
          index: 1
        })
      } else if (e.target.dataset.type === 1) { // 购房工具
        wx.navigateTo({
          url: '/pages/SelfServiceTool/index'
        })
      } else if (e.target.dataset.type === 2) { // 电话咨询
        wx.makePhoneCall({
          phoneNumber: '025-12345678'
        })
      }
    }
  }
})