index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <div>
  3. <div style="margin-bottom: 10px" v-if="!props.selectStatus">
  4. <el-card class="top-card">
  5. <el-radio-group v-model="sourceList.pagination.departmentId" v-for="(item, index) in departmentList" :key="index" @change="changeDepartment">
  6. <el-radio-button :label="item.id" style="margin: 0 10px 10px 0">{{ showName(item) }}</el-radio-button>
  7. </el-radio-group>
  8. </el-card>
  9. </div>
  10. <el-row :gutter="10">
  11. <el-col :span="4" v-if="!props.selectStatus">
  12. <el-card style="height: calc(100vh - 242px); overflow-y: auto; overflow-x: hidden">
  13. <el-tree
  14. ref="treeCategory"
  15. :data="warehouseList"
  16. :props="{ children: 'children', label: 'name' }"
  17. node-key="id"
  18. default-expand-all
  19. :expand-on-click-node="false"
  20. :render-content="renderContent"
  21. @node-click="handleNodeClick" />
  22. </el-card>
  23. </el-col>
  24. <el-col :span="props.selectStatus ? 24 : 20">
  25. <el-card :style="'overflow-y: auto; overflow-x: hidden; ' + (props.selectStatus ? 'height: calc(100vh - 184px)' : 'height: calc(100vh - 242px)')">
  26. <byTable
  27. :source="sourceList.data"
  28. :pagination="sourceList.pagination"
  29. :config="config"
  30. :loading="loading"
  31. :searchConfig="searchConfig"
  32. highlight-current-row
  33. :action-list="[
  34. {
  35. text: '导出Excel',
  36. action: () => deriveExcel(),
  37. },
  38. ]"
  39. @get-list="getList"
  40. @clickReset="clickReset">
  41. <template #total="{ item }">
  42. <div>{{ getTotal(item) }}</div>
  43. </template>
  44. <template #quantity="{ item }">
  45. <div>{{ item.quantity + item.lockQuantity }}</div>
  46. </template>
  47. </byTable>
  48. </el-card>
  49. </el-col>
  50. </el-row>
  51. </div>
  52. </template>
  53. <script setup>
  54. import byTable from "/src/components/byTable/index";
  55. import { useRoute } from "vue-router";
  56. import useTagsViewStore from "/src/store/modules/tagsView";
  57. const { proxy } = getCurrentInstance();
  58. const props = defineProps({
  59. selectStatus: Boolean,
  60. departmentId: String,
  61. warehouseId: String,
  62. });
  63. const route = useRoute();
  64. const departmentList = ref([]);
  65. const warehouseList = ref([
  66. {
  67. id: "",
  68. name: "所有仓库",
  69. children: [],
  70. },
  71. ]);
  72. const sourceList = ref({
  73. data: [],
  74. pagination: {
  75. total: 0,
  76. pageNum: 1,
  77. pageSize: 10,
  78. bomClassifyId: "",
  79. bomSpecName: "",
  80. bomSpecCode: "",
  81. bomSpecies: "",
  82. bomChromatophore: "",
  83. bomEmbossingProcess: "",
  84. bomFrontGrain: "",
  85. bomReverseGrain: "",
  86. bomSpecColour: "",
  87. bomSpecLength: "",
  88. bomSpecWidth: "",
  89. departmentId: "",
  90. warehouseId: "",
  91. },
  92. });
  93. const loading = ref(false);
  94. const searchConfig = computed(() => {
  95. return [
  96. {
  97. type: "input",
  98. prop: "bomSpecName",
  99. label: "品名",
  100. },
  101. {
  102. type: "input",
  103. prop: "bomSpecCode",
  104. label: "品号",
  105. },
  106. {
  107. type: "select",
  108. prop: "bomSpecies",
  109. dictKey: "bom_species",
  110. label: "种类",
  111. },
  112. {
  113. type: "select",
  114. prop: "bomChromatophore",
  115. dictKey: "bom_chromatophore",
  116. label: "色层",
  117. },
  118. {
  119. type: "select",
  120. prop: "bomEmbossingProcess",
  121. dictKey: "bom_embossingProcess",
  122. label: "压纹工艺",
  123. },
  124. {
  125. type: "select",
  126. prop: "bomFrontGrain",
  127. dictKey: "bom_frontGrain",
  128. label: "正面纹路",
  129. },
  130. {
  131. type: "select",
  132. prop: "bomReverseGrain",
  133. dictKey: "bom_reverseGrain",
  134. label: "背面纹路",
  135. },
  136. {
  137. type: "input",
  138. prop: "bomSpecColour",
  139. label: "颜色",
  140. },
  141. {
  142. type: "input",
  143. prop: "bomSpecLength",
  144. label: "长(cm)",
  145. },
  146. {
  147. type: "input",
  148. prop: "bomSpecWidth",
  149. label: "宽(cm)",
  150. },
  151. ];
  152. });
  153. const config = computed(() => {
  154. return [
  155. {
  156. attrs: {
  157. label: "仓库",
  158. prop: "warehouseName",
  159. width: 140,
  160. },
  161. },
  162. {
  163. attrs: {
  164. label: "品号",
  165. prop: "bomSpecCode",
  166. width: 140,
  167. },
  168. },
  169. {
  170. attrs: {
  171. label: "品号",
  172. prop: "bomSpecName",
  173. "min-width": 500,
  174. },
  175. },
  176. {
  177. attrs: {
  178. label: "结存单价",
  179. prop: "balanceUnitPrice",
  180. width: 110,
  181. align: "right",
  182. },
  183. },
  184. {
  185. attrs: {
  186. label: "结存总价",
  187. slot: "total",
  188. width: 140,
  189. align: "right",
  190. },
  191. },
  192. {
  193. attrs: {
  194. label: "锁定库存",
  195. prop: "lockQuantity",
  196. width: 110,
  197. },
  198. },
  199. {
  200. attrs: {
  201. label: "可用库存",
  202. prop: "quantity",
  203. width: 110,
  204. },
  205. },
  206. {
  207. attrs: {
  208. label: "库存",
  209. slot: "quantity",
  210. width: 110,
  211. },
  212. },
  213. props.selectStatus
  214. ? {
  215. attrs: {
  216. label: "操作",
  217. width: 80,
  218. align: "center",
  219. fixed: "right",
  220. },
  221. renderHTML(row) {
  222. return [
  223. {
  224. attrs: {
  225. label: "选择",
  226. type: "primary",
  227. text: true,
  228. },
  229. el: "button",
  230. click() {
  231. clickSelect(row);
  232. },
  233. },
  234. ];
  235. },
  236. }
  237. : {
  238. attrs: {
  239. width: 1,
  240. },
  241. },
  242. ];
  243. });
  244. const getDemandData = () => {
  245. if (!props.selectStatus) {
  246. proxy.post("/department/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  247. let list = [
  248. { id: "", name: "全部" },
  249. { id: "0", name: "胜德体育" },
  250. ];
  251. departmentList.value = list.concat(res.rows);
  252. if (!(route.query && route.query.backupDate)) {
  253. proxy.post("/inventory/getQuantityByDepartment", {}).then((res) => {
  254. for (let i = 0; i < departmentList.value.length; i++) {
  255. let list = res.filter((item) => item.departmentId === departmentList.value[i].id);
  256. if (list && list.length > 0) {
  257. departmentList.value[i].quantity = list[0].inventoryQuantity;
  258. }
  259. }
  260. });
  261. }
  262. });
  263. proxy.post("/warehouse/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  264. warehouseList.value[0].children = res.rows;
  265. if (!(route.query && route.query.backupDate)) {
  266. proxy.post("/inventory/getQuantityByWarehouse", { departmentId: sourceList.value.pagination.departmentId }).then((res) => {
  267. if (warehouseList.value[0].children && warehouseList.value[0].children.length > 0) {
  268. for (let i = 0; i < warehouseList.value[0].children.length; i++) {
  269. let list = res.filter((item) => item.warehouseId === warehouseList.value[0].children[i].id);
  270. if (list && list.length > 0) {
  271. warehouseList.value[0].children[i].quantity = list[0].inventoryQuantity;
  272. }
  273. }
  274. }
  275. });
  276. }
  277. });
  278. }
  279. };
  280. getDemandData();
  281. const getList = async (req, status) => {
  282. if (status) {
  283. sourceList.value.pagination = {
  284. pageNum: sourceList.value.pagination.pageNum,
  285. pageSize: sourceList.value.pagination.pageSize,
  286. };
  287. } else {
  288. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  289. }
  290. let path = "/inventory/page";
  291. if (route.query && route.query.backupDate) {
  292. path = "/inventoryBackup/detailPage";
  293. }
  294. if (props.warehouseId) {
  295. sourceList.value.pagination.warehouseId = props.warehouseId;
  296. }
  297. if (props.departmentId) {
  298. sourceList.value.pagination.departmentId = props.departmentId;
  299. }
  300. loading.value = true;
  301. proxy.post(path, sourceList.value.pagination).then((res) => {
  302. sourceList.value.data = res.rows;
  303. sourceList.value.pagination.total = res.total;
  304. setTimeout(() => {
  305. loading.value = false;
  306. }, 200);
  307. });
  308. };
  309. const clickReset = () => {
  310. if (!props.selectStatus) {
  311. proxy.$refs.treeCategory.setCurrentKey(null);
  312. }
  313. getList("", true);
  314. };
  315. const handleNodeClick = (val) => {
  316. getList({ warehouseId: val.id });
  317. };
  318. const getTotal = (item) => {
  319. let total = 0;
  320. if (item.quantity && item.balanceUnitPrice) {
  321. total = Number(Math.round(item.quantity * item.balanceUnitPrice * 100) / 100);
  322. }
  323. return proxy.moneyFormat(total, 2);
  324. };
  325. const changeDepartment = () => {
  326. proxy.$refs.treeCategory.setCurrentKey(null);
  327. if (!(route.query && route.query.backupDate)) {
  328. proxy.post("/inventory/getQuantityByWarehouse", { departmentId: sourceList.value.pagination.departmentId }).then((res) => {
  329. if (warehouseList.value[0].children && warehouseList.value[0].children.length > 0) {
  330. for (let i = 0; i < warehouseList.value[0].children.length; i++) {
  331. let list = res.filter((item) => item.warehouseId === warehouseList.value[0].children[i].id);
  332. if (list && list.length > 0) {
  333. warehouseList.value[0].children[i].quantity = list[0].inventoryQuantity;
  334. } else {
  335. warehouseList.value[0].children[i].quantity = null;
  336. }
  337. }
  338. }
  339. });
  340. }
  341. getList({ departmentId: sourceList.value.pagination.departmentId });
  342. };
  343. const showName = (item) => {
  344. let name = item.name;
  345. if (item.quantity) {
  346. name = name + "(" + item.quantity + ")";
  347. }
  348. return name;
  349. };
  350. const renderContent = (h, data) => {
  351. if (data.data.quantity) {
  352. return h("span", h("span", null, data.node.label + "(" + data.data.quantity + ")"));
  353. } else {
  354. return h("span", h("span", null, data.node.label));
  355. }
  356. };
  357. onMounted(() => {
  358. if (route.query && route.query.backupDate) {
  359. useTagsViewStore().visitedViews = useTagsViewStore().visitedViews.map((item) => {
  360. if (item.query && item.query.backupDateStr === route.query.backupDateStr) {
  361. return {
  362. ...item,
  363. name: "库存快照: " + route.query.backupDateStr,
  364. title: "库存快照: " + route.query.backupDateStr,
  365. };
  366. } else {
  367. return {
  368. ...item,
  369. };
  370. }
  371. });
  372. getList({ backupDate: route.query.backupDate });
  373. } else {
  374. getList();
  375. }
  376. });
  377. const emit = defineEmits(["selectBOM"]);
  378. const clickSelect = (item) => {
  379. emit("selectBOM", item);
  380. };
  381. const deriveExcel = () => {
  382. if (route.query && route.query.backupDate) {
  383. proxy.getFile("/inventory/exportBackExcel", sourceList.value.pagination).then((res) => {
  384. proxy.downloadFile(res, "库存.xlsx");
  385. });
  386. } else {
  387. proxy.getFile("/inventory/exportExcel", sourceList.value.pagination).then((res) => {
  388. proxy.downloadFile(res, "库存.xlsx");
  389. });
  390. }
  391. };
  392. </script>
  393. <style lang="scss" scoped>
  394. ::v-deep(.top-card) {
  395. height: 112px;
  396. overflow-y: auto;
  397. overflow-x: hidden;
  398. display: grid;
  399. place-items: center;
  400. .el-card__body {
  401. width: 100%;
  402. padding: 15px 20px 10px 20px !important;
  403. }
  404. }
  405. </style>