<template>
  <div class="page-container column-container">
    <!-- 功能按钮区 -->

    <!-- 搜索区 -->
    <el-form
      class="list-search-container"
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="公告标题：" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入公告标题"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="list-btns-container" style="display: flex">
      <el-button
        type="primary"
        icon="Plus"
        @click="handleAdd"
        v-hasPermi="['business:notification:add']"
        >新增</el-button
      >

      <el-button
        type="warning"
        icon="Edit"
        :disabled="single"
        @click="handleUpdate"
        v-hasPermi="['business:notification:edit']"
        >修改</el-button
      >

      <el-button
        type="danger"
        icon="Delete"
        :disabled="multiple"
        @click="handleDelete"
        v-hasPermi="['business:notification:remove']"
        >删除</el-button
      >
      <!-- 添加一个占位元素 -->
      <div class="flex-grow"></div>
      <el-button
        type="success"
        icon="Edit"
        @click="handleDelete"
        v-hasPermi="['business:notification:remove']"
        >更新展示维护</el-button
      >
      <!-- 
      <el-button
        type="warning"
        icon="Download"
        @click="handleExport"
        v-hasPermi="['business:notification:export']"
        >导出</el-button
      > -->
      <!--<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>-->
    </div>

    <div class="el-table-container">
      <div class="el-table-inner-container">
        <!-- 列表区 -->
        <el-table
          v-loading="loading"
          :data="notificationList"
          size="small"
          border
          height="100%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column
            type="index"
            label="行号"
            width="50"
            align="center"
          />
          <el-table-column label="公告标题" align="center" prop="title" />
          <el-table-column
            label="公告类型"
            align="center"
            width="200"
            prop="type"
          />
          <el-table-column
            label="公告状态"
            align="center"
            width="200"
            prop="status"
          />
          <el-table-column
            label="创建时间"
            width="200"
            align="center"
            prop="createTime"
          >
            <template #default="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="备注"
            width="200"
            align="center"
            prop="remark"
          />
          <el-table-column
            label="操作"
            align="center"
            width="150"
            class-name="small-padding fixed-width"
          >
            <template #default="scope">
              <el-button
                link
                type="warning"
                icon="Edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['business:notification:edit']"
                >修改</el-button
              >
              <el-button
                link
                type="danger"
                icon="Delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['business:notification:remove']"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 表单 -->
    <notification-form
      ref="notificationRef"
      :get-list="getList"
    ></notification-form>
  </div>
</template>

<script setup name="Notification">
import { listNotification, delNotification } from "@/api/business/notification";
import notificationForm from "./form";
const { proxy } = getCurrentInstance();
/** 字典数组区 */
/** 查询 对象 */

const notificationList = ref([]);
const loading = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
/** 查询对象 */
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  title: null,
  type: null,
  content: null,
  updateContent: null,
  status: null,
});

/***********************  方法区  ****************************/

/** 查询发版通知公告列表 */
function getList() {
  loading.value = true;
  listNotification(queryParams.value).then((response) => {
    notificationList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  proxy.$refs.notificationRef.open();
}

/** 修改按钮操作 */
function handleUpdate(row) {
  const id = row.id || ids.value;
  proxy.$refs.notificationRef.open(id);
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal
    .confirm("是否确认删除选中的数据项？")
    .then(function () {
      return delNotification(_ids);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功！");
    })
    .catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    "business/notification/export",
    {
      ...queryParams.value,
    },
    `notification_${new Date().getTime()}.xlsx`
  );
}

getList();
</script>
<style>
.flex-grow {
  flex-grow: 1;
}
</style>
