index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <div class="tenant">
  3. <div class="content">
  4. <byTable
  5. :source="sourceList.data"
  6. :pagination="sourceList.pagination"
  7. :config="config"
  8. :loading="loading"
  9. :selectConfig="selectConfig"
  10. highlight-current-row
  11. :action-list="[
  12. {
  13. text: '手动出库',
  14. action: () => openModal(),
  15. },
  16. ]"
  17. @get-list="getList">
  18. </byTable>
  19. </div>
  20. <el-dialog title="手动出库" v-if="dialogVisible" v-model="dialogVisible" width="1000" v-loading="loadingDialog">
  21. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="submit">
  22. <template #details>
  23. <div style="width: 100%">
  24. <el-button type="primary" @click="clickAdd()">添加明细</el-button>
  25. <el-table :data="formData.data.list" style="width: 100%; margin-top: 16px">
  26. <el-table-column prop="productCode" label="产品编码" width="140" />
  27. <el-table-column prop="productName" label="产品名称" min-width="160" />
  28. <el-table-column prop="productSpec" label="规格型号" width="160" />
  29. <el-table-column prop="productUnit" label="单位" width="100" />
  30. <el-table-column prop="productQuantity" label="库存数量" width="120" />
  31. <el-table-column label="出库数量" width="160">
  32. <template #default="{ row, $index }">
  33. <div style="width: 100%">
  34. <el-form-item :prop="'list.' + $index + '.quantity'" :rules="rules.quantity" :inline-message="true">
  35. <el-input-number v-model="row.quantity" placeholder="请输入出库数量" style="width: 100%" :precision="0" :controls="false" :min="0" />
  36. </el-form-item>
  37. </div>
  38. </template>
  39. </el-table-column>
  40. <el-table-column align="center" label="操作" width="80" fixed="right">
  41. <template #default="{ row, $index }">
  42. <el-button type="primary" link @click="handleDelete($index)">删除</el-button>
  43. </template>
  44. </el-table-column>
  45. </el-table>
  46. </div>
  47. </template>
  48. </byForm>
  49. <template #footer>
  50. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  51. <el-button type="primary" @click="submitForm()" size="large">确 定</el-button>
  52. </template>
  53. </el-dialog>
  54. <el-dialog v-model="openProduct" title="选择商品" width="80%" append-to-body>
  55. <InventoryInquiry
  56. :selectStatus="true"
  57. :warehouseId="formData.data.warehouseId"
  58. @cancel="openProduct = false"
  59. @select="select"
  60. :key="formData.data.warehouseId">
  61. </InventoryInquiry>
  62. </el-dialog>
  63. </div>
  64. </template>
  65. <script setup>
  66. import { computed, ref } from "vue";
  67. import byTable from "@/components/byTable/index";
  68. import byForm from "@/components/byForm/index";
  69. import { ElMessage } from "element-plus";
  70. import InventoryInquiry from "@/views/purchaseSales/outAndInWarehouse/inventoryInquiry/index";
  71. const { proxy } = getCurrentInstance();
  72. const warehouseList = ref([]);
  73. const sourceList = ref({
  74. data: [],
  75. pagination: {
  76. total: 0,
  77. pageNum: 1,
  78. pageSize: 10,
  79. keyword: "",
  80. warehouseId: "",
  81. type: "2",
  82. },
  83. });
  84. const loading = ref(false);
  85. const selectConfig = computed(() => {
  86. return [
  87. {
  88. label: "仓库名称",
  89. prop: "warehouseId",
  90. data: warehouseList.value,
  91. },
  92. ];
  93. });
  94. const config = computed(() => {
  95. return [
  96. {
  97. attrs: {
  98. label: "仓库名称",
  99. prop: "warehouseName",
  100. width: 220,
  101. },
  102. },
  103. {
  104. attrs: {
  105. label: "物品编码",
  106. prop: "productCode",
  107. width: 160,
  108. },
  109. },
  110. {
  111. attrs: {
  112. label: "物品名称",
  113. prop: "productName",
  114. "min-width": 220,
  115. },
  116. },
  117. {
  118. attrs: {
  119. label: "规格型号",
  120. prop: "productSpec",
  121. width: 160,
  122. },
  123. },
  124. {
  125. attrs: {
  126. label: "单位",
  127. prop: "productUnit",
  128. width: 120,
  129. },
  130. },
  131. {
  132. attrs: {
  133. label: "出库数量",
  134. prop: "quantity",
  135. width: 140,
  136. },
  137. },
  138. {
  139. attrs: {
  140. label: "操作人",
  141. prop: "opUserName",
  142. width: 140,
  143. },
  144. },
  145. {
  146. attrs: {
  147. label: "操作时间",
  148. prop: "createTime",
  149. width: 160,
  150. },
  151. },
  152. ];
  153. });
  154. const getDict = () => {
  155. proxy.post("/warehouse/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  156. if (res.rows && res.rows.length > 0) {
  157. warehouseList.value = res.rows.map((item) => {
  158. return {
  159. label: item.name,
  160. value: item.id,
  161. };
  162. });
  163. }
  164. });
  165. };
  166. const getList = async (req) => {
  167. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  168. loading.value = true;
  169. proxy.post("/stockJournalDetails/page", sourceList.value.pagination).then((res) => {
  170. sourceList.value.data = res.rows;
  171. sourceList.value.pagination.total = res.total;
  172. setTimeout(() => {
  173. loading.value = false;
  174. }, 200);
  175. });
  176. };
  177. getDict();
  178. getList();
  179. const dialogVisible = ref(false);
  180. const loadingDialog = ref(false);
  181. const submit = ref(null);
  182. const openProduct = ref(false);
  183. const formOption = reactive({
  184. inline: true,
  185. labelWidth: 100,
  186. itemWidth: 100,
  187. rules: [],
  188. });
  189. const formData = reactive({
  190. data: {},
  191. });
  192. const formConfig = computed(() => {
  193. return [
  194. {
  195. label: "基本信息",
  196. },
  197. {
  198. type: "select",
  199. prop: "warehouseId",
  200. label: "仓库名称",
  201. required: true,
  202. data: warehouseList.value,
  203. fn: () => {
  204. changeWarehouse();
  205. },
  206. },
  207. {
  208. type: "slot",
  209. slotName: "details",
  210. label: "出库明细",
  211. },
  212. ];
  213. });
  214. const rules = ref({
  215. warehouseId: [{ required: true, message: "请选择仓库", trigger: "change" }],
  216. quantity: [{ required: true, message: "请输入出库数量", trigger: "blur" }],
  217. });
  218. const openModal = () => {
  219. formData.data = {
  220. type: "2",
  221. list: [],
  222. };
  223. loadingDialog.value = false;
  224. dialogVisible.value = true;
  225. };
  226. const clickAdd = () => {
  227. if (formData.data.warehouseId) {
  228. openProduct.value = true;
  229. } else {
  230. ElMessage("请先选择仓库");
  231. }
  232. };
  233. const changeWarehouse = () => {
  234. formData.data.list = [];
  235. };
  236. const select = (item) => {
  237. if (formData.data.list && formData.data.list.length > 0) {
  238. let data = formData.data.list.filter((row) => row.productId === item.productId);
  239. if (data && data.length > 0) {
  240. return ElMessage("请勿重复添加");
  241. }
  242. }
  243. formData.data.list.push({
  244. productCode: item.productCode,
  245. productId: item.productId,
  246. productName: item.productName,
  247. productSpec: item.productSpec,
  248. productUnit: item.productUnit,
  249. productQuantity: item.quantity,
  250. quantity: undefined,
  251. });
  252. ElMessage({
  253. message: "添加成功!",
  254. type: "success",
  255. });
  256. };
  257. const submitForm = () => {
  258. submit.value.handleSubmit(() => {
  259. if (formData.data.list && formData.data.list.length > 0) {
  260. for (let i = 0; i < formData.data.list.length; i++) {
  261. if (formData.data.list[i].productQuantity < formData.data.list[i].quantity) {
  262. return ElMessage("出库数量不能大于库存数量");
  263. }
  264. }
  265. } else {
  266. return ElMessage("请添加出库产品");
  267. }
  268. loadingDialog.value = true;
  269. proxy.post("/stock/edit", formData.data).then(
  270. () => {
  271. ElMessage({
  272. message: "提交成功",
  273. type: "success",
  274. });
  275. dialogVisible.value = false;
  276. getList();
  277. },
  278. (err) => {
  279. console.log(err);
  280. loadingDialog.value = false;
  281. }
  282. );
  283. });
  284. };
  285. const handleDelete = (index) => {
  286. formData.data.list.splice(index, 1);
  287. };
  288. </script>
  289. <style lang="scss" scoped>
  290. .tenant {
  291. padding: 20px;
  292. }
  293. ::v-deep(.el-input-number .el-input__inner) {
  294. text-align: left;
  295. }
  296. </style>