quick.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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" />
  31. <el-table-column label="BOM品名" prop="bomSpecName" min-width="220" />
  32. <el-table-column label="仓库名称" prop="warehouseName" width="160" />
  33. <el-table-column label="剩余库存" prop="inventoryQuantity" width="120" />
  34. <el-table-column label="出库数量" width="140">
  35. <template #default="{ row }">
  36. <span :style="!row.inventoryQuantity || row.inventoryQuantity < row.outQuantity ? 'color: red' : ''">{{ row.outQuantity }}</span>
  37. </template>
  38. </el-table-column>
  39. </el-table>
  40. </div>
  41. </template>
  42. </byForm>
  43. </div>
  44. <div style="text-align: center; margin: 10px">
  45. <el-button @click="clickCancel()" size="large">取 消</el-button>
  46. <el-button type="primary" @click="submitForm()" size="large" v-preReClick>确 定</el-button>
  47. </div>
  48. </div>
  49. </template>
  50. <script setup>
  51. import byForm from "/src/components/byForm/index";
  52. import { ElMessage } from "element-plus";
  53. const { proxy } = getCurrentInstance();
  54. const departmentList = ref([{ dictKey: "0", dictValue: "胜德体育" }]);
  55. const props = defineProps({
  56. pagination: Object,
  57. });
  58. const submit = ref(null);
  59. const formOption = reactive({
  60. inline: true,
  61. labelWidth: "100px",
  62. itemWidth: 100,
  63. rules: [],
  64. labelPosition: "right",
  65. });
  66. const formData = reactive({
  67. data: {
  68. // departmentId: props.departmentId,
  69. outDepartmentId: "0",
  70. applicant: proxy.useUserStore().user.nickName,
  71. ...props.pagination,
  72. },
  73. });
  74. const inOutStorageBomList = ref([]);
  75. const formConfig = computed(() => {
  76. return [
  77. {
  78. type: "title",
  79. title: "出库信息",
  80. label: "",
  81. },
  82. {
  83. type: "slot",
  84. slotName: "basicInformation",
  85. label: "",
  86. },
  87. {
  88. type: "title",
  89. title: "物料信息",
  90. label: "",
  91. },
  92. {
  93. type: "slot",
  94. slotName: "inOutStorageBomList",
  95. label: "",
  96. },
  97. ];
  98. });
  99. const rules = ref({
  100. outDepartmentId: [{ required: true, message: "请选择事业部", trigger: "change" }],
  101. applicant: [{ required: true, message: "请输入申请人", trigger: "blur" }],
  102. });
  103. const getDemandData = () => {
  104. proxy.post("/department/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  105. if (res.rows && res.rows.length > 0) {
  106. departmentList.value = departmentList.value.concat(
  107. res.rows.map((item) => {
  108. return {
  109. dictKey: item.id,
  110. dictValue: item.name,
  111. };
  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. proxy.post("/stockPreparation/outBomList", formData.data).then((res) => {
  149. inOutStorageBomList.value = Object.freeze(res);
  150. });
  151. });
  152. const changeDepartment = () => {
  153. proxy.post("/stockPreparation/outBomList", formData.data).then((res) => {
  154. inOutStorageBomList.value = Object.freeze(res);
  155. });
  156. };
  157. const statisticalQuantity = () => {
  158. let quantity = 0;
  159. let material = {};
  160. if (inOutStorageBomList.value && inOutStorageBomList.value.length > 0) {
  161. let principal = inOutStorageBomList.value.filter((item) => item.classifyParentId == "1");
  162. if (principal && principal.length > 0) {
  163. for (let j = 0; j < principal.length; j++) {
  164. if (principal[j].outQuantity) {
  165. quantity = Number(Math.round(quantity + principal[j].outQuantity));
  166. }
  167. }
  168. }
  169. let auxiliaryMaterial = inOutStorageBomList.value.filter((item) => item.classifyParentId != "1");
  170. if (auxiliaryMaterial && auxiliaryMaterial.length > 0) {
  171. for (let i = 0; i < auxiliaryMaterial.length; i++) {
  172. if (material[auxiliaryMaterial[i].classifyId]) {
  173. material[auxiliaryMaterial[i].classifyId].quantity = Number(
  174. Math.round(material[auxiliaryMaterial[i].classifyId].quantity + auxiliaryMaterial[i].outQuantity)
  175. );
  176. } else {
  177. material[auxiliaryMaterial[i].classifyId] = {
  178. name: auxiliaryMaterial[i].classifyName,
  179. quantity: auxiliaryMaterial[i].outQuantity,
  180. };
  181. }
  182. }
  183. }
  184. }
  185. let text = "主材数量: " + quantity;
  186. for (let key in material) {
  187. if (key && material[key].name) {
  188. text = text + ", " + material[key].name + ": " + material[key].quantity;
  189. }
  190. }
  191. return text;
  192. };
  193. </script>
  194. <style lang="scss" scoped>
  195. ::v-deep(.el-input-number .el-input__inner) {
  196. text-align: left;
  197. }
  198. :deep(.el-dialog) {
  199. margin-top: 10px !important;
  200. margin-bottom: 10px !important;
  201. }
  202. </style>