Blame view

src/views/project/order/ExportModal.vue 7.15 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
16
17
      <a-button type="primary" @click="handleExport" className="ml-4" :loading="exportLoading"
        >导出</a-button
      >
sanmu authored
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
    </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,
      },
44
45
46
      ids: {
        type: Array<string | number>,
      },
sanmu authored
47
48
49
50
51
    },
    setup(props) {
      const orderStore = useOrderStoreWithOut();
      const { manualPreform, exchangeRate } = useOrderInfo(orderStore);
      const checkedList = ref([
sanmu authored
52
53
54
55
56
        // 'baseFields',
        // 'reportFields',
        // 'profitAnalysisFields',
        // 'trackStageFields',
        // 'inspectionStageFields',
sanmu authored
57
58
      ]);
      const loading = ref(true);
sanmu authored
59
      const exportLoading = ref(false);
sanmu authored
60
61
62
63
64
65
66
67
68
69
      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(() => {
sanmu authored
70
71
72
73
74
75
76
77
78
79
80
        // 运营总监-基本信息,跟单,质检
        if (props.role === ROLE.DATA_REPORT_USER) {
          return [
            { label: '基本信息', value: 'baseFields' },
            { label: '跟单信息', value: 'trackStageFields' },
            { label: '质检信息', value: 'inspectionStageFields' },
          ];
        }
        if (props.role === ROLE.BUSINESS) {
          return [
            { label: '基本信息', value: 'baseFields' },
81
            { label: '项目报告', value: 'reportFields' },
sanmu authored
82
            { label: '利润分析', value: 'profitAnalysisFields' },
83
84
85
86
87
88
89
90
91
            { label: '跟单信息', value: 'trackStageFields' },
            { label: '质检信息', value: 'inspectionStageFields' },
          ];
        }
        if (props.role === ROLE.FINANCE) {
          return [
            { label: '基本信息', value: 'baseFields' },
            { label: '项目报告', value: 'reportFields' },
            { label: '利润分析', value: 'profitAnalysisFields' },
sanmu authored
92
93
94
95
            { label: '跟单信息', value: 'trackStageFields' },
            { label: '质检信息', value: 'inspectionStageFields' },
          ];
        }
sanmu authored
96
97
98
99
100
101
102
103
        if (props.role === ROLE.TRACKER) {
          return [
            { label: '基本信息', value: 'baseFields' },
            { label: '利润分析', value: 'profitAnalysisFields' },
            { label: '跟单信息', value: 'trackStageFields' },
            { label: '质检信息', value: 'inspectionStageFields' },
          ];
        }
sanmu authored
104
105

        if (props.role === ROLE.ADMIN) {
sanmu authored
106
107
          return [
            { label: '基本信息', value: 'baseFields' },
sanmu authored
108
109
            { label: '项目报告', value: 'reportFields' },
            { label: '利润分析', value: 'profitAnalysisFields' },
sanmu authored
110
111
112
113
            { label: '跟单信息', value: 'trackStageFields' },
            { label: '质检信息', value: 'inspectionStageFields' },
          ];
        }
sanmu authored
114
柏杨 authored
115
116
117
118
119
120
121
        if (props.role === ROLE.INSPECT) {
          return [
            { label: '基本信息', value: 'baseFields' },
            { label: '质检信息', value: 'inspectionStageFields' },
          ];
        }
sanmu authored
122
123
124
125
        return [
          { label: '基本信息', value: 'baseFields' },
          { label: '质检信息', value: 'inspectionStageFields' },
        ];
sanmu authored
126
127
128
129
130
131
132
133
134
      });

      function handleShow(visible: boolean) {
        if (visible) {
          loading.value = true;
          setModalProps({ loading: false, confirmLoading: false });
        }
      }
sanmu authored
135
      async function handleExport() {
sanmu authored
136
137
138
139
140
141
142
        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);
柏杨 authored
143
144
145
146
            if (props.role === ROLE.PRODUCE) {
              // 从 baseFields 中去除 orderHod
              delete fieldVO.baseFields['orderHodTime'];
            }
sanmu authored
147
148
149
150
151
152
153
154
          } 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
155
156
157
                .filter((k) =>
                  [
                    'customerPrice',
sanmu authored
158
159
                    'productionDepartmentPrice',
                    'productionDepartmentTotalPrice',
sanmu authored
160
                  ].includes(k.dataIndex),
sanmu authored
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
                )
                .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);
          }
        });
184
185
        //导出选中的订单
        fieldVO.orderIds = props.ids;
sanmu authored
186
        exportLoading.value = true;
sanmu authored
187
        await orderExport({ ...searchData.value, fieldVO });
sanmu authored
188
        exportLoading.value = false;
sanmu authored
189
190
191
192
193
194
195
196
197
198

        closeModal();
      }
      return {
        register,
        options,
        loading,
        handleShow,
        info,
        manualPreform,
sanmu authored
199
        handleExport,
sanmu authored
200
201
202
        activeUser,
        exchangeRate,
        checkedList,
sanmu authored
203
        exportLoading,
sanmu authored
204
205
206
207
      };
    },
  });
</script>