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

Page({
  data: {
    device: {},
    swiperlist:[],
    imglist:[],
    record:null
  },
  onLoad: function (option) {
    var that = this;
    wx.getStorage({ //获取页面传递过来的数据
      key: 'gotopage',
      success(res) {
        var deviceinfo = res.data.devicedata;
        console.log(deviceinfo);
        if (!deviceinfo.device.imgs) {
          deviceinfo.device.imgs = [];
        } else {
          deviceinfo.device.imgs = deviceinfo.device.imgs.split(',');
        }
        if (!deviceinfo.deviceRecode) {
          that.setData({
            device: deviceinfo.device,
            swiperlist: deviceinfo.device.imgs
          });
        } else {
          if (!deviceinfo.deviceRecode.images) {
            deviceinfo.device.images = [];
          } else {
            deviceinfo.deviceRecode.images = deviceinfo.deviceRecode.images.split(',');
          }
          deviceinfo.deviceRecode.checkJson = JSON.parse(deviceinfo.deviceRecode.checkJson);
          that.setData({
            device: deviceinfo.device,
            swiperlist: deviceinfo.device.imgs,
            record: deviceinfo.deviceRecode,
            imglist: deviceinfo.deviceRecode.images
          });
        }
        wx.setNavigationBarTitle({
          title: deviceinfo.device.title
        });
      },
      fail(res) {
        wx.navigateBack({ delta: 1 });
        return false;
      }
    });
  },

  //图片预览
  previewImage: function (e) {
    var current = e.target.dataset.src;
    wx.previewImage({
      current: current, // 当前显示图片的http链接  
      urls: this.data.imglist, // 需要预览的图片http链接列表  
      success: function(e){}
    })
  },

  //查看更多
  deviceRecord: function(e){
    if (app.globalData.isTourist){
      wx.showToast({
        title: '游客模式无权限操作',
        icon: 'none',
        duration: 2000
      });
      return false;
    }
    var deviceId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/device/record/index?id=' + deviceId
    })
  }
})
