<template>
  <div class="my-alert">
    <div class="breadcrumb"></div>
    <div class="content">
      <bg-table-list>
        <template #filter>
          <bg-filter-form
            :keyword="search"
            placeholder="请输入预警点"
            :options="filter_data"
            @keyword="keywordAction"
            @filters="get_filter_list"
          >
          </bg-filter-form>
        </template>

        <template #main>
          <bg-table
            ref="listtable"
            :headers="headers"
            :rows="rows"
            height="100%"
            :isIndex="true"
            :stripe="true"
          >
            <template #warning_point="{ row, header }">
              <BgTableHref :row="row" :header="header"></BgTableHref>
            </template>
            <template #operation="{ row }">
              <span class="primary-edit" @click="operation(row)">
                处置反馈
              </span>
            </template>
          </bg-table>
        </template>
        <template #footer>
          <bg-pagination
            :pagination="pagination"
            @sizechange="sizechange"
            @current="current"
          >
          </bg-pagination>
        </template>
      </bg-table-list>
      <!-- <el-button type="primary" size="default" @click="feedback">
        处置反馈
      </el-button> -->
      <!-- <ManualDistributionForm ref="form" :disabled="true" /> -->
      <FeedBack v-model:visible="visible" :active_row="active_row" />
      <!-- <ManualDistribution v-model:visible="visible" /> -->
    </div>
  </div>
</template>

<script setup>
// import { nextTick, onBeforeMount, onMounted, ref } from "vue";
// import ManualDistribution from "@/components/manual-distribution/index.vue";
// import ManualDistributionForm from "@/components/manual-distribution/form.vue";
// const form = ref(null);
// onMounted(async () => {
//   await nextTick();
//   form.value.init({
//     method: ["1", "2"],
//     lists: [
//       {
//         user_id: 1,
//         user_name: 1111,
//         phone: "13011111111",
//       },
//     ],
//   });
// });
import { ref, reactive, onMounted, nextTick } from "vue";
import bgTableList from "@/components/table/bg-table-list.vue";
import BgTableHref from "@/components/table/bg-table-href.vue";
import bgFilterForm from "@/components/table/bg-filter-form.vue";
import bgPagination from "@/components/table/bg-pagination.vue";
import bgTable from '@/components/table/bg-table.vue'
import FeedBack from "../modules/feedback.vue";
let search = ref("");
let filter_data = reactive([
  {
    label: "预警分类",
    prop: "waining_type",
    type: "select",
    options: [
      {
        value: "",
        label: "全部",
      },
    ],
  },
  {
    label: "预警指标",
    prop: "warning_index",
    type: "select",
    options: [
      {
        value: "",
        label: "全部",
      },
    ],
  },
  {
    label: "风险等级",
    prop: "risk_level",
    type: "select",
    options: [
      {
        value: "",
        label: "全部",
      },
    ],
  },
  {
    label: "状态",
    prop: "status",
    type: "select",
    options: [
      {
        value: "",
        label: "全部",
      },
    ],
  },
  {
    label: "预警时段",
    prop: "date",
    type: "datetimerange",
  },
]);
let headers = reactive([
  {
    label: "预警点",
    prop: "warning_point",
    align: "left",
    href: {
      baseurl: "/work-order/my-alert-detail",
      params: { id: "warning_point" },
    },
  },
  {
    label: "预警时间",
    prop: "warning_time",
    align: "left",
  },
  {
    label: "预警分类",
    prop: "warning_type",
    align: "left",
  },
  {
    label: "预警指标",
    prop: "warning_index",
    align: "left",
  },
  {
    label: "风险等级",
    prop: "risk_level",
    align: "left",
  },
  {
    label: "当前报警值",
    prop: "current_alarm_value",
    align: "left",
  },
  {
    label: "预警阀值",
    prop: "warning_threshold",
    align: "left",
  },
  {
    label: "推送次数",
    prop: "push_num",
    align: "left",
  },
  {
    label: "最近推送时间",
    prop: "push_time",
    align: "left",
  },
  {
    label: "状态",
    prop: "status",
    align: "left",
  },
  {
    label: "操作",
    prop: "operation",
    align: "left",
    width: "80px",
  },
]);
let rows = ref([{
    warning_point:1
}]);
const pagination = reactive({
  rowsPerPage: 15,
  page: 1,
  total: 0,
});
let searchData = reactive({
  date: [],
  waining_type: "",
  warning_index: "",
  risk_level: "",
  status: "",
});
// *********分页start
const sizechange = (val) => {
  pagination.page = 1;
  pagination.rowsPerPage = val;
  init();
};
const current = (val) => {
  pagination.page = val;
  init();
};
onMounted(() => {
  init();
});
//搜索内容
const get_filter_list = (
  { date, waining_type, warning_index, risk_level, status },
  val
) => {
  pagination.rowsPerPage = 15;
  pagination.page = 1;
  searchData.date = date || [];
  searchData.waining_type = waining_type;
  searchData.warning_index = warning_index;
  searchData.risk_level = risk_level;
  searchData.status = status;
  search.value = val.value;
  init();
};

const init = async () => {
  let [startTime, endTime] = searchData.date;
  let urlParams = {
    keyword: search.value || "",
    startTime,
    endTime,
    waining_type: searchData.waining_type,
    warning_index: searchData.warning_index,
    risk_level: searchData.risk_level,
    status: searchData.status,
    page: pagination.page,
    limit: pagination.rowsPerPage,
  };
  //   const { data, total } = await instanceList(urlParams);
  //   rows.value = data.list || [];
  //   pagination.total = data.total_count;
};
const keywordAction = async (val) => {
  search.value = val;
  init();
};
// 处置反馈
const visible = ref(false);
const active_row = ref(null);
const operation = (row) => {
  active_row.value = row;
  visible.value = true;
};
</script>

<style lang="scss" scoped>
.my-alert {
  width: 100%;
  height: 100%;
  padding: 0 24px 16px;
  .breadcrumb {
    width: 100%;
    height: 46px;
  }
  .content {
    width: 100%;
    height: calc(100% - 46px);
    background-color: #ffffff;
    box-shadow: 0px 1px 4px 0px rgba(0, 7, 101, 0.15);
    border-radius: 6px;
  }
}
</style>
