quick.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <template>
  2. <div class='replenishment-start-quick fs-14'>
  3. <div class="plr10 bgc-fff ptb10">
  4. <div class="drug-item kitbox" :key="k">
  5. <div class="photo">
  6. <img src="@/assets/images/drug_default.png" alt="">
  7. </div>
  8. <div class="box-flex-1 pl10">
  9. <div class="fs-15 ellipsis_1 c-333">{{query.drugName}}</div>
  10. <div class="fs-14 c-666 kitbox">
  11. <div class="box-flex-1">
  12. <div>规格:{{decodeStr(query.specif)}}</div>
  13. <div>当前库存量:{{query.qty}}</div>
  14. <div v-if="outDetailId">未放置数量:{{query.quantity}}</div>
  15. </div>
  16. <div class="stepper kitbox">
  17. <van-stepper v-model="num" integer min="0" max="99" />
  18. <div v-if="repAll" class="text">补满</div>
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. <div class="fs-14 pl15 ptb10 bgc-fff kitbox">
  25. <div class="box-flex-1 lh24">
  26. <span>从上往下数</span>
  27. <div class="color-block"></div>
  28. <span class="ml5 fs-12">已关闭</span>
  29. <div class="color-block ml10 red"></div>
  30. <span class="ml5 fs-12">故障</span>
  31. </div>
  32. </div>
  33. <div class="list-panel">
  34. <div class="kitbox ">
  35. <div class="left-list">
  36. <van-sidebar v-model="activeKey">
  37. <van-sidebar-item v-for="(item, i) in list" :key="i" :title="(i+1)+'层'" />
  38. </van-sidebar>
  39. </div>
  40. <div class="list box-flex-1 bgc-fff">
  41. <template v-if="curItem">
  42. <template v-for="(item, k) in curItem.list">
  43. <div class="item" v-if="item.state!=20 && (item.drugCode == query.drugCode || !item.drugCode)" :key="k">
  44. <ProductItem v-longpress="()=>{gotoDetail(item)}" bussuness="quick" @onChange="onChange($event, item)" :data="item" :index="k"/>
  45. </div>
  46. </template>
  47. <!-- <div class="item" v-for="(item, k) in curItem.list" :key="k">
  48. <ProductItem v-if="item.state!=20" bussuness="quick" @onChange="onChange($event, item)" :data="item" :index="k"/>
  49. </div> -->
  50. </template>
  51. </div>
  52. </div>
  53. </div>
  54. <div class="bot-banner">
  55. <div class="kitbox">
  56. <div class="box-flex-1 plr5"><van-button @click="openAndCloseCargo" block plain color="#17b3ec" type="primary" round>关闭/开启货道</van-button></div>
  57. <div class="box-flex-1 plr5"><van-button @click="mergeAndSplitCargo" block plain color="#17b3ec" type="primary" round>合并/拆分货道</van-button></div>
  58. <div class="box-flex-1 plr5"><van-button @click="sumit" block color="#17b3ec" type="primary" round>完成补货({{allNum}})</van-button></div>
  59. </div>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. import medicineAbinetApi from '@/api/api-medicineAbinet'
  65. import ProductItem from '@/components/ProductItem'
  66. export default{
  67. name: 'replenishmentStartQuick',
  68. components: {
  69. ProductItem
  70. },
  71. data(){
  72. return {
  73. num: 0,
  74. query: this.$route.query,
  75. selItemList: [],
  76. allNum: 0,
  77. curCargo: '',
  78. deviceId: this.$route.query.deviceId,
  79. list: [],
  80. activeKey: 0,
  81. curItem: [],
  82. repAll: true,
  83. outDetailId: this.$route.query.outDetailId || ''
  84. }
  85. },
  86. watch:{
  87. activeKey(n){
  88. this.curItem = ''
  89. this.$nextTick(()=>{
  90. this.curItem = this.list[n]
  91. })
  92. },
  93. num(n, o){
  94. this.repAll = false
  95. this.accessNum()
  96. }
  97. },
  98. created() {
  99. this.initPage()
  100. },
  101. methods:{
  102. decodeStr(str){
  103. return (str&&decodeURIComponent(str)) || ""
  104. },
  105. $refreshData(p){
  106. if(p){
  107. var oQty = this.curCargo.cargoCapacity - this.curCargo.qty
  108. //1修改容量 2矫正库存 3下架药品 4更换药品
  109. switch(Number(p.bussiness)){
  110. case 1:
  111. case 2:
  112. if(p.bussiness==1){
  113. // 1修改容量
  114. this.curCargo.cargoCapacity = p.data
  115. if(this.curCargo.qty > this.curCargo.cargoCapacity){
  116. this.curCargo.qty = this.curCargo.cargoCapacity
  117. }
  118. } else {
  119. // 2矫正库存
  120. this.curCargo.qty = p.data
  121. if(this.curCargo.qty > this.curCargo.cargoCapacity){
  122. this.curCargo.cargoCapacity = this.curCargo.qty
  123. }
  124. }
  125. if(this.curCargo.isActive){
  126. this.allNum = this.allNum - oQty + (this.curCargo.cargoCapacity - this.curCargo.qty)
  127. }
  128. break;
  129. case 3:
  130. // 3下架药品
  131. this.curCargo.shelfStatus = 0
  132. this.curCargo.qty = 0
  133. if(this.curCargo.isActive){
  134. this.allNum = this.allNum - oQty + this.curCargo.cargoCapacity
  135. }
  136. break;
  137. case 4:
  138. // 4更换药品
  139. this.curItem.list.splice(this.curItem.list.indexOf(this.curCargo), 1)
  140. if(this.curCargo.isActive){
  141. this.allNum = this.allNum - oQty
  142. }
  143. break;
  144. }
  145. } else {
  146. this.findMediicinecabinetInventoryByDeviceId()
  147. }
  148. },
  149. initPage(){
  150. this.findMediicinecabinetInventoryByDeviceId()
  151. },
  152. findMediicinecabinetInventoryByDeviceId(){
  153. this.$loading('加载中..')
  154. let p = {
  155. deviceId: this.deviceId
  156. }
  157. console.log('params', p)
  158. medicineAbinetApi
  159. .findMediicinecabinetInventoryByDeviceId(p)
  160. .then(res=>{
  161. console.log('findMediicinecabinetInventoryByDeviceId', res)
  162. this.$toast.clear()
  163. if(res.detailModelList && res.detailModelList.length){
  164. var list = _.map(res.detailModelList, v=>{
  165. var key = _.keys(v)[0]
  166. return {
  167. index: key,
  168. list: _.filter(v[key], m=>{
  169. m.layerNo = Number(m.layerNo)
  170. m.wayerNo = Number(m.wayerNo)
  171. m.isActive = false
  172. return true
  173. return m.drugCode == this.query.drugCode || !m.drugCode
  174. }),
  175. }
  176. })
  177. list = _.sortBy(list, 'index')
  178. this.list = list
  179. this.curItem = this.list[this.activeKey]
  180. console.log(list, this.curItem)
  181. }
  182. })
  183. .catch(err=>{
  184. console.error(err)
  185. })
  186. },
  187. onChange(isActive, item){
  188. var num = this.accessItemNum(item)
  189. item.isActive = isActive
  190. if(isActive){
  191. this.selItemList.push(item)
  192. this.allNum += num
  193. } else {
  194. this.selItemList.splice(this.selItemList.indexOf(item), 1)
  195. this.allNum -= num
  196. }
  197. console.log(this.curItem.list.indexOf(item))
  198. },
  199. accessItemNum(item){
  200. var num = 0
  201. if(this.repAll){
  202. num += item.cargoCapacity - item.qty
  203. } else {
  204. if(this.num - item.qty > 0){
  205. num += (this.num - item.qty)
  206. }
  207. }
  208. return num
  209. },
  210. accessNum(){
  211. var num = 0
  212. this.selItemList.forEach(v=>{
  213. num += this.accessItemNum(v)
  214. })
  215. this.allNum = num
  216. },
  217. sumit(){
  218. if(!this.selItemList || !this.selItemList.length){
  219. this.$toast("请选择操作货道")
  220. return
  221. }
  222. if(!this.repAll){
  223. var exist = _.find(this.selItemList, v=>{
  224. return v.qty > this.num
  225. })
  226. if(exist){
  227. this.$dialog.alert({
  228. title: '补货设置',
  229. message: `补货数量不能小于当前货道库存,请重新选择数量进行补货`,
  230. confirmButtonText: '我已知悉',
  231. })
  232. return
  233. }
  234. }
  235. if(this.outDetailId && this.query.quantity<this.allNum){
  236. this.$toast('当前补货数量超过了未放置数量,请重新设置')
  237. return
  238. }
  239. this.$dialog.confirm({
  240. title: '补货设置',
  241. message: `确定进行补货?`,
  242. confirmButtonText: '确定',
  243. })
  244. .then(() => {
  245. var list = _.map(this.selItemList, v=>{
  246. return {
  247. cargoId: v.id,
  248. drugId: this.query.drugId,
  249. qty: this.repAll? Number(v.cargoCapacity) : this.num
  250. }
  251. })
  252. this.$nextTick(()=>{
  253. this.$loading('保存中..')
  254. let p = {
  255. list: JSON.stringify({list: list}),
  256. userId: this.user.id,
  257. outDetailId: this.outDetailId
  258. }
  259. console.log('params', p)
  260. medicineAbinetApi
  261. .batchAddInventory(p)
  262. .then(res=>{
  263. this.query.qty += this.allNum
  264. this.query.quantity -= this.allNum
  265. if(this.query.quantity<0){
  266. this.query.quantity = 0
  267. }
  268. this.allNum = 0
  269. console.log('batchAddInventory', res)
  270. this.selItemList.forEach(v=>{
  271. v.isActive = false
  272. })
  273. this.selItemList = []
  274. this.$toast({
  275. message: '操作成功',
  276. forbidClick: true,
  277. onClose: ()=>{
  278. }
  279. })
  280. this.setBackRefresh(true)
  281. this.$refreshData()
  282. })
  283. .catch(err=>{
  284. console.error(err)
  285. })
  286. })
  287. })
  288. var exist = _.find(this.selItemList, v=>{
  289. return v.faultState == 1
  290. })
  291. // if(exist){
  292. // this.$toast('所选货道存在故障货道')
  293. // return
  294. // }
  295. // batchAddInventory
  296. },
  297. checkOpenOrClose(){
  298. return new Promise((resolve, reject)=>{
  299. var g = _.groupBy(this.selItemList, 'cargoState')
  300. if(g[1] && g[0]){
  301. this.$dialog.confirm({
  302. title: '货道设置',
  303. message: `选中货道已包含"关闭"和"开启"货道,请选择`,
  304. confirmButtonText: '全部开启',
  305. cancelButtonText: '全部关闭'
  306. })
  307. .then(() => {
  308. resolve(1)
  309. })
  310. .catch(()=>{
  311. resolve(0)
  312. })
  313. } else {
  314. resolve(g[1]? 0 : 1)
  315. }
  316. })
  317. },
  318. openAndCloseCargo(){
  319. if(!this.selItemList || !this.selItemList.length){
  320. this.$toast('请选择要操作的货道')
  321. return
  322. }
  323. this.checkOpenOrClose().then(cargoState=>{
  324. this.$nextTick(()=>{
  325. this.$loading('保存中..')
  326. var ids = []
  327. this.selItemList.forEach(v=>{
  328. if(v.state == 21){
  329. var cargoIds = v.merge.split(',')
  330. cargoIds.forEach(m => {
  331. ids.push(this.list[Number(v.layerNo)-1].list[Number(m)-1].id)
  332. })
  333. } else {
  334. ids.push(v.id)
  335. }
  336. })
  337. console.log('ids', ids)
  338. let p = {
  339. cargoIds: ids.join(','),//必穿 货道id,多个id,英文逗号隔开,例如 1,2 4,5,6
  340. cargoState //必传 1开启,0关闭
  341. }
  342. console.log('params', p)
  343. medicineAbinetApi
  344. .openAndCloseCargo(p)
  345. .then(res=>{
  346. console.log('openAndCloseCargo', res)
  347. this.selItemList.forEach(v=>{
  348. v.isActive = false
  349. v.cargoState = cargoState
  350. })
  351. this.selItemList = []
  352. this.$toast({
  353. message: '操作成功',
  354. forbidClick: true,
  355. onClose: ()=>{
  356. }
  357. })
  358. this.setBackRefresh(true)
  359. })
  360. .catch(err=>{
  361. console.error(err)
  362. })
  363. })
  364. })
  365. },
  366. checkMerge(){
  367. return new Promise((resolve, reject)=>{
  368. var exist = _.find(this.selItemList, v=>{
  369. return !!v.drugCode
  370. })
  371. if(exist){
  372. this.$toast.clear()
  373. this.$dialog.confirm({
  374. message: '当前合并货道存在药品,需把药品下架并取出,如您继续合并默认下架全部药品',
  375. confirmButtonText: '继续合并'
  376. })
  377. .then(() => {
  378. this.$loading('保存中..')
  379. resolve(true)
  380. })
  381. .catch(() => {
  382. resolve(false)
  383. });
  384. return
  385. }
  386. resolve(true)
  387. })
  388. },
  389. checkSplit(){
  390. return new Promise((resolve, reject)=>{
  391. this.$toast.clear()
  392. this.$dialog.confirm({
  393. message: '货道拆分后请取下货道上的药品',
  394. confirmButtonText: '继续拆分'
  395. })
  396. .then(() => {
  397. resolve(true)
  398. })
  399. .catch(() => {
  400. resolve(false)
  401. });
  402. })
  403. },
  404. async mergeAndSplitCargo(){
  405. this.$loading('保存中..')
  406. var ids = []
  407. var g = _.groupBy(this.selItemList, 'state')
  408. if((g['21'] || g['20']) && g['1']){
  409. this.$toast.clear()
  410. this.$dialog.alert({
  411. title: '货道设置',
  412. message: `当前选中货道包含合并,您需要先手动拆分合并的货道`,
  413. confirmButtonText: '我已知悉',
  414. })
  415. return
  416. }
  417. var isMerge = g['21']? false : true
  418. if(isMerge){
  419. console.log(this.selItemList, 'this.selectList')
  420. if(!this.selItemList.length || this.selItemList.length<2){
  421. this.$toast('至少选择两个相邻的货道')
  422. return
  423. }
  424. var list = _.sortBy(this.selItemList, ['layerNo', 'wayerNo'])
  425. var exist = _.find(list, (v, i)=>{
  426. var next = list[i+1]
  427. if(next){
  428. if(next && v.layerNo!=next.layerNo){
  429. return true
  430. }
  431. if(Number(v.wayerNo)+1 != Number(next.wayerNo)){
  432. return true
  433. }
  434. }
  435. return false
  436. })
  437. if(exist){
  438. this.$toast('只能选择相邻的货道进行合并')
  439. return
  440. }
  441. if(!await this.checkMerge()){
  442. return
  443. }
  444. ids = _.map(list, v=>{
  445. return v.id
  446. })
  447. } else {
  448. if(!this.selItemList.length || this.selItemList.length>1 || this.selItemList[0].state!=21){
  449. this.$toast('请选择一个主货道')
  450. return
  451. }
  452. if(!await this.checkSplit()){
  453. return
  454. }
  455. this.$loading('保存中..')
  456. var item = this.selItemList[0]
  457. ids.push(item.id)
  458. }
  459. var p = {
  460. userId: this.user.id,
  461. cargoIds: ids.join(','),
  462. isMerge
  463. }
  464. console.log(p)
  465. medicineAbinetApi
  466. .mergeAndSplitCargo(p)
  467. .then(res=>{
  468. console.log('mergeAndSplitCargo', res)
  469. if(res.status == 200){
  470. this.selItemList = []
  471. this.$toast('操作成功')
  472. this.$refreshData()
  473. this.setBackRefresh(true)
  474. }
  475. })
  476. .catch(err=>{
  477. console.error(err)
  478. })
  479. },
  480. gotoDetail(item){
  481. if(item.shelfStatus==1){
  482. this.curCargo = item;
  483. this.gotoUrl('./productDetail', {
  484. id: item.id,
  485. from: 'quick'
  486. })
  487. }
  488. }
  489. },
  490. }
  491. </script>
  492. <style lang='scss' scoped>
  493. .replenishment-start-quick{
  494. display: -webkit-box;
  495. -webkit-box-orient: vertical;
  496. height: 100vh;
  497. .list-panel{
  498. -webkit-box-flex: 1;
  499. position: relative;
  500. >.kitbox{
  501. height: 100%;
  502. width: 100%;
  503. position: absolute;
  504. }
  505. }
  506. .drug-item{
  507. img{
  508. width: 60px;
  509. border-radius: 5px;
  510. }
  511. .stepper{
  512. -webkit-box-align: end;
  513. position: relative;
  514. .text{
  515. position: absolute;
  516. background: #f2f3f5;
  517. width: 34px;
  518. text-align: center;
  519. left: 50%;
  520. transform: translateX(-50%);
  521. bottom: 0;
  522. line-height: 27px;
  523. }
  524. }
  525. }
  526. .list{
  527. display: flex;
  528. flex-wrap: wrap;
  529. align-content: flex-start;
  530. .item{
  531. margin-left: 5px;
  532. margin-bottom: 5px;
  533. height: 80px;
  534. .components-product-item{
  535. width: 90px;
  536. }
  537. }
  538. }
  539. .left-list, .list{
  540. height: 100%;
  541. overflow-y: auto;
  542. }
  543. .color-block{
  544. background: #ff9526;
  545. width: 10px;
  546. height: 10px;
  547. display: inline-block;
  548. margin-left: 20px;
  549. border-radius: 2px;
  550. &.red{
  551. background: #ff5e6c;
  552. }
  553. }
  554. .bot-banner{
  555. padding: 10px 5px;
  556. position: relative;
  557. bottom: 0;
  558. width: 100%;
  559. left: 0;
  560. background: #fff;
  561. z-index: 3;
  562. >div{
  563. -webkit-box-flex: 1;
  564. .van-button{
  565. padding: 0;
  566. font-size: 13px;
  567. height: 36px;
  568. }
  569. }
  570. }
  571. }
  572. </style>
  573. <style lang="scss">
  574. .mainNobotHasTop{
  575. .replenishment-start-quick{
  576. height: calc(100vh - 46px);
  577. }
  578. }
  579. @supports(bottom: env(safe-area-inset-bottom)){
  580. .replenishment-start-quick{
  581. .bot-banner{
  582. &::after{
  583. content: "";
  584. height: env(safe-area-inset-bottom);
  585. width: 100%;
  586. display: block;
  587. }
  588. }
  589. }
  590. }
  591. </style>