Newer
Older
xc-business-system / src / views / system / baseInfo / remind / list.vue
dutingting on 18 Dec 2023 4 KB 系统管理-到期提醒搭建
<!-- 到期提醒管理列表 -->
<script name="RemindList" lang="ts" setup>
import type { Ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import dayjs from 'dayjs'
import DetailDialog from './detailDialog.vue'
import type { TableColumn } from '@/components/NormalTable/table_interface'
const $router = useRouter()
const loadingTable = ref(false)
// 查询条件
const listQuery = ref({
  limit: 20,
  offset: 1,
})
// 表头
const columns = ref<TableColumn[]>([
  { text: '提醒名称', value: 'logNo', align: 'center', width: '180' },
  { text: '提醒时间', value: 'logName', align: 'center' },
])
const list = ref([]) // 列表
const total = ref(0) // 数据总条数
const detailDialogRef = ref() // 详情组件ref
// ---------------------------------------------------------------------------------------------------------
// 数据查询
function fetchData(isNowPage = false) {
  // loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  // getResumeWeekMonthList(listQuery.value).then((response) => {
  //   list.value = response.data.rows.map((item: { packingTime: string }) => {
  //     return {
  //       ...item,
  //       packingTime: item.packingTime ? dayjs(item.packingTime).format('YYYY-MM-DD') : item.packingTime,
  //     }
  //   })
  //   total.value = parseInt(response.data.total)
  //   loadingTable.value = false
  // })
}
// 清除条件
const clearList = () => {
  listQuery.value = {
    limit: 20,
    offset: 1,
  }
  fetchData()
}
// 搜索
const searchList = () => {
  fetchData(true)
}

// 新建
const add = () => {
  detailDialogRef.value.initDialog('add')
}

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number; page?: number }) => {
  if (val && val.size) {
    listQuery.value.limit = val.size
  }
  if (val && val.page) {
    listQuery.value.offset = val.page
  }
  fetchData(true)
}

// 操作
const handleEdit = (row: any, val: string) => {
  switch (val) {
    case 'delete':
      ElMessageBox.confirm(
        '确认删除吗?',
        '提示',
        {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning',
        },
      )
        .then(() => {
        })
      break
    default: // 编辑和详情
      detailDialogRef.value.initDialog(val)
      break
  }
}

// ---------------------------------------钩子----------------------------------------------
onMounted(() => {
  // fetchData(false)
})
</script>

<template>
  <app-container>
    <table-container>
      <template #btns-right>
        <icon-button icon="icon-add" title="新建" type="primary" @click="add" />
      </template>
      <normal-table
        :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable"
        @change="changePage"
      >
        <template #preColumns>
          <el-table-column label="序号" width="55" align="center">
            <template #default="scope">
              {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
        <template #columns>
          <el-table-column
            label="操作"
            align="center"
            fixed="right"
            width="150"
          >
            <template #default="{ row }">
              <el-button
                size="small"
                type="primary"
                link
                @click="handleEdit(row, 'detail')"
              >
                查看
              </el-button>
              <el-button
                size="small"
                link
                type="primary"
                @click="handleEdit(row, 'edit')"
              >
                编辑
              </el-button>
              <el-button
                size="small"
                type="danger"
                link
                @click="handleEdit(row, 'delete')"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
  <detail-dialog ref="detailDialogRef" />
</template>