WarehouseChoose.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <template>
  2. <view>
  3. <uni-popup ref="popup" background-color="#fff" :mask-click="false">
  4. <view class="title">
  5. 选择货位
  6. <!-- <view class="btn">
  7. <u-icon name="scan" color="#fff" size="80" @click="handleScan"></u-icon>
  8. </view> -->
  9. </view>
  10. <view class="select-group" :key="forceUpdate">
  11. <view class="select-col">
  12. <text class="select-label">仓库</text>
  13. <picker @change="e => handlePicker(e, warehouseList, 'warehouseName', 'warehouseId')" :disabled="warehouseDisabled" :value="pickerIndex" :range="warehouseList" range-key="name">
  14. <text class="select-label">{{ formData.warehouseName ? formData.warehouseName : '请选择' }}</text>
  15. <!-- <u-input :value="formData.warehouseName" disableColor="#ffffff" placeholder="请选择" disabled type="select" /> -->
  16. </picker>
  17. <!-- <uni-data-select
  18. v-model="warehouse"
  19. v-if="!warehouseDisabled"
  20. :localdata="warehouseList"
  21. ></uni-data-select> -->
  22. <!-- <template v-else> {{ formData.warehouse.name }}</template> -->
  23. </view>
  24. <view class="select-col">
  25. <text class="select-label">库区</text>
  26. <picker @change="e => handlePicker(e, areaList, 'areaName', 'area')" :value="pickerIndex" :range="areaList" range-key="name" :disabled="!formData.warehouseId">
  27. <text class="select-label">{{ formData.areaName ? formData.areaName : '请选择' }}</text>
  28. <!-- <u-input @click.native="areaClick" :value="formData.areaName" disableColor="#ffffff" placeholder="请选择" type="select" /> -->
  29. </picker>
  30. <!-- <uni-data-select
  31. v-model="area"
  32. :localdata="areaList"
  33. ></uni-data-select> -->
  34. </view>
  35. <view class="select-col">
  36. <text class="select-label">货架</text>
  37. <picker @change="e => handlePicker(e, shelvesList, 'shelvesName', 'shelves')" :value="pickerIndex" :range="shelvesList" :disabled="!formData.area" range-key="name">
  38. <text class="select-label">{{ formData.shelvesName ? formData.shelvesName : '请选择' }}</text>
  39. <!-- <u-input @click.native="shelvesClick" :value="formData.shelvesName" disableColor="#ffffff" placeholder="请选择" disabled type="select" /> -->
  40. </picker>
  41. <!-- <uni-data-select
  42. v-model="shelves"
  43. :localdata="shelvesList"
  44. ></uni-data-select> -->
  45. </view>
  46. <view class="select-col">
  47. <text class="select-label">货位</text>
  48. <picker @change="e => handlePicker(e, freightList, 'freightName', 'freight')" :value="pickerIndex" :range="freightList" :disabled="!formData.shelves" range-key="name">
  49. <text class="select-label">{{ formData.freightName ? formData.freightName : '请选择' }}</text>
  50. </picker>
  51. </view>
  52. </view>
  53. <!-- <scroll-view>
  54. <view class="content-box" :key="forceUpdate">
  55. <view
  56. v-for="p in locationList"
  57. :key="p.id"
  58. class="box"
  59. @click="cur = p"
  60. :class="{ active: cur.goodsAllocationId == p.goodsAllocationId }"
  61. :style="{
  62. 'background-color': getStatus(p.allocationStatus).color,
  63. cursor: [1, 2].includes(p.allocationStatus) ? 'pointer' : 'not-allowed'
  64. }">
  65. {{ p.goodsAllocationCode }}
  66. </view>
  67. <view class="placeholder-box"></view>
  68. <view class="placeholder-box"></view>
  69. <view class="placeholder-box"></view>
  70. <view class="placeholder-box"></view>
  71. </view>
  72. </scroll-view> -->
  73. <view class="footer">
  74. <uni-button @tap="cancel">取消</uni-button>
  75. <uni-button @tap="handleSelect" type="success" class="confim">确认</uni-button>
  76. </view>
  77. </uni-popup>
  78. </view>
  79. </template>
  80. <script>
  81. import { postJ } from '@/utils/api.js'
  82. import { getWarehouseList, getWarehouseTrees } from '@/api/warehouseManagement'
  83. import ScanCode from '@/components/ScanCode.vue'
  84. const warehouseDefinition_locationStatus = [
  85. { id: 1, label: '空置', color: 'rgba(202, 249, 130, 1)' },
  86. { id: 2, label: '在用', color: 'rgba(129, 211, 248, 1)' },
  87. { id: 3, label: '已满', color: 'rgba(255, 14, 14, 1)' },
  88. { id: 4, label: '失效', color: 'rgba(215, 215, 215, 1)' }
  89. ]
  90. export default {
  91. components: {
  92. ScanCode
  93. },
  94. props: {
  95. // 主动关闭
  96. selfClose: {
  97. type: Boolean,
  98. default: false
  99. }
  100. },
  101. data() {
  102. return {
  103. treeList: [],
  104. pickerIndex: 0,
  105. forceUpdate: false,
  106. warehouseDisabled: false,
  107. visible: false,
  108. value: '',
  109. row: {},
  110. cur: {},
  111. formData: {
  112. // warehouse: {},
  113. // area: {},
  114. // shelves: {},
  115. warehouseName: '',
  116. warehouseId: '',
  117. area: '',
  118. areaName: '',
  119. shelves: '',
  120. shelvesName: '',
  121. freight: '',
  122. freightName: ''
  123. },
  124. warehouse: '',
  125. area: '',
  126. areaName: '',
  127. shelves: '',
  128. shelvesName: '',
  129. warehouseList: [],
  130. callback: null
  131. }
  132. },
  133. computed: {
  134. areaList() {
  135. this.formData.areaName = ''
  136. this.formData.area = ''
  137. this.formData.shelvesName = ''
  138. this.formData.shelves = ''
  139. console.log('this.treeList-----222----', this.treeList)
  140. return this.treeList?.length > 0 && this.formData.warehouseId ? this.treeList.filter(item => item.id == this.formData.warehouseId)[0].children : []
  141. // return (this.warehouseList.find(i => i.id === this.formData.warehouseId)?.wareHouseArea || []).map(i => ({
  142. // name: i.areaName,
  143. // id: i.areaId,
  144. // ...i
  145. // }))
  146. },
  147. shelvesList() {
  148. this.formData.shelvesName = ''
  149. this.formData.shelves = ''
  150. console.log('this.formData.area---------', this.formData.area)
  151. return this.formData.area ? this.areaList.filter(item => item.id == this.formData.area)[0].children : []
  152. // return (this.areaList.find(i => i.areaId === this.formData.area)?.wareHouseGoodsshelves || []).map(i => ({
  153. // name: i.goodsshelvesCode,
  154. // id: i.goodsshelvesId,
  155. // ...i
  156. // }))
  157. },
  158. freightList() {
  159. this.formData.freightName = ''
  160. this.formData.freight = ''
  161. console.log('formData.freight------', this.formData.shelves)
  162. console.log(this.shelvesList)
  163. return this.formData.shelves ? this.shelvesList.filter(item => item.id == this.formData.shelves)[0].children : []
  164. },
  165. locationList() {
  166. return (this.shelvesList.find(i => i.goodsshelvesId === this.formData.shelves)?.wareHouseGoodsAllocation || []).map(i => ({
  167. name: i.goodsAllocationCode,
  168. id: i.goodsAllocationId,
  169. ...i
  170. }))
  171. }
  172. },
  173. created() {
  174. this._getWarehouseChildren()
  175. this.getTreeData()
  176. },
  177. mounted() {},
  178. methods: {
  179. async getTreeData() {
  180. try {
  181. let res = await getWarehouseTrees({ factoriesId: '1829469035436822529' })
  182. this.treeList = res
  183. } catch (error) {
  184. console.log(error)
  185. }
  186. },
  187. scancodedate(data) {
  188. this.qrContent = data.code.trim()
  189. this.getData()
  190. },
  191. initScan() {
  192. this.$store.commit('app/SET_SCANCODEDATE', 'warehouse')
  193. const _this = this
  194. uni.$off('warehouse') // 每次进来先 移除全局自定义事件监听器
  195. uni.$on('warehouse', function (data) {
  196. _this.qrContent = data.code.trim()
  197. _this.getData()
  198. })
  199. },
  200. handleScan() {
  201. const _this = this
  202. uni.scanCode({
  203. onlyFromCamera: true,
  204. success: function (res) {
  205. console.log('条码类型:' + res.scanType)
  206. console.log('条码内容:' + res.result)
  207. _this.isCamera = true
  208. _this.qrContent = res.result.trim()
  209. _this.getData()
  210. }
  211. })
  212. },
  213. open(warehouse, callback) {
  214. console.log('warehouse--------', warehouse)
  215. this.cur = {}
  216. this.formData.areaName = ''
  217. this.formData.area = ''
  218. this.formData.shelvesName = ''
  219. this.formData.shelves = ''
  220. this.formData.freight = ''
  221. this.formData.freightName = ''
  222. if (warehouse) {
  223. this.formData.type = warehouse.type
  224. this.formData.warehouseName = warehouse.name
  225. this.formData.warehouseId = warehouse.id
  226. this.warehouseDisabled = !!warehouse?.id
  227. } else {
  228. this.formData.warehouseName = ''
  229. this.formData.warehouseId = ''
  230. }
  231. this.$refs.popup.open('bottom')
  232. this.visible = true
  233. this.initScan()
  234. this.callback = callback
  235. },
  236. openDefault(warehouse, callback) {
  237. if (warehouse) {
  238. this.cur = warehouse
  239. this.cur.goodsAllocationId = warehouse.cargoSpaceId
  240. this.cur.goodsAllocationCode = warehouse.cargoSpaceCode
  241. this.formData.warehouseName = warehouse?.warehouseName
  242. this.formData.warehouseId = warehouse?.warehouseId
  243. this.$nextTick(() => {
  244. this.formData.area = warehouse?.areaId || ''
  245. this.$nextTick(() => {
  246. this.formData.shelves = warehouse?.shelfId || ''
  247. })
  248. })
  249. }
  250. this.$refs.popup.open('bottom')
  251. this.visible = true
  252. this.initScan()
  253. this.callback = callback
  254. },
  255. shelvesClick() {
  256. if (!this.formData.area) {
  257. uni.showToast({
  258. title: '请先选择库区!',
  259. icon: 'none'
  260. })
  261. }
  262. },
  263. areaClick() {
  264. if (!this.formData.warehouseId) {
  265. uni.showToast({
  266. title: '请先选择库区!',
  267. icon: 'none'
  268. })
  269. }
  270. },
  271. // 根据条码请求设备数据 @_@
  272. getData() {
  273. let par = {
  274. barType: this.qrContent.split('@_@')[1] || 0,
  275. qrContent: this.qrContent
  276. }
  277. if (!['2', '7'].includes(par.barType)) {
  278. return uni.showToast({
  279. title: '请扫描货架或货位码',
  280. icon: 'none'
  281. })
  282. }
  283. // postJ(this.apiUrl + "/scan/getAssetInfo", par).then((res) => {
  284. // let data = res.data;
  285. // console.log(data, "qrContent");
  286. // this.setWarehosue(data, par.barType);
  287. // });
  288. },
  289. setWarehosue(data, barType) {
  290. if (this.warehouseDisabled) {
  291. // 选定仓库
  292. if (data.warehouseId != this.formData.warehouseId) {
  293. uni.showToast({
  294. title: `请扫描${this.formData.warehouseName}下的${barType == 2 ? '货位' : '货架'}`,
  295. icon: 'none'
  296. })
  297. return
  298. }
  299. }
  300. this.cur = {}
  301. this.formData.area = ''
  302. this.formData.areaName = ''
  303. // this.cur.goodsAllocationId = data.cargoSpaceId
  304. // this.cur.goodsAllocationCode = data.cargoSpaceCode
  305. this.formData.warehouseName = data?.warehouseName
  306. this.formData.warehouseId = data?.warehouseId
  307. this.$nextTick(() => {
  308. this.formData.area = data?.warehouseAreaId || ''
  309. this.formData.areaName = data?.warehouseAreaName || ''
  310. this.$nextTick(() => {
  311. this.formData.shelves = data?.warehouseAreaGoodsId || data?.id || ''
  312. this.formData.shelvesName = data?.warehouseAreaGoodsCode || data?.goodsshelvesCode || ''
  313. })
  314. })
  315. if (barType == 2) {
  316. this.cur = {
  317. allocationStatus: data.allocationStatus,
  318. goodsAllocationCode: data.goodsAllocationCode,
  319. goodsAllocationId: data.id,
  320. id: data.id
  321. }
  322. }
  323. },
  324. cancel() {
  325. this.warehouse = ''
  326. this.$refs.popup.close()
  327. this.visible = false
  328. this.$store.commit('app/RESET_SCANCODEDATE')
  329. },
  330. // 抬头下拉信息保存
  331. handlePicker(e, list, nameKey, idKey) {
  332. console.log('-------------点击了--')
  333. if (idKey) {
  334. this.formData[idKey] = list[e?.detail.value]?.id
  335. }
  336. if (nameKey) {
  337. this.formData[nameKey] = list[e?.detail.value]?.name
  338. }
  339. },
  340. getStatus(id) {
  341. return warehouseDefinition_locationStatus.find(item => item.id === id) || {}
  342. },
  343. handleSelect() {
  344. const data = {}
  345. data.warehouseId = this.formData.warehouseId
  346. data.warehouseName = this.formData.warehouseName
  347. data.areaId = this.formData.area
  348. data.areaName = this.formData.areaName
  349. data.shelfId = this.formData.shelves
  350. data.shelfCode = this.formData.shelvesName
  351. data.cargoSpaceId = this.formData.freight
  352. data.cargoSpaceCode = this.formData.freightName
  353. this.callback && this.callback(data)
  354. this.$emit('success', data)
  355. if (!this.selfClose) {
  356. this.cancel()
  357. }
  358. },
  359. // handleSelect() {
  360. // if (!this.cur?.id) {
  361. // uni.showToast({
  362. // title: '请选择货位',
  363. // icon: 'none'
  364. // })
  365. // return
  366. // }
  367. // if (this.formData.type == 'out') {
  368. // if (this.cur.allocationStatus === 4) {
  369. // uni.showToast({
  370. // title: '失效的货位无法选择',
  371. // icon: 'none'
  372. // })
  373. // return
  374. // } else if (this.cur.allocationStatus === 1) {
  375. // uni.showToast({
  376. // title: '当前货位无货物!',
  377. // icon: 'none'
  378. // })
  379. // return
  380. // }
  381. // } else if (![1, 2].includes(this.cur.allocationStatus)) {
  382. // uni.showToast({
  383. // title: '已满和失效的货位无法选择',
  384. // icon: 'none'
  385. // })
  386. // return
  387. // }
  388. // const data = {}
  389. // data.warehouseId = this.formData.warehouseId
  390. // data.warehouseName = this.formData.warehouseName
  391. // data.areaId = this.formData.area
  392. // data.areaName = this.formData.areaName
  393. // data.shelfId = this.formData.shelves
  394. // data.shelfCode = this.formData.shelvesName
  395. // data.cargoSpaceId = this.cur.goodsAllocationId
  396. // data.cargoSpaceCode = this.cur.goodsAllocationCode
  397. // this.callback && this.callback(data)
  398. // this.$emit('success', data)
  399. // if (!this.selfClose) {
  400. // this.cancel()
  401. // }
  402. // },
  403. async _getWarehouseChildren() {
  404. let res = await getWarehouseList()
  405. this.warehouseList = res.data
  406. // const res = await postJ(this.apiUrl + '/outInWarehouse/select/getWarehouseChildren')
  407. // if (res?.success) {
  408. // this.warehouseList = res.data.map(i => ({
  409. // name: i.name,
  410. // id: i.id,
  411. // ...i
  412. // }))
  413. // }
  414. }
  415. }
  416. }
  417. </script>
  418. <style lang="scss" scoped>
  419. .title {
  420. font-size: 32rpx;
  421. font-weight: bold;
  422. text-align: center;
  423. line-height: 80rpx;
  424. background-color: $j-primary-border-green;
  425. color: #fff;
  426. .btn {
  427. position: absolute;
  428. right: 0rpx;
  429. top: 0;
  430. display: flex;
  431. justify-content: center;
  432. align-items: center;
  433. height: 80rpx;
  434. padding-right: 30rpx;
  435. }
  436. }
  437. .select-group {
  438. display: flex;
  439. flex-wrap: wrap;
  440. .select-col {
  441. width: 50%;
  442. display: flex;
  443. align-items: center;
  444. padding: 20rpx;
  445. box-sizing: border-box;
  446. .select-label {
  447. width: 5em;
  448. }
  449. }
  450. }
  451. .content-box {
  452. display: flex;
  453. justify-content: space-between;
  454. align-content: flex-start;
  455. flex-wrap: wrap;
  456. max-height: 60vh;
  457. min-height: 40vh;
  458. overflow: auto;
  459. padding: 0 12rpx;
  460. .box {
  461. cursor: pointer;
  462. min-width: 120rpx;
  463. padding: 0 10rpx;
  464. height: 80rpx;
  465. margin-right: 6rpx;
  466. margin-bottom: 12rpx;
  467. line-height: 80rpx;
  468. text-align: center;
  469. &.active {
  470. box-shadow: 2px 2px 2px 2px #ccc;
  471. }
  472. }
  473. .placeholder-box {
  474. width: 120rpx;
  475. }
  476. }
  477. .footer {
  478. display: flex;
  479. justify-content: space-between;
  480. button {
  481. width: 50%;
  482. border: none;
  483. border-radius: 0;
  484. }
  485. .confim {
  486. background-color: $j-primary-green;
  487. color: #fff;
  488. }
  489. }
  490. </style>