"use strict";
const common_vendor = require("../../../common/vendor.js");
require("../../../stores/dict.js");
require("../../../stores/user.js");
require("../../../utils/storage.js");
require("../../../utils/constant.js");
require("../../../utils/auth.js");
require("../../../utils/request.js");
require("../../../config.js");
require("../../../utils/errorCode.js");
require("../../../utils/common.js");
if (!Array) {
  const _easycom_u_navbar2 = common_vendor.resolveComponent("u-navbar");
  const _easycom_u_button2 = common_vendor.resolveComponent("u-button");
  const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  const _easycom_u_loadmore2 = common_vendor.resolveComponent("u-loadmore");
  const _easycom_u_empty2 = common_vendor.resolveComponent("u-empty");
  const _easycom_u__input2 = common_vendor.resolveComponent("u--input");
  const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
  const _easycom_u_datetime_picker2 = common_vendor.resolveComponent("u-datetime-picker");
  (_easycom_u_navbar2 + _easycom_u_button2 + _easycom_u_icon2 + _easycom_u_loadmore2 + _easycom_u_empty2 + _easycom_u__input2 + _easycom_u_popup2 + _easycom_u_datetime_picker2)();
}
const _easycom_u_navbar = () => "../../../node-modules/uview-plus/components/u-navbar/u-navbar.js";
const _easycom_u_button = () => "../../../node-modules/uview-plus/components/u-button/u-button.js";
const _easycom_u_icon = () => "../../../node-modules/uview-plus/components/u-icon/u-icon.js";
const _easycom_u_loadmore = () => "../../../node-modules/uview-plus/components/u-loadmore/u-loadmore.js";
const _easycom_u_empty = () => "../../../node-modules/uview-plus/components/u-empty/u-empty.js";
const _easycom_u__input = () => "../../../node-modules/uview-plus/components/u--input/u--input.js";
const _easycom_u_popup = () => "../../../node-modules/uview-plus/components/u-popup/u-popup.js";
const _easycom_u_datetime_picker = () => "../../../node-modules/uview-plus/components/u-datetime-picker/u-datetime-picker.js";
if (!Math) {
  (_easycom_u_navbar + _easycom_u_button + _easycom_u_icon + _easycom_u_loadmore + _easycom_u_empty + _easycom_u__input + _easycom_u_popup + _easycom_u_datetime_picker)();
}
const _sfc_main = {
  __name: "deviceLogs",
  setup(__props) {
    const { proxy } = common_vendor.getCurrentInstance();
    const instance = common_vendor.getCurrentInstance();
    const {
      device_log_type,
      device_type,
      mqtt_cmd_templet_task
    } = proxy.$useDict("device_log_type", "device_type", "mqtt_cmd_templet_task");
    const dicts = common_vendor.reactive({
      device_type: [],
      device_log_type: [],
      mqtt_cmd_templet_task: []
    });
    const searchMenu = common_vendor.reactive({
      showPopMenu: false,
      selStatus: 0,
      style: {
        marginTop: "174rpx"
      },
      searchMenu_body_style: {
        height: "600rpx"
      },
      params: {
        deviceId: void 0,
        type: void 0,
        beginLogBeginTime: void 0,
        endLogBeginTime: void 0
      }
    });
    function openSearchMenu() {
      searchMenu.showPopMenu = true;
      getTreeData();
    }
    function resetSearchMenu() {
      searchMenu.params.deviceId = void 0;
      searchMenu.params.type = void 0;
    }
    function doSearch(o) {
      if (o == 0)
        resetSearchMenu();
      setTimeout(function() {
        searchMenu.showPopMenu = false;
        data.curPage = 1;
        getList();
      }, 500);
    }
    function formatDate(time) {
      return time.getFullYear() + "-" + (time.getMonth() + 1 < 10 ? "0" : "") + (time.getMonth() + 1) + "-" + (time.getDate() < 10 ? "0" : "") + time.getDate() + " " + (time.getHours() < 10 ? "0" : "") + time.getHours() + ":" + (time.getMinutes() < 10 ? "0" : "") + time.getMinutes() + ":" + (time.getSeconds() < 10 ? "0" : "") + time.getSeconds();
    }
    const picLogMenu = common_vendor.reactive({
      showPopMenu: false,
      showTimePicker: false,
      selTimeIdx: 0,
      selTime: Number(new Date()),
      style: {
        marginTop: "174rpx"
      },
      searchMenu_body_style: {
        height: "600rpx"
      },
      params: {
        deviceId: void 0,
        logType: void 0,
        startTime: void 0,
        endTime: void 0
      },
      reqUrls: {
        sendCommand: "/device/mqtt/senCommand"
      }
    });
    function showTimePicker(idx) {
      picLogMenu.selTimeIdx = idx;
      if (0 == idx) {
        picLogMenu.selTime = Number(new Date(picLogMenu.params.startTime));
        console.log("--------", picLogMenu.params.startTime, new Date(picLogMenu.params.startTime));
      } else {
        picLogMenu.selTime = Number(new Date(picLogMenu.params.endTime));
      }
      picLogMenu.showTimePicker = true;
    }
    function onSelectTime(o) {
      var time = new Date(o.value);
      if (0 == picLogMenu.selTimeIdx) {
        picLogMenu.params.startTime = formatDate(time);
      } else {
        picLogMenu.params.endTime = formatDate(time);
      }
      console.log("----------", o, picLogMenu.selTime.toLocaleString(), time);
      picLogMenu.showTimePicker = false;
    }
    function onCancelSelectTime() {
      picLogMenu.showTimePicker = false;
    }
    function formatter(type, value) {
      if (type === "year") {
        return `${value}年`;
      }
      if (type === "month") {
        return `${value}月`;
      }
      if (type === "day") {
        return `${value}日`;
      }
      if (type === "hour") {
        return `${value}时`;
      }
      if (type === "minute") {
        return `${value}分`;
      }
      return value;
    }
    function openPicLogMenu() {
      picLogMenu.showPopMenu = true;
    }
    function sendCommand() {
      if (!picLogMenu.params.deviceId || picLogMenu.params.deviceId.length == 0) {
        proxy.$modal.msg("请填写机器编号~");
        return;
      }
      if (!picLogMenu.params.logType || picLogMenu.params.logType.length == 0) {
        proxy.$modal.msg("请选择指令类型~");
        return;
      }
      var templet = void 0;
      console.log(dicts.mqtt_cmd_templet_task);
      templet = JSON.parse(proxy.$getDictByCode(dicts.mqtt_cmd_templet_task, "log").value);
      templet.data.logType = picLogMenu.params.logType;
      templet.data.startTime = picLogMenu.params.startTime;
      templet.data.endTime = picLogMenu.params.endTime;
      var params = [{
        deviceId: picLogMenu.params.deviceId,
        templet
      }];
      console.log("------------", JSON.stringify(params));
      proxy.$request({
        url: picLogMenu.reqUrls.sendCommand,
        data: params,
        method: "post"
      }).then((res) => {
        console.log("***", res);
        proxy.$modal.msg("指令已下发~");
        resolve(res);
      }).catch((err) => {
        console.log("***", err);
      });
    }
    const data = common_vendor.reactive({
      reqUrls: {
        list: "/device/device-log/page"
      },
      curPage: 1,
      loadmoreStatus: "nomore",
      params: {
        readState: 1,
        priority: 1,
        page: {
          current: 1,
          size: 10,
          orders: [
            {
              asc: false,
              column: "create_time"
            }
          ]
        }
      },
      fullHeight: 0,
      screenHeight: 1920,
      // screenWidht:1080,
      dataList: [],
      total: 0
    });
    common_vendor.onMounted(() => {
      dicts.device_log_type = [{ value: null, label: "全部" }].concat(device_log_type.value);
      dicts.mqtt_cmd_templet_task = [{ value: null, label: "全部" }].concat(mqtt_cmd_templet_task.value);
      data.screenHeight = common_vendor.index.getSystemInfoSync().windowHeight;
      searchMenu.searchMenu_body_style.height = data.screenHeight - 90 + "px";
      var time = new Date();
      picLogMenu.params.startTime = formatDate(time);
      time.setTime(time.getTime() + 30 * 60 * 1e3);
      picLogMenu.params.endTime = formatDate(time);
      proxy.$refs.datetimePicker.setFormatter(formatter);
      getList();
      const query = common_vendor.index.createSelectorQuery().in(instance);
      query.select(".scrollview").boundingClientRect((r) => {
        common_vendor.index.getSystemInfo({
          success(res) {
            const model = res.model;
            const modelInclude = [
              "iPhone X",
              "iPhone XR",
              "iPhone XS",
              "iPhone XS MAX",
              "iPhone 12/13 mini",
              "iPhone 12/13 (Pro)",
              "iPhone 12/13 Pro Max",
              "iPhone 14 Pro Max"
            ];
            let safeDistance = modelInclude.includes(model);
            console.log(res.windowHeight, r.top);
            let h = 0;
            if (safeDistance) {
              h = res.windowHeight - r.top;
            } else {
              h = res.windowHeight - r.top;
            }
            data.fullHeight += h + "px";
          }
        });
      }).exec();
    });
    function scrolltolower() {
      if (data.loadmoreStatus == "nomore")
        return;
      data.curPage++;
      getList();
    }
    function getList() {
      return new Promise((resolve2, reject) => {
        data.params.page.current = data.curPage;
        data.params.deviceId = searchMenu.params.deviceId;
        data.params.type = searchMenu.params.type;
        if (data.curPage == 1) {
          data.dataList = [];
        }
        proxy.$request({
          url: data.reqUrls.list,
          data: data.params,
          method: "post"
        }).then((res) => {
          console.log("***", res);
          if (res.records) {
            data.dataList = data.dataList.concat(res.records);
          }
          data.total = res.total;
          if (res.records.length < 10) {
            data.loadmoreStatus = "nomore";
          } else {
            data.loadmoreStatus = "loadmore";
          }
          resolve2(res);
        }).catch((err) => {
          reject(err);
        });
      });
    }
    function showLog(file) {
      proxy.$tab.navigateTo(`/pages/xy_system/logs/logFile?file=${file}`);
    }
    function rightClick() {
      console.log("点击了右侧");
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.o(rightClick),
        b: common_vendor.p({
          title: "设备日志",
          titleStyle: "color:#fff;fontSize:36rpx;",
          bgColor: "#2C6FF3",
          autoBack: true,
          leftIconColor: "#fff",
          placeholder: true
        }),
        c: common_vendor.t(data.total),
        d: common_vendor.o(openPicLogMenu),
        e: common_vendor.p({
          size: "mini"
        }),
        f: common_vendor.o(getList),
        g: common_vendor.p({
          size: "mini"
        }),
        h: common_vendor.p({
          name: "arrow-right",
          size: "14"
        }),
        i: common_vendor.o(openSearchMenu),
        j: data.dataList.length > 0
      }, data.dataList.length > 0 ? common_vendor.e({
        k: common_vendor.f(data.dataList, (item1, index1, i0) => {
          return common_vendor.e({
            a: item1.deviceName
          }, item1.deviceName ? {
            b: common_vendor.t(item1.deviceId),
            c: common_vendor.t(item1.deviceId)
          } : {
            d: common_vendor.t(item1.deviceId)
          }, {
            e: common_vendor.t(common_vendor.unref(proxy).$getDictByValue(dicts.device_log_type, item1.type).label),
            f: common_vendor.t(item1.logName),
            g: common_vendor.o(($event) => showLog(item1.logName), item1.deviceId),
            h: common_vendor.t(item1.logBeginTime),
            i: common_vendor.t(item1.logEndTime),
            j: item1.deviceId
          });
        }),
        l: data.dataList.length > 0
      }, data.dataList.length > 0 ? {
        m: common_vendor.p({
          status: data.loadmoreStatus
        })
      } : {}) : {
        n: common_vendor.p({
          mode: "data",
          text: "数据为空"
        })
      }, {
        o: common_vendor.o(scrolltolower),
        p: data.fullHeight,
        q: common_vendor.o(($event) => searchMenu.params.deviceId = $event),
        r: common_vendor.p({
          placeholder: "请输入设备编号",
          border: "surround",
          modelValue: searchMenu.params.deviceId
        }),
        s: common_vendor.f(dicts.device_log_type, (item, index, i0) => {
          return {
            a: common_vendor.t(item.label),
            b: common_vendor.n(searchMenu.params.type == item.value ? "tab-item tab-show" : "tab-item"),
            c: common_vendor.o(($event) => searchMenu.params.type = item.value, item.value),
            d: item.value
          };
        }),
        t: common_vendor.o(($event) => doSearch(0)),
        v: common_vendor.p({
          size: "normal",
          plain: true,
          text: "关闭"
        }),
        w: common_vendor.o(resetSearchMenu),
        x: common_vendor.p({
          size: "normal",
          type: "primary",
          plain: true,
          text: "重置"
        }),
        y: common_vendor.o(($event) => doSearch(1)),
        z: common_vendor.p({
          size: "normal",
          type: "primary",
          text: "查找"
        }),
        A: common_vendor.s(searchMenu.searchMenu_body_style),
        B: common_vendor.p({
          show: searchMenu.showPopMenu,
          duration: "0",
          customStyle: searchMenu.style,
          round: 10,
          mode: "right",
          duration: 300,
          overlay: false
        }),
        C: common_vendor.o(($event) => picLogMenu.params.deviceId = $event),
        D: common_vendor.p({
          placeholder: "请输入设备编号",
          border: "surround",
          modelValue: picLogMenu.params.deviceId
        }),
        E: common_vendor.f(dicts.device_log_type, (item, index, i0) => {
          return {
            a: common_vendor.t(item.label),
            b: item.label != "全部",
            c: common_vendor.n(picLogMenu.params.logType == item.value ? "tab-item tab-show" : "tab-item"),
            d: common_vendor.o(($event) => picLogMenu.params.logType = item.value, item.value),
            e: item.value
          };
        }),
        F: common_vendor.o(($event) => picLogMenu.params.startTime = $event),
        G: common_vendor.p({
          placeholder: "",
          border: "surround",
          modelValue: picLogMenu.params.startTime
        }),
        H: common_vendor.o(($event) => showTimePicker(0)),
        I: common_vendor.o(($event) => picLogMenu.params.endTime = $event),
        J: common_vendor.p({
          placeholder: "",
          border: "surround",
          modelValue: picLogMenu.params.endTime
        }),
        K: common_vendor.o(($event) => showTimePicker(1)),
        L: common_vendor.sr("datetimePicker", "b96d7042-17,b96d7042-11"),
        M: common_vendor.o(onSelectTime),
        N: common_vendor.o(onCancelSelectTime),
        O: common_vendor.o(($event) => picLogMenu.selTime = $event),
        P: common_vendor.p({
          show: picLogMenu.showTimePicker,
          mode: "datetime",
          modelValue: picLogMenu.selTime
        }),
        Q: common_vendor.o(($event) => picLogMenu.showPopMenu = false),
        R: common_vendor.p({
          size: "normal",
          plain: true,
          text: "关闭"
        }),
        S: common_vendor.o(($event) => sendCommand()),
        T: common_vendor.p({
          size: "normal",
          type: "primary",
          text: "捞日志"
        }),
        U: common_vendor.s(searchMenu.searchMenu_body_style),
        V: common_vendor.p({
          show: picLogMenu.showPopMenu,
          duration: "0",
          customStyle: picLogMenu.style,
          round: 10,
          mode: "right",
          duration: 300,
          overlay: false
        })
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-b96d7042"], ["__file", "F:/兴元/开门柜项目/平台端管理系统小程序/src/pages/xy_system/logs/deviceLogs.vue"]]);
wx.createPage(MiniProgramPage);
