| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517 |
- <template>
- <view>
- <uni-popup ref="popup" background-color="#fff" :mask-click="false">
- <view class="title"
- >选择货位
- <view class="btn">
- <u-icon
- name="scan"
- color="#fff"
- size="80"
- @click="handleScan"
- ></u-icon>
- </view>
- </view>
- <view class="select-group" :key="forceUpdate">
- <view class="select-col">
- <text class="select-label">仓库</text>
- <picker
- @change="
- (e) =>
- handlePicker(e, warehouseList, 'warehouseName', 'warehouseId')
- "
- :disabled="warehouseDisabled"
- :value="pickerIndex"
- :range="warehouseList"
- range-key="name"
- ><u-input
- :value="formData.warehouseName"
- disableColor="#ffffff"
- placeholder="请选择"
- disabled
- type="select"
- /></picker>
- <!-- <uni-data-select
- v-model="warehouse"
- v-if="!warehouseDisabled"
- :localdata="warehouseList"
- ></uni-data-select> -->
- <!-- <template v-else> {{ formData.warehouse.name }}</template> -->
- </view>
- <view class="select-col">
- <text class="select-label">库区</text>
- <picker
- @change="(e) => handlePicker(e, areaList, 'areaName', 'area')"
- :value="pickerIndex"
- :range="areaList"
- range-key="name"
- :disabled="!formData.warehouseId"
- ><u-input
- @click.native="areaClick"
- :value="formData.areaName"
- disableColor="#ffffff"
- placeholder="请选择"
- disabled
- type="select"
- /></picker>
- <!-- <uni-data-select
- v-model="area"
- :localdata="areaList"
- ></uni-data-select> -->
- </view>
- <view class="select-col">
- <text class="select-label">货架</text>
- <picker
- @change="
- (e) => handlePicker(e, shelvesList, 'shelvesName', 'shelves')
- "
- :value="pickerIndex"
- :range="shelvesList"
- :disabled="!formData.area"
- range-key="name"
- ><u-input
- @click.native="shelvesClick"
- :value="formData.shelvesName"
- disableColor="#ffffff"
- placeholder="请选择"
- disabled
- type="select"
- /></picker>
- <!-- <uni-data-select
- v-model="shelves"
- :localdata="shelvesList"
- ></uni-data-select> -->
- </view>
- </view>
- <scroll-view>
- <view class="content-box" :key="forceUpdate">
- <view
- v-for="p in locationList"
- :key="p.id"
- class="box"
- @click="cur = p"
- :class="{ active: cur.goodsAllocationId == p.goodsAllocationId }"
- :style="{
- 'background-color': getStatus(p.allocationStatus).color,
- cursor: [1, 2].includes(p.allocationStatus)
- ? 'pointer'
- : 'not-allowed',
- }"
- >
- {{ p.goodsAllocationCode }}
- </view>
- <view class="placeholder-box"></view>
- <view class="placeholder-box"></view>
- <view class="placeholder-box"></view>
- <view class="placeholder-box"></view>
- </view>
- </scroll-view>
- <view class="footer">
- <uni-button @tap="cancel">取消</uni-button>
- <uni-button @tap="handleSelect" type="success" class="confim"
- >确认</uni-button
- >
- </view>
- </uni-popup>
- </view>
- </template>
- <script>
- import { postJ } from "@/utils/api.js";
- import ScanCode from "@/components/ScanCode.vue";
- const warehouseDefinition_locationStatus = [
- { id: 1, label: "空置", color: "rgba(202, 249, 130, 1)" },
- { id: 2, label: "在用", color: "rgba(129, 211, 248, 1)" },
- { id: 3, label: "已满", color: "rgba(255, 14, 14, 1)" },
- { id: 4, label: "失效", color: "rgba(215, 215, 215, 1)" },
- ];
- export default {
- components: {
- ScanCode,
- },
- props: {
- // 主动关闭
- selfClose: {
- type: Boolean,
- default: false,
- },
- },
- data() {
- return {
- pickerIndex: 0,
- forceUpdate: false,
- warehouseDisabled: false,
- visible: false,
- value: "",
- row: {},
- cur: {},
- formData: {
- // warehouse: {},
- // area: {},
- // shelves: {},
- warehouseName: "",
- warehouseId: "",
- area: "",
- areaName: "",
- shelves: "",
- shelvesName: "",
- },
- warehouse: "",
- area: "",
- areaName: "",
- shelves: "",
- shelvesName: "",
- warehouseList: [],
- callback: null,
- };
- },
- computed: {
- areaList() {
- this.formData.areaName = "";
- this.formData.area = "";
- this.formData.shelvesName = "";
- this.formData.shelves = "";
- return (
- this.warehouseList.find((i) => i.id === this.formData.warehouseId)
- ?.wareHouseArea || []
- ).map((i) => ({
- name: i.areaName,
- id: i.areaId,
- ...i,
- }));
- },
- shelvesList() {
- this.formData.shelvesName = "";
- this.formData.shelves = "";
- return (
- this.areaList.find((i) => i.areaId === this.formData.area)
- ?.wareHouseGoodsshelves || []
- ).map((i) => ({
- name: i.goodsshelvesCode,
- id: i.goodsshelvesId,
- ...i,
- }));
- },
- locationList() {
- return (
- this.shelvesList.find((i) => i.goodsshelvesId === this.formData.shelves)
- ?.wareHouseGoodsAllocation || []
- ).map((i) => ({
- name: i.goodsAllocationCode,
- id: i.goodsAllocationId,
- ...i,
- }));
- },
- },
- created() {
- this._getWarehouseChildren();
- },
- mounted() {},
- methods: {
- scancodedate(data) {
- this.qrContent = data.code.trim();
- this.getData();
- },
- initScan() {
- this.$store.commit("app/SET_SCANCODEDATE", "warehouse");
- const _this = this;
- uni.$off("warehouse"); // 每次进来先 移除全局自定义事件监听器
- uni.$on("warehouse", function (data) {
- _this.qrContent = data.code.trim();
- _this.getData();
- });
- },
- handleScan() {
- const _this = this;
- uni.scanCode({
- onlyFromCamera: true,
- success: function (res) {
- console.log("条码类型:" + res.scanType);
- console.log("条码内容:" + res.result);
- _this.isCamera = true;
- _this.qrContent = res.result.trim();
- _this.getData();
- },
- });
- },
- open(warehouse, callback) {
- this.cur = {};
- this.formData.warehouseName = "";
- this.formData.warehouseId = "";
- this.formData.areaName = "";
- this.formData.shelvesName = "";
- this.formData.shelves = "";
- if (warehouse) {
- this.formData.type = warehouse.type;
- this.formData.warehouseName = warehouse.name;
- this.formData.warehouseId = warehouse.id;
- this.warehouseDisabled = !!warehouse?.id;
- }
- this.$refs.popup.open("bottom");
- this.visible = true;
- this.initScan();
- this.callback = callback;
- },
- openDefault(warehouse, callback) {
- if (warehouse) {
- this.cur = warehouse;
- this.cur.goodsAllocationId = warehouse.cargoSpaceId;
- this.cur.goodsAllocationCode = warehouse.cargoSpaceCode;
- this.formData.warehouseName = warehouse?.warehouseName;
- this.formData.warehouseId = warehouse?.warehouseId;
- this.$nextTick(() => {
- this.formData.area = warehouse?.areaId || "";
- this.$nextTick(() => {
- this.formData.shelves = warehouse?.shelfId || "";
- });
- });
- }
- this.$refs.popup.open("bottom");
- this.visible = true;
- this.initScan();
- this.callback = callback;
- },
- shelvesClick() {
- if (!this.formData.area) {
- uni.showToast({
- title: "请先选择库区!",
- icon: "none",
- });
- }
- },
- areaClick() {
- if (!this.formData.warehouseId) {
- uni.showToast({
- title: "请先选择库区!",
- icon: "none",
- });
- }
- },
- // 根据条码请求设备数据 @_@
- getData() {
- let par = {
- barType: this.qrContent.split("@_@")[1] || 0,
- qrContent: this.qrContent,
- };
- if (!["2", "7"].includes(par.barType)) {
- return uni.showToast({
- title: "请扫描货架或货位码",
- icon: "none",
- });
- }
- postJ(this.apiUrl + "/scan/getAssetInfo", par).then((res) => {
- let data = res.data;
- console.log(data, "qrContent");
- this.setWarehosue(data, par.barType);
- });
- },
- setWarehosue(data, barType) {
- if (this.warehouseDisabled) {
- // 选定仓库
- if (data.warehouseId != this.formData.warehouseId) {
- uni.showToast({
- title: `请扫描${this.formData.warehouseName}下的${
- barType == 2 ? "货位" : "货架"
- }`,
- icon: "none",
- });
- return;
- }
- }
- this.cur = {};
- this.formData.area = "";
- this.formData.areaName = "";
- // this.cur.goodsAllocationId = data.cargoSpaceId
- // this.cur.goodsAllocationCode = data.cargoSpaceCode
- this.formData.warehouseName = data?.warehouseName;
- this.formData.warehouseId = data?.warehouseId;
- this.$nextTick(() => {
- this.formData.area = data?.warehouseAreaId || "";
- this.formData.areaName = data?.warehouseAreaName || "";
- this.$nextTick(() => {
- this.formData.shelves = data?.warehouseAreaGoodsId || data?.id || "";
- this.formData.shelvesName =
- data?.warehouseAreaGoodsCode || data?.goodsshelvesCode || "";
- });
- });
- if (barType == 2) {
- this.cur = {
- allocationStatus: data.allocationStatus,
- goodsAllocationCode: data.goodsAllocationCode,
- goodsAllocationId: data.id,
- id: data.id,
- };
- }
- },
- cancel() {
- this.warehouse = "";
- this.$refs.popup.close();
- this.visible = false;
- this.$store.commit("app/RESET_SCANCODEDATE");
- },
- // 抬头下拉信息保存
- handlePicker(e, list, nameKey, idKey) {
- if (idKey) {
- this.formData[idKey] = list[e?.detail.value]?.id;
- }
- if (nameKey) {
- this.formData[nameKey] = list[e?.detail.value]?.name;
- }
- },
- getStatus(id) {
- return (
- warehouseDefinition_locationStatus.find((item) => item.id === id) || {}
- );
- },
- handleSelect() {
- if (!this.cur?.id) {
- uni.showToast({
- title: "请选择货位",
- icon: "none",
- });
- return;
- }
- if (this.formData.type == "out") {
- if (this.cur.allocationStatus === 4) {
- uni.showToast({
- title: "失效的货位无法选择",
- icon: "none",
- });
- return;
- } else if (this.cur.allocationStatus === 1) {
- uni.showToast({
- title: "当前货位无货物!",
- icon: "none",
- });
- return;
- }
- } else if (![1, 2].includes(this.cur.allocationStatus)) {
- uni.showToast({
- title: "已满和失效的货位无法选择",
- icon: "none",
- });
- return;
- }
- const data = {};
- data.warehouseId = this.formData.warehouseId;
- data.warehouseName = this.formData.warehouseName;
- data.areaId = this.formData.area;
- data.areaName = this.formData.areaName;
- data.shelfId = this.formData.shelves;
- data.shelfCode = this.formData.shelvesName;
- data.cargoSpaceId = this.cur.goodsAllocationId;
- data.cargoSpaceCode = this.cur.goodsAllocationCode;
- this.callback && this.callback(data);
- this.$emit("success", data);
- if (!this.selfClose) {
- this.cancel();
- }
- },
- async _getWarehouseChildren() {
- const res = await postJ(
- this.apiUrl + "/outInWarehouse/select/getWarehouseChildren"
- );
- if (res?.success) {
- this.warehouseList = res.data.map((i) => ({
- name: i.name,
- id: i.id,
- ...i,
- }));
- }
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .title {
- font-size: 32rpx;
- font-weight: bold;
- text-align: center;
- line-height: 80rpx;
- background-color: $j-primary-border-green;
- color: #fff;
- .btn {
- position: absolute;
- right: 0rpx;
- top: 0;
- display: flex;
- justify-content: center;
- align-items: center;
- height: 80rpx;
- padding-right: 30rpx;
- }
- }
- .select-group {
- display: flex;
- flex-wrap: wrap;
- .select-col {
- width: 50%;
- display: flex;
- align-items: center;
- padding: 20rpx;
- box-sizing: border-box;
- .select-label {
- width: 5em;
- }
- }
- }
- .content-box {
- display: flex;
- justify-content: space-between;
- align-content: flex-start;
- flex-wrap: wrap;
- max-height: 60vh;
- min-height: 40vh;
- overflow: auto;
- padding: 0 12rpx;
- .box {
- cursor: pointer;
- min-width: 120rpx;
- padding: 0 10rpx;
- height: 80rpx;
- margin-right: 6rpx;
- margin-bottom: 12rpx;
- line-height: 80rpx;
- text-align: center;
- &.active {
- box-shadow: 2px 2px 2px 2px #ccc;
- }
- }
- .placeholder-box {
- width: 120rpx;
- }
- }
- .footer {
- display: flex;
- justify-content: space-between;
- button {
- width: 50%;
- border: none;
- border-radius: 0;
- }
- .confim {
- background-color: $j-primary-green;
- color: #fff;
- }
- }
- </style>
|