Newer
Older
xc-business-system / src / views / business / subpackage / directories / list.vue
dutingting on 11 Sep 11 KB 分包方名录页面修改完成
<!-- 测试、校准或检定合格分包方名录列表 -->
<script name="SubpackageDirectoriesList" setup lang="ts">
import type { Ref } from 'vue'
import { getCurrentInstance, onMounted, ref, watch } from 'vue'
import type { DateModelType } from 'element-plus'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import dayjs from 'dayjs'
import type { IList, IListQuery } from './directories-interface'
import { printPdf } from '@/utils/printUtils'
import { getStream } from '@/api/business/subpackage/directories'
// import delReasonDialog from './dialog/delReasonDialog.vue'
import {
  exportDirectoriesList,
  getDirectoriesList,
} from '@/api/business/subpackage/directories'
import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue'
import type { deptType } from '@/global'
import ButtonBox from '@/components/buttonBox/buttonBox.vue'
import { exportFile } from '@/utils/exportUtils'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDictByCode } from '@/api/system/dict'
import { SCHEDULE } from '@/utils/scheduleDict'
import { getDeptTreeList } from '@/api/system/dept'
import { getStaffList } from '@/api/resource/register'
import { toTreeList } from '@/utils/structure'
import type { IMenu } from '@/components/buttonBox/buttonBox'

const $router = useRouter()
const { proxy } = getCurrentInstance() as any
const active = ref('')
const operateWidth = ref('150') // 操作栏的宽度
// 查询条件
const listQuery: Ref<IListQuery> = ref({
  approvalStatus: active.value, // 审批状态
  director: '', // 机构负责人
  outsourcerName: '', // 单位名称
  outsourcerNo: '', // 分包方编号
  formId: SCHEDULE.SUBPACKAGE_DIRECTORIES_APPROVAL, // 表单id
  createTimeStart: '', // 创建时间(开始)
  createTimeEnd: '', // 创建时间(结束)
  offset: 1,
  limit: 20,
})
const total = ref(0) // 数据条数
const loadingTable = ref(false) // 表格loading
const menu = ref<IMenu[]>([]) // 审批状态按钮组合
// 表头
const columns = ref<TableColumn[]>([
  // { text: '分包方编号', value: 'outsourcerNo', align: 'center', width: '180' },
  { text: '分包方名称', value: 'outsourcerName', align: 'center', width: '180' },
  // { text: '单位名称', value: 'outsourcerName', align: 'center' },
  { text: '机构负责人', value: 'director', align: 'center' },
  { text: '地址', value: 'fullAddress', align: 'center' },
  { text: '联系人', value: 'lxr', align: 'center' },
  { text: '联系电话', value: 'phone', align: 'center' },
  { text: '技术能力', value: 'businessScope', align: 'center' },
  { text: '创建人', value: 'createUserName', align: 'center', width: '180' },
  { text: '创建时间', value: 'createTime', align: 'center', width: '180' },
])
const list = ref<IList[]>([]) // 表格数据
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
const checkoutList = ref<string[]>([])// 选中的内容

// -----------------------------------------字典--------------------------------------------------------------
const useDeptList = ref<deptType[]>([]) // 所属部门列表
const userList = ref<{ [key: string]: string }[]>([]) // 用户列表

