Blame view

src/views/project/approve/ReceivePanel.vue 16.6 KB
1
2
3
4
5
6
7
8
<template>
  <BasicTable @register="registerTable" className="p-0">
    <template #form-custom> custom-slot </template>
    <template #bodyCell="{ column, record }">
      <template v-if="column.key === 'picUrl'">
        <img
          :width="50"
          :height="50"
柏杨 authored
9
10
          :src="record?.invoiceFieldVo?.smallPicUrl"
          @click="handlePreview(record?.invoiceFieldVo?.picUrl)"
11
12
13
14
        />
      </template>
      <template v-if="column.key === 'action'">
        <TableAction
15
          v-if="!isApproved"
16
17
          :actions="[
            {
柏杨 authored
18
              label: '审核',
19
20
21
22
23
              // icon: 'ic:outline-delete-outline',
              onClick: handleDetail.bind(null, record),
            },
          ]"
        />
24
25
26
27
28
29
30
31
32
33
        <TableAction
          v-if="isApproved"
          :actions="[
            {
              label: '详情',
              // icon: 'ic:outline-delete-outline',
              onClick: handleDetail.bind(null, record),
            },
          ]"
        />
34
35
36
      </template>
    </template>
  </BasicTable>
37
  <BasicModal
38
    :formFooter="(!isApproved && role === ROLE.ADMIN) || showInvoice"
39
    @register="registerModal"
40
41
    title="申请信息"
    okText="通过"
柏杨 authored
42
    width="1000px"
43
    @ok="handleTrue"
柏杨 authored
44
    @visible-change="handleShow"
45
46
    :showCancelBtn="(!isApproved && role === ROLE.ADMIN) || (showInvoice && role === ROLE.FINANCE)"
    :showOkBtn="(!isApproved && role === ROLE.ADMIN) || (showInvoice && role === ROLE.FINANCE)"
47
  >
柏杨 authored
48
    <!-- <Description
49
50
51
52
53
54
      class="mt-4"
      layout="vertical"
      :collapseOptions="{ canExpand: true, helpMessage: 'help me' }"
      :column="2"
      :data="mockData"
      :schema="schema"
柏杨 authored
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
    /> -->
    <table
      v-if="!showInvoice"
      style="
        width: 100%;
        border-collapse: collapse;
        text-align: center;
        border: 1px solid black;
        font-size: 16px;
      "
    >
      <thead>
        <!-- <tr>
          <th colspan="4" style="border: 1px solid black">净利润分析表</th>
        </tr> -->
      </thead>
      <tbody>
        <tr
          ><td colspan="7" style="text-align: center; font-weight: bold; font-size: 24px"
            >收款单</td
          ></tr
        >
        <tr>
          <td style="border: 1px solid black; width: 14%">Invoice编号</td>
          <td style="border: 1px solid black; width: 14%">实际收款金额汇总</td>
          <td style="border: 1px solid black; width: 14%">客户总价金额汇总</td>
          <td style="border: 1px solid black; width: 14%">发生扣款金额汇总</td>
柏杨 authored
82
          <td style="border: 1px solid black; width: 14%">其他费用汇总</td>
柏杨 authored
83
84
85
86
87
88
89
90
          <td style="border: 1px solid black; width: 14%">必须回款日期</td>
          <td style="border: 1px solid black; width: 14%">实际回款日期</td>
        </tr>
        <tr>
          <td style="border: 1px solid black; width: 14%">{{ invoiceNo }}</td>
          <td style="border: 1px solid black; width: 14%">${{ totalPayAmount }}</td>
          <td style="border: 1px solid black; width: 14%">${{ totalCustomerAmount }}</td>
          <td style="border: 1px solid black; width: 14%">${{ deductAmount }}</td>
柏杨 authored
91
          <td style="border: 1px solid black; width: 14%">${{ otherAmount }}</td>
柏杨 authored
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
          <td style="border: 1px solid black; width: 14%">{{ backRefundDate }}</td>
          <td style="border: 1px solid black; width: 14%">{{ actualRefundDate }}</td>
        </tr>
        <tr>
          <td colspan="7" style="border: 1px solid black; padding: 10px">
            <div style="display: flex; justify-content: space-between">
              <span style="width: 20%">收款单位:</span>
              <span style="width: 80%">
                {{ payee }}
              </span>
            </div>
          </td>
        </tr>
      </tbody>
    </table>
107
108
109
    <a v-if="showInvoice" @click="openPic(mockData.invoiceUrl)" rel="noopener noreferrer">{{
      mockData.invoiceName
    }}</a>
110
    <template #appendFooter>
