my-modal-material.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. <!-- 物料选择组件 -->
  2. <template>
  3. <div class="container-wrap">
  4. <div class="container">
  5. <div class="content">
  6. <div class="left">
  7. <div class="title">
  8. 排班面料
  9. </div>
  10. <div class="main">
  11. <my-table
  12. ref="table"
  13. :data="data2"
  14. :columns="columnsV3"
  15. :is-show-filter="false"
  16. :is-show-page="false"
  17. :selected-list="handleData"
  18. :select-key="selectKey"
  19. :multiple="multiple"
  20. :show-flag="modal"
  21. :key="renderKey"
  22. @on-select="tableSelectChange"
  23. @on-select-cancel="tableSelectCancel"
  24. @on-select-all-cancel="allCancel"
  25. @event-handle="eventHandle"
  26. @on-change="changePage"
  27. @on-select-all="selectAll"
  28. ></my-table>
  29. </div>
  30. </div>
  31. <div class="right">
  32. <div class="title">
  33. 待领面料
  34. </div>
  35. <div class="main">
  36. <my-table
  37. ref="handleTable"
  38. :data="data"
  39. :columns="columns"
  40. :table-filter="tableFilter"
  41. :table-page="params"
  42. :selected-list="handleData"
  43. :select-key="selectKey"
  44. :multiple="multiple"
  45. :show-flag="modal"
  46. :is-show-filter="false"
  47. @on-select="tableSelectChange"
  48. @on-select-cancel="tableSelectCancel"
  49. @on-select-all-cancel="allCancel"
  50. @event-handle="eventHandle"
  51. @on-change="changePage"
  52. @on-select-all="selectAll"
  53. ></my-table>
  54. </div>
  55. </div>
  56. <div class="handle-list">
  57. <div class="title">
  58. 已选物料
  59. </div>
  60. <div class="main table-3">
  61. <my-table
  62. ref="cfmTable"
  63. :key="renderKey"
  64. :data="handleData"
  65. :columns="columns2"
  66. :is-show-page="false"
  67. :is-show-filter="false"
  68. style="height:auto"
  69. >
  70. </my-table>
  71. <ul>
  72. <li v-for="(i,index) in restrictedPickingData" :key="index">
  73. <div style="width:30%">
  74. <span class="cl-blue">推荐卷</span><br>
  75. <span>长度</span>{{i.quantity}}m
  76. </div>
  77. <div>
  78. <span>标签值</span>{{i.rfidCode}}<br>
  79. <span>位置</span>{{i.areaName || '暂未绑定位置'}}
  80. </div>
  81. </li>
  82. </ul>
  83. </div>
  84. </div>
  85. </div>
  86. <div class="footer">
  87. <Button type="success" size="large" @click="cfm">领料</Button>
  88. </div>
  89. </div>
  90. </div>
  91. </template>
  92. <script>
  93. import {
  94. GetV3PlanData,
  95. GetMaterialCategoryZTree,
  96. GetV3PlanData2
  97. } from '@/api/integrated'
  98. import MyTable from '@/components/my-table/my-table'
  99. import MyNumberBoardInput from '@/components/my-number-board-input/my-number-board-input'
  100. import axios from 'axios'
  101. export default {
  102. name: 'material_maintenance',
  103. components: {
  104. MyTable,
  105. MyNumberBoardInput
  106. },
  107. watch: {
  108. value: {
  109. handler (n) {
  110. this.modal = n
  111. },
  112. immediate: true
  113. },
  114. modal (n) {
  115. this.$emit('input', n)
  116. },
  117. treeData: {
  118. handler (newVal, oldVal) {
  119. this.initData(this.treeData)
  120. },
  121. deep: true
  122. }
  123. },
  124. props: {
  125. // 已选数据
  126. selectedList: {
  127. type: Array,
  128. default () {
  129. return []
  130. }
  131. },
  132. /* 数据回填所根据的key */
  133. selectKey: {
  134. type: String,
  135. default: 'code'
  136. },
  137. /* 是否单选 */
  138. multiple: {
  139. type: Boolean,
  140. default: false
  141. },
  142. // 是否显示表单
  143. value: {
  144. type: Boolean,
  145. default: false,
  146. require: true
  147. }
  148. },
  149. data () {
  150. return {
  151. modal: false,
  152. categoryCode: '',
  153. columns2: [
  154. {
  155. title: '物料名称',
  156. key: 'name',
  157. minWidth: 150
  158. },
  159. {
  160. title: '数量',
  161. minWidth: 100,
  162. render: (h, params) => {
  163. let that = this
  164. return h(MyNumberBoardInput, {
  165. props: {
  166. min: 1,
  167. value: that.handleData[params.row._index].quantity
  168. },
  169. on: {
  170. 'on-change'(val){
  171. console.log('???????val', val)
  172. that.handleData[params.row._index].quantity = Number.parseFloat(val)
  173. console.log(that.handleData[params.row._index].quantity)
  174. if (that.handleData[params.row._index].stockQty < that.handleData[params.row._index].quantity) {
  175. that.$Message.error('输入数量不可大于实时库存')
  176. }
  177. that.handleArea(params.row._index)
  178. }
  179. }
  180. })
  181. }
  182. },
  183. {
  184. title: '操作',
  185. width: 80,
  186. align: 'center',
  187. render: (h, params) => {
  188. let that = this
  189. return h('Icon', {
  190. props: {
  191. type: 'ios-trash',
  192. size: 24,
  193. color: 'red'
  194. },
  195. style: {
  196. cursor: 'pointer'
  197. },
  198. on: {
  199. click(e) {
  200. e.stopPropagation()
  201. that.handleData.splice(params.row._index, 1)
  202. that.handleDelArea(params.row.name)
  203. that.renderKey = new Date().getTime()
  204. that.$refs.handleTable.handleCancel(params.row.code)
  205. that.$refs.table.handleCancel(params.row.code)
  206. }
  207. }
  208. })
  209. }
  210. }
  211. ],
  212. columnsV3: [
  213. {
  214. title: '物料名称',
  215. key: 'name',
  216. minWidth: 200,
  217. render:(h,p)=>{
  218. return h('div',[
  219. h('span',{
  220. style:{
  221. padding:'5px',
  222. background:"red",
  223. margin:"0 5px",
  224. borderRadius:"5px",
  225. color:"#fff"
  226. },
  227. },'限'),
  228. h('span',{},p.row.name)
  229. ])
  230. }
  231. },
  232. {
  233. title: '排班面积',
  234. key: 'canTakeQty',
  235. minWidth: 150
  236. }
  237. ],
  238. columns: [
  239. {
  240. type: 'selection',
  241. width: 60
  242. },
  243. {
  244. title: '物料名称',
  245. key: 'name',
  246. minWidth: 150
  247. },
  248. {
  249. title: '实时库存',
  250. key: 'stockQty',
  251. minWidth: 150
  252. },
  253. {
  254. title: '门幅',
  255. key: 'width',
  256. minWidth: 150
  257. },
  258. {
  259. title: '可领用数量',
  260. key: 'canTakeQty',
  261. minWidth: 150,
  262. render: (h, params) => {
  263. return h('span', {
  264. style: {
  265. color: params.row.canTakeQty > 0 ? 'green' : 'red'
  266. }
  267. }, params.row.canTakeQty)
  268. }
  269. }
  270. ],
  271. tableFilter: [
  272. {
  273. name: 'Input',
  274. value: 'key',
  275. placeholder: '请输入关键字'
  276. },
  277. {
  278. name: 'Button',
  279. type: 'primary',
  280. text: '查询',
  281. e: 'search'
  282. }
  283. ],
  284. params: {
  285. pageIndex: 1,
  286. pageSize: 20,
  287. total: 0,
  288. categoryCode: this.$store.state.materialCategoryId
  289. },
  290. data: [],
  291. data2: [],
  292. handleData: [],
  293. checkedList: [],
  294. renderKey: new Date().getTime(),
  295. restrictedPickingData:[]
  296. }
  297. },
  298. methods: {
  299. //查询限定领料
  300. getRestrictedPicking(){
  301. const v = this
  302. axios.post('/cloudApi/stockDetail/restrictedPicking',{jobNo:window.localStorage.getItem('jobNo')}).then(res=>{
  303. for (let i = 0; i < res.data.data.length; i++) {
  304. const element = res.data.data[i];
  305. this.data2.push({
  306. name:element.materialName,
  307. canTakeQty:element.availableArea,
  308. icon:"xian"
  309. })
  310. this.data.push({
  311. name:element.materialName,
  312. stockQty:element.totalArea,
  313. width:element.materialWidth,
  314. canTakeQty:element.quantity || '未匹配到合适的物料',
  315. _checked:true,
  316. _disabled: true,
  317. bgRed:true,
  318. })
  319. }
  320. v.restrictedPickingData = res.data.data
  321. console.log(res)
  322. })
  323. },
  324. handlePageChange () {
  325. let arr = []
  326. this.handleData.forEach(item => {
  327. this.data2.forEach(data => {
  328. if (item.name.split('-')[0] === data.name) {
  329. arr.push(data.name)
  330. }
  331. })
  332. })
  333. Array.from(new Set(arr)).forEach(item => {
  334. this.handleDelArea(item)
  335. })
  336. console.log('??????处理的数据')
  337. console.log(Array.from(new Set(arr)))
  338. },
  339. /* 处理排班面积数量 删除已选数据时自动计算可领用数量 */
  340. handleDelArea (name) {
  341. let findObj = this.data2.find(item => name.split('-')[0] === item.name)
  342. if (findObj) {
  343. /* 当前勾选的所有相关面料的数量 */
  344. let quantity = 0
  345. this.handleData.filter(item => item.name.split('-')[0] === findObj.name).forEach(dataItem => {
  346. quantity += dataItem.quantity
  347. })
  348. this.data.forEach(item => {
  349. if (item.name.split('-')[0] === findObj.name) {
  350. let canApplyNum = (findObj.canTakeQty - (quantity * item.width / 100)) / (item.width / 100)
  351. console.log('计算可领用数量')
  352. console.log(canApplyNum)
  353. this.$set(item, 'oldCanTakeQty', item.canTakeQty)
  354. this.$set(item, 'canTakeQty', canApplyNum.toFixed(1))
  355. }
  356. })
  357. }
  358. },
  359. /* 处理排班面积数量 自动计算可领用数量 */
  360. handleArea(index, defultNum) {
  361. let data = this.handleData[index]
  362. console.log('当前操作数据')
  363. console.log(data)
  364. /* 当前勾选的面料是否需要特殊处理 */
  365. let findObj = this.data2.find(item => data.name.split('-')[0] === item.name)
  366. if (findObj && (data.quantity || data.quantity === 0)) {
  367. console.log('获取到排班物料')
  368. console.log(findObj)
  369. /* 当前勾选的所有相关面料的数量 */
  370. let quantity = 0
  371. if (defultNum) {
  372. quantity = defultNum
  373. } else {
  374. this.handleData.filter(item => item.name.split('-')[0] === findObj.name).forEach(dataItem => {
  375. quantity += dataItem.quantity
  376. })
  377. }
  378. console.log('处理总数量')
  379. console.log(quantity)
  380. this.data.forEach(item => {
  381. if (item.name.split('-')[0] === findObj.name) {
  382. let canApplyNum = (findObj.canTakeQty - (quantity * item.width / 100)) / (item.width / 100)
  383. console.log('计算可领用数量')
  384. console.log(canApplyNum)
  385. this.$set(item, 'oldCanTakeQty', item.canTakeQty)
  386. this.$set(item, 'canTakeQty', canApplyNum.toFixed(1))
  387. }
  388. })
  389. console.log('处理后的data')
  390. console.log(this.data)
  391. }
  392. },
  393. cfm () {
  394. // this.$refs.table.clear()
  395. // this.modal = false
  396. this.$emit('getselectedList', this.handleData,this.restrictedPickingData)
  397. console.log(this.handleData)
  398. },
  399. cancel () {
  400. this.$refs.table.clear()
  401. this.modal = false
  402. },
  403. getTree () {
  404. GetMaterialCategoryZTree().then(res => {
  405. if (res.code === 0) {
  406. this.treeData = res.result
  407. }
  408. })
  409. },
  410. getList () {
  411. this.params.jobNo = window.localStorage.getItem('jobNo')
  412. GetV3PlanData2(this.params).then(res => {
  413. if (res.code === 0) {
  414. this.data = res.result.allMaterialList.list
  415. this.params.total = res.result.allMaterialList.totalCount
  416. this.data2 = res.result.v3DataList
  417. this.data.forEach(item => {
  418. item.name = item.materialName
  419. item.code = item.materialCode
  420. })
  421. this.getRestrictedPicking()
  422. this.handlePageChange()
  423. console.log('??????????')
  424. console.log(this.data)
  425. }
  426. })
  427. // GetOutMaterialPageList(this.params).then(res => {
  428. // if (res.code === 0) {
  429. // this.data = res.result.list
  430. // this.params.total = res.result.totalCount
  431. // }
  432. // })
  433. // GetUserTakeMaterialRankList().then(res => {
  434. // if (res.code === 0) {
  435. // this.data2 = res.result
  436. // this.data2.forEach(item => {
  437. // item.name = item.materialName
  438. // item.code = item.materialCode
  439. // })
  440. // }
  441. // })
  442. },
  443. initData (array) {
  444. array.forEach(item => {
  445. item.title = item.name
  446. if (item.children) {
  447. this.initData(item.children)
  448. }
  449. })
  450. },
  451. allCancel(data) {
  452. data.forEach(data => {
  453. this.handleData.forEach((item, index) => {
  454. if (data.code === item.code) {
  455. this.handleData.splice(index, 0)
  456. }
  457. })
  458. })
  459. },
  460. // 获取表格选中数据
  461. tableSelectChange (selection, row) {
  462. if (this.handleData.length < 1 && row.code) {
  463. this.handleData.push({ ...row, quantity: 0})
  464. // this.handleArea(this.handleData.length - 1, 1)
  465. } else {
  466. let isExist = false
  467. this.handleData.forEach(item => {
  468. if (item.code === row.code) {
  469. isExist = true
  470. }
  471. })
  472. if (!isExist && selection.length > 0 && row.code) {
  473. this.handleData.push({ ...row, quantity: 0})
  474. // this.handleArea(this.handleData.length - 1, 1)
  475. }
  476. }
  477. },
  478. selectAll(selection) {
  479. selection.forEach(data => {
  480. let isExist = false
  481. this.handleData.forEach(item => {
  482. if (item.code === data.code) {
  483. isExist = true
  484. }
  485. })
  486. if (!isExist) {
  487. this.handleData.push({ ...data, quantity: 0})
  488. }
  489. })
  490. },
  491. tableSelectCancel(selection, row) {
  492. console.log('??????????/row')
  493. console.log(row)
  494. console.log(selection)
  495. // this.handleData.forEach((item, index) => {
  496. // if (item.code === row.code) {
  497. // this.handleData.splice(index, 1)
  498. // }
  499. // })
  500. console.log('handleData-----')
  501. console.log(this.handleData)
  502. },
  503. changePage (pageIndex) {
  504. this.params.pageIndex = pageIndex
  505. this.getList()
  506. },
  507. // 检索条件事件处理
  508. eventHandle (option) {
  509. switch (option._evnet) {
  510. case 'search':
  511. this.params.pageIndex = 1
  512. this.params.key = option.key
  513. this.getList()
  514. break
  515. }
  516. },
  517. // 选择物料分类 显示物料列表
  518. treeCheck (data) {
  519. this.categoryCode = data.value
  520. this.params.categoryCode = data.value
  521. this.getList()
  522. }
  523. },
  524. mounted () {
  525. this.getList()
  526. this.getTree()
  527. }
  528. }
  529. </script>
  530. <style lang="scss" scoped>
  531. .table-3 .table-content{
  532. height: auto!important;
  533. }
  534. .table-3{
  535. ul{
  536. color: #6E6E6E;
  537. li{
  538. background: #FFE7E7;
  539. border-bottom: 1px solid #DDDCDC;
  540. display: flex;
  541. text-align: left;
  542. padding: 0 10px;
  543. line-height: 30px;
  544. span{
  545. display: inline-block;
  546. width: 50px;
  547. }
  548. .cl-blue{
  549. color: #0268FF;
  550. font-weight: bold;
  551. }
  552. }
  553. }
  554. }
  555. .container-wrap {
  556. width: 100%;
  557. height: 100%;
  558. .container {
  559. height: 100%;
  560. overflow: hidden;
  561. .content {
  562. padding: 10px;
  563. display: flex;
  564. justify-content: space-between;
  565. height: calc(100% - 60px);
  566. .left, .right, .handle-list {
  567. height: 100%;
  568. overflow: auto;
  569. box-shadow: 3px 3px 5px rgba(57, 57, 57, 0.8);
  570. background-color: #FFFFFF;
  571. border-radius: 5px;
  572. .title {
  573. padding: 5px 0;
  574. background-color: #2c3034;
  575. font-size: 18px;
  576. font-weight: bold;
  577. text-align: center;
  578. color: #FFFFFF;
  579. }
  580. .main {
  581. box-sizing: border-box;
  582. padding: 10px;
  583. height: calc(100% - 48px);
  584. overflow: auto
  585. }
  586. }
  587. .left {
  588. margin-right: 15px;
  589. flex: 1;
  590. min-width: 400px;
  591. .main {
  592. overflow-x: hidden;
  593. }
  594. }
  595. .right {
  596. margin-right: 15px;
  597. flex: 2;
  598. min-width: 500px;
  599. }
  600. .handle-list {
  601. flex: 1;
  602. min-width: 400px;
  603. }
  604. }
  605. }
  606. .footer {
  607. padding: 10px 0;
  608. /deep/ .ivu-btn-large {
  609. border-radius: 20px;
  610. font-weight: bold;
  611. width: 150px;
  612. }
  613. }
  614. }
  615. /deep/ .ivu-tree {
  616. ul {
  617. text-align: left;
  618. }
  619. }
  620. </style>