outSourceMaterials.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. <template>
  2. <gui-page :custom-header="true" :header-class="['gui-theme-background-color']">
  3. <template #gHeader>
  4. <view style="height:44px;" class="gui-flex gui-nowrap gui-rows gui-align-items-center">
  5. <!-- 使用组件实现返回按钮及返回首页按钮 -->
  6. <text style="font-size:44rpx;" class="gui-header-leader-btns gui-color-white font-icons"
  7. @tap="goBack">&#xe6c5;</text>
  8. <!-- 导航文本此处也可以是其他自定义内容 -->
  9. <text
  10. class="gui-h4 gui-blod gui-flex1 gui-text-center gui-ellipsis gui-color-white gui-primary-text">备料明细</text>
  11. <!-- 此处加一个右侧展位元素与左侧同宽,实现标题居中 -->
  12. <!-- 实际宽度请根据自己情况设置 -->
  13. <view style="width:40px;" />
  14. <!-- 如果右侧有其他内容可以利用条件编译和定位来实现-->
  15. </view>
  16. </template>
  17. <template #gBody>
  18. <view class="list-content">
  19. <view class="scan">
  20. <view class="scan-card">
  21. <uni-easyinput ref="easyinput" v-model="scanBatchNumber" :input-border="false"
  22. :clearable="false" type="text" focus @focus="handleInputFocus" placeholder="请扫描物料二维码"
  23. @confirm="handleKeydown" />
  24. <text class="font-icons" @click="handleScanMaterial">&#xe6b7;</text>
  25. </view>
  26. </view>
  27. <view class="tabs">
  28. <div class="tabs-list">
  29. <text :class="!isBefore?'tabs-item-active':'tabs-item'" @click="isBefore = false">备料需求</text>
  30. <text :class="isBefore?'tabs-item-active':'tabs-item'" @click="isBefore = true">已备物料</text>
  31. </div>
  32. </view>
  33. <view v-if="!isBefore" class="custom-table">
  34. <uni-table border stripe empty-text="暂无更多数据">
  35. <!-- 表头行 -->
  36. <uni-tr class="custom-table-head">
  37. <uni-th align="center" width="180px">物料</uni-th>
  38. <uni-th align="center" width="120px">应备数</uni-th>
  39. <uni-th align="center" width="120px">已备数</uni-th>
  40. </uni-tr>
  41. <!-- 表格数据行 -->
  42. <uni-tr v-for="(item, key) in tableData" :key="key" @click="handleShowDetailsList(item)">
  43. <uni-td align="center">{{ item.materialNo }}({{ item.materialName }})</uni-td>
  44. <uni-td align="center">{{ item.shouldPrepareQty }}</uni-td>
  45. <uni-td align="center"
  46. style="color: orange;font-weight: bold;">{{ item.preparedQty }}</uni-td>
  47. </uni-tr>
  48. </uni-table>
  49. </view>
  50. <view v-else class="custom-table">
  51. <uni-table border stripe empty-text="暂无更多数据">
  52. <uni-tr class="custom-table-head">
  53. <uni-th align="center" width="180px">物料</uni-th>
  54. <uni-th align="center" width="120px">应备数</uni-th>
  55. <uni-th align="center" width="120px">已备数</uni-th>
  56. </uni-tr>
  57. <uni-tr v-for="(item, key) in beforeTableData" :key="key" @click="handleShowDetailsList(item)">
  58. <uni-td align="center">{{ item.materialNo }}({{ item.materialName }})</uni-td>
  59. <uni-td align="center">{{ item.shouldPrepareQty }}</uni-td>
  60. <uni-td align="center">{{ item.preparedQty }}</uni-td>
  61. </uni-tr>
  62. </uni-table>
  63. </view>
  64. <view class="card-list-item"
  65. style="margin: 12px 0;display: grid;grid-template-columns: 1fr;grid-template-rows: 1fr;">
  66. <button type="primary" style="width: calc(100% - 8px);margin: 0 4px;"
  67. @click="handleComplete">生成发料单</button>
  68. </view>
  69. <uni-popup ref="popup" background-color="#fff">
  70. <view class="popup-content">
  71. <view class="list-title" style="margin-bottom: 8px;">
  72. <span class="font-icons"
  73. style="font-size: 20px;color: #00a0e9;width: 40px;text-align: center;">&#xe6a3;</span>
  74. <span>已备明细</span>
  75. </view>
  76. <view v-if="demandDetailsList?.length > 0" class="list-panel">
  77. <div v-for="(item, key) in demandDetailsList" :key="item.id" class="panel">
  78. <div class="panel-row">
  79. <span>{{ item.materialNo }}</span>
  80. </div>
  81. <div class="panel-row">
  82. <span>物料名称</span>
  83. <span>{{ item.materialName }}</span>
  84. </div>
  85. <div class="panel-row">
  86. <span>数量</span>
  87. <span>{{ item.batchQty }}</span>
  88. </div>
  89. </div>
  90. </view>
  91. <view v-else>
  92. <view class="bg-image">
  93. <image src="@/static/empty.png" mode="heightFix" />
  94. <text>这里什么都没有...</text>
  95. </view>
  96. </view>
  97. </view>
  98. </uni-popup>
  99. <gui-modal ref="modalForm" :custom-class="['gui-bg-white', 'gui-dark-bg-level-3', 'gui-border-radius']"
  100. title="提示">
  101. <template #content>
  102. <view class="gui-padding gui-bg-gray gui-dark-bg-level-2">
  103. <text class="gui-block gui-text-center gui-text gui-color-gray"
  104. style="line-height:100rpx; padding:10rpx;">备料超出,是否拆分?</text>
  105. </view>
  106. </template>
  107. <!-- 利用 flex 布局 可以放置多个自定义按钮哦 -->
  108. <template #btns>
  109. <view class="gui-flex gui-row gui-space-between operation-flex">
  110. <view hover-class="gui-tap" class="modal-btns gui-flex1" @tap="modalForm.close()">
  111. <text class="modal-btns gui-color-gray">取消</text>
  112. </view>
  113. <view class="line" />
  114. <view hover-class="gui-tap" class="modal-btns gui-flex1" @tap="handleSplitMaterial">
  115. <text class="modal-btns gui-primary-color">确认</text>
  116. </view>
  117. </view>
  118. </template>
  119. </gui-modal>
  120. <uni-popup ref="errorTip" type="dialog">
  121. <uni-popup-dialog type="error" cancel-text="关闭" confirm-text="确认" title="提示"
  122. :content="errorTipMessage" @confirm="handleCloseErrorTipsModal"
  123. @close="handleCloseErrorTipsModal" />
  124. </uni-popup>
  125. </view>
  126. </template>
  127. </gui-page>
  128. </template>
  129. <script>
  130. import {
  131. onReachBottom
  132. } from '@dcloudio/uni-app'
  133. import {
  134. ref,
  135. onMounted,
  136. defineComponent,
  137. onBeforeMount
  138. } from 'vue'
  139. export default defineComponent({
  140. setup(options) {
  141. const popup = ref()
  142. const queryParams = ref({
  143. pageSize: 20,
  144. pageNo: 1,
  145. masterId: options?.id ?? '',
  146. wmsProductionWorkOrderBomId: options?.id ?? ''
  147. })
  148. const errorTip = ref('')
  149. const errorTipMessage = ref('')
  150. const easyinput = ref('')
  151. const errorState = ref(0)
  152. const modalForm = ref()
  153. const parentRow = uni.getStorageSync('masterId') ?? {}
  154. const masterId = ref('')
  155. const scanBatchNumber = ref('')
  156. const isBefore = ref(false)
  157. const tableData = ref([])
  158. const demandDetailsList = ref([])
  159. const beforeTableData = ref([])
  160. const scanMaterialList = ref([])
  161. // 当前处理的数据行
  162. const fdIndex = ref(-1)
  163. // 当前扫描的物料
  164. const currentScanMaterial = ref([])
  165. onBeforeMount(() => {
  166. masterId.value = JSON.parse(parentRow)?.id
  167. })
  168. const search = function() {
  169. uni.$reqGet('getPrepareMatersDetails', {
  170. masterId: masterId.value
  171. })
  172. .then(({
  173. code,
  174. data,
  175. msg
  176. }) => {
  177. if (code === 0) {
  178. uni.setStorageSync('ids', JSON.stringify(data?.list[0]))
  179. tableData.value.length = 0
  180. beforeTableData.value.length = 0
  181. data?.list?.forEach(item => {
  182. if (item.shouldPrepareQty === item.preparedQty) {
  183. beforeTableData.value.push(item)
  184. } else {
  185. tableData.value.push(item)
  186. }
  187. })
  188. } else {
  189. uni.showToast({
  190. title: msg,
  191. icon: 'none',
  192. duration: 2000
  193. })
  194. }
  195. })
  196. }
  197. onMounted(() => {
  198. search()
  199. })
  200. const goBack = function() {
  201. uni.removeStorageSync('ids')
  202. uni.$goBack('/pages/workbranch/warehouse/outSourceMaterial/outSourceList')
  203. }
  204. const handleScanMaterial = function() {
  205. // #ifdef APP-PLUS
  206. const mpaasScanModule = uni.requireNativePlugin('Mpaas-Scan-Module')
  207. mpaasScanModule.mpaasScan({
  208. // 扫码识别类型,参数可多选,qrCode、barCode,不设置,默认识别所有
  209. 'scanType': ['qrCode', 'barCode'],
  210. // 是否隐藏相册,默认false不隐藏
  211. 'hideAlbum': false
  212. },
  213. (ret) => {
  214. if (ret.resp_code === 1000) {
  215. uni.$reqGet('scanPrepareMaterial', {
  216. qrCode: ret.resp_result
  217. })
  218. .then(async ({
  219. code,
  220. data,
  221. msg
  222. }) => {
  223. if (code === 0) {
  224. scanBatchNumber.value = ret.resp_result
  225. if (Object.prototype.toString.call(data) ===
  226. '[object Array]') {
  227. fdIndex.value = tableData.value.findIndex(item => item
  228. ?.materialNo === data[
  229. 0]
  230. ?.materialNo)
  231. }
  232. if (fdIndex.value !== -1) {
  233. currentScanMaterial.value = data[0] ?? []
  234. if (tableData.value[fdIndex.value].shouldPrepareQty >
  235. tableData.value[fdIndex.value].preparedQty) {
  236. uni.$reqPost('scanToPrepare', {
  237. id: masterId.value,
  238. materials: data
  239. })
  240. .then(res => {
  241. if (res.code === 0) {
  242. if (res.data === 0) {
  243. search()
  244. setInputFocus()
  245. } else if (res.data === 1) {
  246. modalForm.value.open()
  247. }
  248. } else {
  249. // #ifdef APP-PLUS
  250. plus.device.beep(2)
  251. // #endif
  252. errorTipMessage.value = res.msg
  253. errorTip.value.open()
  254. errorState.value = 0
  255. }
  256. })
  257. }
  258. } else {
  259. // #ifdef APP-PLUS
  260. plus.device.beep(2)
  261. // #endif
  262. errorTipMessage.value = '请扫描所需物料的物料条码'
  263. errorTip.value.open()
  264. errorState.value = 0
  265. }
  266. } else {
  267. // #ifdef APP-PLUS
  268. plus.device.beep(2)
  269. // #endif
  270. errorTipMessage.value = msg
  271. errorTip.value.open()
  272. errorState.value = 0
  273. }
  274. })
  275. }
  276. })
  277. // #endif
  278. }
  279. const handleToNavigate = function() {
  280. uni.navigateTo({
  281. url: '/pages/workbranch/warehouse/production/materialIssuance'
  282. })
  283. }
  284. const handleComplete = function() {
  285. // 生成发料单
  286. uni.$reqPost('scanSyntheticalSendMasterConfirm', {
  287. id: masterId.value
  288. })
  289. .then(({
  290. code,
  291. data,
  292. msg
  293. }) => {
  294. if (code === 0) {
  295. // 生成发料单后需要打印
  296. uni.showToast({
  297. title: '生成发料单成功',
  298. icon: 'none',
  299. duration: 2000
  300. })
  301. } else {
  302. // #ifdef APP-PLUS
  303. plus.device.beep(2)
  304. // #endif
  305. errorTipMessage.value = msg
  306. errorTip.value.open()
  307. errorState.value = 0
  308. }
  309. })
  310. }
  311. // 物料拆分
  312. const handleSplitMaterial = function() {
  313. uni.$reqPost('prepareSplit', {
  314. prepareId: masterId.value,
  315. id: scanBatchNumber.value,
  316. inQty: currentScanMaterial.value?.receiptQty,
  317. splitQty: tableData.value[fdIndex.value].preparedQty - currentScanMaterial.value
  318. ?.receiptQty
  319. })
  320. .then(res => {
  321. search()
  322. modalForm.value.close()
  323. if (res.code === 0) {
  324. // 调取打印机拆分物料后打印标签
  325. uni.showToast({
  326. title: '拆分完毕',
  327. icon: 'none',
  328. duration: 2000
  329. })
  330. } else {
  331. // #ifdef APP-PLUS
  332. plus.device.beep(2)
  333. // #endif
  334. errorTipMessage.value = res.msg
  335. errorTip.value.open()
  336. errorState.value = 0
  337. }
  338. })
  339. }
  340. const handleKeydown = function(e) {
  341. uni.$reqGet('scanPrepareMaterial', {
  342. qrCode: e
  343. })
  344. .then(async ({
  345. code,
  346. data,
  347. msg
  348. }) => {
  349. scanBatchNumber.value = e
  350. if (Object.prototype.toString.call(data) === '[object Array]') {
  351. fdIndex.value = tableData.value.findIndex(item => item?.materialNo ===
  352. data[0]?.materialNo)
  353. }
  354. if (fdIndex.value !== -1) {
  355. currentScanMaterial.value = data[0] ?? []
  356. if (tableData.value[fdIndex.value].shouldPrepareQty > tableData.value[
  357. fdIndex
  358. .value]
  359. .preparedQty) {
  360. uni.$reqPost('scanToPrepare', {
  361. id: masterId.value,
  362. materials: data
  363. })
  364. .then(res => {
  365. if (res.code === 0) {
  366. if (res.data === 0) {
  367. search()
  368. setInputFocus()
  369. } else if (res.data === 1) {
  370. modalForm.value.open()
  371. }
  372. } else {
  373. // #ifdef APP-PLUS
  374. plus.device.beep(2)
  375. // #endif
  376. errorTipMessage.value = res.msg
  377. errorTip.value.open()
  378. errorState.value = 0
  379. }
  380. })
  381. }
  382. } else {
  383. // #ifdef APP-PLUS
  384. plus.device.beep(2)
  385. // #endif
  386. errorTipMessage.value = '请扫描所需物料的物料条码'
  387. errorTip.value.open()
  388. errorState.value = 0
  389. }
  390. })
  391. }
  392. const handleShowDetailsList = function(ret) {
  393. uni.$reqGet('getPrepareMatersDetails', {
  394. wmsSyntheticalSendDetailId: ret?.id
  395. })
  396. .then(({
  397. code,
  398. data,
  399. msg
  400. }) => {
  401. if (code === 0) {
  402. if (popup.value?.showPopup === false) {
  403. popup.value.open('bottom')
  404. }
  405. demandDetailsList.value = data?.list ?? []
  406. } else {
  407. // #ifdef APP-PLUS
  408. plus.device.beep(2)
  409. // #endif
  410. errorTipMessage.value = msg
  411. errorTip.value.open()
  412. errorState.value = 0
  413. }
  414. })
  415. }
  416. const setInputFocus = function() {
  417. scanBatchNumber.value = ''
  418. easyinput.value.onBlur()
  419. easyinput.value.onFocus()
  420. }
  421. // 关闭错误信息弹窗
  422. const handleCloseErrorTipsModal = async function() {
  423. errorTip.value.close()
  424. if (errorState.value === 0) {
  425. await setInputFocus()
  426. }
  427. }
  428. // 禁用软键盘
  429. const handleInputFocus = function() {
  430. setTimeout(() => {
  431. uni.hideKeyboard()
  432. }, 100)
  433. }
  434. // uniapp移动端触底事件
  435. onReachBottom(() => {
  436. queryParams.value.pageNo += 1
  437. uni.$reqGet('getPrepareMaterialList', queryParams.value)
  438. .then(({
  439. data
  440. }) => {
  441. Array.prototype.push.call(scanMaterialList.value, ...data?.list ?? [])
  442. })
  443. })
  444. return {
  445. option: [{
  446. text: '删除',
  447. style: {
  448. backgroundColor: '#dd524d'
  449. }
  450. }],
  451. goBack,
  452. popup,
  453. isBefore,
  454. tableData,
  455. demandDetailsList,
  456. beforeTableData,
  457. handleInputFocus,
  458. modalForm,
  459. easyinput,
  460. errorTip,
  461. errorTipMessage,
  462. handleKeydown,
  463. scanBatchNumber,
  464. handleScanMaterial,
  465. handleToNavigate,
  466. scanMaterialList,
  467. handleComplete,
  468. handleSplitMaterial,
  469. handleShowDetailsList,
  470. handleCloseErrorTipsModal
  471. }
  472. }
  473. })
  474. </script>
  475. <style lang="scss" scoped>
  476. .gui-header-leader-btns {
  477. color: black;
  478. font-size: 24px !important;
  479. margin-left: 24rpx;
  480. }
  481. .list-content {
  482. margin-top: 80px;
  483. background-color: #edeeee;
  484. }
  485. .card-list-flexbox {
  486. display: flex;
  487. flex-direction: row;
  488. align-items: center;
  489. flex-wrap: wrap;
  490. margin: 3px 2px;
  491. .card-list-item {
  492. width: 750rpx;
  493. height: 40px;
  494. margin: 2rpx 0;
  495. display: flex;
  496. flex-direction: row;
  497. align-items: center;
  498. justify-content: space-between;
  499. background-color: #fff;
  500. uni-text {
  501. font-size: 14px;
  502. height: 50rpx;
  503. text-align: left;
  504. padding: 0 12px;
  505. display: flex;
  506. flex-direction: row;
  507. align-items: center;
  508. }
  509. .text-1 {
  510. flex: 1;
  511. height: 40px;
  512. justify-content: flex-start;
  513. }
  514. .text-2 {
  515. flex: 3;
  516. height: 40px;
  517. justify-content: flex-end;
  518. margin-right: 4px;
  519. padding: 2px 6px;
  520. }
  521. }
  522. }
  523. .card-list-flexbox:nth-of-type(2) {
  524. margin-top: 48px;
  525. }
  526. .fixedTop {
  527. bottom: 0 !important;
  528. top: 3.25rem !important;
  529. }
  530. .popup-content {
  531. height: 75vh;
  532. overflow-y: scroll;
  533. background-color: #edeeee;
  534. .list-panel:nth-of-type(2) {
  535. margin-top: 40px;
  536. }
  537. }
  538. .font-icons {
  539. width: 40px;
  540. font-size: 20px;
  541. }
  542. .scan {
  543. height: 45px;
  544. width: calc(100% - 48px);
  545. margin: 12px;
  546. padding: 0 12px;
  547. display: flex;
  548. justify-content: space-between;
  549. align-items: center;
  550. border-radius: 6px;
  551. background-color: white;
  552. .scan-card {
  553. width: 100%;
  554. display: grid;
  555. grid-template-rows: 1fr;
  556. grid-template-columns: 7fr 2fr;
  557. align-items: center;
  558. input {
  559. height: 35px;
  560. line-height: 35px;
  561. }
  562. text {
  563. width: 100%;
  564. text-align: right;
  565. }
  566. }
  567. }
  568. .list-title {
  569. position: fixed;
  570. top: 0;
  571. left: 0;
  572. z-index: 99999;
  573. height: 40px;
  574. line-height: 40px;
  575. width: calc(100% - 24px);
  576. padding: 0 12px;
  577. display: flex;
  578. align-items: center;
  579. font-size: 16px;
  580. font-weight: bold;
  581. background-color: white;
  582. border-top-left-radius: 16px;
  583. border-top-right-radius: 16px;
  584. .block {
  585. width: 4px;
  586. height: 22px;
  587. margin-right: 4px;
  588. display: inline-block;
  589. background-color: skyblue;
  590. line-height: 40px;
  591. }
  592. }
  593. .custom-table {
  594. height: calc(100vh - 265px);
  595. min-height: 230px;
  596. // min-height: 600px;
  597. overflow-y: scroll;
  598. }
  599. .modal-btns {
  600. height: 100rpx;
  601. line-height: 100rpx;
  602. display: flex;
  603. justify-content: center;
  604. align-items: center;
  605. }
  606. .line {
  607. margin-top: 10rpx;
  608. height: 80rpx;
  609. width: 1rpx;
  610. background-color: #dcdcdc;
  611. }
  612. .tabs {
  613. width: 100%;
  614. height: 45px;
  615. display: flex;
  616. align-items: flex-end;
  617. padding: 0 2px;
  618. background-color: white;
  619. .tabs-list {
  620. border-radius: 3px;
  621. overflow: hidden;
  622. }
  623. .tabs-item {
  624. display: inline-block;
  625. width: 72px;
  626. height: 30px;
  627. line-height: 30px;
  628. padding: 0 8px;
  629. font-size: 14px;
  630. font-weight: bold;
  631. text-align: center;
  632. color: black;
  633. border-bottom: 1.5px dashed #00a0e9;
  634. transition: all .5s ease-in-out;
  635. }
  636. .tabs-item-active {
  637. position: relative;
  638. display: inline-block;
  639. width: 72px;
  640. height: 30px;
  641. line-height: 30px;
  642. padding: 0 8px;
  643. font-size: 14px;
  644. font-weight: bold;
  645. text-align: center;
  646. color: white;
  647. border-left: 1px solid #00a0e9;
  648. border-top: 1px solid #00a0e9;
  649. border-right: 1px solid #00a0e9;
  650. border-bottom: 1.5px solid #00a0e9;
  651. border-radius: 5px 5px 0 0;
  652. animation: .3s linear show;
  653. background-color: #00a0e9;
  654. }
  655. .tabs-item-active::before {
  656. content: '';
  657. position: absolute;
  658. left: -10px;
  659. bottom: 0;
  660. width: 10px;
  661. height: 10px;
  662. background: radial-gradient(circle at 0% 25%, transparent 10px, #00a0e9 0)
  663. }
  664. .tabs-item-active::after {
  665. content: '';
  666. position: absolute;
  667. right: -10px;
  668. bottom: 0;
  669. width: 10px;
  670. height: 10px;
  671. background: radial-gradient(circle at 100% 25%, transparent 10px, #00a0e9 0)
  672. }
  673. }
  674. @keyframes show {
  675. from {
  676. transform: translateY(5%);
  677. }
  678. to {
  679. transform: translateY(0%);
  680. }
  681. }
  682. </style>