Newer
Older
xc-metering-front / src / views / tested / MeasurementPlan / plan / components / list.vue
lyg on 16 Jan 2024 15 KB 计量计划需求修改
<!-- 计量计划列表 -->
<script lang="ts" setup name="PlanList">
import { reactive, ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import ApprovalDialog from './ApprovalDialog.vue'
import summaryDialog from './summaryDialog.vue'
import { cancelPlan, delPlan, editPlan, exportPlan, getListPage, submitPlan } from '@/api/eqpt/measurementPlan/paln'
import { getDictByCode } from '@/api/system/dict'
import { SCHEDULE } from '@/utils/scheduleDict'
import { printJSON } from '@/utils/printUtils'
import { exportFile } from '@/utils/exportUtils'
import { getAdminDept, getUserDept, getUserDeptSon, getUserList } from '@/api/system/user'
import { getDeptTreeList } from '@/api/system/dept'
import { toTreeList } from '@/utils/structure'
const $props = defineProps({
  statusName: {
    type: String,
    default: '',
  },
})
const applyDict = ref<{ [key: string]: string }>({
  审批: '',
  草稿箱: '1',
  审批中: '3',
  已通过: '4',
  未通过: '5',
  已取消: '6',
})
const { proxy } = getCurrentInstance() as any
const listQuery = reactive({
  approvalStatus: '', //	申请状态(审批列表传)		false
  createDeptName: '', //	创建单位名称		false
  createTimeEnd: '', //	创建结束时间		false
  createTimeStart: '', //	创建开始时间		false
  formId: SCHEDULE.METERING_PLAN_APPROVAL, //	流程formId(待审批/已审批列表传)		false
  planCategory: '', //	计划分类(原始/追加)		false
  planName: '', //	计划名称		false
  planNo: '', //	计划编号		false
  planType: '', //	计划类型(年/季/月)		false
  createCompanyId: '', // 创建单位
  createDeptId: '', // 部门
  manufactureNo: '', // 出厂编号
  equipmentRemark: '', // 备注
  offset: 1,
  limit: 20,
})
// 是否折叠查询条件
const searchMore = ref(true)
const expandSearch = () => {
  searchMore.value = !searchMore.value
}
// 创建单位
const companyList = ref<{ id: string; value: string; name: string }[]>([])
const deptList = ref<any>([])
const fetchCommpany = () => {
  // 获取单位
  getUserDept().then((res) => {
    if (res.data.fullName === '顶级' || res.data.version === '1' || res.data.version === 1) {
      getAdminDept({}).then((res) => {
        companyList.value = res.data.map((item: any) => ({ id: item.id, value: item.id, name: item.fullName }))
      })
    }
    else {
      companyList.value = [
        {
          name: res.data.fullName,
          value: res.data.id,
          id: res.data.id,
        },
      ]
      listQuery.createCompanyId = ''
    }
  })
  // 获取部门
  // getUserDeptSon({}).then((res) => {
  //   console.log(res.data, '部门')
  // })
}
fetchCommpany()
watch(() => listQuery.createCompanyId, (newVal) => {
  listQuery.createDeptId = ''
  if (newVal) {
    getDeptTreeList({ pid: newVal }).then((res) => {
      deptList.value = toTreeList(res.data.map((item: any) => ({ ...item, label: item.name, value: item.id })))
    })
  }
  else {
    deptList.value = []
  }
})
// 开始结束时间
const datetimerange = ref()
watch(() => datetimerange.value, (newVal) => {
  listQuery.createTimeStart = ''
  listQuery.createTimeEnd = ''
  if (Array.isArray(newVal)) {
    if (newVal.length) {
      listQuery.createTimeStart = `${newVal[0]} 00:00:00`
      listQuery.createTimeEnd = `${newVal[1]} 23:59:59`
    }
  }
})
const columns = ref([
  {
    text: '计划编号',
    value: 'planNo',
    align: 'center',
  },
  {
    text: '计划名称',
    value: 'planName',
    align: 'center',
  },
  {
    text: '计划分类',
    value: 'planCategoryName',
    align: 'center',
  },
  {
    text: '创建单位',
    value: 'createCompanyName',
    align: 'center',
  },
  {
    text: '部门',
    value: 'createDeptName',
    align: 'center',
  },
  {
    text: '创建人',
    value: 'createUserName',
    align: 'center',
  },
  {
    text: '创建时间',
    value: 'createTime',
    align: 'center',
  },
])
const list = ref([])
const total = ref(0)
const listLoading = ref(true)

// 获取列表数据
const fetchData = () => {
  list.value = []
  // total.value = 0
  listLoading.value = true
  // if (!isNowPage) {
  //   // 是否显示当前页,否则跳转第一页
  //   listQuery.offset = 1
  // }
  // console.log(getListPage)
  getListPage(listQuery, $props.statusName).then((response) => {
    list.value = response.data.rows
    total.value = Number(response.data.total)
    listLoading.value = false
  }).catch((_) => {
    listLoading.value = false
  })
  // listLoading.value = false
  // list.value = [
  //   {
  //     planNo: '123',
  //     planName: '计划名称',
  //   },
  // ]
}
// 获取计划分类列表
const planTypeList = ref()
const fetchTypeList = () => {
  getDictByCode('eqptPlanType').then((res) => {
    planTypeList.value = res.data
  })
}
fetchTypeList()
// 查询数据
const search = () => {
  fetchData()
}
// 重置
const reset = () => {
  datetimerange.value = []
  listQuery.offset = 1
  listQuery.limit = 20
  listQuery.planName = ''
  listQuery.createTimeStart = ''
  listQuery.createTimeEnd = ''
  listQuery.planNo = ''
  listQuery.planCategory = ''
  listQuery.createCompanyId = ''
  listQuery.createDeptId = ''
  listQuery.manufactureNo = ''
  listQuery.equipmentRemark = ''
  search()
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size: number; page: number }) => {
  console.log(val, 'val')
  if (val && val.size) {
    listQuery.limit = val.size
  }
  if (val && val.page) {
    listQuery.offset = val.page
  }
  fetchData()
}
// 表格被选中的行
const selectList = ref<any[]>([])
// 表格多选
const multiSelect = (row: any[]) => {
  selectList.value = row
}
const $router = useRouter()
// 新建编辑操作
const handler = (row: any, type: string, category: string) => {
  $router.push({
    path: `plan/${type}`,
    query: {
      row: JSON.stringify(row),
      id: row.id,
      statusName: $props.statusName,
      category,
    },
  })
}
// 详情
const detail = (row: any) => {
  if ($props.statusName === '草稿箱' || $props.statusName === '未通过' || $props.statusName === '已取消') {
    handler(row, 'update', '')
  }
  else {
    $router.push({
      path: 'plan/detail',
      query: {
        row: JSON.stringify(row),
        id: row.id,
        statusName: $props.statusName,
      },
    })
  }
}
// 删除
const delHandler = (row: any) => {
  ElMessageBox.confirm(
    '确认删除此记录吗?',
    '确认',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
    delPlan(row.id).then((res) => {
      ElMessage.success('操作成功')
      // close()
      search()
    })
  })
}
// 取消
const canHandler = (row: any) => {
  ElMessageBox.confirm(
    '确认取消此申请吗?',
    '确认',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
    cancelPlan({ id: row.id, processInstanceId: row.processId, comments: '' }).then((res) => {
      ElMessage.success('操作成功')
      // close()
      search()
    })
  })
}
// 打印列表
const printList = () => {
  if (list.value.length) {
    const properties = columns.value.map((item) => {
      return {
        field: item.value,
        displayName: item.text,
      }
    })
    if (selectList.value.length) {
      printJSON(selectList.value, properties, '计量计划列表')
    }
    else {
      printJSON(list.value, properties, '计量计划列表')
    }
  }
  else {
    ElMessage.warning('无可打印内容')
  }
}
// 导出列表
const exportList = () => {
  if (list.value.length) {
    const loading = ElLoading.service({
      lock: true,
      text: 'Loading',
      background: 'rgba(255, 255, 255, 0.8)',
    })
    const data = {
      ...listQuery,
      offset: undefined,
      limit: undefined,
      ids: selectList.value.map(item => item.id),
    }
    exportPlan(data).then((res) => {
      exportFile(res.data, '计量计划')
      loading.close()
    })
      .catch((_) => {
        loading.close()
      })
  }
  else {
    ElMessage.warning('无可导出内容')
  }
}
// 提交
const submit = (row: any) => {
  ElMessageBox.confirm(
    '确认提交吗?',
    '提示',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then((res) => {
    submitPlan({ id: row.id, formId: SCHEDULE.METERING_PLAN_APPROVAL }).then((res) => {
      ElMessage.success('已提交')
      search()
    })
  })
}
// 同意拒绝
const approvalDialogRef = ref()
const approveHandler = (row: any, type: string) => {
  approvalDialogRef.value.initDialog(type, row.taskId, row.processId, row.id)
}
// 审批状态发生变化
watch(() => $props.statusName, (newVal) => {
  if (newVal) {
    listQuery.approvalStatus = applyDict.value[newVal] as string
    fetchData()
  }
},
{
  deep: true,
  immediate: true,
})
// 汇总监督计划
const summaryRef = ref()
const summary = () => {
  summaryRef.value.initDialog()
}
const permUrl = ref({
  edit: '/tested/pmetering/plan/edit',
  del: '/tested/pmetering/plan/delete',
  submit: '/tested/pmetering/plan/submit',
  cancel: '/tested/pmetering/plan/cancel',
  agree: '/tested/pmetering/plan/agree',
  reject: '/tested/pmetering/plan/reject',
  add: '/tested/pmetering/plan/add',
})
</script>

<template>
  <app-container>
    <!-- 审批弹窗 -->
    <approval-dialog ref="approvalDialogRef" @on-success="search" />
    <!-- 年度汇总 -->
    <summary-dialog ref="summaryRef" />
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="search" @clear="reset">
      <search-item>
        <el-input v-model.trim="listQuery.planNo" placeholder="计划编号" clearable style="width: 100%;" />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.planName" placeholder="计划名称" clearable style="width: 100%;" />
      </search-item>
      <search-item>
        <el-select v-model="listQuery.planCategory" placeholder="计划分类" clearable style="width: 100%;">
          <el-option v-for="item in planTypeList" :key="item.value" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-select v-model="listQuery.createCompanyId" clearable filterable placeholder="创建单位" style="width: 100%;">
          <el-option v-for="item in companyList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </search-item>
      <search-item>
        <!-- <el-select v-model="listQuery.deptIds" clearable filterable placeholder="部门">
          <el-option v-for="item in deptList" :key="item.id" :label="item.name" :value="item.id" />
        </el-select> -->
        <el-tree-select
          v-model="listQuery.createDeptId"
          style="width: 100%;"
          :data="deptList"
          :render-after-expand="false"
          check-strictly
          placeholder="部门"
        />
      </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>
      <!-- 折叠查询条件 -->
      <template #searchMore>
        <icon-button v-show="searchMore" icon="icon-zhankai" title="展开查询条件" style="margin-bottom: 10px;" @click="expandSearch" />
        <icon-button v-show="!searchMore" icon="icon-zhankai" title="折叠查询条件" style="margin-bottom: 10px;transform: rotate(180deg);" @click="expandSearch" />
      </template>
      <span v-show="!searchMore">
        <search-item>
          <el-input v-model.trim="listQuery.manufactureNo" placeholder="设备出厂编号" clearable style="width: 100%;" />
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.equipmentRemark" placeholder="设备备注" clearable style="width: 100%;" />
        </search-item>
      </span>
    </search-area>
    <table-container>
      <template v-if="$props.statusName === '全部'" #btns-right>
        <!-- <icon-button icon="icon-add" title="新增" @click="handler({}, 'create')" /> -->
        <el-button type="primary" @click="summary">
          汇总年度计划
        </el-button>
        <icon-button v-if="proxy.hasPerm(permUrl.add)" icon="icon-year" title="新增年计划" @click="handler({}, 'create', 'year')" />
        <!-- <icon-button v-if="proxy.hasPerm(permUrl.add)" icon="icon-jidu" title="新增季计划" @click="handler({}, 'create', 'season')" />
        <icon-button v-if="proxy.hasPerm(permUrl.add)" icon="icon-month" title="新增月计划" @click="handler({}, 'create', 'month')" /> -->
        <icon-button icon="icon-export" title="导出" @click="exportList" />
        <icon-button icon="icon-print" title="打印" @click="printList" />
      </template>
      <!-- 普通表格 -->
      <normal-table
        :data="list" :total="total" :columns="columns as any" :query="listQuery"
        :list-loading="listLoading" :is-showmulti-select="true" :is-multi="true"
        @change="changePage" @multi-select="multiSelect"
      >
        <template #columns>
          <el-table-column v-if="$props.statusName !== '全部'" label="审批状态" align="center">
            <template #default=" scope ">
              {{ scope.row.approvalStatusName }}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="160" align="center">
            <template #default=" scope ">
              <el-button link type="primary" size="small" @click="detail(scope.row)">
                查看
              </el-button>
              <el-button
                v-if="proxy.buttonPerm.edit.if({ approvalStatusName: $props.statusName }, permUrl.edit) && $props.statusName !== '全部'" link type="primary" size="small"
                @click="handler(scope.row, 'update', '')"
              >
                编辑
              </el-button>
              <el-button
                v-if="proxy.buttonPerm.agree.if({ approvalStatusName: $props.statusName }, permUrl.agree)" link type="primary" size="small"
                @click="approveHandler(scope.row, 'agree')"
              >
                同意
              </el-button>
              <el-button
                v-if="proxy.buttonPerm.reject.if({ approvalStatusName: $props.statusName }, permUrl.reject)" link type="primary" size="small"
                @click="approveHandler(scope.row, 'refuse')"
              >
                拒绝
              </el-button>
              <el-button
                v-if="proxy.buttonPerm.submit.if({ approvalStatusName: $props.statusName }, permUrl.submit)" link type="primary" size="small"
                @click="submit(scope.row)"
              >
                提交
              </el-button>
              <el-button
                v-if="proxy.buttonPerm.cancel.if({ approvalStatusName: $props.statusName }, permUrl.cancel)" link type="primary" size="small"
                @click="canHandler(scope.row)"
              >
                取消
              </el-button>
              <el-button
                v-if="proxy.buttonPerm.delete.if({ approvalStatusName: $props.statusName }, permUrl.del)" link type="danger" size="small"
                @click="delHandler(scope.row)"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>

<style lang="scss" scoped>
.nortable-header {
  ::v-deep(.el-table__body-wrapper) {
    display: none;
  }
}
</style>