From 7408718077dce5375650999e44654444b7b8cae8 Mon Sep 17 00:00:00 2001
From: tanghaolin <1723298894@qq.com>
Date: 星期五, 04 十一月 2022 17:07:42 +0800
Subject: [PATCH] 增加告警记录按日期查询

---
 video/single/index.js |  327 +++++++++++++++++++++++++++++++++---------------------
 1 files changed, 198 insertions(+), 129 deletions(-)

diff --git a/video/single/index.js b/video/single/index.js
index 8e6f6df..6cce8ff 100644
--- a/video/single/index.js
+++ b/video/single/index.js
@@ -1,6 +1,6 @@
 var Constant = require('../../utils/constant.js');
 var app = getApp();
-import Request  from "../../utils/api"
+import Request from "../../utils/api"
 let Utils = require('../../utils/util');
 /**
  * ifRotate:鏄惁鍙棆杞�
@@ -29,23 +29,32 @@
 Page({
   data: {
     list: {
-      Code:"",
-      Name:"",
-      SeriesNO:"",
-      IsRotateAble:true,
-      IsZoomble:false,
-      TokenInfo:{
-        LiveUrl:"",
-        ViewToken:"at.cbyr6wyr12q4av8b35ha4zrs8e8xzzuk-26knzphnzo-10wmjk6-kyxbisivp",
-      }
+      Code: "",
+      Name: "",
+      SeriesNO: "",
+      IsRotateAble: true,
+      IsZoomble: false,
+      TokenInfo: {
+        LiveUrl: "",
+        ViewToken: "at.cbyr6wyr12q4av8b35ha4zrs8e8xzzuk-26knzphnzo-10wmjk6-kyxbisivp",
+      },
     },
-    Name:"",
+    Name: "",
     moreVideo: [],
     fullScreen: false, // 鎿嶄綔鏄惁鏄剧ず
-    btnCmd:"",//褰撳墠鎿嶄綔鐨刢md鎸夐挳
-    videoTabBarIndex:1, //褰撳墠鐨則abbar绱㈠紩
-    isLoadingDeviceAlarmList:false,//鏄惁鍔犺浇浜嗚澶囧憡璀﹁褰�
-    deviceAlarmList:[],//璁惧鍛婅鍒楄〃
+    btnCmd: "", //褰撳墠鎿嶄綔鐨刢md鎸夐挳
+    videoTabBarIndex: 1, //褰撳墠鐨則abbar绱㈠紩
+    isLoadingDeviceAlarmList: false, //鏄惁鍔犺浇浜嗚澶囧憡璀﹁褰�
+    deviceAlarmList: [], //璁惧鍛婅鍒楄〃
+    alarmPageIndex: 0,
+    alarmPageSize: 10,
+    isLoadingAllDeviceAlarmListData: false, //鏄惁鍔犺浇浜嗗叏閮ㄧ殑鍛婅鍒楄〃鏁版嵁
+    isLoad:false,//鍒楄〃鍔犺浇鐘舵��
+    isShowLoadItem:true, //鏄惁鏄剧ず鍔犺浇妗�
+    alarmDate:Utils.getDay("",new Date()) ,
+    currentDate:Utils.getDay("",new Date()),
+    startTime:Date.parse(new Date(new Date(Utils.getDay("",new Date())).setHours(0, 0, 0, 0))),
+    endTime: Date.parse(new Date())
   },
   onLoad(options) {
     this.videoContext = wx.createVideoContext('myVideo')
@@ -60,7 +69,7 @@
         title: videoInfo.Name,
       })
       that.setData({
-        Name:videoInfo.Name
+        Name: videoInfo.Name
       })
     }
     if (options.more == 'CA') {
@@ -70,9 +79,9 @@
       return;
     }
     that.setData({
-      list:videoInfo
+      list: videoInfo
     })
-    console.log(videoInfo,"videoInfo")
+    // console.log(videoInfo,"videoInfo")
     that.getVideoAddressSrc(videoInfo);
 
   },
@@ -105,123 +114,184 @@
     }
   },
 
-//鑾峰彇鎵�鏈夌殑瑙嗛鍒楄〃鐨勬挱鏀捐矾寰�
-getVideoAddressSrc(videoInfo){
-  let that = this
-  // console.log(token,deviceNo + ":" + channelNo,132)
-  wx.request({
-    url: Constant.YING_SHI_URL + "api/lapp/live/address/get",
-    header: {
-      'content-type': 'application/x-www-form-urlencoded'
-    },
-    method: 'POST',
-    data: {
-      accessToken : videoInfo.ViewToken,
-      source:videoInfo.SeriesNO + ":" + videoInfo.ChannelNo
-    },
-    success: function (res) {
-        console.log(res, '鎽勫儚澶存挱鏀惧湴鍧�')
-      let m_allVideoAddressInfo = res.data.data;
-      var m_caremaList = that.data.list;
-      m_caremaList.LiveUrl = m_allVideoAddressInfo[0].hlsHd
-      // console.log(m_caremaList,140)
+  //鑾峰彇鎵�鏈夌殑瑙嗛鍒楄〃鐨勬挱鏀捐矾寰�
+  getVideoAddressSrc(videoInfo) {
+    let that = this
+    // console.log(token,deviceNo + ":" + channelNo,132)
+    wx.request({
+      url: Constant.YING_SHI_URL + "api/lapp/live/address/get",
+      header: {
+        'content-type': 'application/x-www-form-urlencoded'
+      },
+      method: 'POST',
+      data: {
+        accessToken: videoInfo.ViewToken,
+        source: videoInfo.SeriesNO + ":" + videoInfo.ChannelNo
+      },
+      success: function (res) {
+        // console.log(res, '鎽勫儚澶存挱鏀惧湴鍧�')
+        let m_allVideoAddressInfo = res.data.data;
+        var m_caremaList = that.data.list;
+        m_caremaList.LiveUrl = m_allVideoAddressInfo[0].hlsHd
+        // console.log(m_caremaList,140)
 
-      m_caremaList.Code = m_allVideoAddressInfo[0].deviceName
-      m_caremaList.Name= that.data.Name
-      m_caremaList.SeriesNO = m_allVideoAddressInfo[0].deviceSerial
-      m_caremaList.IsRotateAble= true
-      m_caremaList.IsZoomble= false
+        m_caremaList.Code = m_allVideoAddressInfo[0].deviceName
+        m_caremaList.Name = that.data.Name
+        m_caremaList.SeriesNO = m_allVideoAddressInfo[0].deviceSerial
+        m_caremaList.IsRotateAble = true
+        m_caremaList.IsZoomble = false
 
-      that.setData({
-        list: m_caremaList
-      })
-      // that.getVideoPalyBackSrc()
-      //  console.log(that.data.list,"list")
-       
-    },
-    fail: function (res) {
-      console.log('澶辫触')
-    },
-  })
-},
-//鑾峰彇瑙嗛鍥炴斁璺緞
-getVideoPalyBackSrc(){
-  let that = this
-  let m_caremaInfo = that.data.list
-  console.log(m_caremaInfo,181181)
-  // console.log(token,deviceNo + ":" + channelNo,132)
-  wx.request({
-    url: Constant.YING_SHI_URL + "api/lapp/v2/live/address/get",
-    header: {
-      'content-type': 'application/x-www-form-urlencoded'
-    },
-    method: 'POST',
-    data: {
-      accessToken : m_caremaInfo.TokenInfo.ViewToken,
-      deviceSerial:m_caremaInfo.SeriesNO,
-      protocol:1,
-      startTime:"2022-10-13 00:00:00",
-      stopTime:"2022-10-18 00:00:00",
-      type:2
-    },
-    success: function (res) {
-        console.log(res, '鎽勫儚澶村洖鏀惧湴鍧�')
-    },
-    fail: function (res) {
-      console.log('澶辫触')
-    },
-  })
-},
-//鑾峰彇璁惧鍛婅淇℃伅鍒楄〃
-getAlarmByDeviceList(){
-  let _this = this
-  // console.log(_this.data.list,175)
-wx.request({
-  url: Constant.YING_SHI_URL +'api/lapp/alarm/device/list',
-  header: {
-    'content-type': 'application/x-www-form-urlencoded'
+        that.setData({
+          list: m_caremaList
+        })
+        // that.getVideoPalyBackSrc()
+        //  console.log(that.data.list,"list")
+
+      },
+      fail: function (res) {
+        console.log('澶辫触')
+      },
+    })
   },
-  method: 'POST',
-  data:{
-    accessToken:_this.data.list.ViewToken,
-    deviceSerial:_this.data.list.SeriesNO,
+  //鑾峰彇瑙嗛鍥炴斁璺緞
+  getVideoPalyBackSrc() {
+    let that = this
+    let m_caremaInfo = that.data.list
+    // console.log(m_caremaInfo,181181)
+    // console.log(token,deviceNo + ":" + channelNo,132)
+    wx.request({
+      url: Constant.YING_SHI_URL + "api/lapp/v2/live/address/get",
+      header: {
+        'content-type': 'application/x-www-form-urlencoded'
+      },
+      method: 'POST',
+      data: {
+        accessToken: m_caremaInfo.TokenInfo.ViewToken,
+        deviceSerial: m_caremaInfo.SeriesNO,
+        protocol: 1,
+        startTime: "2022-10-13 00:00:00",
+        stopTime: "2022-10-18 00:00:00",
+        type: 2
+      },
+      success: function (res) {
+        // console.log(res, '鎽勫儚澶村洖鏀惧湴鍧�')
+      },
+      fail: function (res) {
+        console.log('澶辫触')
+      },
+    })
   },
-  success:res=>{
-     console.log(res,188)
-    if(res.data.code==200){
-      let arr= []
-      res.data.data.forEach(item=>{
-        item.alarmTime = Utils.formatDay(new Date(item.alarmTime))
-        arr.push(item)
-      })
-      _this.setData({
-        deviceAlarmList:arr,
-        isLoadingDeviceAlarmList:true
-      })
+  //褰撴姤璀﹀垪琛ㄥ姞杞藉埌搴曢儴鐨勬椂鍊欏埛鏂版暟鎹�
+  toLowerLoadAlarmList(){
+    this.getAlarmByDeviceList()
+  },
+  //鑾峰彇璁惧鍛婅淇℃伅鍒楄〃
+  getAlarmByDeviceList() {
+    let _this = this
+    wx.request({
+      url: Constant.YING_SHI_URL + 'api/lapp/alarm/device/list',
+      header: {
+        'content-type': 'application/x-www-form-urlencoded'
+      },
+      method: 'POST',
+      data: {
+        accessToken: _this.data.list.ViewToken,
+        deviceSerial: _this.data.list.SeriesNO,
+        pageStart: _this.data.alarmPageIndex,
+        pageSize: _this.data.alarmPageSize,
+        startTime:_this.data.startTime,
+        endTime: _this.data.endTime
+      },
+      success: res => {
+          console.log(res, 188)
+        _this.setData({
+          isLoad:true,
+          isShowLoadItem:false
+        })
+        if (res.data.code == 200) {
+          if(res.data.data.length == 0){
+            _this.setData({
+              isShowLoadItem:true
+            })
+            return
+          }
+          let arr = []
+          if (_this.data.deviceAlarmList.length < res.data.page.total) {
+            res.data.data.forEach(item => {
+              item.alarmTime = Utils.formatTime(new Date(item.alarmTime))
+              item.alarmType = _this.getAlarmTypeEnum(item.alarmType)
+              arr.push(item)
+            })
+            _this.setData({
+              alarmPageIndex: ++ _this.data.alarmPageIndex,
+              deviceAlarmList: _this.data.deviceAlarmList.concat(arr),
+              isLoadingDeviceAlarmList: true
+            })
+          }
+          if (_this.data.deviceAlarmList.length == res.data.page.total) {
+            _this.setData({
+              isLoadingAllDeviceAlarmListData: true,
+              // isShowLoadItem:true
+            })
+            return
+          }
+        }
+      },
+      fail: err => {
+        console.log(err, 191)
+      }
+    })
+  },
+  // 鑾峰彇璀﹀憡绫诲瀷鏋氫妇
+  getAlarmTypeEnum(type){
+    if(type == 10002){
+      return type = "绉诲姩渚︽祴鍛婅"
     }
   },
-  fail:err=>{
-    console.log(err,191)
-  }
-})
-},
-//鐩戞帶鍔熻兘tabBar鍒囨崲 
-videoTabBarChange(e){
-  // console.log(e,173)
-  if(e.currentTarget.dataset.id == 2 && !this.data.isLoadingDeviceAlarmList){
+  //鐩戞帶鍔熻兘tabBar鍒囨崲 
+  videoTabBarChange(e) {
+    // console.log(e,173)
+    if (e.currentTarget.dataset.id == 2 && !this.data.isLoadingDeviceAlarmList) {
       this.getAlarmByDeviceList()
-  }
-  this.setData({
-    videoTabBarIndex:e.currentTarget.dataset.id
-  })
-},
+    }
+    this.setData({
+      videoTabBarIndex: e.currentTarget.dataset.id
+    })
+  },
+  //鍛婅鏌ヨ鏃ユ湡閫夋嫨
+  alarmDateChange(e){
+    // console.log(e,258)
+    let startTime = ""
+    let endTime = ""
+    let selectDate = Date.parse(new Date(e.detail.value))
+    let currentDate = Date.parse(new Date())
+    //鍒ゆ柇閫夋嫨鐨勬棩鏈熶笌浠婂ぉ鏄笉鏄悓涓�澶�
+    if(selectDate == currentDate){
+      startTime = Date.parse(new Date(new Date(Utils.getDay("",new Date())).setHours(0, 0, 0, 0)))
+      endTime = Date.parse(new Date())
+    }else {
+      startTime = Date.parse(new Date(new Date(e.detail.value).setHours(0, 0, 0, 0)))
+      endTime = Date.parse(new Date(new Date(e.detail.value).setHours(23, 59, 0, 0)))
+    }
+
+    // console.log(selectDate,currentDate,266)
+    this.setData({
+      deviceAlarmList:[],
+      alarmDate:e.detail.value,
+      alarmPageIndex:0,
+      alarmPageSize:10,
+      startTime:startTime,
+      endTime:endTime,
+    })
+    this.getAlarmByDeviceList()
+  },
   fullScreenStart(e) {
     var that = this;
     var m_caremaList = that.data.list;
     var i = 1;
     var cmd = e.currentTarget.dataset.cmd;
     that.setData({
-      btnCmd:e.currentTarget.dataset.direction
+      btnCmd: e.currentTarget.dataset.direction
     })
     wx.request({
       url: Constant.YING_SHI_URL + "api/lapp/device/ptz/start",
@@ -251,7 +321,7 @@
     var i = 1;
     var cmd = e.currentTarget.dataset.cmd;
     that.setData({
-      btnCmd:""
+      btnCmd: ""
     })
     wx.request({
       url: Constant.YING_SHI_URL + "api/lapp/device/ptz/stop",
@@ -267,7 +337,7 @@
         speed: 1,
       },
       success: function (res) {
-          // console.log(res, i, cmd,'鎴愬姛fullScreenEnd')
+        // console.log(res, i, cmd,'鎴愬姛fullScreenEnd')
       },
       fail: function (res) {
         console.log('澶辫触')
@@ -289,16 +359,15 @@
     var videoTime = e.detail
     this.setData({
       videoTime: {
-        currentTime: videoTime.currentTime?videoTime.currentTime:0,
-        duration: videoTime.duration?videoTime.duration:0
+        currentTime: videoTime.currentTime ? videoTime.currentTime : 0,
+        duration: videoTime.duration ? videoTime.duration : 0
       }
     })
   },
-  toPlayBack(){
-    console.log(this.data.moreVideo,305)
+  toPlayBack() {
+    // console.log(this.data.moreVideo,305)
     wx.navigateTo({
       url: '../playBack/index',
     })
   },
-
 })
\ No newline at end of file

--
Gitblit v1.9.3