warehouseShelvesDialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <el-dialog
  3. :visible.sync="visible"
  4. title="仓库"
  5. @before-close="cancel"
  6. width="1000px"
  7. :close-on-click-modal="false"
  8. >
  9. <el-form :model="formData" label-width="100px">
  10. <el-row>
  11. <el-col :span="8">
  12. <el-form-item label="选择仓库">
  13. <el-select
  14. disabled
  15. filterable
  16. v-model="warehouse"
  17. @change="warehouseChange"
  18. >
  19. <el-option
  20. v-for="(item, index) in warehouseList"
  21. :key="index"
  22. :label="item.name"
  23. :value="item.id"
  24. @click.native="changeWarehouse(item)"
  25. ></el-option>
  26. </el-select> </el-form-item
  27. ></el-col>
  28. <el-col :span="8">
  29. <el-form-item label="选择库区">
  30. <el-select filterable v-model="area" @change="getshelvesList">
  31. <el-option
  32. v-for="(item, index) in areaList"
  33. :key="index"
  34. :label="item.name"
  35. :value="item.id"
  36. @click.native="formData.area = item"
  37. ></el-option>
  38. </el-select> </el-form-item
  39. ></el-col>
  40. <el-col :span="8">
  41. <el-form-item label="选择货架">
  42. <el-select filterable v-model="shelves" @change="changeshelvesList">
  43. <el-option
  44. v-for="(item, index) in shelvesList"
  45. :key="index"
  46. :label="item.goodsshelvesCode"
  47. :value="item.goodsshelvesCode"
  48. @click.native="formData.shelves = item"
  49. ></el-option>
  50. </el-select> </el-form-item
  51. ></el-col>
  52. </el-row>
  53. </el-form>
  54. <div class="status-legend">
  55. <div
  56. v-for="(item, index) in warehouseDefinition_locationStatus"
  57. :key="index"
  58. >
  59. <span :style="{ 'background-color': item.color }"></span
  60. >{{ item.label }}
  61. </div>
  62. </div>
  63. <div class="content-box">
  64. <div
  65. v-for="p in locationList"
  66. :key="p.id"
  67. class="box"
  68. @click="handlCur(p)"
  69. :class="{ active: cur.goodsAllocationCode == p.goodsAllocationCode }"
  70. :style="{
  71. 'background-color': getStatus(p.allocationStatus).color,
  72. cursor: [1, 2].includes(p.allocationStatus)
  73. ? 'pointer'
  74. : 'not-allowed'
  75. }"
  76. >
  77. {{ p.goodsAllocationCode }}
  78. </div>
  79. </div>
  80. <el-table :data="tableList" style="width: 940px">
  81. <el-table-column label="序号" type="index"></el-table-column>
  82. <el-table-column label="货位位置" prop="position" width="600">
  83. <template slot-scope="scope">
  84. {{ scope.row.warehouseName }} - {{ scope.row.areaName }} -
  85. {{ scope.row.shelfCode }} - {{ scope.row.cargoSpaceCode }}
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="包装数量" prop="packingQuantity" width="170">
  89. </el-table-column>
  90. <el-table-column width="120" label="操作" fixed="right">
  91. <template slot-scope="scope">
  92. <el-button type="text" @click="delItem(scope.$index)" size="small"
  93. >删除</el-button
  94. >
  95. </template>
  96. </el-table-column>
  97. </el-table>
  98. <template slot="footer">
  99. <el-button @click="handleSelect" type="primary">确认</el-button>
  100. <el-button @click="cancel">关闭</el-button>
  101. </template>
  102. </el-dialog>
  103. </template>
  104. <script>
  105. import warehouseDefinition from '@/api/warehouseManagement/warehouseDefinition';
  106. import { warehouseDefinition_locationStatus } from '@/utils/dict/warehouseDefinition';
  107. import { useDict } from '@/utils/dict/index';
  108. export default {
  109. data() {
  110. return {
  111. warehouseDefinition_locationStatus: [
  112. { code: 1, label: '空置', color: 'rgba(202, 249, 130, 1)' },
  113. { code: 2, label: '在用', color: 'rgba(129, 211, 248, 1)' },
  114. { code: 3, label: '已满', color: 'rgba(255, 14, 14, 1)' },
  115. { code: 4, label: '失效', color: 'rgba(215, 215, 215, 1)' }
  116. ],
  117. visible: false,
  118. warehouseList: [], //仓库
  119. areaList: [], //库区
  120. areaGoodsshelvesList: [], //货架
  121. allocationReqList: [], //货位
  122. value: '',
  123. row: {},
  124. formData: {
  125. warehouse: {},
  126. area: {},
  127. shelves: {}
  128. },
  129. warehouse: '',
  130. area: '',
  131. shelves: '',
  132. cur: {
  133. cargoSpaceId: ''
  134. },
  135. shelvesList: [],
  136. locationList: [],
  137. tableList: [],
  138. idx: null,
  139. type: ''
  140. };
  141. },
  142. created() {},
  143. methods: {
  144. delItem(index) {
  145. // if (index == 0 && this.tableList.length == 1) {
  146. // return this.$message.warning('请至少保存一条数据!');
  147. // }
  148. this.tableList.splice(index, 1);
  149. },
  150. handlCur(row, num) {
  151. if (this.tableList.length > 0) {
  152. return false;
  153. }
  154. if (![1, 2].includes(row.allocationStatus)) {
  155. return;
  156. }
  157. this.cur = { ...row };
  158. console.log('==this.formData', this.formData);
  159. // 仓库
  160. const { area, shelves, warehouse } = this.formData;
  161. let warehouseId = warehouse.id;
  162. let warehouseName = warehouse.name;
  163. // 区域
  164. let areaId = area.id;
  165. let areaName = area.name;
  166. // 货架
  167. let shelfId = shelves.id;
  168. let shelfCode = shelves.goodsshelvesCode;
  169. // 货位
  170. let cargoSpaceId = this.cur.id;
  171. let cargoSpaceCode = this.cur.goodsAllocationCode;
  172. // let flag = true;
  173. // this.tableList.forEach((f) => {
  174. // if (f.cargoSpaceId == cargoSpaceId && f.shelfId == shelfId) {
  175. // this.$message.info('请勿重复选择');
  176. // flag = false;
  177. // }
  178. // });
  179. // if (flag) {
  180. this.tableList.push({
  181. warehouseId: warehouseId,
  182. warehouseName,
  183. areaId,
  184. areaName,
  185. shelfId,
  186. shelfCode,
  187. cargoSpaceId,
  188. cargoSpaceCode,
  189. packingQuantity: num ? num : this.row.packingQuantity
  190. });
  191. // }
  192. },
  193. warehouseChange() {
  194. this.cur = {};
  195. this.shelves = '';
  196. this.locationList = [];
  197. this.area = '';
  198. },
  199. async getshelvesList(e) {
  200. this.cur = {};
  201. this.shelves = '';
  202. this.locationList = [];
  203. this.shelvesList = this.areaGoodsshelvesList.filter(
  204. (i) => i.reservoirAreaCode === this.area
  205. );
  206. const rep = await warehouseDefinition.getListByAreaId(e);
  207. this.shelvesList = rep;
  208. },
  209. async changeshelvesList(id) {
  210. this.cur = {};
  211. // this.locationList = this.allocationReqList.filter(
  212. // (i) => i.goodsAllocationCode === this.shelves
  213. // );
  214. const goodsId = this.shelvesList.filter((item) => {
  215. return item.goodsshelvesCode == id;
  216. })[0].id;
  217. const res = await warehouseDefinition.getListByGoodId(goodsId);
  218. this.locationList = res;
  219. },
  220. getStatus: useDict(warehouseDefinition_locationStatus),
  221. async open(row, idx, type) {
  222. this.locationList = [];
  223. this.tableList = [];
  224. console.log('===123', row);
  225. this.row = row;
  226. this.idx = idx;
  227. this.type = type;
  228. this.visible = true;
  229. await this._getWarehouseChildren(); // 获取仓库列表
  230. if (this.row?.warehouseId) {
  231. this.warehouse = this.row.warehouseId;
  232. this.formData.warehouse = this.warehouseList.find(
  233. (w) => w.id == this.row.warehouseId
  234. );
  235. // const res = await warehouseDefinition.getById({
  236. // id: this.row.warehouseId
  237. // });
  238. // 区域
  239. const rep = await warehouseDefinition.getListByWarehouseId(
  240. this.row.warehouseId
  241. );
  242. this.areaList = rep || [];
  243. console.log('区域列表·······', rep);
  244. if (this.row?.areaId) {
  245. this.formData.area = this.areaList.find(
  246. (w) => w.id == this.row.areaId
  247. );
  248. this.area = this.row.areaId;
  249. // 货架
  250. const result = await warehouseDefinition.getListByAreaId(
  251. this.row.areaId
  252. );
  253. this.areaGoodsshelvesList = result || [];
  254. this.shelvesList = this.areaGoodsshelvesList.filter(
  255. (i) => i.id === this.row.houseList[0].shelfId
  256. );
  257. this.formData.shelves = this.areaGoodsshelvesList.find(
  258. (w) => w.id == this.row.goodsShelfId
  259. );
  260. this.shelves = this.row.goodsShelfId;
  261. // 货位
  262. const loca = await warehouseDefinition.getListByGoodId(
  263. this.row.goodsShelfId
  264. );
  265. this.locationList = loca;
  266. const items = loca.filter(
  267. (item) => item.id == this.row.houseList[0].goodsAllocationId
  268. );
  269. this.handlCur(items[0]);
  270. }
  271. }
  272. },
  273. async changeWarehouse(val) {
  274. this.formData.warehouse = val;
  275. const res = await warehouseDefinition.getListByWarehouseId(val.id);
  276. this.area = '';
  277. this.shelves = '';
  278. this.areaList = res || [];
  279. this.areaGoodsshelvesList = res.goodsShelvesList || [];
  280. this.allocationReqList = res.goodsAllocationList || [];
  281. this.row.warehouseId = val.id;
  282. await this.seachWareHouse();
  283. },
  284. // 查仓库
  285. async seachWareHouse() {
  286. if (this.row?.warehouseId) {
  287. this.warehouse = this.row.warehouseId;
  288. this.formData.warehouse = this.warehouseList.find(
  289. (w) => w.id == this.row.warehouseId
  290. );
  291. const res = await warehouseDefinition.warehouseDetail(
  292. this.row.warehouseId
  293. );
  294. this.areaList = res.warehouseAreasSaveList || [];
  295. this.formData.area = this.areaList.find(
  296. (w) => w.id == this.row.areaId
  297. ); // this.row.areaId
  298. this.area = this.row.areaCode;
  299. this.areaGoodsshelvesList = res.areaGoodsshelvesList || [];
  300. this.shelvesList = this.areaGoodsshelvesList.filter(
  301. (i) => i.reservoirAreaCode === this.area
  302. );
  303. this.formData.shelves = this.areaGoodsshelvesList.find(
  304. (w) => w.code == this.row.shelfCode
  305. );
  306. this.shelves = this.row.shelfCode;
  307. this.allocationReqList = res.allocationReqList || [];
  308. this.locationList = this.allocationReqList.filter(
  309. (i) => i.goodsAllocationCode === this.shelves
  310. );
  311. this.cur = this.allocationReqList.find(
  312. (w) => w.goodsAllocationCode === this.row.cargoSpaceCode
  313. );
  314. }
  315. },
  316. handleSelect() {
  317. if (this.tableList.length > 0) {
  318. this.$emit('houseData', this.tableList, this.idx, this.type);
  319. this.cancel();
  320. } else {
  321. this.$message.error('请选择货位');
  322. }
  323. },
  324. async _getWarehouseChildren() {
  325. const res = await warehouseDefinition.list({});
  326. console.log(res);
  327. this.warehouseList = res.map((item) => {
  328. return { ...item, name: item.name };
  329. });
  330. },
  331. cancel() {
  332. this.row = {};
  333. this.formData = {};
  334. this.warehouse = '';
  335. this.area = '';
  336. this.shelves = '';
  337. this.visible = false;
  338. }
  339. }
  340. };
  341. </script>
  342. <style lang="scss" scoped>
  343. .status-legend {
  344. display: flex;
  345. align-items: center;
  346. justify-content: center;
  347. margin: 12px 0;
  348. div {
  349. margin: 0 12px;
  350. }
  351. span {
  352. display: inline-block;
  353. width: 13px;
  354. height: 13px;
  355. margin: 0 4px;
  356. }
  357. }
  358. .content-box {
  359. display: flex;
  360. justify-content: space-between;
  361. flex-wrap: wrap;
  362. max-height: 40vh;
  363. overflow: auto;
  364. .box {
  365. cursor: pointer;
  366. width: 134px;
  367. height: 64px;
  368. background-clip: content-box;
  369. margin-bottom: 4px;
  370. line-height: 64px;
  371. text-align: center;
  372. &:hover,
  373. &.active {
  374. box-shadow: 2px 2px 2px 2px #ccc;
  375. }
  376. }
  377. .placeholder-box {
  378. width: 134px;
  379. }
  380. }
  381. </style>