Newer
Older
smart-metering-front / src / views / device / deviceMaintenance / components / listMaintenanceApproval.vue
<script lang="ts" setup name="listMaintenanceApproval">
import type { PropType, Ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox, buttonEmits } from 'element-plus'
import type { IButton, ISupplier, IlistTypes, supplierExportQuery } from '@views/measure/source/list_interface'
import type { IOptions } from '../checkList_interface'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDeptTree } from '@/api/system/plan'
import { deleteEquipmentApply, getEquipmentApplyList, submitEquipmentApply } from '@/api/device/checkList'
import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue'
import { SCHEDULE } from '@/utils/scheduleDict'
import { submitApproval } from '@/api/approval'
const props = defineProps({
  status: {
    type: String,
    default: '',
  },
  buttons: {
    type: Array as PropType<IButton[]>,
    default: () => [],
  },
})
const emit = defineEmits(['setData']) // 关闭

// 操作列宽度-计算属性
const operationWidth = computed(() => {
  return props.buttons.length * 32 + 24
})

// 查询条件
const listQuery: Ref<IlistTypes> = ref({
  approvalStatus: props.status,
  formId: SCHEDULE.DEVICE_FIX_APPROVAL,
  applyName: '',
  applyNo: '',
  applyPerson: '',
  applyType: '7',
  applyUnit: '',
  businessKeys: [],
  createUser: '',
  endTime: '',
  ids: [],
  processResult: '',
  startTime: '',
  offset: 1,
  limit: 20,
})
// 表格数据
const list = ref<ISupplier[]>([])
// 总数
const total = ref(0)
// 控制审批操作弹窗的开关
const applyShow = ref(false)
// 表头
const columns = ref<TableColumn[]>([
  {
    text: '检修申请编号',
    value: 'checkApplyNo',
    width: '120',
    align: 'center',
  },
  {
    text: '检修申请名称',
    value: 'checkApplyName',
    width: '120',
    align: 'center',
  },
  {
    text: '设备编号',
    value: 'applyNo',
    align: 'center',
  },
  {
    text: '设备名称',
    value: 'applyName',
    align: 'center',
  },
  {
    text: '出厂编号',
    value: 'overhaulPerson',
    align: 'center',
  },
  {
    text: '设备型号',
    value: 'createTime',
    align: 'center',
  },
  {
    text: '送修单位',
    value: 'createTime',
    align: 'center',
  },
  {
    text: '送修人',
    value: 'createTime',
    align: 'center',
  },
  {
    text: '申请日期',
    value: 'createTime',
    align: 'center',
  },
  {
    text: '审批状态',
    value: 'approvalStatusName',
    align: 'center',
  },
])
// 初始化路由
const $router = useRouter()
const buttonArray = ref<string[]>([])
// 选中的内容
const checkoutList = ref<string[]>([])
// 文件上传input
const fileRef = ref()
// 删除id
const deleteId = ref('')
// 详情id
const infoId = ref('0')
// 点击按钮
const buttonType = ref('')
const loadingTable = ref(false)
const fetchData = (isNowPage: boolean) => {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getEquipmentApplyList(listQuery.value).then((response) => {
    list.value = response.data.rows
    // list.value = [
    //   { approvalStatus: '4', approvalStatusName: '已通过', bankAccount: '453', bankAccountNumber: '354', bankName: '543', briefName: '35431', businessContent: '5434', businessScope: '354', companyAddress: '2313', companyArea: '210103', companyCity: '210100', companyCountry: '中国', companyProvince: '210000', createTime: '2022-12-06 17:21:40', director: '354', fax: '354', id: '1600057880174956546', invoiceAddress: '213123', invoiceArea: '150302', invoiceCity: '150300', invoiceCountry: '中国', invoiceProvince: '150000', mailbox: '354', minioFileName: '', mobile: '354', phone: '354', postalCode: '534', remark: '', supplierName: '北京公司2', supplierNo: 'sygf202212060003', taxNumber: '3543', traceSupplierPersonList: [], website: '354' },
    // ]
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  }).catch((_) => {
    // list.value = [
    //   { approvalStatus: '4', approvalStatusName: '已通过', bankAccount: '453', bankAccountNumber: '354', bankName: '543', briefName: '35431', businessContent: '5434', businessScope: '354', companyAddress: '2313', companyArea: '210103', companyCity: '210100', companyCountry: '中国', companyProvince: '210000', createTime: '2022-12-06 17:21:40', director: '354', fax: '354', id: '1600057880174956546', invoiceAddress: '213123', invoiceArea: '150302', invoiceCity: '150300', invoiceCountry: '中国', invoiceProvince: '150000', mailbox: '354', minioFileName: '', mobile: '354', phone: '354', postalCode: '534', remark: '', supplierName: '北京公司2', supplierNo: 'sygf202212060003', taxNumber: '3543', traceSupplierPersonList: [], website: '354' },
    // ]
    loadingTable.value = false
  })
}
// fetchData(true)
// 多选发生改变时
const handleSelectionChange = (e: any) => {
  checkoutList.value = e.map((item: { id: string }) => item.id)
}
// 点击删除和编辑的参数类型
interface rowReturn {
  id: string
  supplierName: string
  taskId: string
}
const buttonTypeMap = ref('')
// 点击删除或者取消
const handleDelete = (row: rowReturn) => {
  ElMessageBox.confirm(
    '确认删除所选记录吗?',
    '提示',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
    deleteEquipmentApply({ id: row.id, taskId: row.taskId }).then((res) => {
      if (res.code === 200) {
        ElMessage({
          type: 'success',
          message: '删除成功',
        })
        fetchData(true)
      }
    })
  })
}

