index.jsx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import {
  2. getPurchaseList,
  3. getPurchaseDetail,
  4. savePurchase,
  5. updatePurchase,
  6. deletePurchase,
  7. } from "@/services/purchase";
  8. import { queryTable } from "@/utils/request";
  9. import { PageContainer, ProTable } from "@ant-design/pro-components";
  10. import { useNavigate } from "react-router-dom";
  11. import { Button, message, Popconfirm } from "antd";
  12. import { useRef, useState, useEffect } from "react";
  13. import { floatMultiply, floatDivide } from "@/utils/float";
  14. // type plan 采购计划 bill 采购账单 inStore 采购入库
  15. const StockList = (props) => {
  16. const { type } = props;
  17. const [showDetail, setShowDetail] = useState(false);
  18. const [activeKey, setActiveKey] = useState("");
  19. const actionRef = useRef();
  20. const navigate = useNavigate();
  21. // console.log(props, "props");
  22. useEffect(() => {
  23. actionRef.current.reload();
  24. }, [type]);
  25. const handleDelete = (id) => {
  26. if (id) {
  27. deletePurchase(id).then((res) => {
  28. actionRef.current.reload();
  29. });
  30. }
  31. };
  32. const columns = [
  33. {
  34. title: "采购计划",
  35. dataIndex: "title",
  36. },
  37. {
  38. title: "计划时间",
  39. dataIndex: "planDate",
  40. },
  41. {
  42. title: "采购项目",
  43. dataIndex: "items",
  44. search: false,
  45. },
  46. {
  47. title: "是否入库",
  48. dataIndex: "isInStore",
  49. valueEnum: {
  50. false: { text: "否", status: "Error" },
  51. true: { text: "是", status: "Success" },
  52. },
  53. search: false,
  54. },
  55. {
  56. title: "是否采购完成",
  57. dataIndex: "isCompleted",
  58. valueEnum: {
  59. false: { text: "否", status: "Error" },
  60. true: { text: "是", status: "Success" },
  61. },
  62. search: false,
  63. },
  64. {
  65. title: "操作",
  66. valueType: "option",
  67. width: 200,
  68. render: (_, record) => [
  69. type === "plan" ? (
  70. <Button
  71. key={2}
  72. style={{ padding: 0 }}
  73. type="link"
  74. onClick={() => {
  75. navigate(`/purchase/plan/edit?id=${record.id}`);
  76. }}
  77. >
  78. 修改
  79. </Button>
  80. ) : null,
  81. type === "bill" ? (
  82. <Button
  83. key={4}
  84. style={{ padding: 0 }}
  85. type="link"
  86. disabled={record?.isCompleted}
  87. onClick={() => {
  88. navigate(`/purchase/bill/edit?id=${record.id}`);
  89. }}
  90. >
  91. 采购
  92. </Button>
  93. ) : null,
  94. type === "inStore" ? (
  95. <Button
  96. key={5}
  97. style={{ padding: 0 }}
  98. type="link"
  99. disabled={record?.isInStore}
  100. onClick={() => {
  101. navigate(`/purchase/inStore/edit?id=${record.id}`);
  102. }}
  103. >
  104. 入库
  105. </Button>
  106. ) : null,
  107. type === "plan" ? (
  108. <Popconfirm
  109. key={3}
  110. title="您是否确认删除 ?"
  111. onConfirm={() => handleDelete(record.id)}
  112. okText="确定"
  113. cancelText="取消"
  114. >
  115. {/* manualPush */}
  116. <Button style={{ padding: 0 }} type="link">
  117. 删除
  118. </Button>
  119. </Popconfirm>
  120. ) : null,
  121. ],
  122. },
  123. ];
  124. return (
  125. <PageContainer>
  126. <ProTable
  127. actionRef={actionRef}
  128. rowKey="id"
  129. params={type === "inStore" ? { isCompleted: true } : {}}
  130. toolBarRender={() => [
  131. type === "plan" ? (
  132. <Button
  133. key="2"
  134. type="primary"
  135. onClick={() => {
  136. navigate("/purchase/plan/edit");
  137. }}
  138. >
  139. 新增
  140. </Button>
  141. ) : null,
  142. ]}
  143. // search={false}
  144. request={queryTable(getPurchaseList)}
  145. columns={columns}
  146. />
  147. </PageContainer>
  148. );
  149. };
  150. export default StockList;