ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<script lang="ts" setup>
import { ref } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
import { downloadByUrl } from '@jnpf/utils';
 
import { exportExcel } from '#/api/extend/employee';
 
const [registerModal, { closeModal, changeOkLoading }] = useModalInner(init);
const { createMessage } = useMessage();
const dataType = ref(0);
const isIndeterminate = ref(false);
const checkAll = ref(false);
const columnList = ref<any[]>([
  { fullName: '工号', id: 'enCode' },
  { fullName: '姓名', id: 'fullName' },
  { fullName: '性别', id: 'gender' },
  { fullName: '部门', id: 'departmentName' },
  { fullName: '岗位', id: 'positionName' },
  { fullName: '用工性质', id: 'workingNature' },
  { fullName: '身份证号', id: 'idNumber' },
  { fullName: '联系电话', id: 'telephone' },
  { fullName: '出生年月', id: 'birthday' },
  { fullName: '参加工作', id: 'attendWorkTime' },
  { fullName: '最高学历', id: 'education' },
  { fullName: '所学专业', id: 'major' },
  { fullName: '毕业院校', id: 'graduationAcademy' },
  { fullName: '毕业时间', id: 'graduationTime' },
  { fullName: '创建时间', id: 'creatorTime' },
]);
const checkedList = ref<string[]>([]);
const defaultCheckedList = ref<string[]>([]);
const listQuery = ref({});
 
function init(data) {
  dataType.value = 0;
  checkedList.value = columnList.value.map((o) => o.id);
  handleCheckedChange(checkedList.value);
  listQuery.value = data.listQuery;
}
function handleCheckAllChange(e) {
  const val = e.target.checked;
  checkedList.value = val ? columnList.value.map((o) => o.id) : defaultCheckedList.value;
  isIndeterminate.value = val ? false : !!defaultCheckedList.value.length;
}
function handleCheckedChange(val) {
  const checkedCount = val.length;
  checkAll.value = checkedCount === columnList.value.length;
  isIndeterminate.value = !!checkedCount && checkedCount < columnList.value.length;
}
function handleSubmit() {
  if (!checkedList.value.length) return createMessage.warning('请至少选择一个导出字段');
  changeOkLoading(true);
  const query = {
    ...listQuery.value,
    dataType: dataType.value,
    selectKey: checkedList.value.join(','),
  };
  exportExcel(query)
    .then((res) => {
      changeOkLoading(false);
      if (!res.data.url) return;
      downloadByUrl({ url: res.data.url });
      closeModal();
    })
    .catch(() => {
      changeOkLoading(false);
    });
}
</script>
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="导出" ok-text="导出" @ok="handleSubmit" destroy-on-close class="jnpf-export-modal">
    <a-form :colon="false" label-align="left" :label-col="{ style: { width: '90px' } }">
      <a-form-item>
        <a-radio-group v-model:value="dataType">
          <a-radio :value="0">当前页面数据</a-radio>
          <a-radio :value="1">全部页面数据</a-radio>
        </a-radio-group>
      </a-form-item>
      <div class="export-line">
        <p class="export-label">导出数据<span>请选择导出字段</span></p>
      </div>
      <a-checkbox :indeterminate="isIndeterminate" v-model:checked="checkAll" @change="handleCheckAllChange">全选</a-checkbox>
      <a-checkbox-group v-model:value="checkedList" class="options-list" @change="handleCheckedChange">
        <a-checkbox v-for="item in columnList" :key="item.id" :value="item.id" class="options-item">
          {{ item.fullName }}
        </a-checkbox>
      </a-checkbox-group>
    </a-form>
  </BasicModal>
</template>