outsourceIndex.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. <template>
  2. <ele-modal
  3. title="领料单"
  4. :visible.sync="visible"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  7. :maxable="true"
  8. :close-on-press-escape="false"
  9. append-to-body
  10. width="80%"
  11. @update:fullscreen="fullscreen"
  12. :fullscreen="isFullscreen"
  13. :height="dialogDynamicHeight"
  14. >
  15. <el-form>
  16. <el-row :gutter="24">
  17. <el-col :span="6">
  18. <el-form-item label="领料单编号" prop="pickCode" label-width="90px">
  19. <el-input v-model="pickCode" disabled=""></el-input>
  20. </el-form-item>
  21. </el-col>
  22. <el-col :span="6">
  23. <el-form-item label="领料单名称" prop="pickName" label-width="90px">
  24. <el-input v-model="pickName" style="width: 260px"></el-input>
  25. </el-form-item>
  26. </el-col>
  27. </el-row>
  28. </el-form>
  29. <div v-for="(item, idx) in workList" :key="idx">
  30. <el-form
  31. :ref="`formRef${idx}`"
  32. :model="{ pickList: item }"
  33. :rules="tableRules"
  34. size="mini"
  35. label-position="left"
  36. >
  37. <div class="tableZ_box">
  38. <div class="row">
  39. <div class="col">
  40. <div class="name">生产工单号</div>
  41. <div class="content">{{ item.code }}</div>
  42. </div>
  43. <div class="col">
  44. <div class="name">产品编码</div>
  45. <div class="content">{{ item.productCode }}</div>
  46. </div>
  47. <div class="col">
  48. <div class="name">产品名称</div>
  49. <div class="content">{{ item.productName }}</div>
  50. </div>
  51. <div class="col">
  52. <div class="name">批次号</div>
  53. <div class="content">{{ item.batchNo }}</div>
  54. </div>
  55. <div class="col pd6" v-if="clientEnvironmentId != 21">
  56. <el-button type="primary" size="mini" @click="openPicking()"
  57. >获取委外单</el-button
  58. >
  59. </div>
  60. </div>
  61. </div>
  62. <div>
  63. <el-table
  64. :ref="`tableRef${idx}`"
  65. class="table_content"
  66. :max-height="300"
  67. :data="item.pickList"
  68. tooltip-effect="dark"
  69. style="width: 100%"
  70. stripe
  71. border
  72. >
  73. <el-table-column label="序号" type="index" width="60">
  74. <template slot-scope="{ row, $index }">
  75. {{ $index + 1 }}
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="类型" prop="rootCategoryLevelId" width="80">
  79. <template slot-scope="{ row, $index }">
  80. <el-tag size="mini">{{
  81. typeName[Number(row.rootCategoryLevelId)]
  82. }}</el-tag>
  83. </template>
  84. </el-table-column>
  85. <el-table-column
  86. label="编码"
  87. prop="assetCode"
  88. show-overflow-tooltip
  89. >
  90. <template slot-scope="{ row, $index }">
  91. <span
  92. v-if="
  93. Object.prototype.hasOwnProperty.call(row, 'isBom') &&
  94. row.isBom == 1
  95. "
  96. style="color: #faad14"
  97. >
  98. {{ row.categoryCode }}
  99. </span>
  100. <span>
  101. {{
  102. row.rootCategoryLevelId == 4 ? row.codeNumber : row.code
  103. }}</span
  104. >
  105. </template>
  106. </el-table-column>
  107. <el-table-column label="名称" prop="name" show-overflow-tooltip>
  108. <template slot-scope="{ row, $index }">
  109. <span
  110. v-if="
  111. Object.prototype.hasOwnProperty.call(row, 'isBom') &&
  112. row.isBom == 1
  113. "
  114. >
  115. {{ row.categoryName }}
  116. </span>
  117. <span> {{ row.name }}</span>
  118. <span v-if="row.isOut" style="color: #faad14"> (委外) </span>
  119. </template>
  120. </el-table-column>
  121. <el-table-column
  122. label="型号"
  123. prop="modelType"
  124. show-overflow-tooltip
  125. >
  126. </el-table-column>
  127. <el-table-column
  128. label="规格"
  129. prop="specification"
  130. show-overflow-tooltip
  131. >
  132. </el-table-column>
  133. <el-table-column label="批次号" prop="batchNo"> </el-table-column>
  134. <el-table-column label="数量" prop="demandQuantity">
  135. <template slot-scope="{ row, $index }">
  136. <el-form-item>
  137. <el-input
  138. v-model="row.demandQuantity"
  139. @input="
  140. row.demandQuantity > row.availableCountBase
  141. ? (row.demandQuantity = row.availableCountBase)
  142. : row.demandQuantity
  143. "
  144. size="mini"
  145. style="width: 120px"
  146. >
  147. <template slot="append">{{ row.unit }}</template>
  148. </el-input>
  149. </el-form-item>
  150. </template>
  151. </el-table-column>
  152. <el-table-column label="计量库存数量" prop="availableCountBase">
  153. <template slot-scope="{ row, $index }">
  154. {{ row.availableCountBase }} {{ row.unit }}
  155. </template>
  156. </el-table-column>
  157. <el-table-column label="领料仓库" prop="warehouseId">
  158. <template slot-scope="{ row, $index }">
  159. <div
  160. v-if="
  161. Object.prototype.hasOwnProperty.call(row, 'isBom') &&
  162. row.isBom == 1
  163. "
  164. >
  165. <el-select
  166. v-model="row.warehouseId"
  167. placeholder="请选择"
  168. filterable
  169. >
  170. <el-option
  171. v-for="item in row.warehouseList"
  172. :label="item.name"
  173. :value="item.id"
  174. :key="item.id"
  175. >
  176. </el-option>
  177. </el-select>
  178. </div>
  179. <div v-else-if="clientEnvironmentId == 21">
  180. <el-select
  181. v-model="row.warehouseId"
  182. placeholder="请选择"
  183. filterable
  184. >
  185. <el-option
  186. v-for="item in row.warehouseList"
  187. :label="item.name"
  188. :value="item.id"
  189. :key="item.id"
  190. >
  191. </el-option>
  192. </el-select>
  193. </div>
  194. <div v-else-if="row.warehouseName">
  195. <span>{{ row.warehouseName }}</span>
  196. </div>
  197. <div v-else>
  198. <el-select
  199. v-model="row.warehouseId"
  200. placeholder="请选择"
  201. filterable
  202. >
  203. <el-option
  204. v-for="item in row.warehouseLists"
  205. :label="item.warehouse_name"
  206. :value="item.warehouse_id"
  207. :key="item.warehouse_id"
  208. >
  209. </el-option>
  210. </el-select>
  211. </div>
  212. </template>
  213. </el-table-column>
  214. <el-table-column label="操作" fixed="right" width="100px">
  215. <template slot-scope="{ $index, row }">
  216. <el-link type="danger" @click="removeItem(idx, $index)"
  217. >删除</el-link
  218. >
  219. </template>
  220. </el-table-column>
  221. </el-table>
  222. </div>
  223. </el-form>
  224. </div>
  225. <template slot="footer">
  226. <el-button size="mini" @click="handleClose">取 消</el-button>
  227. <el-button
  228. size="mini"
  229. type="primary"
  230. :loading="loadingBtn"
  231. @click="save()"
  232. >确 定</el-button
  233. >
  234. </template>
  235. <!-- <pickingList
  236. isType="pick"
  237. ref="pickingListRef"
  238. @allSelection="allSelection"
  239. ></pickingList> -->
  240. <outsourcingPickingList
  241. v-if="outsourcingPickingShow"
  242. ref="outsourcingPickingListRef"
  243. :workTaskId="workListIds[0]"
  244. :taskId="taskObj.id"
  245. @closeOutsourcingPicking="closeOutsourcingPicking"
  246. @outsourceEmit="outsourceEmit"
  247. ></outsourcingPickingList>
  248. </ele-modal>
  249. </template>
  250. <script>
  251. import pickingList from './pickingList.vue';
  252. import {
  253. workorderList,
  254. getCode,
  255. getInventoryTotal,
  256. znworkorderList
  257. } from '@/api/produce/workOrder';
  258. import { typeName } from '../common.js';
  259. import {
  260. batchSave,
  261. znfindVoucherList,
  262. listOutsourceInWarehouse
  263. } from '@/api/produce/picking';
  264. import outsourcingPickingList from './outsourcingPickingList.vue';
  265. export default {
  266. components: {
  267. pickingList,
  268. outsourcingPickingList
  269. },
  270. props: {
  271. workListIds: {
  272. type: Array,
  273. default() {
  274. return [];
  275. }
  276. }
  277. },
  278. data() {
  279. return {
  280. visible: true,
  281. workList: [],
  282. rules: {},
  283. pickCode: null,
  284. pickName: null,
  285. typeName,
  286. tableRules: {},
  287. loadingBtn: false,
  288. outsourcingPickingShow: false,
  289. isFullscreen: false
  290. };
  291. },
  292. computed: {
  293. taskObj() {
  294. return this.$store.state.user.taskObj;
  295. },
  296. clientEnvironmentId() {
  297. return this.$store.state.user.info.clientEnvironmentId;
  298. },
  299. dialogDynamicHeight() {
  300. if (this.isFullscreen) {
  301. // 全屏时,高度为窗口高度
  302. console.log(window.innerHeight + 'px', '全屏高度');
  303. this.tabalHeight = window.innerHeight - 200;
  304. return window.innerHeight + 'px';
  305. } else {
  306. this.tabalHeight = 300;
  307. return '500px';
  308. }
  309. }
  310. },
  311. watch: {},
  312. methods: {
  313. getList() {
  314. let param = {
  315. ids: this.workListIds,
  316. taskId: this.taskObj.id
  317. };
  318. console.log('1111122222', this.clientEnvironmentId);
  319. if (this.clientEnvironmentId == 21) {
  320. znworkorderList(param).then((res) => {
  321. let arr = res.map((e) => {
  322. e.bomDetailDTOS.map((d) => {
  323. e.warehouseId =
  324. d.warehouseList.length > 0 ? d.warehouseList[0].id : '';
  325. });
  326. // e.pickList = [...e.bomDetailDTOS];
  327. e.pickList = [];
  328. e.bomDetailDTOS = [];
  329. return e;
  330. });
  331. this.pickName = res[0].productName + '领料';
  332. // arr.bomDetailDTOS.map(v=>{
  333. // this.getInventoryTotalFn(v.id)
  334. // })
  335. // getInventoryTotal
  336. // this.workList = arr;
  337. this.$set(this, 'workList', arr);
  338. this.getOrderCode();
  339. this.$forceUpdate();
  340. });
  341. } else {
  342. workorderList(param).then((res) => {
  343. let arr = res.map((e) => {
  344. e.bomDetailDTOS.map((d) => {
  345. e.warehouseId =
  346. d.warehouseList.length > 0 ? d.warehouseList[0].id : '';
  347. // this.getInventoryTotalFn([d.categoryCode])
  348. });
  349. // e.pickList = [...e.bomDetailDTOS];
  350. e.pickList = [];
  351. e.bomDetailDTOS = [];
  352. return e;
  353. });
  354. this.pickName = res[0].productName + '领料';
  355. // arr.bomDetailDTOS.map(v=>{
  356. // this.getInventoryTotalFn(v.id)
  357. // })
  358. // getInventoryTotal
  359. // this.workList = arr;
  360. this.$set(this, 'workList', arr);
  361. this.getOrderCode();
  362. this.getInventoryTotalFn();
  363. this.$forceUpdate();
  364. });
  365. }
  366. },
  367. async getInventoryTotalFn(id) {
  368. let ids = [];
  369. this.workList.map((item) => {
  370. item.pickList.map((pitem) => {
  371. ids.push(pitem.code);
  372. });
  373. });
  374. if (ids.length == 0) {
  375. return;
  376. }
  377. const res = await getInventoryTotal(ids);
  378. res.map((ritem) => {
  379. this.workList.map((item) => {
  380. item.pickList.map((pitem, index) => {
  381. if (pitem.warehouseName == ritem.warehouseName) {
  382. // pitem.availableCountBase = ritem.availableCountBase;
  383. this.$set(
  384. this.workList[0].pickList[index],
  385. 'availableCountBase',
  386. ritem.availableCountBase
  387. );
  388. }
  389. });
  390. });
  391. });
  392. console.log(this.workList, 'this.workList');
  393. // console.log('cashasisasa', res);
  394. },
  395. async getOrderCode() {
  396. console.log(this.workListIds, '555555');
  397. this.pickCode = await getCode('pick_order_code');
  398. },
  399. removeItem(idx, index) {
  400. this.workList[idx].pickList.splice(index, 1);
  401. },
  402. handleClose() {
  403. this.loadingBtn = false;
  404. this.$emit('close', false);
  405. },
  406. outsourceEmit(list) {
  407. if (list) {
  408. let param = {
  409. outsourceOrder: list || [],
  410. workOrderId: this.workListIds[0],
  411. taskId: this.taskObj.id,
  412. isPC: 1
  413. };
  414. listOutsourceInWarehouse(param).then((res) => {
  415. let indexList = [];
  416. res.list.forEach((item) => {
  417. item.isOut = 1;
  418. this.workList[0].pickList.forEach((i, index) => {
  419. if (i.categoryId == item.categoryId) {
  420. indexList.push(index);
  421. }
  422. });
  423. });
  424. if (indexList.length > 0) {
  425. indexList.forEach((i) => {
  426. this.workList[0].pickList.splice(i, 1);
  427. });
  428. }
  429. let _arr = [...this.workList[0].pickList, ...res.list];
  430. this.$set(this.workList[0], 'pickList', _arr);
  431. this.$forceUpdate();
  432. console.log(this.workList[0], 'this.workList[0]');
  433. // this.getInventoryTotalFn(this.workList[0])
  434. // let ids = [];
  435. // console.log(list, 'list111');
  436. // this.workList[0].pickList.forEach((item) => {
  437. // ids.push(item.code);
  438. // });
  439. // console.log(ids, 'ids');
  440. // if (ids.length != 0) {
  441. this.getInventoryTotalFn();
  442. // }
  443. });
  444. }
  445. this.closeOutsourcingPicking();
  446. },
  447. openPicking(id, item) {
  448. this.outsourcingPickingShow = true;
  449. // this.$refs.pickingListRef.open(id, item, '选择列表');
  450. },
  451. allSelection(id, list) {
  452. this.workList.forEach((e) => {
  453. if (e.id == id) {
  454. e.pickList = list;
  455. this.$forceUpdate();
  456. }
  457. });
  458. },
  459. save() {
  460. console.log(this.workList, 'cvassasasag');
  461. if (this.workList.length > 0) {
  462. let bol;
  463. let _i;
  464. bol = this.workList.every((e, i) => {
  465. _i = i;
  466. return (
  467. Object.prototype.hasOwnProperty.call(e, 'pickList') &&
  468. e.pickList.length > 0
  469. );
  470. });
  471. if (!bol) {
  472. this.$message.warning(
  473. `生成工单${this.workList[_i].code}领料不能为空`
  474. );
  475. return false;
  476. }
  477. }
  478. if (this.workList.length > 0) {
  479. let name;
  480. let bol2;
  481. let _i;
  482. this.workList.forEach((e, i) => {
  483. _i = i;
  484. console.log(e.pickList);
  485. bol2 = e.pickList.every((y) => {
  486. name = y.name;
  487. return (
  488. Object.prototype.hasOwnProperty.call(y, 'demandQuantity') &&
  489. Number(y.demandQuantity) > 0
  490. );
  491. });
  492. });
  493. if (!bol2) {
  494. this.$message.warning(
  495. `${this.workList[_i].code}的${name}数量不能为空`
  496. );
  497. return false;
  498. }
  499. }
  500. let _arr = [];
  501. _arr = this.workList.map((m) => {
  502. m.instanceList = [];
  503. m.bomDetailDTOSList = [];
  504. m.pickList.forEach((e) => {
  505. if (
  506. Object.prototype.hasOwnProperty.call(e, 'isBom') &&
  507. e.isBom == 1
  508. ) {
  509. m.bomDetailDTOSList.push(e);
  510. } else {
  511. m.instanceList.push(e);
  512. }
  513. });
  514. m.workOrderId = m.id;
  515. delete m.id;
  516. return {
  517. ...m
  518. };
  519. });
  520. this.loadingBtn = true;
  521. if (_arr.length != 0) {
  522. _arr.forEach((it) => {
  523. it.isOutsource = 1;
  524. });
  525. }
  526. // if (this.clientEnvironmentId == 21) {
  527. // let param = {
  528. // workOrderId: this.workListIds[0],
  529. // pickingCode: this.pickCode
  530. // };
  531. // znfindVoucherList(param).then((res) => {
  532. // this.loadingBtn = false;
  533. // this.$message.success('领料成功');
  534. // });
  535. // }
  536. let param = {
  537. allPickList: _arr,
  538. pickName: this.pickName,
  539. pickCode: this.pickCode
  540. };
  541. batchSave(param)
  542. .then((res) => {
  543. this.loadingBtn = false;
  544. this.$message.success('领料成功');
  545. this.$emit('close', true);
  546. })
  547. .catch((err) => {
  548. this.loadingBtn = false;
  549. });
  550. },
  551. closeOutsourcingPicking() {
  552. this.outsourcingPickingShow = false;
  553. },
  554. fullscreen() {
  555. this.isFullscreen = !this.isFullscreen;
  556. }
  557. },
  558. created() {
  559. this.getList();
  560. },
  561. mounted() {
  562. this.$nextTick(() => {
  563. // this.outsourcingPickingShow = true;
  564. setTimeout(() => {
  565. // this.outsourcingPickingShow = true;
  566. }, 5000);
  567. });
  568. }
  569. };
  570. </script>
  571. <style lang="scss" scoped>
  572. .table_content {
  573. margin-bottom: 10px;
  574. }
  575. .tableZ_box {
  576. border: 1px solid #e3e5e5;
  577. margin: 6px 0;
  578. &:last-child {
  579. border-bottom: none;
  580. }
  581. .row {
  582. width: 100%;
  583. display: flex;
  584. }
  585. .col {
  586. width: calc(100% / 5);
  587. display: flex;
  588. align-items: center;
  589. min-width: 200px;
  590. min-height: 32px;
  591. border-bottom: 1px solid #e3e5e5;
  592. border-right: 1px solid #e3e5e5;
  593. &:last-child {
  594. border-right: none;
  595. }
  596. .name {
  597. display: flex;
  598. align-items: center;
  599. padding: 4px;
  600. width: 80px;
  601. height: 100%;
  602. background-color: #d0e4d5;
  603. color: #000;
  604. }
  605. .content {
  606. padding: 4px 6px;
  607. color: #000;
  608. }
  609. }
  610. .pd6 {
  611. padding: 0 6px;
  612. }
  613. }
  614. </style>
  615. <style>
  616. :v-deep .el-form-item__error {
  617. bottom: -6px !important;
  618. }
  619. </style>