Newer
Older
smart-metering-front / src / views / business / lab / components / selectReportTemplate.vue
dutingting on 1 Aug 6 KB bug修复
<!-- 选择证书报告模板 -->
<script lang="ts" setup name="SelectReportTemplate">
import { ElMessage } from 'element-plus'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getTypeSelect } from '@/api/system/price'
import { getDictByCode } from '@/api/system/dict'
import type { typeofSign } from '@/views/system/tool/tool_interface'
import { templatePage } from '@/api/system/tool'

const emits = defineEmits(['confirm'])
const dialogFormVisible = ref(false) // 控制弹窗显隐
const createTime = ref()
// 查询参数
const searchQuery = reactive({
  templateNo: '', // 编号
  templateName: '', // 名称
  templateCreator: '', // 负责人
  createStartTime: '',
  createEndTime: '',
  limit: 5,
  offset: 1,
  certificationType: '0',
  ids: [] as string[],
}) // 查询参数
const loadingTable = ref(false) // loading
const list = ref([]) // 表格参数
const total = ref(0)
const columns = ref<TableColumn[]>([
  { text: '编号', value: 'templateNo', align: 'center', width: '160' },
  { text: '模板名称', value: 'templateName', align: 'center' },
  { text: '模板类型', value: 'templateTypeName', align: 'center', width: '100' },
  { text: '负责人', value: 'templateCreator', align: 'center', width: '100' },
  { text: '内容描述', value: 'templateDesc', align: 'center' },
  { text: '创建时间', value: 'createTime', align: 'center', width: '180' },
])
const checkoutList = ref<string[]>([]) // 多选选中参数
// ---------------------------------------字典--------------------------------------------
const templateTypeMap = ref([]) as any // 模板类型
// 获取字典值
async function getDict() {
  // 模板类型
  const res = await getDictByCode('certificationType')
  res.data.forEach((item: { value: string; name: string }) => {
    templateTypeMap.value[`${item.value}`] = item.name
  })
}
// ----------------------------------------------------------------------------------------------
// 获取数据列表
const getList = () => {
  loadingTable.value = true
  templatePage(searchQuery).then((res) => {
    if (res.code === 200) {
      list.value = res.data.rows.map((item: { certificationType: string }) => {
        return {
          ...item,
          templateTypeName: `${item.certificationType}` ? templateTypeMap.value[item.certificationType] : item.certificationType, // 模板类型
        }
      })
      total.value = res.data.total
    }
    loadingTable.value = false
  }).catch((_) => {
    loadingTable.value = false
  })
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number; page?: number }) => {
  if (val && val.size) {
    searchQuery.limit = val.size
  }
  if (val && val.page) {
    searchQuery.offset = val.page
  }
  getList()
}

// 搜索
const search = () => {
  getList()
}
// 重置
const clearList = () => {
  searchQuery.templateNo = '' // 编号
  searchQuery.templateName = '' // 名称
  searchQuery.templateCreator = '' // 负责人
  searchQuery.createStartTime = ''
  searchQuery.createEndTime = ''
  searchQuery.limit = 5
  searchQuery.offset = 1
  searchQuery.certificationType = '0'
  createTime.value = ''
  searchQuery.ids = []
  getList()
}

// 点击保存
const submitForm = () => {
  if (!checkoutList.value.length) {
    ElMessage.warning('请选择证书模板')
  }
  else {
    emits('confirm', checkoutList.value[0])
    dialogFormVisible.value = false
  }
}

// 取消
const resetForm = () => {
  dialogFormVisible.value = false
}

// 多选选中
const handleSelectionChange = (val: any) => {
  checkoutList.value = val
}

// 初始化
const initDialog = () => {
  dialogFormVisible.value = true
  getDict().then((_) => {
    getList()
  })
}
watch(() => createTime.value, (newVal) => {
  if (newVal) {
    searchQuery.createStartTime = newVal[0]
    searchQuery.createEndTime = newVal[1]
  }
  else {
    searchQuery.createStartTime = ''
    searchQuery.createEndTime = ''
  }
})
defineExpose({ initDialog })
</script>

<template>
  <el-dialog v-model="dialogFormVisible" class="select-report-template-dialog" title="选择证书模板" width="65%">
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="search" @clear="clearList">
      <search-item>
        <el-input v-model="searchQuery.templateNo" placeholder="编号" clearable class="w-50 m-2 normal-input" />
      </search-item>
      <search-item>
        <el-input v-model="searchQuery.templateName" placeholder="模板名称" clearable class="w-50 m-2 normal-input" />
      </search-item>
      <search-item>
        <el-input v-model="searchQuery.templateCreator" placeholder="负责人" clearable class="w-50 m-2 normal-input" />
      </search-item>
      <search-item>
        <el-date-picker
          v-model="createTime"
          type="datetimerange"
          format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss"
          range-separator="至"
          start-placeholder="创建开始时间"
          end-placeholder="创建结束时间"
          clearable
        />
      </search-item>
    </search-area>
    <!-- 查询结果Table显示 -->
    <div style="padding: 12px;">
      <normal-table
        :data="list"
        :total="total"
        :columns="columns"
        :query="searchQuery"
        is-showmulti-select
        :list-loading="loadingTable"
        :is-multi="false"
        :page-sizes="[5]"
        @change="changePage"
        @multi-select="handleSelectionChange"
      >
        <!-- 序号 -->
        <template #preColumns>
          <el-table-column label="#" width="55" align="center" fixed>
            <template #default="scope">
              {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="submitForm">确认</el-button>
        <el-button @click="resetForm">
          取消
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<style lang="scss">
.select-report-template-dialog {
  .el-radio__label {
    display: none !important;
  }
}
</style>