quick.vue 21 KB

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