Newer
Older
xc-business-system / src / views / business / taskMeasure / labTask / list.vue
dutingting on 16 Aug 2023 13 KB 修复报错
<!-- 实验室任务列表 -->
<script name="TaskMeasureLabTaskList" lang="ts" setup>
import { getCurrentInstance, ref } from 'vue'
import type { Ref } from 'vue'
import type { DateModelType } from 'element-plus'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import RollbackDialog from '../myTask/dialog/rollbackDialog.vue'
import type { IList, IListQuery } from '@/views/business/taskMeasure/myTask/myTask-interface'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { exportFile } from '@/utils/exportUtils'
import { getDictByCode } from '@/api/system/dict'
import distributeDialog from '@/views/business/manager/sendReceive/dialog/distributeDialog.vue'
// import { getMyMeasureList, getTaskDetail, myExecutiveDone, myExecutiveReceive } from '@/api/business/schedule/task'
import type { dictType } from '@/global'
import type { IMenu } from '@/components/buttonBox/buttonBox'
const buttonBoxActive = 'businessLabTask' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态
const { proxy } = getCurrentInstance() as any
const $router = useRouter()
// 右上角按钮
const menu = ref<IMenu[]>([]) // 右上角审批状态按钮组合
const active = ref('') // 选中的按钮
// 查询条件
const timeRange = ref<[DateModelType, DateModelType]>(['', ''])
const listQuery: Ref<IListQuery> = ref({
  equipmentNo: '', // 统一编号
  equipmentName: '', // 受检设备名称
  customerName: '', // 委托方
  orderCode: '', // 任务单编号
  startTime: '', // 要求检完时间-开始
  endTime: '', // 要求检完时间-结束
  measureStatus: active.value, // 检测状态
  offset: 1,
  limit: 20,
})
const operateWidth = ref('160') // 操作栏的宽度

const columns = ref<TableColumn[]>([ // 表头
  { text: '统一编号', value: 'equipmentNo', width: '160', align: 'center' },
  { text: '受检设备名称', value: 'equipmentName', align: 'center' },
  { text: '任务单编号', value: 'orderCode', align: 'center' },
  { text: '委托方', value: 'customerName', align: 'center' },
  { text: '要求检完时间', value: 'requireOverTime', align: 'center', width: '180' },
  { text: '是否加急', value: 'isUrgentName', align: 'center', width: '55px', styleFilter: (row: IList) => { return row.isUrgentName == '是' ? 'color: red' : '' } },
  { text: '当前环节', value: 'currentSegment', align: 'center' },
  { text: '证书出具', value: 'certificationState', align: 'center', filter: (row: IList) => { return `${row.currentCertifications}/${row.requireCertifications}` } },
])
const list = ref<IList[]>([]) // 表格数据
const total = ref(0) // 总数
const loadingTable = ref(false) // 表格加载状态
const checkoutList = ref<IList[]>([]) // 选中的内容

// --------------------------------------------字典--------------------------------------

const isUrgentList = ref<dictType[]>([])// 是否加急
const isUrgentMap = ref({}) as any // 是否加急{1: 是}

function getDict() {
  // 是否加急
  getDictByCode('isUrgent').then((response) => {
    isUrgentList.value = response.data
    response.data.forEach((item: any) => {
      isUrgentMap.value[`${item.value}`] = item.name
    })
  })
  return new Promise((resolve, reject) => {
    // 获取菜单字典
    getDictByCode('measureStatus').then((response) => {
      response.data.forEach((item: dictType) => {
        if (['待检测', '检测中', '检测完成'].includes(item.name)) {
          menu.value.push({
            name: item.name,
            id: `${item.value}`,
          })
          resolve(menu.value)
        }
      })
    })
  })
}

// -----------------------------------------表格数据--------------------------------------------

