Blame view

src/views/project/approve/ProfitFieldPanel.vue 5.93 KB
柏杨 authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<template>
  <BasicTable @register="registerTable" className="p-0">
    <template #bodyCell="{ column, record }">
      <template v-if="column.key === 'action'">
        <TableAction
          :actions="[
            {
              label: '详情',
              // icon: 'ic:outline-delete-outline',
              onClick: handleDetail.bind(null, record),
            },
          ]"
        />
      </template>
    </template>
  </BasicTable>
  <BasicDrawer
    width="500"
    :showFooter="!isApproved && (role === ROLE.ADMIN || role === ROLE.BUSINESS)"
    @register="registerDrawer"
    title="申请信息"
    okText="通过"
    @ok="handleTrue"
柏杨 authored
24
    :showOkBtn="!isApproved && role === ROLE.ADMIN"
柏杨 authored
25
26
  >
    <BaseInfo :baseInfos="baseInfos" />
柏杨 authored
27
    <h2>申请字段</h2>
柏杨 authored
28
29
    <div>{{ fieldInfos.baseFields.join(' , ') }}</div>
    <template #appendFooter>
柏杨 authored
30
      <a-button @click="handleFalse" v-if="!isApproved && role === ROLE.ADMIN"> 不通过</a-button>
柏杨 authored
31
32
33
34
35
36
37
38
39
40
41
    </template>
  </BasicDrawer>
  <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';
  import { BasicDrawer, useDrawer } from '/@/components/Drawer';
  import { approveAuditApi, getApprovedListApi, getWaitListApi } from '/@/api/project/approve';
  import { getAuditApply, getApplyList } from '/@/api/project/invoice';
柏杨 authored
42
43
  import { FIELDS_BASE_INFO } from '../finance/financeProfit/ServiceProfit/ServiceProfit/tableData';
  import { COLUMNS } from '../finance/financeProfit/ServiceProfit/ServiceProfit/data';
柏杨 authored
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
  import { find, isEmpty } from 'lodash-es';
  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';

  const userStore = useUserStoreWithOut();

  export default defineComponent({
    components: {
      BasicTable,
      BasicDrawer,
      TableAction,
      BaseInfo,
      MsgModal,
    },
    props: {
      isApproved: { type: Boolean },
    },
    setup(props) {
      // visible 用于msgModal显示隐藏
      const msgVisible = ref(false);

      const checkedKeys = ref<Array<string | number>>([]);
      const currentKey = ref('1');
      const [registerDrawer, { openDrawer, closeDrawer }] = useDrawer();
      const fieldInfos = ref({
        baseFields: [],
      });
      const baseInfos = ref({});
      const id = ref('');

      let columns = [
        {
          title: '申请人',
          dataIndex: 'createBy',
          width: 150,
        },
        {
          title: '审核字段类型',
          dataIndex: 'auditRoleCodes',
          width: 150,
          customRender: (column) => {
柏杨 authored
88
            return '业务研发净利字段';
柏杨 authored
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
          },
        },
        {
          title: '项目号',
          dataIndex: 'projectNoPrefix',
          width: 150,
        },
        {
          title: '申请原因',
          dataIndex: 'applyRemark',
          width: 150,
        },
      ];

      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 },
        ]);
      }
      const [registerTable, { reload }] = useTable({
        scroll: false,
柏杨 authored
120
121
        api: getApplyList,
        searchInfo: props.isApproved ? { status: 10 } : {},
柏杨 authored
122
        columns,
柏杨 authored
123
        useSearchForm: false,
柏杨 authored
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
        formConfig: getFormConfig('true'),
        rowKey: 'id',
        actionColumn: {
          width: 160,
          title: 'Action',
          dataIndex: 'action',
          // slots: { customRender: 'action' },
        },
      });

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

      function handleProfitModal() {}

      async function handleDetail(data) {
柏杨 authored
142
        id.value = data.id;
柏杨 authored
143
144
145
146
        fieldInfos.value = {
          baseFields: [],
        };
        openDrawer(true, { data });
柏杨 authored
147
148
149
150
151
152
153
154
        !isEmpty(data.fields) &&
          Object.entries(data.fields)?.map(([key, value]) => {
            if (value === 'UN_LOCKED') {
              const obj = find(FIELDS_BASE_INFO, { field: key });
              fieldInfos.value.baseFields.push(obj?.label);
            }
          });
        baseInfos.value = COLUMNS.map((field) => {
柏杨 authored
155
          return {
柏杨 authored
156
157
            label: field.title,
            value: data[field.dataIndex],
柏杨 authored
158
159
160
161
162
          };
        }).filter((item) => !!item.value);
      }

      async function handleTrue() {
柏杨 authored
163
        await getAuditApply({ status: 10, id: id.value });
柏杨 authored
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
        reload();
        closeDrawer();
      }

      async function handleFalse() {
        msgVisible.value = true;
      }

      const role = computed(() => {
        return userStore.getUserInfo?.roleSmallVO?.code;
      });

      // 定义MsgModalClose的事件,方便子组件调用
      const handleMsgModalClose = async (data) => {
        if (data) {
柏杨 authored
179
          await getAuditApply({ status: 20, id: id.value, refuseRemark: data });
柏杨 authored
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
          reload();
          closeDrawer();
        }
        msgVisible.value = false;
      };

      const handlePreview = (url) => {
        createImgPreview({ imageList: [url], defaultWidth: 500 });
        return false;
      };

      return {
        handleProfitModal,
        registerTable,
        checkedKeys,
        currentKey,
        handleEdit,
        handleDetail,
        registerDrawer,
        fieldInfos,
        baseInfos,
        handleTrue,
        handleFalse,
        ROLE,
        role,
        msgVisible,
        handleMsgModalClose,
        handlePreview,
      };
    },
  });
</script>