index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <div>
  3. <div style="margin-bottom: 10px">
  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">
  12. <el-card style="height: calc(100vh - 197px); 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="20">
  25. <el-card style="overflow-y: auto; overflow-x: hidden; height: calc(100vh - 197px)">
  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. const { proxy } = getCurrentInstance();
  56. const departmentList = ref([]);
  57. const warehouseList = ref([
  58. {
  59. id: "",
  60. name: "所有仓库",
  61. children: [],
  62. },
  63. ]);
  64. const sourceList = ref({
  65. data: [],
  66. pagination: {
  67. total: 0,
  68. pageNum: 1,
  69. pageSize: 10,
  70. bomClassifyId: "",
  71. bomSpecName: "",
  72. bomSpecCode: "",
  73. bomSpecies: "",
  74. bomChromatophore: "",
  75. bomEmbossingProcess: "",
  76. bomFrontGrain: "",
  77. bomReverseGrain: "",
  78. bomSpecColour: "",
  79. bomSpecLength: "",
  80. bomSpecWidth: "",
  81. departmentId: "0",
  82. warehouseId: "",
  83. },
  84. });
  85. const loading = ref(false);
  86. const searchConfig = computed(() => {
  87. return [
  88. {
  89. type: "input",
  90. prop: "bomSpecName",
  91. label: "品名",
  92. },
  93. {
  94. type: "input",
  95. prop: "bomSpecCode",
  96. label: "品号",
  97. },
  98. {
  99. type: "select",
  100. prop: "bomSpecies",
  101. dictKey: "bom_species",
  102. label: "种类",
  103. },
  104. {
  105. type: "select",
  106. prop: "bomChromatophore",
  107. dictKey: "bom_chromatophore",
  108. label: "色层",
  109. },
  110. {
  111. type: "select",
  112. prop: "bomEmbossingProcess",
  113. dictKey: "bom_embossingProcess",
  114. label: "压纹工艺",
  115. },
  116. {
  117. type: "select",
  118. prop: "bomFrontGrain",
  119. dictKey: "bom_frontGrain",
  120. label: "正面纹路",
  121. },
  122. {
  123. type: "select",
  124. prop: "bomReverseGrain",
  125. dictKey: "bom_reverseGrain",
  126. label: "背面纹路",
  127. },
  128. {
  129. type: "input",
  130. prop: "bomSpecColour",
  131. label: "颜色",
  132. },
  133. {
  134. type: "input",
  135. prop: "bomSpecLength",
  136. label: "长(cm)",
  137. },
  138. {
  139. type: "input",
  140. prop: "bomSpecWidth",
  141. label: "宽(cm)",
  142. },
  143. ];
  144. });
  145. const config = computed(() => {
  146. return [
  147. {
  148. attrs: {
  149. label: "仓库",
  150. prop: "warehouseName",
  151. width: 140,
  152. },
  153. },
  154. {
  155. attrs: {
  156. label: "品号",
  157. prop: "bomSpecCode",
  158. width: 140,
  159. },
  160. },
  161. {
  162. attrs: {
  163. label: "品号",
  164. prop: "bomSpecName",
  165. "min-width": 500,
  166. },
  167. },
  168. {
  169. attrs: {
  170. label: "结存单价",
  171. prop: "balanceUnitPrice",
  172. width: 110,
  173. align: "right",
  174. },
  175. },
  176. {
  177. attrs: {
  178. label: "结存总价",
  179. slot: "total",
  180. width: 140,
  181. align: "right",
  182. },
  183. },
  184. {
  185. attrs: {
  186. label: "锁定库存",
  187. prop: "lockQuantity",
  188. width: 110,
  189. },
  190. },
  191. {
  192. attrs: {
  193. label: "可用库存",
  194. prop: "quantity",
  195. width: 110,
  196. },
  197. },
  198. {
  199. attrs: {
  200. label: "库存",
  201. slot: "quantity",
  202. width: 110,
  203. },
  204. },
  205. ];
  206. });
  207. const getDemandData = () => {
  208. proxy.post("/department/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  209. let list = [{ id: "0", name: "胜德体育" }];
  210. if (res.rows && res.rows.length > 0) {
  211. departmentList.value = list.concat(res.rows.filter((item) => item.id === proxy.useUserStore().user.deptId));
  212. }
  213. proxy.post("/inventory/getQuantityByDepartment", {}).then((res) => {
  214. for (let i = 0; i < departmentList.value.length; i++) {
  215. let list = res.filter((item) => item.departmentId === departmentList.value[i].id);
  216. if (list && list.length > 0) {
  217. departmentList.value[i].quantity = list[0].inventoryQuantity;
  218. }
  219. }
  220. });
  221. });
  222. proxy.post("/warehouse/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  223. warehouseList.value[0].children = res.rows.filter((item) => item.type !== "1");
  224. proxy.post("/inventory/getQuantityByWarehouse", { departmentId: sourceList.value.pagination.departmentId }).then((res) => {
  225. if (warehouseList.value[0].children && warehouseList.value[0].children.length > 0) {
  226. for (let i = 0; i < warehouseList.value[0].children.length; i++) {
  227. let list = res.filter((item) => item.warehouseId === warehouseList.value[0].children[i].id);
  228. if (list && list.length > 0) {
  229. warehouseList.value[0].children[i].quantity = list[0].inventoryQuantity;
  230. }
  231. }
  232. }
  233. });
  234. });
  235. };
  236. getDemandData();
  237. const getList = async (req, status) => {
  238. if (status) {
  239. sourceList.value.pagination = {
  240. pageNum: sourceList.value.pagination.pageNum,
  241. pageSize: sourceList.value.pagination.pageSize,
  242. };
  243. } else {
  244. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  245. }
  246. let path = "/inventory/page";
  247. loading.value = true;
  248. proxy.post(path, sourceList.value.pagination).then((res) => {
  249. sourceList.value.data = res.rows;
  250. sourceList.value.pagination.total = res.total;
  251. setTimeout(() => {
  252. loading.value = false;
  253. }, 200);
  254. });
  255. };
  256. const clickReset = () => {
  257. proxy.$refs.treeCategory.setCurrentKey(null);
  258. getList("", true);
  259. };
  260. const handleNodeClick = (val) => {
  261. getList({ warehouseId: val.id });
  262. };
  263. const getTotal = (item) => {
  264. let total = 0;
  265. if (item.quantity && item.balanceUnitPrice) {
  266. total = Number(Math.round(item.quantity * item.balanceUnitPrice * 100) / 100);
  267. }
  268. return proxy.moneyFormat(total, 2);
  269. };
  270. const changeDepartment = () => {
  271. proxy.$refs.treeCategory.setCurrentKey(null);
  272. proxy.post("/inventory/getQuantityByWarehouse", { departmentId: sourceList.value.pagination.departmentId }).then((res) => {
  273. if (warehouseList.value[0].children && warehouseList.value[0].children.length > 0) {
  274. for (let i = 0; i < warehouseList.value[0].children.length; i++) {
  275. let list = res.filter((item) => item.warehouseId === warehouseList.value[0].children[i].id);
  276. if (list && list.length > 0) {
  277. warehouseList.value[0].children[i].quantity = list[0].inventoryQuantity;
  278. } else {
  279. warehouseList.value[0].children[i].quantity = null;
  280. }
  281. }
  282. }
  283. });
  284. getList({ departmentId: sourceList.value.pagination.departmentId });
  285. };
  286. const showName = (item) => {
  287. let name = item.name;
  288. if (item.quantity) {
  289. name = name + "(" + item.quantity + ")";
  290. }
  291. return name;
  292. };
  293. const renderContent = (h, data) => {
  294. if (data.data.quantity) {
  295. return h("span", h("span", null, data.node.label + "(" + data.data.quantity + ")"));
  296. } else {
  297. return h("span", h("span", null, data.node.label));
  298. }
  299. };
  300. onMounted(() => {
  301. getList();
  302. });
  303. const emit = defineEmits(["selectBOM"]);
  304. const deriveExcel = () => {
  305. proxy.getFile("/inventory/exportExcel", sourceList.value.pagination).then((res) => {
  306. proxy.downloadFile(res, "库存.xlsx");
  307. });
  308. };
  309. </script>
  310. <style lang="scss" scoped>
  311. ::v-deep(.top-card) {
  312. height: 67px;
  313. overflow-y: auto;
  314. overflow-x: hidden;
  315. display: grid;
  316. place-items: center;
  317. .el-card__body {
  318. width: 100%;
  319. padding: 15px 20px 10px 20px !important;
  320. }
  321. }
  322. </style>