quick.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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" :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 m.drugCode == this.query.drugCode || !m.drugCode
  173. }),
  174. }
  175. })
  176. list = _.sortBy(list, 'index')
  177. this.list = list
  178. this.curItem = this.list[this.activeKey]
  179. console.log(list, this.curItem)
  180. }
  181. })
  182. .catch(err=>{
  183. console.error(err)
  184. })
  185. },
  186. onChange(isActive, item){
  187. var num = this.accessItemNum(item)
  188. item.isActive = isActive
  189. if(isActive){
  190. this.selItemList.push(item)
  191. this.allNum += num
  192. } else {
  193. this.selItemList.splice(this.selItemList.indexOf(item), 1)
  194. this.allNum -= num
  195. }
  196. console.log(this.curItem.list.indexOf(item))
  197. },
  198. accessItemNum(item){
  199. var num = 0
  200. if(this.repAll){
  201. num += item.cargoCapacity - item.qty
  202. } else {
  203. if(this.num - item.qty > 0){
  204. num += (this.num - item.qty)
  205. }
  206. }
  207. return num
  208. },
  209. accessNum(){
  210. var num = 0
  211. this.selItemList.forEach(v=>{
  212. num += this.accessItemNum(v)
  213. })
  214. this.allNum = num
  215. },
  216. sumit(){
  217. if(!this.selItemList || !this.selItemList.length){
  218. this.$toast("请选择操作货道")
  219. return
  220. }
  221. if(!this.repAll){
  222. var exist = _.find(this.selItemList, v=>{
  223. return v.qty > this.num
  224. })
  225. if(exist){
  226. this.$dialog.alert({
  227. title: '补货设置',
  228. message: `补货数量不能小于当前货道库存,请重新选择数量进行补货`,
  229. confirmButtonText: '我已知悉',
  230. })
  231. return
  232. }
  233. }
  234. if(this.outDetailId && this.query.quantity<this.allNum){
  235. this.$toast('当前补货数量超过了未放置数量,请重新设置')
  236. return
  237. }
  238. this.$dialog.confirm({
  239. title: '补货设置',
  240. message: `确定进行补货?`,
  241. confirmButtonText: '确定',
  242. })
  243. .then(() => {
  244. var list = _.map(this.selItemList, v=>{
  245. return {
  246. cargoId: v.id,
  247. drugId: this.query.drugId,
  248. qty: this.repAll? Number(v.cargoCapacity) : this.num
  249. }
  250. })
  251. this.$nextTick(()=>{
  252. this.$loading('保存中..')
  253. let p = {
  254. list: JSON.stringify({list: list}),
  255. userId: this.user.id,
  256. outDetailId: this.outDetailId
  257. }
  258. console.log('params', p)
  259. medicineAbinetApi
  260. .batchAddInventory(p)
  261. .then(res=>{
  262. this.query.qty += this.allNum
  263. this.query.quantity -= this.allNum
  264. if(this.query.quantity<0){
  265. this.query.quantity = 0
  266. }
  267. this.allNum = 0
  268. console.log('batchAddInventory', res)
  269. this.selItemList.forEach(v=>{
  270. v.isActive = false
  271. })
  272. this.selItemList = []
  273. this.$toast({
  274. message: '操作成功',
  275. forbidClick: true,
  276. onClose: ()=>{
  277. }
  278. })
  279. this.setBackRefresh(true)
  280. this.$refreshData()
  281. })
  282. .catch(err=>{
  283. console.error(err)
  284. })
  285. })
  286. })
  287. var exist = _.find(this.selItemList, v=>{
  288. return v.faultState == 1
  289. })
  290. // if(exist){
  291. // this.$toast('所选货道存在故障货道')
  292. // return
  293. // }
  294. // batchAddInventory
  295. },
  296. checkOpenOrClose(){
  297. return new Promise((resolve, reject)=>{
  298. var g = _.groupBy(this.selItemList, 'cargoState')
  299. if(g[1] && g[0]){
  300. this.$dialog.confirm({
  301. title: '货道设置',
  302. message: `选中货道已包含"关闭"和"开启"货道,请选择`,
  303. confirmButtonText: '全部开启',
  304. cancelButtonText: '全部关闭'
  305. })
  306. .then(() => {
  307. resolve(1)
  308. })
  309. .catch(()=>{
  310. resolve(0)
  311. })
  312. } else {
  313. resolve(g[1]? 0 : 1)
  314. }
  315. })
  316. },
  317. openAndCloseCargo(){
  318. if(!this.selItemList || !this.selItemList.length){
  319. this.$toast('请选择要操作的货道')
  320. return
  321. }
  322. this.checkOpenOrClose().then(cargoState=>{
  323. this.$nextTick(()=>{
  324. var ids = _.map(this.selItemList, v=>{
  325. return v.id
  326. })
  327. this.$loading('保存中..')
  328. let p = {
  329. cargoIds: ids.join(','),//必穿 货道id,多个id,英文逗号隔开,例如 1,2 4,5,6
  330. cargoState //必传 1开启,0关闭
  331. }
  332. console.log('params', p)
  333. medicineAbinetApi
  334. .openAndCloseCargo(p)
  335. .then(res=>{
  336. console.log('openAndCloseCargo', res)
  337. this.selItemList.forEach(v=>{
  338. v.isActive = false
  339. v.cargoState = cargoState
  340. })
  341. this.selItemList = []
  342. this.$toast({
  343. message: '操作成功',
  344. forbidClick: true,
  345. onClose: ()=>{
  346. }
  347. })
  348. this.setBackRefresh(true)
  349. })
  350. .catch(err=>{
  351. console.error(err)
  352. })
  353. })
  354. })
  355. },
  356. checkMerge(){
  357. return new Promise((resolve, reject)=>{
  358. var exist = _.find(this.selItemList, v=>{
  359. return !!v.drugCode
  360. })
  361. if(exist){
  362. this.$toast.clear()
  363. this.$dialog.confirm({
  364. message: '当前合并货道存在药品,需把药品下架并取出,如您继续合并默认下架全部药品',
  365. confirmButtonText: '继续合并'
  366. })
  367. .then(() => {
  368. this.$loading('保存中..')
  369. resolve(true)
  370. })
  371. .catch(() => {
  372. resolve(false)
  373. });
  374. return
  375. }
  376. resolve(true)
  377. })
  378. },
  379. checkSplit(){
  380. return new Promise((resolve, reject)=>{
  381. this.$toast.clear()
  382. this.$dialog.confirm({
  383. message: '货道拆分后请取下货道上的药品',
  384. confirmButtonText: '继续拆分'
  385. })
  386. .then(() => {
  387. resolve(true)
  388. })
  389. .catch(() => {
  390. resolve(false)
  391. });
  392. })
  393. },
  394. async mergeAndSplitCargo(){
  395. this.$loading('保存中..')
  396. var ids = []
  397. var g = _.groupBy(this.selItemList, 'state')
  398. if((g['21'] || g['20']) && g['1']){
  399. this.$toast.clear()
  400. this.$dialog.alert({
  401. title: '货道设置',
  402. message: `当前选中货道包含合并,您需要先手动拆分合并的货道`,
  403. confirmButtonText: '我已知悉',
  404. })
  405. return
  406. }
  407. var isMerge = g['21']? false : true
  408. if(isMerge){
  409. console.log(this.selItemList, 'this.selectList')
  410. if(!this.selItemList.length || this.selItemList.length<2){
  411. this.$toast('至少选择两个相邻的货道')
  412. return
  413. }
  414. var list = _.sortBy(this.selItemList, ['layerNo', 'wayerNo'])
  415. var exist = _.find(list, (v, i)=>{
  416. var next = list[i+1]
  417. if(next){
  418. if(next && v.layerNo!=next.layerNo){
  419. return true
  420. }
  421. if(Number(v.wayerNo)+1 != Number(next.wayerNo)){
  422. return true
  423. }
  424. }
  425. return false
  426. })
  427. if(exist){
  428. this.$toast('只能选择相邻的货道进行合并')
  429. return
  430. }
  431. if(!await this.checkMerge()){
  432. return
  433. }
  434. ids = _.map(list, v=>{
  435. return v.id
  436. })
  437. } else {
  438. if(!this.selItemList.length || this.selItemList.length>1 || this.selItemList[0].state!=21){
  439. this.$toast('请选择一个主货道')
  440. return
  441. }
  442. if(!await this.checkSplit()){
  443. return
  444. }
  445. this.$loading('保存中..')
  446. var item = this.selItemList[0]
  447. ids.push(item.id)
  448. }
  449. var p = {
  450. userId: this.user.id,
  451. cargoIds: ids.join(','),
  452. isMerge
  453. }
  454. console.log(p)
  455. medicineAbinetApi
  456. .mergeAndSplitCargo(p)
  457. .then(res=>{
  458. console.log('mergeAndSplitCargo', res)
  459. if(res.status == 200){
  460. this.selItemList = []
  461. this.$toast('操作成功')
  462. this.$refreshData()
  463. this.setBackRefresh(true)
  464. }
  465. })
  466. .catch(err=>{
  467. console.error(err)
  468. })
  469. },
  470. gotoDetail(item){
  471. if(item.shelfStatus==1){
  472. this.curCargo = item;
  473. this.gotoUrl('./productDetail', {
  474. id: item.id,
  475. from: 'quick'
  476. })
  477. }
  478. }
  479. },
  480. }
  481. </script>
  482. <style lang='scss' scoped>
  483. .replenishment-start-quick{
  484. display: -webkit-box;
  485. -webkit-box-orient: vertical;
  486. height: 100vh;
  487. .list-panel{
  488. -webkit-box-flex: 1;
  489. position: relative;
  490. >.kitbox{
  491. height: 100%;
  492. width: 100%;
  493. position: absolute;
  494. }
  495. }
  496. .drug-item{
  497. img{
  498. width: 60px;
  499. border-radius: 5px;
  500. }
  501. .stepper{
  502. -webkit-box-align: end;
  503. position: relative;
  504. .text{
  505. position: absolute;
  506. background: #f2f3f5;
  507. width: 34px;
  508. text-align: center;
  509. left: 50%;
  510. transform: translateX(-50%);
  511. bottom: 0;
  512. line-height: 27px;
  513. }
  514. }
  515. }
  516. .list{
  517. display: flex;
  518. flex-wrap: wrap;
  519. align-content: flex-start;
  520. .item{
  521. margin-left: 5px;
  522. margin-bottom: 5px;
  523. height: 80px;
  524. .components-product-item{
  525. width: 90px;
  526. }
  527. }
  528. }
  529. .left-list, .list{
  530. height: 100%;
  531. overflow-y: auto;
  532. }
  533. .color-block{
  534. background: #ff9526;
  535. width: 10px;
  536. height: 10px;
  537. display: inline-block;
  538. margin-left: 20px;
  539. border-radius: 2px;
  540. &.red{
  541. background: #ff5e6c;
  542. }
  543. }
  544. .bot-banner{
  545. padding: 10px 5px;
  546. position: relative;
  547. bottom: 0;
  548. width: 100%;
  549. left: 0;
  550. background: #fff;
  551. z-index: 3;
  552. >div{
  553. -webkit-box-flex: 1;
  554. .van-button{
  555. padding: 0;
  556. font-size: 13px;
  557. height: 36px;
  558. }
  559. }
  560. }
  561. }
  562. </style>
  563. <style lang="scss">
  564. .mainNobotHasTop{
  565. .replenishment-start-quick{
  566. height: calc(100vh - 46px);
  567. }
  568. }
  569. @supports(bottom: env(safe-area-inset-bottom)){
  570. .replenishment-start-quick{
  571. .bot-banner{
  572. &::after{
  573. content: "";
  574. height: env(safe-area-inset-bottom);
  575. width: 100%;
  576. display: block;
  577. }
  578. }
  579. }
  580. }
  581. </style>