Newer
Older
xc-business-system / src / views / quality / internal / internalPlan / index.vue
liyaguang on 19 Feb 7 KB 质量活动问题需改
<!-- 内部审核计划 -->
<script name="QualityInternalPlan" lang="ts" setup>
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import { Message } from '@element-plus/icons-vue'
import { getDictByCode } from '@/api/system/dict'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { deleteInternalPlan, exportInternalPlanZip, getInternalPlanList } from '@/api/quality/internal/internalPlan'
import useUserStore from '@/store/modules/user'
import { exportFile } from '@/utils/exportUtils'
const active = ref<string>('全部')
const buttonBoxActive = ref('InternalPlan')
const menu = ref<any[]>([])
const userStore = useUserStore()
// 查询条件
const listQuery = ref({
  fileName: '',
  fileCode: '',
  bizLabCode: '',
  commanderName: '',
  createTimeStart: '',
  createTimeEnd: '',
  offset: 1,
  limit: 20,
})
// 开始结束时间
const datetimerange = ref()
watch(() => datetimerange.value, (newVal) => {
  listQuery.value.createTimeStart = ''
  listQuery.value.createTimeEnd = ''
  if (Array.isArray(newVal)) {
    if (newVal.length) {
      listQuery.value.createTimeStart = `${newVal[0]} 00:00:00`
      listQuery.value.createTimeEnd = `${newVal[1]} 23:59:59`
    }
  }
})
// 列表数据
const tableList = ref([])
const total = ref(0)
const loadingTable = ref(true)
const checkoutList = ref<string[]>([])// 选中的内容
// 列
const columns = ref<TableColumn[]>([
  { text: '文件编号', value: 'fileCode', align: 'center' },
  { text: '文件名称', value: 'fileName', align: 'center' },
  { text: '实验室', value: 'bizLabCodeName', align: 'center' },
  { text: '质量负责人', value: 'commanderName', align: 'center' },
  { text: '创建时间', value: 'updateTime', align: 'center' },
])
// 数据查询
function fetchData(isNowPage = false) {
  if (/[\u4e00-\u9fa5]/.test(active.value)) {
    return
  }
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getInternalPlanList({...listQuery.value, planStatus: active.value, commanderId: active.value === '0' ? userStore.id : '' }).then((response) => {
    tableList.value = response.data.rows
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 搜索
const searchList = () => {
  fetchData(true)
}

// 重置查询条件
const clearList = () => {
  datetimerange.value = []
  listQuery.value = {
    fileName: '',
    fileCode: '',
    bizLabCode: '',
    commanderName: '',
    createTimeStart: '',
    createTimeEnd: '',
    offset: 1,
    limit: 20,
  }
  searchList()
}
// 多选发生改变时
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 $router = useRouter()
const handler = (type: string, row: any) => {
  $router.push({
    path: `/internalplan/${type}`,
    query: {
      id: row.id,
      data: JSON.stringify(row),
    },
  })
}
// 删除
const deleteRow = (row: any) => {
  ElMessageBox.confirm(
    '确认删除该数据吗?',
    '提示',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then((res) => {
    deleteInternalPlan({ id: row.id }).then((res) => {
      ElMessage.success('删除成功')
      searchList()
    })
  })
}

const changeCurrentButton = (val: string) => {
  if (/[\u4e00-\u9fa5]/.test(val)) {
    return
  }
  active.value = val
  window.sessionStorage.setItem(buttonBoxActive.value, val)
  setTimeout(() => {
    clearList() // 刷新
  })

}
onMounted(async () => {
  // searchList()
  setTimeout(() => {
    menu.value = [
      {
        name: '全部',
        id: '1',
      },
      {
        name: '草稿箱',
        id: '0',
      },
    ]
    if (window.sessionStorage.getItem(buttonBoxActive.value) && !(/[\u4e00-\u9fa5]/.test(window.sessionStorage.getItem(buttonBoxActive.value) || '全部'))) {
      active.value = window.sessionStorage.getItem(buttonBoxActive.value)!
    }
    else {
      active.value = menu.value.find(item => item.name === '全部')!.id as string // 全部
    }
  })
})
const { proxy } = getCurrentInstance() as any

// 导出
const exportList = () => {
  if (!tableList.value.length) {
    ElMessage.warning('暂无导出数据')
    return
  }
  const params = {
    ...listQuery.value,
    ids: checkoutList.value,
  }
  const loading = ElLoading.service({
    lock: true,
    text: '下载中请稍后',
    background: 'rgba(255, 255, 255, 0.8)',
  })
  exportInternalPlanZip(params).then((res) => {
    if (res.data.type.includes('zip') && res.data.size) {
      const blob = new Blob([res.data])
      loading.close()
      exportFile(blob, '内部审核计划.zip')
    }
    else {
      ElMessage.warning('导出失败')
      loading.close()
    }
  })
}
</script>

<template>
  <button-box :active="active" :total-refuse="totalRefuse" :total-approval="totalApproval"
    :total-to-approval="totalToApproval" :menu="menu" @change-current-button="changeCurrentButton" />
  <app-container>
    <search-area :need-clear="true" @search="searchList" @clear="clearList">
      <search-item>
        <el-input v-model="listQuery.fileCode" placeholder="文件编号" clearable />
      </search-item>
      <search-item>
        <el-input v-model="listQuery.fileName" placeholder="文件名称" clearable />
      </search-item>
      <search-item>
        <el-input v-model="listQuery.commanderName" placeholder="质量负责人" clearable />
      </search-item>
      <search-item>
        <el-date-picker v-model="datetimerange" type="daterange" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
          range-separator="至" start-placeholder="创建开始时间" end-placeholder="创建结束时间" clearable />
      </search-item>
    </search-area>

    <table-container>
      <template  v-if="active === '1'" #btns-right>
        <icon-button v-if="proxy.hasPerm('/quality/internal/plan/add')" icon="icon-add" title="新建" type="primary"
          @click="handler('create', {})" />
        <icon-button v-if="proxy.hasPerm('/quality/internal/plan/export')" icon="icon-export" title="导出" type="primary"
          @click="exportList" />
      </template>
      <normal-table :data="tableList" :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="120">
            <template #default="{ row }">
              <el-button  v-if="active === '1'" size="small" type="primary" link @click="handler('detail', row)">
                详情
              </el-button>
              <el-button v-if="proxy.hasPerm('/quality/internal/plan/update') && active === '0'" size="small" type="primary" link
                :disabled="row.commanderId !== userStore.id" @click="handler('update', row)">
                编辑
              </el-button>
              <el-button v-if="proxy.hasPerm('/quality/internal/plan/delete')" size="small" type="danger" link
                @click="deleteRow(row)">
                删除
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>