index.vue 5.25 KB
<template>
  <div>
    <BasicTable :clickToRowSelect="false" @register="registerTable">
      <template #toolbar>
        <Authority value="api:yt:product:category:post">
          <Button type="primary" @click="handleCreate">
            {{ t('inspection.servicePlan.createPlanText') }}
          </Button>
        </Authority>
      </template>
      <template #status="{ record }">
        <Tag
          :color="
            record.status == 'NOTSTART'
              ? 'red'
              : record.status == 'UNDERWAY'
              ? 'blue': record.status == 'COMPLETED'
              ? 'green': 'yellow'
          "
          class="ml-2"
        >
          {{ t(`inspection.servicePlan.${record.status}`) }}
        </Tag>
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: t('common.editText'),
              auth: 'api:yt:product:category:update',
              icon: 'clarity:note-edit-line',
              // onClick: handleEdit.bind(null, record),
              ifShow: () => record.status === 'NOTSTART',
            },
            {
              label: t('common.delText'),
              auth: 'api:yt:product:category:delete',
              icon: 'ant-design:delete-outlined',
              color: 'error',
              ifShow: () => record.status === 'NOTSTART',
              popConfirm: {
                title: t('common.deleteConfirmText'),
                confirm: handleDelete.bind(null, record),
              },
            },
            {
              label: t('common.start'),
              auth: 'api:yt:product:category:delete',
              icon: 'ant-design:caret-right-outlined',
              ifShow: () => record.status === 'NOTSTART',
              popConfirm: {
                title: t('common.startConfirmText'),
                confirm: handleUpdateStatus.bind(null, record),
              },
            },
            {
              label: t('common.stop'),
              auth: 'api:yt:product:category:delete',
              icon: ' <PauseCircleOutlined />',
              ifShow: () => record.status === 'NOTSTART' || record.status === 'UNDERWAY',
              popConfirm: {
                title: t('common.stopConfirmText'),
                confirm: handleUpdateStatus.bind(null, record,'STOP'),
              },
            },
            {
              label: t('common.down'),
              auth: 'api:yt:product:category:delete',
              icon: 'ant-design:check-circle-outlined',
              ifShow: () => record.status === 'UNDERWAY',
              popConfirm: {
                title: t('common.downConfirmText'),
                confirm: handleUpdateStatus.bind(null, record),
              },
            },
          ]"
        />
      </template>
    </BasicTable>
    <servicePlanModal @register="registerModal" @handleReload="handleReload" />

  </div>
</template>
<script setup lang="ts">
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import {deleteServePlan, getServicePlanList, updateServiceStatus} from '/@/api/inspection/servicePlan';
  import { columns, searchFormSchema } from './index';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { Button, Tag } from 'ant-design-vue';
  import {useModal} from "/@/components/Modal";
  import {useMessage} from "/@/hooks/web/useMessage";
  const { t } = useI18n();
  const [registerModal, { openModal }] = useModal();
  const { createMessage } = useMessage();

  const [
    registerTable,
    { reload, setLoading, getSelectRowKeys, setSelectedRowKeys, getRowSelection },
  ] = useTable({
    title: t('inspection.servicePlan.listText'),
    api: getServicePlanList,
    columns,
    formConfig: {
      labelWidth: 100,
      schemas: searchFormSchema,
    },
    immediate: true,
    useSearchForm: true,
    showTableSetting: true,
    bordered: true,
    showIndexColumn: false,
    clickToRowSelect: false,
    rowKey: 'id',
    actionColumn: {
      width: 230,
      title: t('common.actionText'),
      slots: { customRender: 'action' },
      fixed: 'right',
    },
    rowSelection: {
      type: 'checkbox',
      getCheckboxProps: (record: any) => {},
    },
  });

  // 新增
  const handleCreate = () => {
    openModal(true, {
      isUpdate: false,
    });
  };

  const handleReload = () => {
    setSelectedRowKeys([]);
    reload();
  };

  const handleDelete = async (record?: any) => {
    let id = record.id;
    try {
      setLoading(true);
      await deleteServePlan({ id });
      createMessage.success(t('common.deleteSuccessText'));
      handleReload();
    } catch (error) {
      throw error;
    } finally {
      setLoading(false);
    }
  };

  const handleUpdateStatus = async (record?: any,value?: string) => {
    let id = record.id;
    let status = '';
    if (record.status === 'NOTSTART') {
      status = 'UNDERWAY'
    }else if(record.status === 'UNDERWAY'){
      status = 'COMPLETED'
    }else if(record.status === 'COMPLETED'){
      status = 'STOP'
    }
    if (value === 'STOP') {
      status = 'STOP'
    }
    try {
      setLoading(true);
      await updateServiceStatus({ id,status });
      createMessage.success(t('common.editSuccessText'));
      handleReload();
    } catch (error) {
      throw error;
    } finally {
      setLoading(false);
    }
  }

</script>