Operation.tsx 3.87 KB
import React from 'react';
import { Button, message, Modal, Dropdown, Menu } from 'antd';
import { history } from 'umi';
import { common } from '@/typing/common';
import * as API from '../api';
// import * as IF from '../interface.d';

const { confirm } = Modal;

interface Props extends common.ConnectProps {
  record: MarketingManage.Item,
  /** 刷新列表 */
  onRefreshing: () => any,
}

export default function Oparetion(props: Props) {
  const { record, onRefreshing } = props;
  /** 1草稿2待审核3未通过4待发布5进行中6提前结束7正常结束) */
  const status = record.status;

  /** 提审 */
  function commitAudit() {
    confirm({
      title: '您确定提交审核吗,提审后活动不可进行编辑?',
      okText: "确定",
      cancelText: "取消",
      onOk: () => {
        API.approveApi(record.activityNo).then(res => {
          message.success("提审成功,请等待审核结果");
          onRefreshing && onRefreshing();
        }).catch((e: any) => {
          message.error(e.message);
        });
      },
    });
  }

  /** 查看/编辑 */
  function viewDetail() {
    history.push(`/mkt/manage/create/${record.activityNo}/${record.status}`);
  }
  /** 变更信息 */
  function changeBaseInfo() {
    history.push(`/mkt/manage/create/${record.activityNo}/${record.status}/change`);
  }
  /** 变更记录 */
  function changeRecords() {
    history.push(`/mkt/prize/record/changes/${record.activityNo}`);
  }

  /** 删除 */
  function deleteItem(row: MarketingManage.Item) {
    confirm({
      title: `活动删除后不可恢复,是否删除【${record.activityName}】?`,
      okText: '确定',
      okType: 'danger',
      cancelText: '取消',
      onOk: () => {
        API.deleteApi(row.activityNo).then(res => {
          message.success("删除成功");
          onRefreshing && onRefreshing();
        }).catch(e => {
          message.error(e.message);
        });
      },
    });
  }

  /** 终止 */
  function endActivity() {
    confirm({
      title: `活动结束后不可再次编辑或发布,是否终止${record.activityName}活动?`,
      okText: '确定',
      okType: 'danger',
      cancelText: '取消',
      onOk: () => {
        API.finishApi(record.activityNo).then(res => {
          message.success("已提交审批");
          onRefreshing && onRefreshing();
        }).catch(e => {
          message.error(e.message, 5);
        });
      },
    });
  }

  return (
    <Dropdown.Button
      type="primary"
      size="small"
      onClick={viewDetail}
      overlay={() => {
        let menus: any[] = [];
        /* 草稿、审核失败 */
        if ([1, 3].includes(status)) {
          menus = [
            <Button type="primary" ghost size="small" onClick={viewDetail}>编辑</Button>,
            <Button type="primary" ghost size="small" onClick={commitAudit}>提审</Button>,
            <Button danger ghost size="small" onClick={() => deleteItem(record)}>删除</Button>,
          ];
        }
        /* 待审核 */
        // if ([2].includes(status)) {
        //   menus = [
        //     <Button type="primary" ghost size="small" onClick={commitAudit}>提审</Button>,
        //   ];
        // }
        /* 审核成功、待发布 ;未开始,进行中*/
        if ([4, 5].includes(status) && record.changeStatus !== 2) {
          menus = [
            <Button type="primary" ghost size="small" onClick={changeBaseInfo}>变更信息</Button>,
            <Button type="primary" ghost size="small" onClick={changeRecords}>变更记录</Button>,
            // <Button danger ghost size="small" onClick={endActivity}>终止</Button>,
          ];
        }
        return (
          <Menu>
            {menus.map((item, i) => (
              <Menu.Item key={`item_${i}`}>
                {item}
              </Menu.Item>
            ))}
          </Menu>
        );
      }}
    >
      查看
    </Dropdown.Button>
  );
}