SetStockDialog.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <div class="replenishment-start-set-stock-dialog ">
  3. <van-popup v-model="value" close-on-popstate :close-on-click-overlay="false">
  4. <div class="plr15 ptb10 c-pr" style="width: 80vw">
  5. <div class="close fs-20"><van-icon @click="emitValue(false)" name="close" /></div>
  6. <div class="tc fs-14 c-333">
  7. <span>{{ bussiness == 1 ? '修改容量' : bussiness == 2 ? '矫正库存' : bussiness == 4 || bussiness == 5 ? '设置库存' : bussiness == 6 ? '新增' : '' }}</span>
  8. </div>
  9. <template v-if="bussiness == 1 || bussiness == 4 || bussiness == 5 || bussiness == 6">
  10. <div class="tc pt30 pb20"><van-stepper v-model="stock" min="1" :max="bussiness == 4 ? data.cargoCapacity : 99" button-size="36px" input-width="60px" /></div>
  11. </template>
  12. <div class="tc" v-else>
  13. <div class="pt10">
  14. <van-image radius="5px" :src="require('@/assets/images/drug_default.png')" />
  15. </div>
  16. <div class="pt10 c-333 fs-16">{{ data.drugName }}</div>
  17. <div class="pt10 c-999">软件显示库存:{{ data.qty }}</div>
  18. <div class="pt10 pb20 ipt plr50">
  19. <div class="tc ">
  20. <van-stepper placeholder="实际库存" v-model="stock" min="1" :max="data.cargoCapacity" button-size="36px" input-width="60px" @change="changeStock" />
  21. </div>
  22. </div>
  23. </div>
  24. <div v-if="bussiness != 4">
  25. <div class="title mb8">
  26. <span>药品追溯码(</span>
  27. <span class="c-17b3ec">{{ fillNum }}</span>
  28. <span>/{{ stock }})</span>
  29. </div>
  30. <div class="code-box">
  31. <codeList :codeList="newCodeList" :qty="data.qty" :stock="stock" :bussiness="bussiness" @scan="scan"></codeList>
  32. </div>
  33. </div>
  34. <div class="ptb10">
  35. <van-button type="info" @click="confirm" size="small" block>确认</van-button>
  36. </div>
  37. </div>
  38. </van-popup>
  39. </div>
  40. </template>
  41. <script>
  42. import medicineAbinetApi from '@/api/api-medicineAbinet'
  43. import codeList from './codeList.vue'
  44. export default {
  45. components: {
  46. codeList
  47. },
  48. props: {
  49. value: {},
  50. bussiness: {
  51. default: 1 //1修改容量 2矫正库存 4设置库存 5选择药品后 设置库存 6备药时选择药品
  52. },
  53. data: {
  54. default: function() {
  55. return {}
  56. }
  57. },
  58. trackId: { default: '' },
  59. deviceId: { default: '' },
  60. drugId: { default: '' },
  61. codeList: {
  62. type: Array,
  63. default: () => {
  64. return []
  65. }
  66. },
  67. inventoryObj: {
  68. default: () => {
  69. return {}
  70. }
  71. }
  72. },
  73. data() {
  74. return {
  75. stock: 1,
  76. keyword: '',
  77. items: [],
  78. newCodeList: [],
  79. init: true
  80. }
  81. },
  82. computed: {
  83. fillNum() {
  84. let num = 0
  85. this.newCodeList.forEach(el => {
  86. if (el.code) {
  87. num++
  88. }
  89. })
  90. return num
  91. }
  92. },
  93. watch: {
  94. value: {
  95. handler(val) {
  96. if (this.init && val) {
  97. // 如果是初始化 则赋值。解决扫码回来这个地方重复调用的问题
  98. this.stock = this.bussiness == 1 ? this.data.cargoCapacity : this.data.qty
  99. console.log(this.codeList, 'this.codeList')
  100. this.newCodeList = JSON.parse(JSON.stringify(this.codeList))
  101. this.init = false
  102. }
  103. },
  104. immediate: true
  105. }
  106. },
  107. mounted() {
  108. this.$EventBus.$on('getScanData', item => {
  109. this.newCodeList = item.codeList
  110. })
  111. },
  112. beforeDestroy() {
  113. this.$EventBus.$off('getScanData')
  114. },
  115. created() {},
  116. methods: {
  117. confirm() {
  118. const codeList = []
  119. this.newCodeList.forEach((el, index) => {
  120. codeList.push({
  121. code: el.code,
  122. sort: this.newCodeList.length - index
  123. })
  124. })
  125. let p = {
  126. id: this.trackId,
  127. userId: this.user.id,
  128. codeStr: JSON.stringify(codeList)
  129. }
  130. if (this.bussiness == 1) {
  131. //修改容量
  132. if (this.fillNum > this.stock) {
  133. this.$toast('追溯码数量不能大于容量')
  134. return
  135. }
  136. p.cargoCapacity = this.stock
  137. medicineAbinetApi.updateMediicinecabineInventoryInfoById(p).then(res => {
  138. this.emitValue(false)
  139. this.$toast.clear()
  140. this.$emitRefreshPage('replenishmentStartDeviceDetail')
  141. // history.back()
  142. this.$emit('refresh')
  143. })
  144. } else if (this.bussiness == 2) {
  145. // 矫正库存
  146. if (this.fillNum != this.stock * 1) {
  147. this.$toast('追溯码数量必须等于库存')
  148. return
  149. }
  150. p.drugId = this.drugId
  151. p.qty = this.stock
  152. medicineAbinetApi
  153. .updateMediicinecabineInventory(p)
  154. .then(res => {
  155. this.emitValue(false)
  156. this.$toast.clear()
  157. this.$emitRefreshPage('replenishmentStartDeviceDetail')
  158. // history.back()
  159. this.$emit('refresh')
  160. })
  161. .catch(err => {
  162. console.error(err)
  163. })
  164. } else {
  165. if (this.bussiness == 4) {
  166. // 更换商品
  167. this.$router.push({
  168. path: '/replenishment/start/traceability',
  169. query: {
  170. deviceId: this.deviceId,
  171. trackId: this.trackId,
  172. drugId: this.drugId,
  173. stock: this.stock,
  174. type: 3
  175. }
  176. })
  177. return
  178. }
  179. if (this.trackId) {
  180. this.updateMediicinecabineInventory()
  181. return
  182. }
  183. this.$emit('onConfirm', { stock: this.stock, codeList: this.newCodeList })
  184. this.emitValue(false)
  185. }
  186. },
  187. emitValue(show) {
  188. this.init = true
  189. this.$emit('input', show)
  190. },
  191. updateMediicinecabineInventory(data) {
  192. this.$loading('保存中..')
  193. const codeList = []
  194. this.newCodeList.forEach((el, index) => {
  195. codeList.push({
  196. code: el.code,
  197. sort: this.newCodeList.length - index
  198. })
  199. })
  200. let p = {
  201. id: this.trackId,
  202. drugId: this.drugId,
  203. qty: this.stock,
  204. userId: this.user.id,
  205. codeStr: JSON.stringify(codeList)
  206. }
  207. medicineAbinetApi
  208. .updateMediicinecabineInventory(p)
  209. .then(res => {
  210. this.setStockShow = false
  211. this.$toast.clear()
  212. this.$emitRefreshPage('replenishmentStartDeviceDetail')
  213. history.back()
  214. })
  215. .catch(err => {
  216. console.error(err)
  217. })
  218. },
  219. changeStock(val) {
  220. if (val > this.newCodeList.length) {
  221. this.newCodeList.push({
  222. code: ''
  223. })
  224. } else if (val < this.newCodeList.length) {
  225. if (!this.newCodeList[this.newCodeList.length - 1].code) {
  226. this.newCodeList.pop()
  227. }
  228. }
  229. },
  230. scan(data) {
  231. sessionStorage.setItem('scanData', JSON.stringify({ ...data, codeList: this.newCodeList, ...this.inventoryObj }))
  232. this.$router.push({
  233. path: '/replenishment/start/scan'
  234. })
  235. }
  236. }
  237. }
  238. </script>
  239. <style lang="scss" scoped>
  240. .replenishment-start-set-stock-dialog {
  241. .close {
  242. position: absolute;
  243. right: 10px;
  244. top: 10px;
  245. }
  246. // ::v-deep .van-field {
  247. // padding: 0;
  248. // .van-cell__value {
  249. // border: 1px solid #e1e1e1;
  250. // input {
  251. // text-align: center;
  252. // }
  253. // }
  254. // }
  255. .van-image {
  256. width: 200px;
  257. height: 150px;
  258. }
  259. .scan {
  260. position: absolute;
  261. right: 36px;
  262. top: 50%;
  263. transform: translateY(-50%);
  264. }
  265. .drag {
  266. width: 20px;
  267. height: 20px;
  268. }
  269. }
  270. ::v-deep {
  271. .van-field__label {
  272. color: #999;
  273. width: 60px;
  274. margin-right: 0;
  275. }
  276. .van-field__control {
  277. padding-right: 15px;
  278. }
  279. }
  280. </style>