Blame view

src/views/project/order/index.vue 10.2 KB
sanmu authored
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
93
94
<template>
  <div>
    <BasicTable @register="registerTable" bordered>
      <template #headerCell="{ column }">
        <!-- <template v-if="column.key === 'address1'">
          <span class="flex items-center justify-center"> 自定义字段列11 </span>
        </template> -->
        <template v-if="SELECT_FIELD_COLUMNS.includes(column.key)">
          <span class="flex items-center justify-center">
            {{ column.customTitle }}
            <FormOutlined class="ml-2 cursor-pointer" @click="handleFieldVisible(column)" />
          </span>
        </template>
        <template v-else>
          <HeaderCell :column="column" />
        </template>
      </template>
      <template #headerTop>
        <a-alert type="info" show-icon>
          <template #message>
            <template v-if="checkedKeys.length > 0">
              <span>已选中{{ checkedKeys.length }}条记录(可跨页)</span>
              <a-button type="link" @click="checkedKeys = []" size="small">清空</a-button>
            </template>
            <template v-else>
              <span>未选中任何订单</span>
            </template>
          </template>
        </a-alert>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                label: '编辑',
                // icon: 'ic:outline-delete-outline',
                onClick: handleEdit.bind(null, record),
              },
              {
                label: '申请权限',
                // icon: 'ic:outline-delete-outline',
                onClick: handleCheck.bind(null, record),
              },
            ]"
            :dropDownActions="[
              {
                label: '历史记录',
                onClick: handleHistory.bind(null, record),
              },
            ]"
          />
        </template>
        <template v-if="column.key === 'picUrl'">
          <img
            :width="100"
            :height="100"
            :src="record.picUrl"
            :key="record.picUrl"
            @click="handlePreview(record.picUrl)"
          />
        </template>
      </template>

      <template #toolbar>
        <a-button type="primary" @click="handleExport">导出</a-button>
        <a-button type="primary" @click="handleProfitModal" :disabled="!checkedKeys.length"
          >分析利润</a-button
        >
        <a-button type="primary" @click="handleAdd">创建订单</a-button>
      </template>
    </BasicTable>
    <FormDetail
      @register="formDetailRegister"
      :onGoCheckDetail="handleGoCheckDetail"
      @success="handleFormSuccess"
    />
    <ProfitAnalysis @register="profitModalRegister" />
    <CheckDetail @register="checkModalRegister" :onGoFormDetail="handleGoFormDetail" />
    <HistoryDetail @register="historyDetailRegister" />
    <FieldDetail @register="fieldDetailRegister" />
  </div>
</template>
<script lang="ts">
  import { defineComponent, onMounted, ref, toRaw, toRefs, unref } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { FormOutlined } from '@ant-design/icons-vue';
  import HeaderCell from '/@/components/Table/src/components/HeaderCell.vue';
  import { Alert } from 'ant-design-vue';

  import { useDrawer } from '/@/components/Drawer';
  import ProfitAnalysis from './ProfitAnalysis.vue';
  import { useModal } from '/@/components/Modal';
sanmu authored
95
96
  import { getFormConfig, getOrderColumns, SELECT_FIELD_COLUMNS } from './tableData';
  import FormDetail from './FormDetail/index.vue';
sanmu authored
97
98
99
100
101
102
  import CheckDetail from './CheckDetail.vue';
  import HistoryDetail from './HistoryDetail.vue';
  import FieldDetail from './FieldDetail.vue';
  import { createImgPreview } from '/@/components/Preview/index';
  import { getOrderList, orderExport } from '/@/api/project/order';
  import { useOrderStoreWithOut } from '/@/store/modules/order';
sanmu authored
103
104
  import { keyBy, reduce } from 'lodash-es';
  import { useUserStoreWithOut } from '/@/store/modules/user';
sanmu authored
105
106

  const orderStore = useOrderStoreWithOut();
sanmu authored
107
  const userStore = useUserStoreWithOut();