柏杨 authored
111
112
113
114
115
116
      <a-button
        v-if="!isApproved && (role === ROLE.ADMIN || role === ROLE.FINANCE)"
        @click="handleFalse"
      >
        不通过</a-button
      >
117
      <a-button v-if="(isApproved && role === ROLE.ADMIN) || (isApproved && showInvoice && role === ROLE.FINANCE)" @click="handleFalse"> 驳回重填</a-button>
柏杨 authored
118
      <a-button @click="handleExport"> 导出</a-button>
119
    </template>
120
  </BasicModal>
121
122
123
124
125
126
  <MsgModal v-if="msgVisible" @msg-modal-close="handleMsgModalClose" />
</template>
<script lang="ts">
  import MsgModal from './MsgModal.vue';
  import { computed, defineComponent, ref } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
127
  import { BasicModal, useModal } from '/@/components/Modal';
柏杨 authored
128
  import axios from 'axios';
129
130
131
132
133
134
135
136

  import { approveAuditApi, getApprovedListApi, getWaitListApi } from '/@/api/project/approve';
  import { FIELDS_BASE_INFO, FIELDS_PROFIT_INFO, FIELDS_REPORT_INFO } from '../order/tableData';
  import { ROLE } from '../order//type.d';
  import { useUserStoreWithOut } from '/@/store/modules/user';
  import BaseInfo from './BaseInfo.vue';
  import { createImgPreview } from '/@/components/Preview';
  import { getFormConfig } from './data';
137
  import { Description, DescItem, useDescription } from '@/components/Description';
