ReceivePanel.vue 7.66 KB
<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"
          :src="record?.orderBaseInfo?.smallPicUrl"
          @click="handlePreview(record?.orderBaseInfo?.picUrl)"
        />
      </template>
      <template v-if="column.key === 'action'">
        <TableAction
          :actions="[
            {
              label: '编辑',
              // icon: 'ic:outline-delete-outline',
              onClick: handleDetail.bind(null, record),
            },
          ]"
        />
      </template>
    </template>
  </BasicTable>
  <BasicModal
    :showFooter="!isApproved && role === ROLE.ADMIN"
    @register="registerModal"
    title="申请信息"
    okText="通过"
    @ok="handleTrue"
  >
    <Description
      class="mt-4"
      layout="vertical"
      :collapseOptions="{ canExpand: true, helpMessage: 'help me' }"
      :column="2"
      :data="mockData"
      :schema="schema"
    />
    <template #appendFooter>
      <a-button @click="handleFalse"> 不通过</a-button>
    </template>
  </BasicModal>
  <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 { BasicModal, useModal } from '/@/components/Modal';

  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';
  import { Description, DescItem, useDescription } from '@/components/Description';

  const userStore = useUserStoreWithOut();

  export default defineComponent({
    components: {
      BasicTable,
      BasicModal,
      TableAction,
      Description,
      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 [registerModal, { openModal, closeModal }] = useModal();
      const fieldInfos = ref({});
      const baseInfos = ref({});
      const id = ref('');

      const mockData = ref();
      const schema: DescItem[] = [
        {
          field: 'actualReceivableAmount',
          label: '实际收款金额汇总',
        },
        {
          field: 'all',
          label: '客户总价金额汇总',
        },
        {
          field: 'deductAmount',
          label: '发生扣款金额汇总',
        },
        {
          field: 'backRefundDate',
          label: '必须回款日期',
        },
        {
          field: 'addr',
          label: '实际回款日期',
        },
        {
          field: 'otherAmount',
          label: '其他费用汇总',
        },
      ];
      // const [register] = useDescription({
      //   title: 'useDescription',
      //   data: mockData,
      //   schema: schema,
      // });

      let columns = [
        {
          title: '申请人',
          dataIndex: 'createBy',
          width: 150,
        },
        {
          title: 'INVOICE编号',
          dataIndex: 'invoiceNo',
          width: 150,
          customRender: (column) => {
            console.log(column, '5656coapprove');
            const { record } = column || {};
            return record?.fieldInfos?.invoiceBillOrderDO?.invoiceNo;
          },
        },
        {
          title: '内部编号',
          dataIndex: 'innerNo',
          width: 150,
          customRender: (column) => {
            const { record } = column || {};
            return record?.fieldInfos?.invoiceBillOrderDO?.innnerNo;
          },
        },
        // {
        //   title: '内部编号',
        //   dataIndex: 'innerNo',
        //   width: 150,
        //   customRender: (column) => {
        //     const { record } = column || {};
        //     return record?.fieldInfos?.invoiceBillOrderDO?.innerNo;
        //   },
        // },
      ];

      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({
        api: props.isApproved ? getApprovedListApi : getWaitListApi,
        searchInfo: { type: 30 },
        // scroll: {
        //   scrollToFirstRowOnChange: true,
        // },
        columns,
        useSearchForm: true,
        formConfig: getFormConfig(),
        rowKey: 'id',
        actionColumn: {
          width: 160,
          title: 'Action',
          dataIndex: 'action',
          // slots: { customRender: '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) {
        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) {
        e?.stopPropagation();
        return false;
      }

      function handleProfitModal() {}

      async function handleDetail(data) {
        openModal(true, { data });
        mockData.value = data.fieldInfos.invoiceBillOrderDO;
        console.log(mockData.value, 5656);
        id.value = data.id;
      }

      async function handleTrue() {
        await approveAuditApi({ status: 10, id: id.value });
        reload();
        closeModal();
      }

      async function handleFalse() {
        msgVisible.value = true;
        // await approveAuditApi({ status: 20, id: id.value });
        // reload();
        // closeModal();
      }

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

      // 定义MsgModalClose的事件,方便子组件调用
      const handleMsgModalClose = async (data) => {
        if (data) {
          await approveAuditApi({ status: 20, id: id.value, refuseRemark: data });
          reload();
          closeModal();
        }
        msgVisible.value = false;
      };

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

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