const util = require('../../../../utils/util.js');

//获取应用实例
var app = getApp()

Page({
    data: {
        // 幻灯片数据
        slideList: [],
        // 最新动态列表
        newsList: [],
        // 产品列表
        goodsList: [],

        img: '#',
        title: '微先锋企业小程序系统',
      intro: '微先锋企业小程序系统由【微先锋www.vXianFeng.com】开发提供！微先锋为您提供微商城源码,三级分销商城源码,山寨币源码,返现平台源码,山寨区块链源码,资金池源码,直销系统源码,小程序,公众号,免费下载',
      contact: '微先锋',
      mobile: "	130-6066-8161",
      email: "	894849526@qq.com",
      address: "广州市天河区天河软件园建工路",
      windowWidth: wx.getSystemInfoSync().windowWidth, // 宽度,
      windowHeight: wx.getSystemInfoSync().windowHeight, // 高度,
    },
    onLoad: function () {
        var that = this;
        /* wx.getSystemInfo({
            success: function (res) {
                that.setData({
                    windowHeight: res.windowHeight + "px",
                    windowWidth: res.windowWidth + "px",
                });
            }
        }); */

        // 幻灯片列表
        util.AJAX("/slide/index", function (res) {
            //console.log(JSON.stringify(res));
            // 重新写入数据
            wx.setNavigationBarTitle({
              title:res.data.data.basedata.title
            }) ;
            that.setData({
                slideList: res.data.data.list,
                img: res.data.data.basedata.logo,
                intro: res.data.data.basedata.intro,
                contact: res.data.data.basedata.contact,
                mobile:  res.data.data.basedata.mobile,
                email: res.data.data.basedata.email,
                address: res.data.data.basedata.address,
            });
        }, { "limit": 5 });

        // 新闻列表
        util.AJAX("/article/index", function (res) {
            var newsList = res.data.data.list;
            if (newsList) {
                for (var i = 0; i < newsList.length; i++) {
                    var time = util.getTime(newsList[i]['pubdate']);
                    newsList[i]['pubdate'] = time['Y'] + '-' + time['m'] + '-' + time['d'];
                }
            }

            // 重新写入数据
            that.setData({
                newsList: newsList
            });
        },{typeid:2});

        // 产品列表
        util.AJAX("/goods/index", function (res) {
            var goodsList = res.data.data.list;
            if (goodsList) {
                for (var i = 0; i < goodsList.length; i++) {
                    var time = util.getTime(goodsList[i]['pubdate']);
                    goodsList[i]['pubdate'] = time['Y'] + '-' + time['m'] + '-' + time['d'];
                }
            }

            // 重新写入数据
            that.setData({
                goodsList: goodsList
            });
        }, { "limit": 8 });
    },
    //打电话
    makePhoneCall: function () {
        wx.makePhoneCall({
            phoneNumber: this.data.mobile,
            success: function () {
                console.log("成功拨打电话")
            }
        })
    }
})