choosespare.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. <template>
  2. <view class="price apply-credit" :class="(showCalendar || showPicker)?'popupShow':''">
  3. <view class="picker-btn">
  4. <view class="btn">
  5. <u-button type="primary" @click="sureChangePrice">
  6. {{$t('settings.confirmText')}}
  7. </u-button>
  8. </view>
  9. </view>
  10. <u-sticky bgColor="#fff">
  11. <view class="change-price-title">
  12. <view class="btn">
  13. <u-button type="primary" @click="batchAdd">{{$t('spare.batchAdd')}}</u-button>
  14. </view>
  15. <view class="btn">
  16. <u-button type="primary" @click="orderAdd">{{work=='in'?$t('spare.orderAdd'):$t('spare.applyAdd')}}</u-button>
  17. </view>
  18. </view>
  19. </u-sticky>
  20. <template v-if="details.length">
  21. <view class="order-card" v-for="(item, index) in details" :key="index">
  22. <view class="order-info">
  23. <p class="info-line">
  24. <text class="label">{{$t('spare.spareName')}}:</text>
  25. <text class="info">
  26. <template v-if="item.sourceType == '101'">
  27. {{`${item.materialCode}_${item.materialName}_${item.materialSpec}_${getLabel(item.materialUnit,unitList)}`}}
  28. </template>
  29. <template v-else>
  30. {{`${item.code}_${item.name}_${item.spec}_${getLabel(item.unit,unitList)}`}}
  31. </template>
  32. </text>
  33. </p>
  34. <template v-if="work=='in'">
  35. <p class="info-line">
  36. <text class="label">{{$t('spare.source')}}:</text>
  37. <text class="info">{{item.sourceType == '102'?'批量添加':'订单:'+item.orderCode}}</text>
  38. </p>
  39. <p class="info-line">
  40. <text class="label">{{$t('spare.inStoreNumber')}}:</text>
  41. <u-input class="info" suffixIcon="edit-pen" border="none" :placeholder="$t('base.common.placeholderI')+$t('spare.inStoreNumber')" type="number" v-model="item.count" />
  42. </p>
  43. <p class="info-line">
  44. <text class="label">{{$t('spare.shelf')}}:</text>
  45. <u-icon class="info" name="list" size="30" @click="openShelf(item)" color="#2979ff"></u-icon>
  46. </p>
  47. <p class="info-line">
  48. <text class="label">{{$t('approval.remark')}}:</text>
  49. <u-input class="info" suffixIcon="edit-pen" :placeholder="$t('approval.remark')" border="none" v-model="item.remark" />
  50. </p>
  51. </template>
  52. <template v-else>
  53. <p class="info-line">
  54. <text class="label">{{$t('spare.source')}}:</text>
  55. <text class="info">{{item.sourceType == '102'?'批量添加':'申请:'+item.takeCode}}</text>
  56. </p>
  57. <p class="info-line">
  58. <text class="label">{{$t('spare.canOutNumber')}}:</text>
  59. <text class="info">
  60. {{item.sourceType == '101'?(item.number - item.outNum):item.totalNum}}
  61. </text>
  62. </p>
  63. <p class="info-line">
  64. <text class="label">{{$t('spare.outStoreNumber')}}:</text>
  65. <u-input class="info"
  66. @change="countChange(item)"
  67. :disabled='item.materialShelves.length>1'
  68. suffixIcon="edit-pen"
  69. border="none"
  70. placeholder="请输入出库数量"
  71. type="number"
  72. v-model="item.count" />
  73. </p>
  74. <p class="info-line">
  75. <text class="label">{{$t('spare.shelf')}}:</text>
  76. <u-icon class="info" name="list" size="30" @click="openShelf(item)" color="#2979ff"></u-icon>
  77. </p>
  78. <p class="info-line">
  79. <text class="label">{{$t('approval.remark')}}:</text>
  80. <u-input class="info" suffixIcon="edit-pen" :placeholder="$t('approval.remark')" border="none" v-model="item.remark" />
  81. </p>
  82. </template>
  83. </view>
  84. <view>
  85. <view class="card-oper">
  86. <view class="btn">
  87. <u-button type='error' size="small" @click="tableDelete(item)">{{$t('search.delete')}}</u-button>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </template>
  93. <template v-else>
  94. <u-empty mode="list" text='请添加入库明细' icon="https://cdn.uviewui.com/uview/empty/list.png">
  95. </u-empty>
  96. </template>
  97. <!-- 货架 -->
  98. <u-popup :show="shelfShow" mode="center" @close="shelfShow = false" >
  99. <view class="picker-card">
  100. <view style="height:100%;overflow-y:auto;display:block">
  101. <template v-if="work == 'in'">
  102. <view class="order-card shelf-card" v-for="(item, index) in currentRow.shelfList" :key="index">
  103. <view class="order-info">
  104. <p class="info-line">
  105. <text class="label">货架:</text>
  106. <u-input class="info" suffixIcon="edit-pen" border="none" :clearable="false" v-model="item.shelf"></u-input>
  107. </p>
  108. <p class="info-line">
  109. <text class="label">货层:</text>
  110. <u-input class="info" suffixIcon="edit-pen" border="none" :clearable="false" v-model="item.floor"></u-input>
  111. </p>
  112. <p class="info-line">
  113. <text class="label">货位:</text>
  114. <u-input class="info" suffixIcon="edit-pen" border="none" :clearable="false" v-model="item.seat"></u-input>
  115. </p>
  116. <p class="info-line">
  117. <text class="label">附加码:</text>
  118. <u-input class="info" suffixIcon="edit-pen" border="none" :clearable="false" v-model="item.sign"></u-input>
  119. </p>
  120. <p class="info-line">
  121. <text class="label">数量:</text>
  122. <u-input class="info" type="number" suffixIcon="edit-pen" border="none" :clearable="false" v-model="item.num"></u-input>
  123. </p>
  124. <p class="info-line">
  125. <text class="label"></text>
  126. <u-button type='error' size="small" @click="deleteShelve(item,index)">删除</u-button>
  127. </p>
  128. </view>
  129. </view>
  130. </template>
  131. <template v-else>
  132. <view class="order-card shelf-card" v-for="(item, index) in currentRow.materialShelves" :key="index">
  133. <view class="order-info">
  134. <p class="info-line">
  135. <text class="label">货架:</text>
  136. <text class="info">{{item.shelf}}</text>
  137. </p>
  138. <p class="info-line">
  139. <text class="label">货层:</text>
  140. <text class="info">{{item.floor}}</text>
  141. </p>
  142. <p class="info-line">
  143. <text class="label">货位:</text>
  144. <text class="info">{{item.seat}}</text>
  145. </p>
  146. <p class="info-line">
  147. <text class="label">附加码:</text>
  148. <text class="info">{{item.sign}}</text>
  149. </p>
  150. <p class="info-line">
  151. <text class="label">库存数量:</text>
  152. <text class="info">{{item.shelfNum}}</text>
  153. </p>
  154. <p class="info-line">
  155. <text class="label">出库数量:</text>
  156. <u-input class="info" type="number"
  157. @change="changeShelveNum(item)"
  158. suffixIcon="edit-pen"
  159. border="none"
  160. :clearable="false"
  161. v-model="item.num">
  162. </u-input>
  163. </p>
  164. </view>
  165. </view>
  166. </template>
  167. </view>
  168. <view class="card-oper">
  169. <view class="btn" v-if="work == 'in'">
  170. <u-button @click="addShelf">添加货架</u-button>
  171. </view>
  172. <view class="btn" v-else>
  173. <u-button @click="confirmShelf">取 消</u-button>
  174. </view>
  175. <view class="btn">
  176. <u-button type='primary' @click="confirmShelf">{{$t('settings.confirmText')}}</u-button>
  177. </view>
  178. </view>
  179. </view>
  180. </u-popup>
  181. <!-- 到货日期 -->
  182. <u-calendar
  183. color="#4680F9"
  184. round='25'
  185. :show="showCalendar"
  186. @confirm="onDateConfirm"
  187. @close="showCalendar=false">
  188. </u-calendar>
  189. </view>
  190. </template>
  191. <script>
  192. import { getLabel } from '../../utils/util'
  193. import {request} from '../../utils/request'
  194. import dayjs from 'dayjs'
  195. import {
  196. fetchTree,
  197. getSpareOption
  198. } from "../../api/stock"
  199. export default {
  200. data(){
  201. return {
  202. getLabel,
  203. shelfShow:false,
  204. showCalendar:false,
  205. showPicker:false,
  206. details:[],
  207. currentIndex:'',
  208. keyword:'',
  209. spareKeyword:'',
  210. detailList:[], //选择的备件
  211. unitList:[],
  212. work:'',
  213. purveyId:'',
  214. currentRow:{},
  215. }
  216. },
  217. onLoad(options) {
  218. this.work = options.work
  219. this.details = JSON.parse(options.content)
  220. this.purveyId = options.purveyId
  221. this.dept = options.dept
  222. this.getSpareTree()
  223. },
  224. onReady() {
  225. },
  226. methods:{
  227. //确认调价
  228. sureChangePrice(){
  229. let pages = getCurrentPages();
  230. let prevPage = pages[pages.length - 2]; //上一个页面
  231. prevPage.$vm.form.detailList = this.details;
  232. uni.navigateBack();
  233. },
  234. //批量添加
  235. batchAdd(){
  236. uni.navigateTo({ url: `/subpages/spare/batchAdd`})
  237. },
  238. //订单添加
  239. orderAdd(){
  240. if(this.work == 'in'){
  241. uni.navigateTo({ url: `/subpages/spare/chooseorder?purveyId=${this.purveyId}&work=in`})
  242. }else{
  243. uni.navigateTo({ url: `/subpages/spare/chooseorder?dept=${this.dept}&work=out`})
  244. }
  245. },
  246. //确认货架
  247. confirmShelf(){
  248. let num = 0
  249. console.log(this.currentRow.materialShelves);
  250. this.currentRow.materialShelves.forEach(item=>{
  251. num+=parseInt(item.num) || 0
  252. })
  253. this.currentRow.count = num
  254. console.log(this.currentRow);
  255. this.details=JSON.parse(JSON.stringify(this.details))
  256. this.shelfShow = false
  257. },
  258. //备件大类
  259. getSpareTree(){
  260. //获取单位
  261. request({
  262. url:'/admin/dict/type/spare_unit',
  263. method:'get',
  264. })
  265. .then(res=>{
  266. if(res.data.code == 0){
  267. this.unitList = res.data.data
  268. }
  269. })
  270. },
  271. //出库数量变化
  272. countChange(row){
  273. if(row.sourceType == '101'){
  274. if(row.count>(row.number - row.outNum)){
  275. row.count = row.number - row.outNum
  276. uni.showToast({
  277. title: '出库数量不能大于可出库数量!',
  278. icon: 'none',
  279. mask: true
  280. })
  281. console.log(row);
  282. this.details=JSON.parse(JSON.stringify(this.details))
  283. }
  284. }else{
  285. if(row.count>row.totalNum){
  286. row.count = row.totalNum
  287. uni.showToast({
  288. title: '出库数量不能大于可出库数量!',
  289. icon: 'none',
  290. mask: true
  291. })
  292. console.log(row);
  293. this.details=JSON.parse(JSON.stringify(this.details))
  294. }
  295. }
  296. },
  297. //修改货架数量
  298. changeShelveNum(row){
  299. if(row.num>row.shelfNum){
  300. uni.showToast({
  301. title: '出库数量不能大于库存数量!',
  302. icon: 'none',
  303. mask: true
  304. })
  305. row.num = row.shelfNum
  306. }
  307. console.log(row);
  308. },
  309. //获取产品选项
  310. getSpare(id){
  311. let data = {
  312. fullCode:id,
  313. }
  314. getSpareOption(data,this.spareKeyword).then(res=>{
  315. if(res.data.code == 0){
  316. this.spareList=res.data.data
  317. this.spareList.forEach(item=>{
  318. item.content = JSON.stringify(item)
  319. })
  320. }
  321. })
  322. },
  323. //货架删除
  324. deleteShelve(row,index){
  325. if(this.currentRow.shelfList.length==1){
  326. uni.showToast({
  327. title: '最少保留一条货架信息',
  328. icon:'none',
  329. mask: true
  330. })
  331. }else{
  332. this.currentRow.shelfList.splice(index,1)
  333. }
  334. },
  335. //添加货架
  336. addShelf(){
  337. this.currentRow.shelfList.push({
  338. shelf:0,
  339. floor:0,
  340. seat:0,
  341. sign:0,
  342. num:0,
  343. })
  344. },
  345. //打开货架
  346. openShelf(item){
  347. console.log(item);
  348. this.currentRow = item
  349. this.shelfShow = true
  350. },
  351. //确认选择备件
  352. spareConfirm(){
  353. this.detailList.forEach(item=>{
  354. let obj = JSON.parse(item)
  355. let isHave = false
  356. this.details.forEach(i=>{
  357. if(obj.id == i.id && i.sourceType == '102'){
  358. isHave = true
  359. }
  360. })
  361. if(!isHave && this.work == 'in'){
  362. obj.materialId = obj.id
  363. obj.count=''
  364. obj.remark=''
  365. obj.sourceType = '102'
  366. if(obj.defaultShelves.length){
  367. obj.shelfList = obj.defaultShelves
  368. }else{
  369. obj.shelfList = [{
  370. shelf:0,
  371. floor:0,
  372. seat:0,
  373. sign:0,
  374. num:0,
  375. }]
  376. }
  377. this.details.push(obj)
  378. }else if(!isHave && this.work == 'out'){
  379. obj.materialName = obj.name
  380. obj.materialId = obj.id
  381. obj.count=0
  382. // item.materialShelves.forEach(i=>{
  383. // i.num = 0
  384. // })
  385. obj.remark=''
  386. obj.cess = parseInt(obj.cess)
  387. obj.sourceType = '102'
  388. this.details.push(obj)
  389. }
  390. })
  391. this.showPicker = false
  392. },
  393. //打开日期选择
  394. setArrivalDate(index){
  395. this.currentIndex = index
  396. this.showCalendar = true
  397. },
  398. //确认选择
  399. onDateConfirm(date){
  400. this.details[this.currentIndex].arrivalDate = dayjs(date).format('YYYY-MM-DD')
  401. console.log(this.details);
  402. this.showCalendar = false;
  403. },
  404. //删除
  405. tableDelete(e){
  406. this.details = this.details.filter(item=>{
  407. return item.id != e.id
  408. })
  409. },
  410. }
  411. }
  412. </script>
  413. <style lang="scss" scoped>
  414. @import '../../common/css/apply.scss';
  415. /* #ifndef APP-NVUE */
  416. view {
  417. display: flex;
  418. box-sizing: border-box;
  419. flex-direction: column;
  420. }
  421. page {
  422. background-color: #f8f8f8;
  423. }
  424. /* #endif*/
  425. .price{
  426. /* #ifndef APP-NVUE */
  427. display: flex;
  428. width: 750rpx;
  429. min-height: 100vh;
  430. /* #endif */
  431. flex-direction: column;
  432. flex: 1;
  433. background-color: #f8f8f8;
  434. padding-bottom: 160rpx;
  435. .change-price-title{
  436. background-color: #fff;
  437. padding: 24rpx 32rpx;
  438. width: 100%;
  439. display: flex;
  440. flex-direction: row;
  441. justify-content: space-between;
  442. .btn{
  443. width: 48%;
  444. }
  445. }
  446. .picker-btn{
  447. padding: 32rpx;
  448. position: fixed;
  449. bottom: 0;
  450. width: 100%;
  451. flex-direction: row;
  452. justify-content: space-between;
  453. background-color: #fff;
  454. z-index: 100;
  455. .btn{
  456. width: 100%;
  457. }
  458. }
  459. // padding: 32rpx;
  460. .picker-card{
  461. padding: 32rpx 32rpx 144rpx;
  462. position: relative;
  463. height: 100%;
  464. overflow-y: scroll;
  465. display: block;
  466. .choose-wrap{
  467. display: flex;
  468. flex-direction: row;
  469. justify-content: space-around;
  470. height: 100%;
  471. .item{
  472. width: 45%;
  473. height: 100%;
  474. overflow-y: scroll;
  475. .search-wrap{
  476. margin-bottom: 24rpx;
  477. }
  478. .tree{
  479. p{
  480. line-height: 64rpx;
  481. }
  482. }
  483. }
  484. }
  485. .card-oper{
  486. position: absolute;
  487. width: 100%;
  488. bottom: 0;
  489. left:0;
  490. display: flex;
  491. flex-direction: row;
  492. justify-content: space-between;
  493. padding: 24rpx;
  494. .btn{
  495. width: 45%;
  496. }
  497. }
  498. }
  499. }
  500. /deep/ .u-popup__content{
  501. height: 70%;
  502. width: 90%;
  503. overflow-y: scroll;
  504. border-radius: 6px;
  505. background-color: #f8f8f8;
  506. }
  507. .popupShow {
  508. overflow: hidden;
  509. position: fixed;
  510. }
  511. .order-card{
  512. position: relative;
  513. box-shadow:0 0 16rpx 0px rgba(0, 0, 0, 0.1);
  514. // background-color: #fff;
  515. border-radius: 20rpx;
  516. overflow: hidden;
  517. // margin-top: 24rpx;
  518. margin: 24rpx 24rpx 0;
  519. z-index: 50;
  520. display: block;
  521. .order-card-title{
  522. display: flex;
  523. flex-direction: row;
  524. justify-content: space-between;
  525. // background: linear-gradient(to right, rgb(245, 249, 255), #fff);
  526. padding: 16rpx 24rpx;
  527. line-height: 50rpx;
  528. font-size: 32rpx;
  529. font-weight: 600;
  530. color: #fff;
  531. box-shadow:0 0 16rpx 0px rgba(0, 0, 0, 0.1);
  532. }
  533. .order-info {
  534. background-color: #fff;
  535. font-size: 28rpx;
  536. line-height: 56rpx;
  537. padding: 24rpx;
  538. color: #333;
  539. position: relative;
  540. .info-line {
  541. display: flex;
  542. flex-direction: row;
  543. align-items: center;
  544. line-height: 72rpx;
  545. .label {
  546. width: 200rpx;
  547. text-align: center;
  548. font-size: 24rpx;
  549. }
  550. .info {
  551. flex: 1;
  552. font-weight: bold;
  553. font-size: 28rpx;
  554. }
  555. .tag{
  556. padding: 0 16rpx 0 12rpx;
  557. border-top-right-radius: 40rpx;
  558. border-bottom-right-radius: 40rpx;
  559. height: 40rpx;
  560. line-height: 40rpx;
  561. }
  562. .tag-ls{
  563. border: 1px solid #f9ae3d;
  564. background-color: #fdf6ec;
  565. color: #f9ae3d;
  566. }
  567. .tag-gd{
  568. border: 1px solid #3c9cff;
  569. background-color: #ecf5ff;
  570. color: #3c9cff;
  571. }
  572. .tag-gx{
  573. border: 1px solid #5ac725;
  574. background-color: #f5fff0;
  575. color: #5ac725;
  576. }
  577. }
  578. .qrcode-logo{
  579. position: absolute;
  580. width: 128rpx;
  581. height: 128rpx;
  582. bottom: 24rpx;
  583. right: 24rpx;
  584. .img{
  585. width: 100%;
  586. height: 100%;
  587. }
  588. }
  589. }
  590. .card-oper{
  591. background-color: #fff;
  592. display: flex;
  593. flex-direction: row;
  594. justify-content: flex-end;
  595. padding: 24rpx;
  596. .btn{
  597. width: 25%;
  598. margin-left: 32rpx;
  599. }
  600. }
  601. }
  602. .shelf-card{
  603. margin: 0 0 24rpx;
  604. display: block;
  605. .order-info{
  606. flex-direction: row;
  607. flex-wrap: wrap;
  608. .info-line{
  609. width: 50%;
  610. .label{
  611. width: 120rpx;
  612. }
  613. }
  614. }
  615. }
  616. </style>