// 查询字典
const getDict = async () => {
  loadingTable.value = true
  // 审批状态
  const res = await getDictByCode('approvalStatus')
  // 制作右上角的菜单
  const tempMenu = ['全部', '已审批', '待审批', '审批', '草稿箱', '审批中', '已通过', '未通过', '已取消']
  tempMenu.forEach((item) => {
    const tempFindData = res.data.find((e: { name: string; value: string }) => e.name === item)
    if (tempFindData) {
      menu.value.push({
        name: tempFindData.name,
        id: `${tempFindData.value}`,
      })
    }
  })

  // 获取部门列表
  getDeptTreeList().then((res) => {
    // 转成树结构
    useDeptList.value = toTreeList(res.data, '0', true)
  })
  // 获取用户列表
  getStaffList({ offset: 1, limit: 999999 }).then((res: any) => {
    userList.value = res.data.rows
  })
}
// ------------------------------------------列表数据-------------------------------------------------------------
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  if (listQuery.value.approvalStatus === '10') { listQuery.value.approvalStatus = '' } // 审批状态不允许传字典要求传''

  getDirectoriesList(listQuery.value).then((response) => {
    list.value = response.data.rows.map((item: { estimateSignDate: string; agreementAmount: number; measureValidDate: string }) => {
      return {
        ...item,
        measureValidDate: item.measureValidDate ? dayjs(item.measureValidDate).format('YYYY-MM-DD') : item.measureValidDate,
      }
    })
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 搜索
const searchList = () => {
  fetchData(true)
}

// 重置
const clearList = () => {
  listQuery.value = {
    approvalStatus: active.value, // 审批状态
    director: '', // 机构负责人
    outsourcerName: '', // 单位名称
    outsourcerNo: '', // 分包方编号
    formId: SCHEDULE.SUBPACKAGE_DIRECTORIES_APPROVAL, // 表单id
    createTimeStart: '', // 创建时间(开始)
    createTimeEnd: '', // 创建时间(结束)
    offset: 1,
    limit: 20,
  }
  dateRange.value = ['', '']
  fetchData(true)
}

// 多选发生改变时
function handleSelectionChange(e: any) {
  checkoutList.value = e.map((item: { id: string }) => item.id)
}

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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 exportAll = () => {
  const loading = ElLoading.service({
    lock: true,
    text: '下载中请稍后',
    background: 'rgba(255, 255, 255, 0.6)',
  })
  if (list.value.length > 0) {
    const params = {
      approvalStatus: listQuery.value.approvalStatus, // 审批状态
      director: listQuery.value.director, // 机构负责人
      outsourcerName: listQuery.value.outsourcerName, // 单位名称
      outsourcerNo: listQuery.value.outsourcerNo, // 分包方编号
      formId: listQuery.value.formId, // 表单id
      createTimeStart: listQuery.value.createTimeStart, // 创建时间(开始)
      createTimeEnd: listQuery.value.createTimeEnd, // 创建时间(结束)
      offset: 1,
      limit: 20,
      ids: checkoutList.value,
    }
    exportDirectoriesList(params).then((res) => {
      const blob = new Blob([res.data])
      loading.close()
      exportFile(blob, '测试、校准或检定合格分包方名录.xlsx')
    })
  }
  else {
    loading.close()
    ElMessage.warning('无数据可导出数据')
  }
}

// 打印
const print = () => {
  if (!checkoutList.value.length) {
    ElMessage.warning('请至少选中一条数据')
    return false
  }
  const loading = ElLoading.service({
    lock: true,
    text: '加载中...',
    background: 'rgba(255, 255, 255, 0.6)',
  })
  getStream({ id: checkoutList.value[0], pdf: true }).then((res) => {
    const pdfStream = new Blob([res.data])
    const blobUrl = URL.createObjectURL(pdfStream)
    printPdf(blobUrl)
    loading.close()
  })
}

// ----------------------------------------------操作---------------------------------------------------
const handleEdit = (row: IList, type: string) => {
  $router.push({
    path: `/directories/${type}/${row.id}`,
    query: {
    },
  })
}

// ----------------------------------------------钩子------------------------------------------------------
watch(dateRange, (val) => {
  if (val) {
    listQuery.value.createTimeStart = `${val[0]}`
    listQuery.value.createTimeEnd = `${val[1]}`
  }
  else {
    listQuery.value.createTimeStart = ''
    listQuery.value.createTimeEnd = ''
  }
})

onMounted(async () => {
  await getDict()
  fetchData()
})
</script>

<template>
  <app-container>
    <search-area :need-clear="true" @search="searchList" @clear="clearList">
      <search-item>
        <el-input v-model.trim="listQuery.outsourcerName" placeholder="分包方名称" class="short-input" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.director" placeholder="机构负责人" class="short-input" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.fullAddress" placeholder="地址" class="short-input" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.lxr" placeholder="联系人" class="short-input" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.phone" placeholder="联系电话" class="short-input" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.businessScope" placeholder="测试能力" class="short-input" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.createUserName" placeholder="创建人" class="short-input" clearable />
      </search-item>
      <search-item>
        <el-date-picker
          v-model="dateRange"
          class="short-input"
          type="datetimerange"
          range-separator="至"
          format="YYYY-MM-DD HH:mm:ss"
          value-format="YYYY-MM-DD HH:mm:ss"
          start-placeholder="创建时间(开始)"
          end-placeholder="创建时间(结束)"
        />
      </search-item>
    </search-area>

    <table-container>
      <template #btns-right>
        <!-- <icon-button icon="icon-add" title="新建" type="primary" @click="add" /> -->
        <icon-button icon="icon-print" title="打印" type="primary" @click="print" />
        <icon-button icon="icon-export" title="导出" type="primary" @click="exportAll" />
      </template>
      <normal-table
        :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable"
        is-showmulti-select @change="changePage" @multi-select="handleSelectionChange"
      >
        <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="operateWidth"
          >
            <template #default="{ row }">
              <el-button
                size="small"
                type="primary"
                link
                @click="handleEdit(row, 'detail')"
              >
                查看
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>

<style lang="ts" scoped>

</style>