// 数据查询
function fetchData(isNowPage = false) {
  // loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  // getMyMeasureList(listQuery.value).then((res) => {
  //   list.value = res.data.rows.map((item: ITaskList) => {
  //     item.isUrgentName = item.isUrgent == 1 ? '是' : '否'
  //     return item
  //   })
  //   total.value = res.total
  //   loadingTable.value = false
  // })
  list.value = [{
    id: 'test', // 主键
    equipmentNo: 'test', // 统一编号
    equipmentName: 'test', // 受检设备名称
    orderCode: 'test', // 任务单编号
    customerName: 'test', // 委托方
    requireOverTime: 'test', // 要求检完时间
    isUrgent: 'test', // 是否加急
    isUrgentName: 'test', // 是否加急名称
    currentSegment: 'test', // 当前环节
    currentCertifications: 1, // 当前证书数
    alreadyCertifications: 1, // 已出具证书总数
    requireCertifications: 1, // 应出具证书总数
    distributeState: 'test', // 分发性质-初次分发、退回分发
    handOutProperty: 'test', // 分发性质-初次分发、退回分发
  }]
}

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

// 点击搜索
const searchList = () => {
  fetchData(true)
}
// 点击重置
const clearList = () => {
  listQuery.value = {
    equipmentNo: '', // 统一编号
    equipmentName: '', // 受检设备名称
    customerName: '', // 委托方
    orderCode: '', // 任务单编号
    startTime: '', // 要求检完时间-开始
    endTime: '', // 要求检完时间-结束
    measureStatus: active.value, // 检测状态
    offset: 1,
    limit: 20,
  }
  timeRange.value = ['', '']
  fetchData(false)
}

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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 handleDetail = (row: IList) => {
  $router.push('/labTask/detail/')
}

