<template>
  <u-sticky class="shadow-default" bgColor="#fff" style="top: 0">
    <u-tabs
      :list="state.tabsList"
      :current="state.tabsCurrent"
      @click="tabsClick"
      lineColor="#333"
      :activeStyle="{ color: '#333', fontSize: '14px' }"
      :inactiveStyle="{ color: '#909399', fontSize: '14px' }"
      :scrollable="false"
    ></u-tabs>
  </u-sticky>

  <oa-scroll
    customClass="scroll-height"
    :pageSize="state.pageSize"
    :total="state.total"
    :isSticky="true"
    :refresherLoad="true"
    :refresherEnabled="true"
    :refresherDefaultStyle="'none'"
    :refresherThreshold="44"
    :lowerThreshold="44"
    :refresherBackground="'#f5f6f7'"
    @load="load"
    @refresh="refresh"
    :data-theme="'theme-' + proxy.$settingStore.themeColor.name"
  >
    <template #default>
      <view class="alarmDetailsList-container">
        <view class="menu-list m0">
          <view class="list-cell list-cell-arrow" v-for="(base, index) in state.dataList" :key="index" @click="handleToDetails(base)">
            <view class="menu-item" style="font-size: 13px; flex-flow: row wrap">
              <view class="mb5" style="min-width: 80%; color: #909399"> {{ base.alarmTime }}</view>
              <view class="mb5 pr15" style="min-width: 20%; color: #909399; text-align: right"> {{ base.alarmGrade }}级</view>
              <view class="mb5" style="min-width: 80%; color: #909399">{{ base.deviceName }}</view>
              <view class="mb5 pr15" style="min-width: 20%; text-align: right" :style="`color:${base.handleStatus == 1 ? '#16bf00' : 'red'}`">
                {{ base.handleStatus == 1 ? "已处理" : "未处理" }}
              </view>
              <view class="pr15" style="min-width: 50%">{{ base.alarmContent }}</view>
            </view>
          </view>
        </view>
      </view>
    </template>
  </oa-scroll>
</template>

<script setup>
/*----------------------------------依赖引入-----------------------------------*/
import { onLoad, onShow, onReady, onHide, onLaunch, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
import { ref, reactive, computed, getCurrentInstance, toRefs, inject } from "vue";
/*----------------------------------接口引入-----------------------------------*/
import { baseAlarmList } from "@/api/business/fireIot/alarmManage.js";
/*----------------------------------组件引入-----------------------------------*/
/*----------------------------------store引入-----------------------------------*/
import { useStores, commonStores } from "@/store/modules/index";
/*----------------------------------公共方法引入-----------------------------------*/
/*----------------------------------公共变量-----------------------------------*/
const { proxy } = getCurrentInstance();
const commonStore = commonStores();
/*----------------------------------变量声明-----------------------------------*/
const state = reactive({
  tabsList: [
    { name: "全部", value: "" },
    { name: "未处理", value: 0 },
    { name: "已处理", value: 1 },
  ],
  tabsCurrent: 0,

  dataList: [],
  productCode: "",
  productName: "",
  pageSize: 20,
  current: 1,
  total: 0,
});

/**
 * @页面初始化
 */
function init() {
  selectListApi();
}

/**
 * @列表查询
 * @api接口查询
 */
function selectListApi() {
  baseAlarmList({
    productCode: state.productCode,
    handleStatus: state.tabsList[state.tabsCurrent].value,
    current: state.current,
    size: state.pageSize,
  }).then((requset) => {
    if (requset.status === "SUCCESS") {
      state.dataList = requset.data.records;
      state.total = requset.data.total;

      uni.setNavigationBarTitle({
        title: `${state.productName}（${state.total}）`,
      });
    }
  });
}

/**
 * @跳转详情事件
 */
function handleToDetails(e) {
  proxy.$tab.navigateTo(`/pages/business/fireIot/alarmManage/alarmDetails/index?deviceId=${e.deviceId}&alarmTime=${e.alarmTime}`);
}

/**
 * @scrollView加载数据
 */
function load() {
  state.pageSize += 10;
  init();
}

/**
 * @scrollView刷新数据
 */
function refresh() {
  state.pageSize = 20;
  init();
}

/**
 * @tabs点击事件
 */
function tabsClick(e) {
  state.tabsCurrent = e.index;
  init();
}

onReady(() => {});

onShow(() => {
  //调用系统主题颜色
  proxy.$settingStore.systemThemeColor([1]);
});

onLoad((options) => {
  if ("productName" in options) {
    state.productName = options.productName;
  }
  if ("productCode" in options) {
    state.productCode = options.productCode;
    init();
  }
});
</script>

<style lang="scss" scoped>
.alarmDetailsList-container {
}
</style>
