<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 #work_order_name="{ 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: "work_order_level",
    type: "select",
    options: [
      {
        value: "",
        label: "全部",
      },
    ],
  },
  {
    label: "状态",
    prop: "status",
    type: "select",
    options: [
      {
        value: "",
        label: "全部",
      },
    ],
  },
  {
    label: "创建时间",
    prop: "create_time",
    type: "datetimerange",
  },
  {
    label: "完成时间",
    prop: "finish_time",
    type: "datetimerange",
  },
]);
let headers = reactive([
  {
    label: "工单名称",
    prop: "work_order_name",
    align: "left",
    href: {
      baseurl: "/work-order/my-business-detail",
      params: { id: "id", name: "work_order_name" },
    },
  },
  {
    label: "工单等级",
    prop: "work_order_level",
    align: "left",
  },
  {
    label: "工单状态",
    prop: "work_order_status",
    align: "left",
  },
  {
    label: "下发对象",
    prop: "distribute_target",
    align: "left",
  },
  {
    label: "创建人",
    prop: "create_by",
    align: "left",
  },
  {
    label: "创建时间",
    prop: "create_time",
    align: "left",
  },
  {
    label: "完成时间",
    prop: "finish_time",
    align: "left",
  },
  {
    label: "操作",
    prop: "operation",
    align: "left",
    width: "80px",
  },
]);
let rows = ref([
  { work_order_name: 11, id: 111 },
  { work_order_name: 22, id: 222 },
  { work_order_name: 33, id: 333 },
]);
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 = (
  { create_time, finish_time, work_order_level, status },
  val
) => {
  pagination.rowsPerPage = 15;
  pagination.page = 1;
  searchData.create_time = create_time || [];
  searchData.finish_time = finish_time || [];
  searchData.work_order_level = work_order_level;
  searchData.status = status;
  search.value = val.value;
  init();
};

const init = async () => {
  let [createStartTime, createEndTime] = searchData.create_time;
  let [finishStartTime, finishEndTime] = searchData.finish_time;
  let urlParams = {
    keyword: search.value || "",
    createStartTime,
    createEndTime,
    finishStartTime,
    finishEndTime,
    work_order_level: searchData.work_order_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>
