src/views/lavorissue/issue/index.vue
@@ -35,9 +35,10 @@
            </el-tree>
          </div>
          <div class="right">
            <div v-if="currentPosition" class="position-config">
            <div v-if="currentDept || currentPosition" class="position-config">
              <div class="title">
                <span>岗位配置:{{ currentPosition.label }}</span>
                <span v-if="currentPosition">岗位配置:{{ currentPosition.label }}</span>
                <span v-else-if="currentDept">部门配置:{{ currentDept.label }}</span>
              </div>
              <div class="q-toolbar">
                <el-button size="small" type="primary" @click="openAddItemDialog">新增用品</el-button>
@@ -57,8 +58,20 @@
                  </template>
                </el-table-column>
              </el-table>
              <!-- 分页组件 -->
              <el-pagination
                v-model:current-page="queryParams.current"
                v-model:page-size="queryParams.size"
                :page-sizes="[10, 20, 50, 100]"
                :total="total"
                background
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                style="margin-top: 16px; justify-content: flex-end;s"
              />
            </div>
            <div v-else class="empty">请选择左侧岗位进行配置</div>
            <div v-else class="empty">请选择左侧部门或岗位进行配置</div>
          </div>
        </div>
    <!-- 新增部门/岗位弹窗 -->
@@ -98,7 +111,7 @@
          <el-input-number v-model="addItemForm.quantity" :min="0" :precision="0" />
        </el-form-item>
        <el-form-item label="季度">
          <el-select v-model="addItemForm.quarter" placeholder="选择季度" style="width: 160px">
          <el-select v-model="addItemForm.quarter" placeholder="选择季度">
            <el-option :value="1" :label="quarterLabelFromNumber(1)" />
            <el-option :value="2" :label="quarterLabelFromNumber(2)" />
            <el-option :value="3" :label="quarterLabelFromNumber(3)" />
@@ -200,10 +213,41 @@
  return n === 1 ? '第一季度' : n === 2 ? '第二季度' : n === 3 ? '第三季度' : n === 4 ? '第四季度' : ''
}
// 查询参数和分页相关变量
const queryParams = reactive({
  current: 1,
  size: 10
})
const total = ref(0)
// 分页大小改变
function handleSizeChange(val) {
  queryParams.size = val
  queryParams.current = 1
  loadLaborConf()
}
// 当前页改变
function handleCurrentChange(val) {
  queryParams.current = val
  loadLaborConf()
}
// 加载劳保用品配置列表(支持分页)
async function loadLaborConf(deptPositionId) {
  if (!deptPositionId) {
    const currentId = currentPosition.value?.id ?? currentDept.value?.raw?.id
    if (!currentId) return
    deptPositionId = currentId
  }
  try {
    laborConfLoading.value = true
    const res = await laborConfListPage({ deptPositionId })
    const res = await laborConfListPage({
      deptPositionId,
      current: queryParams.current,
      size: queryParams.size
    })
    laborConfList.value = res.data.records.map(it => ({
      ...it,
      id: it.id ?? it.dictId ?? it.value,
@@ -212,6 +256,7 @@
      quarter: it.quarter,
      quarterLabel: quarterLabelFromNumber(it.quarter),
    }))
    total.value = res.data.total || 0
  } finally {
    laborConfLoading.value = false
  }
@@ -224,7 +269,7 @@
const addItemForm = reactive({ id: undefined, dictId: undefined, quantity: 0, quarter: 1 })
function openAddItemDialog() {
  if (!currentPosition.value) return
  if (!currentDept.value && !currentPosition.value) return
  addItemDialogTitle.value = '新增用品'
  addItemForm.id = undefined
  addItemForm.dictId = undefined
@@ -234,7 +279,7 @@
}
function openEditItemDialog(row) {
  if (!currentPosition.value || !row) return
  if ((!currentDept.value && !currentPosition.value) || !row) return
  addItemDialogTitle.value = '编辑用品'
  addItemForm.id = row.id
  addItemForm.dictId = row.dictId
@@ -248,12 +293,13 @@
}
async function onConfirmAddItem() {
  if (!currentPosition.value) return
  if (!currentDept.value && !currentPosition.value) return
  addItemSaving.value = true
  try {
    const qNum = Number(addItemForm.quarter) || 1
    const deptPositionId = currentPosition.value.id ?? currentPosition.value.raw?.id ?? currentPosition.value?.id
    if (addItemForm.id) {
      // 编辑用品
      await updateLaborConf({
        id: addItemForm.id,
        dictId: addItemForm.dictId,
@@ -261,15 +307,19 @@
        quarter: qNum,
      })
    } else {
      // 新增用品
      const currentId = currentPosition.value?.id ?? currentDept.value?.raw?.id
      await addLaborConf({
        deptPositionId,
        deptPositionId: currentId,
        dictId: addItemForm.dictId,
        num: Number(addItemForm.quantity) || 0,
        quarter: qNum,
      })
    }
    const posId = currentPosition.value.raw?.id ?? currentPosition.value.id
    await loadLaborConf(posId)
    // 重新加载用品配置列表
    await loadLaborConf()
    addItemDialogVisible.value = false
    ElMessage.success('保存成功')
  } catch (e) {
@@ -280,7 +330,7 @@
}
async function onDeleteItem(row) {
  if (!currentPosition.value || !row) return
  if ((!currentDept.value && !currentPosition.value) || !row) return
  try {
    await ElMessageBox.confirm('确定删除该用品配置吗?', '提示', { type: 'warning' })
  } catch {
@@ -288,8 +338,8 @@
  }
  try {
    await deleteLaborConf([row.id])
    const posId = currentPosition.value.raw?.id ?? currentPosition.value.id
    await loadLaborConf(posId)
    // 重新加载用品配置列表
    await loadLaborConf()
    ElMessage.success('删除成功')
  } catch (e) {
    ElMessage.error((e && (e.msg || e.message)) || '删除失败')
@@ -367,12 +417,14 @@
  if (node.type === 1) {
    currentDept.value = node
    currentPosition.value = null
    // 选择部门时,加载部门级别的用品配置
    loadLaborConf()
  } else if (node.type === 2) {
    const dept = findDeptById(departments, node.parentDeptId)
    if (dept) currentDept.value = mapDeptToTree(dept)
    currentPosition.value = node.raw
    // 选择岗位时,按要求查询用品配置列表
    loadLaborConf(node.raw.id)
    // 选择岗位时,查询用品配置列表
    loadLaborConf()
  }
}