// pages/mallInfo.js
const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px';
var config = require("../../config/config.js");
var app = getApp();
const Http = require("../../utils/HttpBasics");
const imgurl = require("../../utils/imgurl");
const util = require("../../utils/util");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    teljpgUrl: imgurl.teljpg.url,
    navigationBarHeight,
    weekName:[],
    times:[],
    dateArr:[
      { name: "星期一", value: "0" },
      { name: "星期二", value: "1" },
      { name: "星期三", value: "2" },
      { name: "星期四", value: "3" },
      { name: "星期五", value: "4" },
      { name: "星期六", value: "5" },
      { name: "星期天", value: "6" }
    ],
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    console.log("渲染开始")
    Http.get({
      url: config.api.getMallInfo,
    })
      .then(res => {
        if (res.data.businessHours){
          let businessHours = JSON.parse(res.data.businessHours)
            businessHours.map((item, index) => {
              item.weekName = [that.data.dateArr.filter(e => e.value == item.week[0])[0].name, that.data.dateArr.filter(e => e.value == item.week[1])[0].name].toString().replace(/\,/g, '  --  '),
                item.time = [util.convertUTCTimeToLocalTime(item.time[0]), util.convertUTCTimeToLocalTime(item.time[1])].toString().replace(/\,/g, ' -')
            })
            console.log(businessHours, 222)
            that.setData({
              name: res.data.name,
              servicePhone: res.data.servicePhone,
              img: res.data.img,
              introduction: res.data.introduction,
              parkPlaceNumber: res.data.parkPlaceNumber,
              businessHoursH: businessHours,
            })
        } 
      })
      .catch(err => {
        wx.showModal({
          title: '提示',
          content: err.message,
          showCancel: false
        })
      })
  },
  phone: function (e) {
    let that = this;
    if (e.currentTarget.dataset.merchantlinkphone) {
      wx.makePhoneCall({
        phoneNumber: e.currentTarget.dataset.merchantlinkphone
      })
    }
  },
})