// 取消
const handleCancel = (row: ISupplier) => {
  const params = {
    taskId: row.taskId!,
    comments: '',
  }
  ElMessageBox.confirm(
    '确认取消该审批吗?',
    '提示',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  )
    .then(() => {
      submitApproval('revoke', params).then((res) => {
        ElMessage({
          type: 'success',
          message: '取消成功',
        })
        fetchData(true)
      })
    })
}

const approvalDialog = ref()

// 点击搜索
const searchList = () => {
  fetchData(false)
}
const cancelEvent = () => {
  console.log('cancel!')
}
// 装载时间数组
const checkTimeArr = ref([listQuery.value.startTime, listQuery.value.endTime])
// 点击重置
const clearList = () => {
  listQuery.value = {
    approvalStatus: props.status,
    formId: SCHEDULE.DEVICE_FIX_APPROVAL,
    applyName: '',
    applyNo: '',
    applyPerson: '',
    applyType: '7',
    applyUnit: '',
    businessKeys: [],
    createUser: '',
    endTime: '',
    ids: [],
    processResult: '',
    startTime: '',
    offset: 1,
    limit: 20,
  }
  checkTimeArr.value = []
}
// 点击跳转
const add = () => {
  $router.push('/maintenance/maintenanceList/add')
}
// 主管部门下拉框
const options = ref<IOptions[]>([])
// 导出
const exportExcelBtn = () => {
  const params: supplierExportQuery = {
    approvalStatus: listQuery.value.approvalStatus,
    businessContent: listQuery.value.businessContent,
    companyArea: listQuery.value.companyArea,
    companyCity: listQuery.value.companyCity,
    companyProvince: listQuery.value.companyProvince,
    formId: listQuery.value.formId,
    supplierName: listQuery.value.supplierName,
    supplierNo: listQuery.value.supplierNo,
  }
  if (checkoutList.value.length > 0) {
    params.ids = checkoutList.value
  }
  // TODO: 审批列表导出
  console.log(params)
  const loading = ElLoading.service({
    lock: true,
    text: 'Loading',
    background: 'rgba(255, 255, 255, 0.8)',
  })
  loading.close()
}

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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 goDetail = (row: ISupplier, type: string) => {
  $router.push(`/maintenance/maintenanceList/${type}/${row.id}`)
}
// 获取到组织信息
const getDept = () => {
  const params = {
    roleId: '',
    deptType: '',
    tips: '',
  }
  getDeptTree(params).then((response) => {
    options.value = response.data
  })
}
getDept()
// 提交
const approvalSubmit = (row: ISupplier) => {
  ElMessageBox.confirm('确认提交吗?', '提示', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning',
  }).then(() => {
    submitEquipmentApply({ id: row.id, formId: SCHEDULE.DEVICE_FIX_APPROVAL }).then((res) => {
      if (res.code === 200) {
        ElMessage({
          type: 'success',
          message: '提交成功',
        })
        fetchData(true)
      }
    })
  })
}
// 批量导出
const exportAll = () => {
  exportExcelBtn()
}
// 审批结束回调
const approvalSuccess = () => {
  fetchData(true)
}
// 审批弹窗关闭
const handleClose = () => {
  applyShow.value = false
}

// 点击数据后的操作按钮
const clickBtn = (row: ISupplier, buttonType: string) => {
  switch (buttonType) {
    case '查看':
      goDetail(row, 'detail')
      break
    case '提交':
      approvalSubmit(row)
      break
    case '编辑':
      goDetail(row, 'edit')
      break
    case '同意':
      approvalDialog.value.initDialog('agree', row.taskId)
      break
    case '驳回':
      approvalDialog.value.initDialog('reject', row.taskId)
      break
    case '拒绝':
      approvalDialog.value.initDialog('refuse', row.taskId)
      break
    case '取消':
      handleCancel(row)
      break
    case '删除':
      handleDelete(row)
      break
  }
}

// 监听status变化,更新approvalStatus
watch (
  () => props.status,
  (newVal: string) => {
    listQuery.value.approvalStatus = newVal
    fetchData(false)
  },
  { immediate: true })
// 打印
const printObj = ref({
  id: 'print', // 需要打印元素的id
  popTitle: '溯源供方列表', // 打印配置页上方的标题
  extraHead: '', // 最上方的头部文字,附加在head标签上的额外标签,使用逗号分割
  preview: false, // 是否启动预览模式,默认是false
  standard: '',
  extarCss: '',
})
</script>

<template>
  <app-container>
    <search-area
      :need-clear="true"
      @search="searchList" @clear="clearList"
    >
      <search-item>
        <el-input
          v-model.trim="listQuery.checkApplyNo"
          placeholder="申请编号"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.checkApplyName"
          placeholder="申请名称"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.applyNo"
          placeholder="设备编号"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.applyName"
          placeholder="设备名称"
          clearable
        />
      </search-item>
      <search-item>
        <el-date-picker
          v-model="checkTimeArr"
          type="datetimerange"
          range-separator="到"
          format="YYYY/MM/DD HH:mm:ss"
          value-format="YYYY-MM-DD h:m:s"
          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-export" title="导出" type="primary" @click="exportAll" />
        <icon-button v-print="printObj" icon="icon-print" title="打印" type="primary" />
      </template>
      <normal-table
        :data="list" :total="total" :columns="columns" :query="listQuery"
        :list-loading="loadingTable" is-showmulti-select @change="changePage" @multiSelect="handleSelectionChange"
      >
        <template #columns>
          <el-table-column label="操作" align="center" :width="operationWidth">
            <template #default="{ row }">
              <el-button
                v-for="(item, index) in buttons"
                :key="index"
                size="small"
                :type="item.type" link
                @click="clickBtn(row, item.name)"
              >
                {{ item.name }}
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
  <approval-dialog ref="approvalDialog" @on-success="approvalSuccess" />
</template>