sanmu authored
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

  export default defineComponent({
    components: {
      HeaderCell,
      BasicTable,
      AAlert: Alert,
      TableAction,
      FormDetail,
      ProfitAnalysis,
      FormOutlined,
      CheckDetail,
      HistoryDetail,
      FieldDetail,
    },
    setup() {
      const checkedKeys = ref<Array<string | number>>([]);
      const [profitModalRegister, { openModal: openProfitModal }] = useModal();
      const tooltipVisible = ref(false);
      const [formDetailRegister, { openDrawer: openFormDetailDrawer }] = useDrawer();
      const [historyDetailRegister, { openDrawer: openHistoryDetailDrawer }] = useDrawer();
      const [fieldDetailRegister, { openDrawer: openFieldDetailDrawer }] = useDrawer();
sanmu authored
130
131
      const user = userStore.getUserInfo;
sanmu authored
132
133
134
135
136
      const [checkModalRegister, { openDrawer: openCheckDetailDrawer }] = useDrawer();
      onMounted(async () => {
        await orderStore.getDict();
      });
sanmu authored
137
      const [registerTable, { getForm, reload, getColumns }] = useTable({
sanmu authored
138
139
140
141
142
        api: getOrderList,
        title: '订单列表',
        pagination: {
          total: 60,
        },
sanmu authored
143
        columns: getOrderColumns(user?.roleSmallVO?.code),
sanmu authored
144
145
146
147
148
149
150
151
152
        useSearchForm: true,
        formConfig: getFormConfig(),
        showTableSetting: true,
        // tableSetting: { fullScreen: true },
        showIndexColumn: false,
        rowKey: 'id',
        rowSelection: {
          type: 'checkbox',
          selectedRowKeys: checkedKeys,
sanmu authored
153
154
          onSelect,
          onSelectAll,
sanmu authored
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
        },
        actionColumn: {
          width: 160,
          title: 'Action',
          dataIndex: 'action',
          // slots: { customRender: 'action' },
        },
      });

      function getFormValues() {
        console.log(getForm().getFieldsValue());
      }

      function onSelect(record, selected) {
        if (selected) {
          checkedKeys.value = [...checkedKeys.value, record.id];
        } else {
          checkedKeys.value = checkedKeys.value.filter((id) => id !== record.id);
        }
      }
      function onSelectAll(selected, selectedRows, changeRows) {
        const changeIds = changeRows.map((item) => item.id);
        if (selected) {
          checkedKeys.value = [...checkedKeys.value, ...changeIds];
        } else {
          checkedKeys.value = checkedKeys.value.filter((id) => {
            return !changeIds.includes(id);
          });
        }
      }

      function handleEdit(record, e) {
        openFormDetailDrawer(true, { ...toRaw(record) });
        e?.stopPropagation();
        return false;
      }

      function handleAdd() {
sanmu authored
193
        openFormDetailDrawer(true, {});
sanmu authored
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
      }

      function handleCheck(record, e) {
        openCheckDetailDrawer(true, record);
        e?.stopPropagation();
        return false;
      }

      function handleHistory(record, e) {
        openHistoryDetailDrawer(true, record);
        e?.stopPropagation();
        return false;
      }

      function handleProfitModal() {
        openProfitModal(true, {
          data: checkedKeys.value,
        });
      }

      function handleFieldVisible(record) {
        openFieldDetailDrawer(true, record);
      }

      function handleGoCheckDetail() {
        openCheckDetailDrawer(true);
        openFormDetailDrawer(false);
      }

      function handleGoFormDetail() {
        openCheckDetailDrawer(false);
        openFormDetailDrawer(true);
      }

      function handlePreview(url, e) {
        createImgPreview({ imageList: [url], defaultWidth: 500 });
        // e?.stopPropagation();
        // e?.preventDefault();
        return false;
      }

      async function handleExport() {
sanmu authored
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
        const columns = getColumns();
        const colObj = keyBy(columns, 'dataIndex');
        const {
          trackStageInfo,
          reportInfo,
          profitAnalysisInfo,
          inspectionStageInfo,
          ...baseFields
        } = colObj;

        for (const key in baseFields) {
          baseFields[key] = 'selected';
        }
        delete baseFields.action;

        const fieldVO = {
          baseFields,
          profitAnalysisFields: profitAnalysisInfo?.children?.length
            ? reduce(
                profitAnalysisInfo.children,
                (result, item) => {
                  result[item.dataIndex] = 'selected';
                  return result;
                },
                {},
              )
            : {},
          reportFields: reportInfo?.children?.length
            ? reduce(
                reportInfo.children,
                (result, item) => {
                  result[item.dataIndex] = 'selected';
                  return result;
                },
                {},
              )
            : {},
          trackStageFields: trackStageInfo?.children?.length
            ? reduce(
                trackStageInfo.children,
                (result, item) => {
                  result[item.dataIndex] = 'selected';
                  return result;
                },
                {},
              )
            : {},
          inspectionStageFields: inspectionStageInfo?.children?.length
            ? reduce(
                inspectionStageInfo.children,
                (result, item) => {
                  result[item.dataIndex] = 'selected';
                  return result;
                },
                {},
              )
            : {},
        };

        await orderExport({ fieldVO });
sanmu authored
296
297
298
299
300
301
302
      }

      const handleFormSuccess = () => {
        reload();
      };

      return {
sanmu authored
303
        SELECT_FIELD_COLUMNS,
sanmu authored
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
        fieldDetailRegister,
        profitModalRegister,
        historyDetailRegister,
        formDetailRegister,
        handleProfitModal,
        registerTable,
        getFormValues,
        checkedKeys,
        onSelect,
        handleEdit,
        handleCheck,
        onSelectAll,
        tooltipVisible,
        handleFieldVisible,
        checkModalRegister,
        handleGoCheckDetail,
        handleGoFormDetail,
        handleHistory,
        handleAdd,
        createImgPreview,
        handleExport,
        handlePreview,
        handleFormSuccess,
      };
    },
  });
</script>

<style>
  .ant-table-thead th,
  .ant-table-tbody td {
    padding: 0;
    white-space: pre-wrap;
  }

  .ant-table-cell img {
    width: 100px;
    height: 100px;
  }
</style>
sanmu authored
344
./constant