138
139
140
141
142
143

  const userStore = useUserStoreWithOut();

  export default defineComponent({
    components: {
      BasicTable,
144
      BasicModal,
145
      TableAction,
146
      Description,
147
148
149
150
151
152
153
154
155
156
157
      BaseInfo,
      MsgModal,
    },
    props: {
      isApproved: { type: Boolean },
    },
    setup(props) {
      // visible 用于msgModal显示隐藏
      const msgVisible = ref(false);
      const checkedKeys = ref<Array<string | number>>([]);
      const currentKey = ref('1');
158
      const [registerModal, { openModal, closeModal }] = useModal();
159
160
161
      const fieldInfos = ref({});
      const baseInfos = ref({});
      const id = ref('');
柏杨 authored
162
163
164
165
166
167
168
169
      const invoiceNo = ref(); // 实际收款金额汇总
      const totalPayAmount = ref(); // 实际收款金额汇总
      const totalCustomerAmount = ref(); // 客户总价金额汇总
      const deductAmount = ref(); // 发生扣款金额汇总
      const backRefundDate = ref(); // 必须回款日期
      const actualRefundDate = ref(); // 实际回款日期
      const otherAmount = ref(); // 其他费用汇总
      const payee = ref(); // 其他费用汇总
柏杨 authored
170
      const projectNo = ref();
柏杨 authored
171
172
      const financePerson = ref('');
      const trackerUser = ref('');
173
      const showInvoice = ref(false);
174
175
176
      const mockData = ref();
      const schema: DescItem[] = [
        {
柏杨 authored
177
          field: 'totalPayAmount',
178
179
180
          label: '实际收款金额汇总',
        },
        {
181
          field: 'totalCustomerAmount',
182
183
184
185
186
187
188
189
190
191
192
193
194
195
          label: '客户总价金额汇总',
        },
        {
          field: 'deductAmount',
          label: '发生扣款金额汇总',
        },
        {
          field: 'backRefundDate',
          label: '必须回款日期',
        },
        {
          field: 'otherAmount',
          label: '其他费用汇总',
        },
柏杨 authored
196
197
198
199
        {
          field: 'actualRefundDate',
          label: '实际回款日期',
        },
200
201
202
203
204
205
206
      ];
      // const [register] = useDescription({
      //   title: 'useDescription',
      //   data: mockData,
      //   schema: schema,
      // });
207
208
209
      let columns = [
        {
          title: '申请人',
柏杨 authored
210
          dataIndex: 'createBy',
211
          width: 150,
柏杨 authored
212
213
214
215
          customRender: (column) => {
            const { record } = column || {};
            return record?.fieldInfos?.checkBillOrderDO?.financePerson;
          },
216
217
218
219
220
221
222
        },
        {
          title: 'INVOICE编号',
          dataIndex: 'invoiceNo',
          width: 150,
          customRender: (column) => {
            const { record } = column || {};
223
224
225
226
227
228
            if(record?.type === 30){
              return record?.fieldInfos?.invoiceFieldVO?.invoiceNo;
            }else if(record?.type === 60){
              return record?.fieldInfos?.deductionUrlFieldVO?.invoiceNo;
            }
229
230
          },
        },
柏杨 authored
231
232
233
234
235
236
        {
          title: '内部编号',
          dataIndex: 'innerNo',
          width: 150,
          customRender: (column) => {
            const { record } = column || {};
237
            if(record?.type === 30){
柏杨 authored
238
239
240
241
242
            const extractedValues = ref<string[]>(
              record?.fieldInfos?.invoiceFieldVO?.innerNo?.map((item) => item),
            );
            // return record?.invoiceFieldVo?.innerNo;
            return extractedValues?.value?.join(',');
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
          }else if(record?.type === 60){
           return record?.fieldInfos?.deductionUrlFieldVO?.innerNo;
          }
          },
        },
        {
          title: '审核类型',
          dataIndex: 'productionDepartment',
          width: 150,
          customRender: (column) => {
            const { record } = column || {};
            if (record?.type === 30) {
              return '应收账单申请';
            } else if (record?.type == 60) {
              return `Invoice扣款单申请${record?.fieldInfos?.deductionUrlFieldVO?.deductAmount ? `(¥${record?.fieldInfos?.deductionUrlFieldVO?.deductAmount?.toFixed(2)})` : ''}`;
            }
柏杨 authored
259
260
          },
        },
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
      ];

      if (props.isApproved) {
        columns = columns.concat([
          {
            title: '状态',
            dataIndex: 'status',
            width: 150,
            customRender: (column) => {
              const { record } = column || {};

              return record.status === 10 ? '通过' : '拒绝';
            },
          },
          { title: '拒绝原因', dataIndex: 'refuseRemark', width: 250 },
        ]);
      }
279
280
281
282
283
284
285
286
287
288
289
290
      const role = computed(() => {
        return userStore.getUserInfo?.roleSmallVO?.code;
      });

      // 根据角色动态设置 searchInfo
      const searchInfo = computed(() => {
        if (role.value === ROLE.BUSINESS || role.value === ROLE.TRACKER) {
          return { type: 60 }; // 只显示 invoice 扣款单类型
        }
        return { type: 30 }; // 显示所有类型
      });
291
292
      const [registerTable, { reload }] = useTable({
        api: props.isApproved ? getApprovedListApi : getWaitListApi,
293
        searchInfo: searchInfo.value,
294
295
        columns,
        useSearchForm: true,
柏杨 authored
296
        formConfig: getFormConfig('invoiceNo'),
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
        rowKey: 'id',
        actionColumn: {
          width: 160,
          title: 'Action',
          dataIndex: 'action',
        },
      });

      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) {
柏杨 authored
313
        const changeIds = changeRows?.map((item) => item.id);
314
315
316
317
318
319
320
321
322
323
324
325
326
327
        if (selected) {
          checkedKeys.value = [...checkedKeys.value, ...changeIds];
        } else {
          checkedKeys.value = checkedKeys.value.filter((id) => {
            return !changeIds.includes(id);
          });
        }
      }
      function handleEdit(record, e) {
        e?.stopPropagation();
        return false;
      }

      function handleProfitModal() {}
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
       // 打开图片或 PDF
       function openPic(url: string) {
        const baseUrl = url.split('?')[0]; // 获取问号前的部分
        if (isImageUrl(baseUrl)) {
          window.open('', '', '').document.write(`<!DOCTYPE html>
      <html>
        <body style="display: flex; justify-content: center; align-items: center;">
          <img src='${url}' width="300px" height="auto"/>
        </body>
      </html>`);
        } else if (isPdfUrl(baseUrl)) {
          view(url); // 新标签页打开 PDF
        } else {
          console.log('不支持的文件类型');
        }
      }
344
345
      async function handleDetail(data) {
346
347
348
349
350
351
352
        if(data.type == 60){
         showInvoice.value = true;
         mockData.value = data.fieldInfos.deductionUrlFieldVO;
        }else if(data.type == 30){
          showInvoice.value=false;
          mockData.value=data.fieldInfos.invoiceFieldVO;
        }
353
354
        openModal(true, { data });
        id.value = data.id;
柏杨 authored
355
356
        financePerson.value = mockData.value?.financePerson;
        trackerUser.value = mockData.value?.trackerUser;
柏杨 authored
357
358
359
        totalPayAmount.value = mockData.value.totalPayAmount?.toFixed(2);
        totalCustomerAmount.value = mockData.value.totalCustomerAmount?.toFixed(2);
        deductAmount.value = mockData.value.deductAmount?.toFixed(2);
柏杨 authored
360
        backRefundDate.value = mockData.value.backRefundDate;
柏杨 authored
361
        projectNo.value = mockData.value.projectNo;
柏杨 authored
362
363
        // actualRefundDate.value = mockData.value.actualRefundDate;
        actualRefundDate.value = '';
柏杨 authored
364
        otherAmount.value = mockData.value.otherAmount?.toFixed(2);
柏杨 authored
365
366
        invoiceNo.value = mockData.value.invoiceNo;
        payee.value = mockData.value.payee;
367
368
369
370
371
372
373
          const match = mockData.value?.deductUrl?.match(/aliyuncs\.com\/(.*?)\?/);
             if (match && match[1]) {
          // 对提取的部分进行解码
              mockData.value.invoiceName = decodeURIComponent(match[1]);
             } else {
             mockData.value.invoiceName = mockData.value?.deductUrl;
            }
374
      }
375
376
377
378

      async function handleTrue() {
        await approveAuditApi({ status: 10, id: id.value });
        reload();
379
        closeModal();
380
381
382
383
384
385
      }

      async function handleFalse() {
        msgVisible.value = true;
        // await approveAuditApi({ status: 20, id: id.value });
        // reload();
386
        // closeModal();
387
388
      }
柏杨 authored
389
390
391
392
393
      function handleShow(visible: boolean) {
        if (!visible) {
        }
      }
394
395
396
397
398
      // 定义MsgModalClose的事件,方便子组件调用
      const handleMsgModalClose = async (data) => {
        if (data) {
          await approveAuditApi({ status: 20, id: id.value, refuseRemark: data });
          reload();
399
          closeModal();
400
401
402
403
404
405
406
407
408
        }
        msgVisible.value = false;
      };

      const handlePreview = (url) => {
        createImgPreview({ imageList: [url], defaultWidth: 500 });
        return false;
      };
柏杨 authored
409
410
411
412
413
414
415
416
417
418
419
420
421
422
      // 定义处理导出的函数
      const handleExport = async () => {
        try {
          const response = await axios.post(
            '/basic-api/order/erp/invoice_bill/exportReceipt',
            {
              invoiceNo: invoiceNo.value,
              totalPayAmount: totalPayAmount.value,
              totalCustomerAmount: totalCustomerAmount.value,
              deductAmount: deductAmount.value,
              backRefundDate: backRefundDate.value,
              actualRefundDate: actualRefundDate.value,
              otherAmount: otherAmount.value,
              payee: payee.value,
柏杨 authored
423
424
              financePerson: financePerson.value,
              trackerUser: trackerUser.value,
柏杨 authored
425
              projectNo: projectNo.value,
柏杨 authored
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
            },
            {
              responseType: 'blob', // 设置响应类型为 'blob'
            },
          );

          // 创建一个 Blob 对象来保存二进制数据
          const blob = new Blob([response.data], { type: 'application/octet-stream' });

          // 获取格式化的当前日期
          const getFormattedDate = () => {
            const date = new Date();
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            const hours = String(date.getHours()).padStart(2, '0');
            const minutes = String(date.getMinutes()).padStart(2, '0');
            return `${year}-${month}-${day} ${hours}:${minutes}`;
          };

          const date = getFormattedDate();

          // 创建一个链接元素用来下载文件
          const link = document.createElement('a');
          link.href = window.URL.createObjectURL(blob);
柏杨 authored
451
          link.download = `收款单_${date}.xlsx`; // 文件命名
柏杨 authored
452
453
454
455
          document.body.appendChild(link);
          link.click(); // 自动点击链接,触发下载
          document.body.removeChild(link); // 下载完成后移除链接
        } catch (error) {
柏杨 authored
456
          console.error('获取收款单时出错:', error);
柏杨 authored
457
458
459
        }
      };
460
461
462
463
464
465
466
467
468
      return {
        handleProfitModal,
        registerTable,
        checkedKeys,
        currentKey,
        onSelect,
        handleEdit,
        onSelectAll,
        handleDetail,
469
        registerModal,
470
471
472
473
474
475
476
477
478
        fieldInfos,
        baseInfos,
        handleTrue,
        handleFalse,
        role,
        ROLE,
        msgVisible,
        handleMsgModalClose,
        handlePreview,
479
480
        showInvoice,
        openPic,
481
482
        mockData,
        schema,
柏杨 authored
483
484
485
486
487
488
489
490
491
492
        totalPayAmount,
        totalCustomerAmount,
        deductAmount,
        backRefundDate,
        actualRefundDate,
        otherAmount,
        invoiceNo,
        payee,
        handleExport,
        handleShow,
493
494
495
496
      };
    },
  });
</script>