WarehouseChoose.vue 15 KB

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