add.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div>
  3. <el-card class="box-card">
  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%">
  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="warehouseId" style="width: 100%; margin-bottom: 18px">
  15. <el-select v-model="formData.data.warehouseId" placeholder="请选择仓库" clearable style="width: 100%">
  16. <el-option v-for="item in warehouseList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item label="出库类型" prop="detailType" style="width: 100%; margin-bottom: 18px">
  20. <el-select v-model="formData.data.detailType" placeholder="请选择出库类型" clearable style="width: 100%">
  21. <el-option v-for="item in useUserStore().allDict['come_stock_type']" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item label="申请人" prop="applicant" style="width: 100%; margin-bottom: 18px">
  25. <el-input v-model="formData.data.applicant" placeholder="请输入申请人" />
  26. </el-form-item>
  27. </el-col>
  28. <el-col :span="12">
  29. <el-form-item label="备注" prop="remark" style="width: 100%; margin-bottom: 18px">
  30. <el-input v-model="formData.data.remark" :rows="4" type="textarea" placeholder="请输入备注" />
  31. </el-form-item>
  32. </el-col>
  33. </el-row>
  34. </div>
  35. </template>
  36. <template #inOutStorageBomList>
  37. <div style="width: 100%; padding: 0 20px">
  38. <div style="margin-bottom: 10px">
  39. <el-button type="primary" size="small" @click="clickAddBOM()">选择BOM</el-button>
  40. </div>
  41. <el-table :data="formData.data.inOutStorageBomList" :row-style="{ height: '35px' }" header-row-class-name="tableHeader">
  42. <el-table-column label="品号" prop="code" width="180" />
  43. <el-table-column label="品名" prop="name" min-width="220" />
  44. <el-table-column label="剩余库存" prop="surplusStock" width="140" />
  45. <el-table-column label="出库数量" width="180">
  46. <template #default="{ row, $index }">
  47. <el-form-item :prop="'inOutStorageBomList.' + $index + '.quantity'" :rules="rules.quantity" :inline-message="true" style="width: 100%">
  48. <el-input-number
  49. onmousewheel="return false;"
  50. v-model="row.quantity"
  51. placeholder="出库数量"
  52. style="width: 100%"
  53. :controls="false"
  54. :min="0"
  55. :precision="0" />
  56. </el-form-item>
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="操作" align="center" fixed="right" width="60">
  60. <template #default="{ $index }">
  61. <el-button type="danger" @click="clickDelete($index)" text>删除</el-button>
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. </div>
  66. </template>
  67. </byForm>
  68. <div style="width: 100%; text-align: center; margin: 10px">
  69. <el-button @click="clickCancel()" size="large">取 消</el-button>
  70. <el-button type="primary" @click="submitForm()" size="large" v-preReClick>确 定</el-button>
  71. </div>
  72. </el-card>
  73. <el-dialog title="选择BOM" v-if="openBOM" v-model="openBOM" width="90%">
  74. <SelectInventory
  75. :selectStatus="true"
  76. :departmentId="formData.data.departmentId"
  77. :warehouseId="formData.data.warehouseId"
  78. @selectBOM="selectBOM"></SelectInventory>
  79. <template #footer>
  80. <el-button @click="openBOM = false" size="large">关 闭</el-button>
  81. </template>
  82. </el-dialog>
  83. </div>
  84. </template>
  85. <script setup>
  86. import byForm from "@/components/byForm/index";
  87. import { ElMessage } from "element-plus";
  88. import { useRouter } from "vue-router";
  89. import useTagsViewStore from "@/store/modules/tagsView";
  90. import SelectInventory from "@/views/production/warehouse/inventory/index";
  91. const { proxy } = getCurrentInstance();
  92. const departmentList = ref([{ dictKey: "0", dictValue: "胜德体育" }]);
  93. const warehouseList = ref([]);
  94. const router = useRouter();
  95. const submit = ref(null);
  96. const formOption = reactive({
  97. inline: true,
  98. labelWidth: "100px",
  99. itemWidth: 100,
  100. rules: [],
  101. labelPosition: "right",
  102. });
  103. const formData = reactive({
  104. data: {
  105. type: 1,
  106. applicant: proxy.useUserStore().user.nickName,
  107. inOutStorageBomList: [],
  108. },
  109. });
  110. const formConfig = computed(() => {
  111. return [
  112. {
  113. type: "title",
  114. title: "出库信息",
  115. label: "",
  116. },
  117. {
  118. type: "slot",
  119. slotName: "basicInformation",
  120. label: "",
  121. },
  122. {
  123. type: "title",
  124. title: "物料信息",
  125. label: "",
  126. },
  127. {
  128. type: "slot",
  129. slotName: "inOutStorageBomList",
  130. label: "",
  131. },
  132. ];
  133. });
  134. const rules = ref({
  135. departmentId: [{ required: true, message: "请选择事业部", trigger: "change" }],
  136. warehouseId: [{ required: true, message: "请选择仓库", trigger: "change" }],
  137. detailType: [{ required: true, message: "请选择出库类型", trigger: "change" }],
  138. applicant: [{ required: true, message: "请输入申请人", trigger: "blur" }],
  139. quantity: [{ required: true, message: "请输入出库数量", trigger: "blur" }],
  140. });
  141. const getDemandData = () => {
  142. proxy.post("/department/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  143. if (res.rows && res.rows.length > 0) {
  144. departmentList.value = departmentList.value.concat(
  145. res.rows.map((item) => {
  146. return {
  147. dictKey: item.id,
  148. dictValue: item.name,
  149. };
  150. })
  151. );
  152. }
  153. });
  154. proxy.post("/warehouse/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  155. if (res.rows && res.rows.length > 0) {
  156. warehouseList.value = res.rows.map((item) => {
  157. return {
  158. dictKey: item.id,
  159. dictValue: item.name,
  160. };
  161. });
  162. }
  163. });
  164. };
  165. getDemandData();
  166. const openBOM = ref(false);
  167. const clickAddBOM = () => {
  168. if (!(formData.data.departmentId || formData.data.departmentId === "0")) {
  169. return ElMessage("请先选择事业部");
  170. }
  171. if (!(formData.data.warehouseId || formData.data.warehouseId === "0")) {
  172. return ElMessage("请先选择仓库");
  173. }
  174. openBOM.value = true;
  175. };
  176. const selectBOM = (item) => {
  177. if (formData.data.inOutStorageBomList && formData.data.inOutStorageBomList.length > 0) {
  178. let list = formData.data.inOutStorageBomList.filter((itemFilter) => itemFilter.bomSpecId === item.id);
  179. if (list && list.length > 0) {
  180. return ElMessage("该BOM已添加");
  181. }
  182. }
  183. if (item.id) {
  184. formData.data.inOutStorageBomList.push({
  185. bomSpecId: item.bomSpecId,
  186. code: item.bomSpecCode,
  187. name: item.bomSpecName,
  188. surplusStock: item.quantity,
  189. quantity: undefined,
  190. });
  191. ElMessage({ message: "选择完成", type: "success" });
  192. }
  193. };
  194. const clickDelete = (index) => {
  195. formData.data.inOutStorageBomList.splice(index, 1);
  196. };
  197. const submitForm = () => {
  198. submit.value.handleSubmit(() => {
  199. if (formData.data.inOutStorageBomList && formData.data.inOutStorageBomList.length > 0) {
  200. for (let i = 0; i < formData.data.inOutStorageBomList.length; i++) {
  201. if (Number(formData.data.inOutStorageBomList[i].surplusStock) < Number(formData.data.inOutStorageBomList[i].quantity)) {
  202. return ElMessage("出库数量大于剩余库存数量");
  203. }
  204. }
  205. proxy.post("/inOutStorage/add", formData.data).then(() => {
  206. ElMessage({
  207. message: "提交成功",
  208. type: "success",
  209. });
  210. clickCancel();
  211. });
  212. } else {
  213. return ElMessage("请添加BOM");
  214. }
  215. });
  216. };
  217. const clickCancel = () => {
  218. const useTagsStore = useTagsViewStore();
  219. useTagsStore.delVisitedView(router.currentRoute.value);
  220. router.replace({
  221. path: "/production/warehouse/warehouse-outbound",
  222. });
  223. };
  224. </script>
  225. <style lang="scss" scoped>
  226. ::v-deep(.el-input-number .el-input__inner) {
  227. text-align: left;
  228. }
  229. :deep(.el-dialog) {
  230. margin-top: 10px !important;
  231. margin-bottom: 10px !important;
  232. }
  233. </style>