// 点击收入
const takeIn = function (row: IList) {
  ElMessageBox.confirm(
    '确认收入该样品吗?',
    '提示',
    { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' },
  ).then(() => {
    // 收入样品
    // myExecutiveReceive(param).then((res) => {
    //   if (res.code == 200) {
    //     ElMessage.success('已收入')
    //     fetchData()
    //   }
    // })
  })
}

// 点击退回
const rollbackRef = ref()
const rollback = function (row: IList) {
  rollbackRef.value.initDialog(row)
}

// 检完
const mearsureOver = function (row: IList) {
  ElMessageBox.confirm(
    '确认完成该设备检测吗?',
    '提示',
    { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' },
  ).then(() => {
    // myExecutiveDone(param).then((res) => {
    //   if (res.code == 200) {
    //     ElMessage.success('检测完成')
    //     fetchData()
    //   }
    // })
  })
}

// -----------------------------------状态按钮------------------------------------------------
// 选择按钮变更
const changeCurrentButton = (val: string) => {
  active.value = val
  window.sessionStorage.setItem(buttonBoxActive, val)
  clearList()
}
// -------------------------------------扫描-------------------------------------------------
const scanSampleRef = ref() // 扫描收入组件ref
const scanOverRef = ref() // 扫描检完组件ref

// 点击扫描增加任务
const scanAddTask = () => {
  ElMessage.info('敬请期待')
}

// 点击扫描收入
const batchScan = () => {
  ElMessage.info('敬请期待')
  // scanSampleRef.value.initDialog(false, '3', '1')
}

// 点击批量捡完
const batchOverScan = () => {
  ElMessage.info('敬请期待')
  // scanOverRef.value.initDialog(false, '3', '2')
}

// 对列表中样品批量收入
const scanOver = function (list: any) {
  takeIn(list)
  scanSampleRef.value.closeDialog()
  fetchData()
}

// 对列表中样品批量捡完
const scanMeasureOver = function (list: any) {
  mearsureOver(list)
  scanOverRef.value.closeDialog()
  fetchData()
}

// --------------------------------------按钮(导出、分发)--------------------------------------------------------
// 导出
const exportAll = () => {
  const loading = ElLoading.service({
    lock: true,
    text: '下载中请稍后',
    background: 'rgba(255, 255, 255, 0.8)',
  })
  if (list.value.length > 0) {
    const param = {
      equipmentNo: listQuery.value.equipmentNo, // 统一编号
      equipmentName: listQuery.value.equipmentName, // 受检设备名称
      customerName: listQuery.value.customerName, // 委托方
      orderCode: listQuery.value.orderCode, // 任务单编号
      startTime: listQuery.value.startTime, // 要求检完时间-开始
      endTime: listQuery.value.endTime, // 要求检完时间-结束
      measureStatus: active.value, // 检测状态
      offset: 1,
      limit: 20,
      ids: checkoutList.value,
    }
    // exportFileListPage(param).then((res) => {
    //   exportFile(res.data, '我的任务')
    //   loading.close()
    //   searchQuery.ids = []
    // })
    //   .catch((_) => {
    //     loading.close()
    //   })
  }
  else {
    ElMessage.warning('无数据可导出数据')
  }
  loading.close()
}

// 点击分发, 弹窗
const distributeDialogRef = ref()
const handleDistribute = (row: IList) => {
  const orderId = '1'
  const sampleId = '2'
  distributeDialogRef.value.initDialog(orderId, sampleId, 'dispatch', true)
}
// ---------------------------------------钩子-------------------------------------------------------
watch(timeRange, (val) => { // 监听时间变化
  if (val) {
    listQuery.value.startTime = `${val[0]}`
    listQuery.value.endTime = `${val[1]}`
  }
  else {
    listQuery.value.startTime = ''
    listQuery.value.endTime = ''
  }
})

onMounted(async () => {
  getDict().then(() => {
    if (window.sessionStorage.getItem(buttonBoxActive) != null) {
      active.value = window.sessionStorage.getItem(buttonBoxActive) as string
    }
    else {
      active.value = menu.value.find(item => item.name === '待检测')!.id as string // 待检测
    }
    listQuery.value.measureStatus = active.value // 检测状态
    fetchData(true)
  })
})
</script>

<template>
  <app-container>
    <button-box :active="active" :menu="menu" @change-current-button="changeCurrentButton" />
    <search-area
      :need-clear="true"
      @search="searchList" @clear="clearList"
    >
      <search-item>
        <el-input
          v-model.trim="listQuery.equipmentNo"
          placeholder="统一编号"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.equipmentName"
          placeholder="受检设备名称"
          clearable
          class="short-input"
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.orderCode"
          placeholder="任务单编号"
          clearable
          class="short-input"
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.customerName"
          placeholder="委托方"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-date-picker
          v-model="timeRange"
          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-scan" title="扫描收入" type="primary" @click="batchScan" />
        <icon-button icon="icon-scan" title="扫描检完" type="primary" @click="batchOverScan" />
        <icon-button icon="icon-export" title="导出" @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 #columns>
          <el-table-column label="操作" align="center" fixed="right" :width="operateWidth">
            <template #default="{ row }">
              <el-button size="small" link type="primary" @click="handleDetail(row)">
                详情
              </el-button>
              <el-button size="small" type="primary" link @click="handleDistribute(row)">
                任务分发
              </el-button>
              <el-button size="small" type="primary" link @click="rollback(row)">
                退回
              </el-button>
              <el-button size="small" type="primary" link @click="mearsureOver(row)">
                检完
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
      <!-- 退回弹窗 -->
      <rollback-dialog ref="rollbackRef" @on-success="fetchData(true)" />
      <!-- 批量收入弹窗 -->
      <scan-sample-dialog ref="scanSampleRef" @confirm="scanOver" />
      <!-- 批量捡完弹窗 -->
      <scan-sample-dialog ref="scanOverRef" title="批量检完" @confirm="scanMeasureOver" />
      <!-- 任务分发弹窗 -->
      <distribute-dialog ref="distributeDialogRef" @close="fetchData(true)" />
    </table-container>
  </app-container>
</template>

<style lang="scss" scoped>
.short-input {
  width: 160px;
}
</style>