WarehouseChoose.vue 14 KB

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