quick.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div v-loading="loading">
  3. <div style="height: calc(100vh - 174px); overflow-y: auto; overflow-x: hidden">
  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="outDepartmentId" style="width: 100%; margin-bottom: 18px">
  10. <el-select v-model="formData.data.outDepartmentId" placeholder="请选择事业部" 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="applicant" style="width: 100%; margin-bottom: 18px">
  15. <el-input v-model="formData.data.applicant" placeholder="请输入申请人" />
  16. </el-form-item>
  17. </el-col>
  18. <el-col :span="12">
  19. <el-form-item label="备注" prop="remark" style="width: 100%; margin-bottom: 18px">
  20. <el-input v-model="formData.data.remark" :rows="4" type="textarea" placeholder="请输入备注" />
  21. </el-form-item>
  22. </el-col>
  23. </el-row>
  24. </div>
  25. </template>
  26. <template #inOutStorageBomList>
  27. <div style="width: 100%; padding: 0 20px">
  28. <div style="margin-bottom: 10px">{{ statisticalQuantity() }}</div>
  29. <el-table :data="inOutStorageBomList" :row-style="{ height: '35px' }" header-row-class-name="tableHeader">
  30. <el-table-column label="BOM品号" prop="bomSpecCode" width="180" v-if="props.pagination.orderStockType == '0'" />
  31. <el-table-column label="BOM品名" prop="bomSpecName" min-width="220" v-if="props.pagination.orderStockType == '0'" />
  32. <el-table-column label="SKU品号" prop="skuSpecCode" width="180" v-if="props.pagination.orderStockType == '1'" />
  33. <el-table-column label="SKU品名" prop="skuSpecName" min-width="220" v-if="props.pagination.orderStockType == '1'" />
  34. <el-table-column label="仓库名称" prop="warehouseName" width="160" />
  35. <el-table-column label="剩余库存" prop="inventoryQuantity" width="120" />
  36. <el-table-column label="出库数量" width="140">
  37. <template #default="{ row }">
  38. <span :style="!row.inventoryQuantity || row.inventoryQuantity < row.outQuantity ? 'color: red' : ''">{{ row.outQuantity }}</span>
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. </div>
  43. </template>
  44. </byForm>
  45. </div>
  46. <div style="text-align: center; margin: 10px">
  47. <el-button @click="clickCancel()" size="large">取 消</el-button>
  48. <el-button type="primary" @click="submitForm()" size="large" v-preReClick>确 定</el-button>
  49. </div>
  50. </div>
  51. </template>
  52. <script setup>
  53. import byForm from "/src/components/byForm/index";
  54. import { ElMessage } from "element-plus";
  55. const { proxy } = getCurrentInstance();
  56. const departmentList = ref([]);
  57. const props = defineProps({
  58. pagination: Object,
  59. });
  60. const submit = ref(null);
  61. const formOption = reactive({
  62. inline: true,
  63. labelWidth: "100px",
  64. itemWidth: 100,
  65. rules: [],
  66. labelPosition: "right",
  67. });
  68. const formData = reactive({
  69. data: {
  70. // departmentId: props.departmentId,
  71. outDepartmentId: "0",
  72. applicant: proxy.useUserStore().user.nickName,
  73. ...props.pagination,
  74. },
  75. });
  76. const inOutStorageBomList = ref([]);
  77. const formConfig = computed(() => {
  78. return [
  79. {
  80. type: "title",
  81. title: "出库信息",
  82. label: "",
  83. },
  84. {
  85. type: "slot",
  86. slotName: "basicInformation",
  87. label: "",
  88. },
  89. {
  90. type: "title",
  91. title: "物料信息",
  92. label: "",
  93. },
  94. {
  95. type: "slot",
  96. slotName: "inOutStorageBomList",
  97. label: "",
  98. },
  99. ];
  100. });
  101. const rules = ref({
  102. outDepartmentId: [{ required: true, message: "请选择事业部", trigger: "change" }],
  103. applicant: [{ required: true, message: "请输入申请人", trigger: "blur" }],
  104. });
  105. const getDemandData = () => {
  106. proxy.post("/department/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  107. if (res.rows && res.rows.length > 0) {
  108. departmentList.value = res.rows.map((item) => {
  109. return {
  110. dictKey: item.id,
  111. dictValue: item.name,
  112. };
  113. });
  114. }
  115. });
  116. };
  117. getDemandData();
  118. const emit = defineEmits(["clickCancel"]);
  119. const loading = ref(false);
  120. const submitForm = () => {
  121. submit.value.handleSubmit(() => {
  122. if (inOutStorageBomList.value && inOutStorageBomList.value.length > 0) {
  123. for (let i = 0; i < inOutStorageBomList.value.length; i++) {
  124. if (Number(inOutStorageBomList.value[i].inventoryQuantity) < Number(inOutStorageBomList.value[i].outQuantity)) {
  125. return ElMessage("出库数量大于剩余库存数量");
  126. }
  127. }
  128. loading.value = true;
  129. proxy.post("/stockPreparation/submit", formData.data).then(
  130. () => {
  131. ElMessage({ message: "提交完成", type: "success" });
  132. emit("clickCancel", true);
  133. },
  134. (err) => {
  135. console.log(err);
  136. loading.value = false;
  137. }
  138. );
  139. } else {
  140. return ElMessage("请添加BOM");
  141. }
  142. });
  143. };
  144. const clickCancel = () => {
  145. emit("clickCancel", false);
  146. };
  147. onMounted(() => {
  148. changeDepartment();
  149. });
  150. const changeDepartment = () => {
  151. if (props.pagination.orderStockType == "1") {
  152. proxy.post("/stockPreparation/outSkuList", formData.data).then((res) => {
  153. if (res && res.length > 0) {
  154. inOutStorageBomList.value = Object.freeze(res.filter((item) => !["吊牌", "不干胶"].includes(item.classifyName)));
  155. } else {
  156. inOutStorageBomList.value = [];
  157. }
  158. });
  159. } else {
  160. proxy.post("/stockPreparation/outBomList", formData.data).then((res) => {
  161. if (res && res.length > 0) {
  162. inOutStorageBomList.value = Object.freeze(res.filter((item) => !["吊牌", "不干胶"].includes(item.classifyName)));
  163. } else {
  164. inOutStorageBomList.value = [];
  165. }
  166. });
  167. }
  168. };
  169. const statisticalQuantity = () => {
  170. let quantity = 0;
  171. let material = {};
  172. if (inOutStorageBomList.value && inOutStorageBomList.value.length > 0) {
  173. let principal = inOutStorageBomList.value.filter((item) => item.classifyParentId == "1");
  174. if (principal && principal.length > 0) {
  175. for (let j = 0; j < principal.length; j++) {
  176. if (principal[j].outQuantity) {
  177. quantity = Number(Math.round(quantity + principal[j].outQuantity));
  178. }
  179. }
  180. }
  181. let auxiliaryMaterial = inOutStorageBomList.value.filter((item) => item.classifyParentId != "1");
  182. if (auxiliaryMaterial && auxiliaryMaterial.length > 0) {
  183. for (let i = 0; i < auxiliaryMaterial.length; i++) {
  184. if (material[auxiliaryMaterial[i].classifyId]) {
  185. material[auxiliaryMaterial[i].classifyId].quantity = Number(
  186. Math.round(material[auxiliaryMaterial[i].classifyId].quantity + auxiliaryMaterial[i].outQuantity)
  187. );
  188. } else {
  189. material[auxiliaryMaterial[i].classifyId] = {
  190. name: auxiliaryMaterial[i].classifyName,
  191. quantity: auxiliaryMaterial[i].outQuantity,
  192. };
  193. }
  194. }
  195. }
  196. }
  197. let text = "主材数量: " + quantity;
  198. for (let key in material) {
  199. if (key && material[key].name) {
  200. text = text + ", " + material[key].name + ": " + material[key].quantity;
  201. }
  202. }
  203. return text;
  204. };
  205. </script>
  206. <style lang="scss" scoped>
  207. ::v-deep(.el-input-number .el-input__inner) {
  208. text-align: left;
  209. }
  210. :deep(.el-dialog) {
  211. margin-top: 10px !important;
  212. margin-bottom: 10px !important;
  213. }
  214. </style>