Blame view

src/views/project/order/ExportModal.vue 5.37 KB
sanmu authored
1
2
3
4
5
<template>
  <BasicModal
    v-bind="$attrs"
    destroyOnClose
    @register="register"
sanmu authored
6
    title="导出"
sanmu authored
7
8
9
10
11
12
13
14
    width="500px"
    :height="100"
    wrapClassName="h-[260px]"
    @visible-change="handleShow"
    :footer="null"
  >
    <CheckboxGroup v-model:value="checkedList" :options="options" />
    <div className="mt-6">
sanmu authored
15
      <a-button type="primary" @click="handleExport" className="ml-4">导出</a-button>
sanmu authored
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
93
94
    </div>
  </BasicModal>
</template>
<script lang="ts">
  import { defineComponent, ref, computed } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { orderExport } from '/@/api/project/order';
  import { ROLE } from './type.d';
  import { CheckboxGroup } from 'ant-design-vue';
  import { useOrderStoreWithOut } from '/@/store/modules/order';
  import { useOrderInfo } from '/@/hooks/component/order';
  import { merge } from 'lodash-es';
  import {
    ORDER_LIST_BASE_FIELDS,
    ORDER_LIST_REPORT_FIELDS,
    ORDER_LIST_PROFIT_FIELDS,
    ORDER_LIST_INSPECT_FIELDS,
    ORDER_LIST_TRACK_FIELDS,
  } from './tableData';

  export default defineComponent({
    components: { BasicModal, CheckboxGroup },
    props: {
      role: {
        type: String,
      },
    },
    setup(props) {
      const orderStore = useOrderStoreWithOut();
      const { manualPreform, exchangeRate } = useOrderInfo(orderStore);
      const checkedList = ref([
        'baseFields',
        'reportFields',
        'profitAnalysisFields',
        'trackStageFields',
        'inspectionStageFields',
      ]);
      const loading = ref(true);
      const activeUser = ref();
      const info = ref();
      const searchData = ref({});
      const [register, { setModalProps, closeModal }] = useModalInner(async (data) => {
        searchData.value = data.data || {};
        activeUser.value = undefined;
        info.value = '';
      });

      const options = computed(() => {
        if (props.role === ROLE.TRACKER) {
          return [
            { label: '基本信息', value: 'baseFields' },
            { label: '利润分析', value: 'profitAnalysisFields' },
            { label: '跟单信息', value: 'trackStageFields' },
            { label: '质检信息', value: 'inspectionStageFields' },
          ];
        }
        if (props.role === ROLE.INSPECT) {
          return [
            { label: '基本信息', value: 'baseFields' },
            { label: '跟单信息', value: 'trackStageFields' },
            { label: '质检信息', value: 'inspectionStageFields' },
          ];
        }
        return [
          { label: '基本信息', value: 'baseFields' },
          { label: '项目报告', value: 'reportFields' },
          { label: '利润分析', value: 'profitAnalysisFields' },
          { label: '跟单信息', value: 'trackStageFields' },
          { label: '质检信息', value: 'inspectionStageFields' },
        ];
      });

      function handleShow(visible: boolean) {
        if (visible) {
          loading.value = true;
          setModalProps({ loading: false, confirmLoading: false });
        }
      }
sanmu authored
95
      async function handleExport() {
sanmu authored
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
        const fieldVO: any = {};
        checkedList.value.forEach((item) => {
          if (item === 'baseFields') {
            fieldVO.baseFields = ORDER_LIST_BASE_FIELDS.map((item) => ({
              [item.dataIndex]: 'selected',
            }));
            fieldVO.baseFields = merge({}, ...fieldVO.baseFields);
          } else if (item === 'reportFields') {
            fieldVO.reportFields = ORDER_LIST_REPORT_FIELDS[0].children.map((item) => ({
              [item.dataIndex]: 'selected',
            }));
            fieldVO.reportFields = merge({}, ...fieldVO.reportFields);
          } else if (item === 'profitAnalysisFields') {
            if (props.role === ROLE.TRACKER) {
              fieldVO.profitAnalysisFields = ORDER_LIST_PROFIT_FIELDS[0].children
sanmu authored
111
112
113
114
115
116
117
                .filter((k) =>
                  [
                    'customerPrice',
                    'customerRmbPrice',
                    'customerTotalPrice',
                    'customerRmbTotalPrice',
                  ].includes(k.dataIndex),
sanmu authored
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
                )
                .map((item) => ({
                  [item.dataIndex]: 'selected',
                }));
            } else {
              fieldVO.profitAnalysisFields = ORDER_LIST_PROFIT_FIELDS[0].children.map((item) => ({
                [item.dataIndex]: 'selected',
              }));
            }
            fieldVO.profitAnalysisFields = merge({}, ...fieldVO.profitAnalysisFields);
          } else if (item === 'trackStageFields') {
            fieldVO.trackStageFields = ORDER_LIST_TRACK_FIELDS[0].children.map((item) => ({
              [item.dataIndex]: 'selected',
            }));
            fieldVO.trackStageFields = merge({}, ...fieldVO.trackStageFields);
          } else if (item === 'inspectionStageFields') {
            fieldVO.inspectionStageFields = ORDER_LIST_INSPECT_FIELDS[0].children.map((item) => ({
              [item.dataIndex]: 'selected',
            }));
            fieldVO.inspectionStageFields = merge({}, ...fieldVO.inspectionStageFields);
          }
        });

        await orderExport({ fieldVO });

        closeModal();
      }
      return {
        register,
        options,
        loading,
        handleShow,
        info,
        manualPreform,
sanmu authored
152
        handleExport,
sanmu authored
153
154
155
156
157
158
159
        activeUser,
        exchangeRate,
        checkedList,
      };
    },
  });
</script>