demo.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <div>
  3. <el-card class="box-card" v-loading="loading">
  4. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="submit">
  5. <template #basicInformation>
  6. <div style="width: 100%">
  7. <el-row>
  8. <el-col :span="12">
  9. <el-form-item label="事业部" prop="departmentId" style="width: 100%; margin-bottom: 18px">
  10. <el-select v-model="formData.data.departmentId" placeholder="请选择事业部" clearable style="width: 100%" @change="changeDepartment">
  11. <el-option v-for="item in departmentList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item label="出库类型" prop="detailType" style="width: 100%; margin-bottom: 18px">
  15. <el-select v-model="formData.data.detailType" placeholder="请选择出库类型" clearable style="width: 100%">
  16. <el-option v-for="item in useUserStore().allDict['come_stock_type']" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item label="申请人" prop="applicant" style="width: 100%; margin-bottom: 18px">
  20. <el-input v-model="formData.data.applicant" placeholder="请输入申请人" />
  21. </el-form-item>
  22. </el-col>
  23. <el-col :span="12">
  24. <el-form-item label="备注" prop="remark" style="width: 100%; margin-bottom: 18px">
  25. <el-input v-model="formData.data.remark" :rows="4" type="textarea" placeholder="请输入备注" />
  26. </el-form-item>
  27. </el-col>
  28. </el-row>
  29. </div>
  30. </template>
  31. <template #inOutStorageBomList>
  32. <div style="width: 100%; padding: 0 20px">
  33. <el-table :data="formData.data.inOutStorageBomList" :row-style="{ height: '35px' }" header-row-class-name="tableHeader">
  34. <el-table-column type="expand">
  35. <template #default="props">
  36. <div style="padding: 0 80px 0 50px">
  37. <el-table
  38. :data="props.row.orderList"
  39. :cell-style="{ padding: '0' }"
  40. :row-style="{ height: '35px' }"
  41. v-loading="loading"
  42. header-row-class-name="tableHeader">
  43. <el-table-column label="订单号" prop="orderCode" width="200" />
  44. <el-table-column label="万里牛单号" prop="orderWlnCode" width="140" />
  45. <el-table-column label="SKU品号" prop="skuSpecCode" width="180" />
  46. <el-table-column label="SKU品名" prop="skuSpecName" min-width="180" />
  47. <el-table-column label="出库数量" width="140">
  48. <template #default="{ row }">
  49. <span>{{ row.quantity }}</span>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. </div>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="品号" prop="code" width="180" />
  57. <el-table-column label="品名" prop="name" min-width="220" />
  58. <el-table-column label="仓库" width="160">
  59. <template #default="{ row, $index }">
  60. <el-form-item :prop="'inOutStorageBomList.' + $index + '.warehouseId'" :rules="rules.warehouseId" :inline-message="true" style="width: 100%">
  61. <el-select
  62. v-model="row.warehouseId"
  63. placeholder="请选择仓库"
  64. clearable
  65. style="width: 100%"
  66. @change="
  67. (val) => {
  68. return changeWarehouse(val, row, $index);
  69. }
  70. ">
  71. <el-option v-for="item in warehouseList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
  72. </el-select>
  73. </el-form-item>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="剩余库存" prop="surplusStock" width="120" />
  77. <el-table-column label="出库数量" width="140">
  78. <template #default="{ row }">
  79. <span :style="row.surplusStock && row.surplusStock < row.quantity ? 'color: red' : ''">{{ row.quantity }}</span>
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="操作" align="center" fixed="right" width="80">
  83. <template #default="{ $index }">
  84. <el-button type="danger" @click="clickDelete($index)" text>删除</el-button>
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. </div>
  89. </template>
  90. </byForm>
  91. <div style="text-align: center; margin: 10px">
  92. <el-button @click="clickCancel()" size="large">取 消</el-button>
  93. <el-button type="primary" @click="submitForm()" size="large" v-preReClick>确 定</el-button>
  94. </div>
  95. </el-card>
  96. </div>
  97. </template>
  98. <script setup>
  99. import byForm from "/src/components/byForm/index";
  100. import { ElMessage } from "element-plus";
  101. const { proxy } = getCurrentInstance();
  102. const departmentList = ref([{ dictKey: "0", dictValue: "胜德体育" }]);
  103. const props = defineProps({
  104. selectData: Array,
  105. });
  106. const warehouseList = ref([]);
  107. const submit = ref(null);
  108. const formOption = reactive({
  109. inline: true,
  110. labelWidth: "100px",
  111. itemWidth: 100,
  112. rules: [],
  113. labelPosition: "right",
  114. });
  115. const formData = reactive({
  116. data: {
  117. departmentId: "0",
  118. type: 0,
  119. applicant: proxy.useUserStore().user.nickName,
  120. inOutStorageBomList: [],
  121. },
  122. });
  123. const formConfig = computed(() => {
  124. return [
  125. {
  126. type: "title",
  127. title: "出库信息",
  128. label: "",
  129. },
  130. {
  131. type: "slot",
  132. slotName: "basicInformation",
  133. label: "",
  134. },
  135. {
  136. type: "title",
  137. title: "物料信息",
  138. label: "",
  139. },
  140. {
  141. type: "slot",
  142. slotName: "inOutStorageBomList",
  143. label: "",
  144. },
  145. ];
  146. });
  147. const rules = ref({
  148. departmentId: [{ required: true, message: "请选择事业部", trigger: "change" }],
  149. warehouseId: [{ required: true, message: "请选择仓库", trigger: "change" }],
  150. detailType: [{ required: true, message: "请选择出库类型", trigger: "change" }],
  151. applicant: [{ required: true, message: "请输入申请人", trigger: "blur" }],
  152. quantity: [{ required: true, message: "请输入出库数量", trigger: "blur" }],
  153. });
  154. const getDemandData = () => {
  155. proxy.post("/department/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  156. if (res.rows && res.rows.length > 0) {
  157. departmentList.value = departmentList.value.concat(
  158. res.rows.map((item) => {
  159. return {
  160. dictKey: item.id,
  161. dictValue: item.name,
  162. };
  163. })
  164. );
  165. }
  166. });
  167. };
  168. getDemandData();
  169. const clickDelete = (index) => {
  170. formData.data.inOutStorageBomList.splice(index, 1);
  171. };
  172. const emit = defineEmits(["clickCancel"]);
  173. const duplicateRemoval = (arr) => {
  174. let list = [];
  175. return arr.filter((item) => !list.includes(item) && list.push(item));
  176. };
  177. const loading = ref(false);
  178. const submitForm = () => {
  179. submit.value.handleSubmit(async () => {
  180. if (formData.data.inOutStorageBomList && formData.data.inOutStorageBomList.length > 0) {
  181. for (let i = 0; i < formData.data.inOutStorageBomList.length; i++) {
  182. if (Number(formData.data.inOutStorageBomList[i].surplusStock) < Number(formData.data.inOutStorageBomList[i].quantity)) {
  183. return ElMessage("出库数量大于剩余库存数量");
  184. }
  185. }
  186. loading.value = true;
  187. for (let i = 0; i < warehouseList.value.length; i++) {
  188. let data = proxy.deepClone(formData.data);
  189. data.inOutStorageBomList = data.inOutStorageBomList.filter((item) => item.warehouseId === warehouseList.value[i].dictKey);
  190. if (data.inOutStorageBomList && data.inOutStorageBomList.length > 0) {
  191. let orderList = [];
  192. for (let j = 0; j < data.inOutStorageBomList.length; j++) {
  193. orderList = orderList.concat(data.inOutStorageBomList[j].orderList.map((itemOrder) => itemOrder.orderSkuId));
  194. }
  195. const resTwo = await proxy.post("/stockPreparation/submit", duplicateRemoval(orderList));
  196. }
  197. }
  198. ElMessage({ message: "提交完成", type: "success" });
  199. loading.value = false;
  200. emit("clickCancel", true);
  201. } else {
  202. return ElMessage("请添加BOM");
  203. }
  204. });
  205. };
  206. const clickCancel = () => {
  207. emit("clickCancel", false);
  208. };
  209. const delSomeObjValue = (arr, keyName, valueName) => {
  210. const idArr = []; // 相同的id放在同一数组中
  211. const resultArr = []; // 最终结果数组
  212. for (let i = 0; i < arr.length; i++) {
  213. const index = idArr.indexOf(arr[i][keyName]);
  214. if (index > -1) {
  215. resultArr[index][valueName] += Number(arr[i][valueName]); //取相同id的value累加
  216. } else {
  217. idArr.push(arr[i][keyName]);
  218. resultArr.push(arr[i]);
  219. }
  220. }
  221. return resultArr;
  222. };
  223. const getWarehouse = () => {
  224. return proxy.post("/warehouse/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  225. if (res.rows && res.rows.length > 0) {
  226. warehouseList.value = res.rows
  227. .filter((item) => ["2", "3"].includes(item.type))
  228. .map((item) => {
  229. return {
  230. dictKey: item.id,
  231. dictValue: item.name,
  232. };
  233. });
  234. }
  235. });
  236. };
  237. onMounted(() => {
  238. Promise.all([getWarehouse()]).then(() => {
  239. if (props.selectData && props.selectData.length > 0) {
  240. formData.data.inOutStorageBomList = delSomeObjValue(
  241. props.selectData.map((item) => {
  242. let num = 0;
  243. if (item.quantity) {
  244. num = Number(item.quantity);
  245. }
  246. return {
  247. bomSpecId: item.bomSpecId,
  248. quantity: num,
  249. name: item.bomSpecName,
  250. code: item.bomSpecCode,
  251. warehouseId: "",
  252. surplusStock: 0,
  253. };
  254. }),
  255. "bomSpecId",
  256. "quantity"
  257. ).map((item) => {
  258. return {
  259. ...item,
  260. orderList: props.selectData
  261. .map((item) => {
  262. let num = 0;
  263. if (item.quantity) {
  264. num = Number(item.quantity);
  265. }
  266. return {
  267. bomSpecId: item.bomSpecId,
  268. quantity: num,
  269. orderSkuId: item.orderSkuId,
  270. orderCode: item.orderCode,
  271. orderWlnCode: item.orderWlnCode,
  272. skuSpecCode: item.skuSpecCode,
  273. skuSpecName: item.skuSpecName,
  274. };
  275. })
  276. .filter((itemSelect) => itemSelect.bomSpecId === item.bomSpecId),
  277. };
  278. });
  279. if (formData.data.inOutStorageBomList && formData.data.inOutStorageBomList.length > 0) {
  280. let bomSpecIdList = [];
  281. bomSpecIdList = formData.data.inOutStorageBomList.map((item) => item.bomSpecId);
  282. proxy
  283. .post("/inventory/getQuantity", {
  284. departmentId: formData.data.departmentId,
  285. warehouseId: warehouseList.value[0].dictKey,
  286. bomSpecIdList: bomSpecIdList,
  287. })
  288. .then((resInventory) => {
  289. let bomSpecIdTwoList = [];
  290. for (let i = 0; i < formData.data.inOutStorageBomList.length; i++) {
  291. if (resInventory[formData.data.inOutStorageBomList[i].bomSpecId]) {
  292. formData.data.inOutStorageBomList[i].warehouseId = warehouseList.value[0].dictKey;
  293. formData.data.inOutStorageBomList[i].surplusStock = resInventory[formData.data.inOutStorageBomList[i].bomSpecId];
  294. } else {
  295. bomSpecIdTwoList.push(formData.data.inOutStorageBomList[i].bomSpecId);
  296. }
  297. }
  298. if (bomSpecIdTwoList && bomSpecIdTwoList.length > 0) {
  299. proxy
  300. .post("/inventory/getQuantity", {
  301. departmentId: formData.data.departmentId,
  302. warehouseId: warehouseList.value[1].dictKey,
  303. bomSpecIdList: bomSpecIdTwoList,
  304. })
  305. .then((inventoryTwo) => {
  306. for (let i = 0; i < formData.data.inOutStorageBomList.length; i++) {
  307. if (inventoryTwo[formData.data.inOutStorageBomList[i].bomSpecId]) {
  308. formData.data.inOutStorageBomList[i].warehouseId = warehouseList.value[1].dictKey;
  309. formData.data.inOutStorageBomList[i].surplusStock = inventoryTwo[formData.data.inOutStorageBomList[i].bomSpecId];
  310. }
  311. }
  312. });
  313. }
  314. });
  315. }
  316. }
  317. });
  318. });
  319. const changeWarehouse = (val, item, index) => {
  320. if (val) {
  321. if (formData.data.departmentId) {
  322. proxy
  323. .post("/inventory/getQuantity", {
  324. departmentId: formData.data.departmentId,
  325. warehouseId: val,
  326. bomSpecIdList: [item.bomSpecId],
  327. })
  328. .then((res) => {
  329. if (res[item.bomSpecId]) {
  330. formData.data.inOutStorageBomList[index].surplusStock = res[item.bomSpecId];
  331. } else {
  332. formData.data.inOutStorageBomList[index].surplusStock = 0;
  333. }
  334. });
  335. } else {
  336. return ElMessage("请先选择事业部");
  337. }
  338. } else {
  339. formData.data.inOutStorageBomList[index].surplusStock = 0;
  340. }
  341. };
  342. const changeDepartment = () => {
  343. if (formData.data.inOutStorageBomList && formData.data.inOutStorageBomList.length > 0) {
  344. formData.data.inOutStorageBomList = formData.data.inOutStorageBomList.map((item) => {
  345. return {
  346. ...item,
  347. warehouseId: "",
  348. surplusStock: 0,
  349. };
  350. });
  351. }
  352. };
  353. </script>
  354. <style lang="scss" scoped>
  355. ::v-deep(.el-input-number .el-input__inner) {
  356. text-align: left;
  357. }
  358. :deep(.el-dialog) {
  359. margin-top: 10px !important;
  360. margin-bottom: 10px !important;
  361. }
  362. </style>