WarehousingDialog.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <el-dialog
  3. :visible.sync="visible"
  4. title="仓库"
  5. @before-close="cancel"
  6. width="50%"
  7. :close-on-click-modal="false"
  8. >
  9. <el-form :model="formData" label-width="100px">
  10. <el-row>
  11. <el-col :span="9">
  12. <el-form-item label="选择仓库">
  13. <el-select filterable v-model="warehouseId">
  14. <el-option
  15. v-for="(item, index) in warehouseList"
  16. :key="index"
  17. :label="item.name"
  18. :value="item.id"
  19. ></el-option>
  20. </el-select> </el-form-item
  21. ></el-col>
  22. <el-col :span="6">
  23. <el-button type="primary" @click="addTableData">添加</el-button>
  24. </el-col>
  25. <el-col :span="6">
  26. <el-form-item label="总包装数量">
  27. <span class="red_color">
  28. {{ this.packingQuantity }}
  29. </span></el-form-item
  30. >
  31. </el-col>
  32. </el-row>
  33. </el-form>
  34. <el-table :data="tableDate" style="width: 100%">
  35. <el-table-column label="序号" type="index"></el-table-column>
  36. <el-table-column label="仓库名称" prop="warehouseName"></el-table-column>
  37. <el-table-column label="包装数量" prop="packingQuantity" width="300">
  38. <template slot-scope="{ row, $index }">
  39. <el-input-number
  40. v-model="row.packingQuantity"
  41. :min="1"
  42. ></el-input-number>
  43. </template>
  44. </el-table-column>
  45. <el-table-column width="120" label="操作" fixed="right">
  46. <template slot-scope="{ row, $index }">
  47. <el-button type="text" @click="delItem($index)" size="small"
  48. >删除</el-button
  49. >
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. <template slot="footer">
  54. <el-button @click="handleSelect" type="primary">确认</el-button>
  55. <el-button @click="cancel">关闭</el-button>
  56. </template>
  57. </el-dialog>
  58. </template>
  59. <script>
  60. import warehouseDefinition from '@/api/warehouseManagement/warehouseDefinition';
  61. export default {
  62. data() {
  63. return {
  64. packingQuantity: 1,
  65. tableDate: [],
  66. visible: false,
  67. warehouseList: [], //仓库
  68. formData: {},
  69. warehouseId: '',
  70. currentIndex: 0
  71. };
  72. },
  73. methods: {
  74. numberChange() {},
  75. cancel() {
  76. this.visible = false;
  77. },
  78. handleSelect() {
  79. if (this.tableDate.length == 0) {
  80. return this.$message.warning('请添加仓库!');
  81. }
  82. let total = this.tableDate.reduce(
  83. (total, currentObj) =>
  84. Number(total) + Number(currentObj.packingQuantity),
  85. 0
  86. );
  87. if (total == this.packingQuantity) {
  88. this.$emit('selection', this.tableDate, this.currentIndex);
  89. this.visible = false;
  90. } else {
  91. this.$message.warning('总包装数量与仓库包装数量不一致!');
  92. }
  93. },
  94. addTableData() {
  95. if (this.tableDate.length < this.packingQuantity) {
  96. let list = this.tableDate.filter(
  97. (item) => item.warehouseId == this.warehouseId
  98. );
  99. if (list.length > 0) {
  100. return this.$message.warning('该仓库已存在!');
  101. }
  102. this.tableDate.push({
  103. packingQuantity: this.packingQuantity,
  104. warehouseName: this.warehouseList.filter(
  105. (item) => item.id == this.warehouseId
  106. )[0].name,
  107. warehouseId: this.warehouseId
  108. });
  109. } else {
  110. this.$message.warning('仓库数量已满!');
  111. }
  112. },
  113. delItem(index) {
  114. if (index == 0 && this.tableDate.length == 1) {
  115. return this.$message.warning('请至少保存一条数据!');
  116. }
  117. this.tableDate.splice(index, 1);
  118. },
  119. async getWarehouseList() {
  120. const res = await warehouseDefinition.list({});
  121. console.log(res);
  122. this.warehouseList = res.map((item) => {
  123. return { ...item, name: item.factoryName + '-' + item.name };
  124. });
  125. },
  126. open(packingQuantity, idx, warehouseId, warehouseName) {
  127. console.log('仓库id', warehouseId, warehouseName);
  128. this.warehouseId = '';
  129. this.tableDate = [];
  130. this.currentIndex = idx;
  131. this.packingQuantity = packingQuantity;
  132. this.visible = true;
  133. this.getWarehouseList();
  134. if (warehouseId && warehouseName) {
  135. this.warehouseId = warehouseId;
  136. this.tableDate.push({
  137. packingQuantity: packingQuantity,
  138. warehouseName: warehouseName,
  139. warehouseId: warehouseId
  140. });
  141. }
  142. }
  143. }
  144. };
  145. </script>
  146. <style lang="scss" scoped>
  147. .red_color {
  148. font-size: 20px;
  149. font-weight: bold;
  150. color: red;
  151. }
  152. </style>