index.vue 10.2 KB
Newer Older
Marcus's avatar
Marcus committed
1 2
<template>
  <div>
3 4
    <div class="area-code">{{ selected.join(', ') }}</div>
    <el-button v-show="!readonly" type="primary" size="mini" @click="handleOpen">选择</el-button>
Marcus's avatar
Marcus committed
5 6

    <el-dialog
Marcus's avatar
Marcus committed
7
      title="储位"
Marcus's avatar
Marcus committed
8 9 10 11
      :visible.sync="dialogVisible"
      width="30%"
      append-to-body
      :before-close="handleClose">
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
      <el-tabs v-model="activeName" type="card" @tab-click="activeWarehouse = {}">
        <el-tab-pane :label="item.name" :name="'' + index" v-for="(item, index) in area" :key="index">
          <div>
            <div style="text-align: center">{{$t('区域')}}</div>
            <div style="background-color: #efefef;padding: 10px 10px 0;border: #dcdcdc solid 1px;border-radius: 2px">
              <el-row :gutter="20">
                <el-col :span="12" v-for="warehouse in item.children" :key="warehouse.id">
                  <div
                    class="warehouse-block"
                    :class="{'warehouse-block-selected': warehouse.selected, 'warehouse-block-active': warehouse.id === activeWarehouse.id}"
                    @click="handleSelectWarehouse(warehouse)"
                  >
                    {{ warehouse.name }}
                  </div>
                </el-col>
              </el-row>
            </div>
          </div>
          <div>
            <div style="text-align: center">{{$t('仓位')}}</div>
            <div class="position-group">
              <div class="position" v-for="position in activeWarehouse.positionList" :key="position.id" @click="handleSelectPosition(position)">
                <template v-if="position.children">
                  <div
                    class="position-item"
                    v-for="item in position.children"
                    :key="item.id"
                    @click.stop="handleSelectPositionChild(item)"
                    :class="{'position-item-active': item.selected}">
                    {{ item.code }}
                  </div>
                </template>
                <template v-else>
                  <div
                    class="position-item"

                    :class="{'position-item-active': position.selected}">
                    {{ position.code }}
                  </div>
                </template>
              </div>
            </div>
          </div>
          <el-divider></el-divider>
          {{$t('已选择')}}:{{ selected.join(', ') }}
          <el-divider></el-divider>
        </el-tab-pane>
      </el-tabs>
Marcus's avatar
Marcus committed
60 61
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
62
    <el-button type="primary" @click="handleSave">确 定</el-button>
Marcus's avatar
Marcus committed
63 64 65 66 67 68
  </span>
    </el-dialog>
  </div>
</template>

<script>
69
import {getByWarehouseId} from "@/api/ecw/warehouseArea"
70
import { updateWarehouseInLocation } from "@/api/ecw/order"
71

Marcus's avatar
Marcus committed
72 73 74 75
export default {
  name: "WarehouseAreaSelect",

  props: {
76
    value: {
Marcus's avatar
Marcus committed
77 78
      type: Array,
      default: () => []
79 80
    },
    orderId: Number,
81 82 83
    orderItemId: Number,
    // 入仓记录id
    warehouseInId: Number,
84 85 86 87 88 89 90 91 92 93 94 95
    warehouseId: {
      type: Number,
      default: undefined
    },
    // 是否入仓修改
    isEditing: {
      type: Boolean,
      default: false
    },
    readonly: {
      type: Boolean,
      default: false
Marcus's avatar
Marcus committed
96 97 98 99 100
    }
  },

  data() {
    return {
101 102 103 104
      dialogVisible: false,
      activeName: '0',
      activeWarehouse: {},
      area: [],
Marcus's avatar
Marcus committed
105 106 107
    }
  },

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
  mounted() {
    this.initArea()
  },

  computed: {
    // code array
    selected() {
      const result = []

      this.area?.forEach(e => {
        // 仓库
        e.children?.forEach(f => {
          // 区域
          if (f.selected) result.push(f.code)
          else f.positionList?.forEach(g => {
            // 位置
            if (g.selected) result.push(f.code + g.code)
            else if(g.children) g.children?.forEach(k => {
              // 子位置
              if (k.selected) result.push(f.code + k.code)
            })
          })
        })
      })

      return result
    },
    inputValue(){
      const result = []

      this.area?.forEach(e => {
        // 仓库
        e.children?.forEach(f => {
          // 区域
          if (f.selected) result.push({
            orderId: this.orderId,
            wareId: f.pid,
dragondean@qq.com's avatar
dragondean@qq.com committed
145 146
            areaId: f.id,
            locationName: f.code
147 148 149 150 151 152 153 154
          })
          else {
            f.positionList?.forEach(g => {
              // 位置
              if (g.selected) result.push({
                orderId: this.orderId,
                wareId: g.domainId,
                areaId: g.areaId,
dragondean@qq.com's avatar
dragondean@qq.com committed
155 156
                locationId: g.id,
                locationName: f.code + g.code
157 158 159 160 161 162 163
              })
              else g.children?.forEach(k => {
                // 子位置
                if (k.selected) result.push({
                  orderId: this.orderId,
                  wareId: k.domainId,
                  areaId: k.areaId,
dragondean@qq.com's avatar
dragondean@qq.com committed
164 165
                  locationId: k.id,
                  locationName: f.code + k.code
166 167 168 169
                })
              })
            })
          }
Marcus's avatar
Marcus committed
170
        })
171 172 173
      })

      return result
Marcus's avatar
Marcus committed
174
    }
175 176 177 178 179
  },

  methods: {
    handleOpen(){
      this.dialogVisible = true
180
      // this.initArea()
181 182
    },
    handleSave(){
Marcus's avatar
Marcus committed
183 184 185 186 187 188 189
      this.$nextTick(() => {
        const data = this.inputValue.map(e => {
          return {
            ...e,
            orderItemId: this.orderItemId,
            warehouseInId: this.warehouseInId
          }
190
        })
Marcus's avatar
Marcus committed
191 192 193
        this.$emit('input', data)
        this.dialogVisible = false

194
        if (this.isEditing || this.warehouseInId) {
195 196 197 198
            updateWarehouseInLocation({
              "orderId": this.orderId,
              "orderItemId": this.orderItemId,
              "orderLocationUpdateReqVOList": data,
199
              "warehouseInId": this.warehouseInId
200
            }).then(() => {
Marcus's avatar
Marcus committed
201 202
              this.$message.success('储位修改成功')
            })
Marcus's avatar
Marcus committed
203 204
        }
      })
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
    },
    handleClose() {
      this.dialogVisible = false
    },
    handleSelectWarehouse(warehouse) {
      this.activeWarehouse = warehouse
      if (!!warehouse.selected) {
        warehouse.selected = false
        return
      } else if(this.activeWarehouseId !== warehouse.id) {
        this.activeWarehouseId = warehouse.id
        if (this.inputValue.find(e => e.areaId === warehouse.id)){
          return
        }
      }
      warehouse.selected = true

      // 区域被选,清空该区域下的位置
      if(warehouse.positionList) warehouse.positionList?.forEach(g => {
        g.selected = false
        g.children?.forEach(k => {
          k.selected = false
        })
      })
    },
    handleSelectPositionChild(position) {
      if (!!position.selected) {
        position.selected = false

        // 反选位置时,检查父区域下是否所有位置被反选,若是,选父区域
        const parentAre = this.area.find(e => e.id === position.domainId).children.find(f => f.id === position.areaId)
        if (!parentAre.selected) {
          // 检查父区域下是否所有位置被反选
          let hasSelected = false
          parentAre.positionList?.forEach(g => {
            // 位置
            g.children?.forEach(k => {
              // 子位置
              if (k.selected) hasSelected = true
            })
          })
          // 所有子位置被反选,选父区域
          if (!hasSelected) parentAre.selected = true
        }
      } else {
        position.selected = true

        // 选位置时,父区域反选
        this.area.find(e => e.id === position.domainId).children.find(f => f.id === position.areaId).selected = false

      }
    },
    handleSelectPosition(position) {
      if (!!position.selected) {
        position.selected = false
      } else {
        position.selected = true

        // 选位置时,父区域反选
        this.area.find(e => e.id === position.domainId).children.find(f => f.id === position.areaId).selected = false

      }
    },

269 270 271 272 273 274 275 276 277 278 279 280
    resetAreaTreeSelected(area) {
      area.forEach(e => {
        // 仓库
        e.children?.forEach(f => {
          // 区域
          f.selected = this.isSelected(e.id, f.id)
          if(f.positionList) f.positionList.forEach(g => {
            // 位置
            g.selected = this.isSelected(e.id, f.id, g.id)
            g.children?.forEach(k => {
              // 子位置
              k.selected = this.isSelected(e.id, f.id, k.id)
281 282 283
            })
          })
        })
284 285 286 287 288 289 290 291
      })
      return area
    },

    initArea(){
      return getByWarehouseId({ warehouseId: this.warehouseId }).then(r => {
        this.area = this.resetAreaTreeSelected(r.data)

292 293 294 295
      })
    },
    // 用于储位回显选中
    isSelected(warehouse, area, position = 0){
296
      return !!this.value.find(e => {
297 298
        // 最后一个条件不能用!e.locationId来判断,会导致选择了没有locationId的全部被选中,上次改这里忘记什么原因了,下次复现再来调整
        return warehouse === e.wareId && area === e.areaId && (position === e.locationId || e.locationId == undefined)
299
      })
300
    },
Marcus's avatar
Marcus committed
301 302 303 304 305
  }
}
</script>

<style scoped>
306 307 308 309
.area-code{
  display: inline-block;
  margin-right: 15px;
}
Marcus's avatar
Marcus committed
310

311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
.warehouse-block{
  background-color: white;
  border-radius: 5px;
  height: 42px;
  line-height: 42px;
  text-align: center;
  margin-bottom: 15px;
  cursor: pointer;
  transition: 0.5s;
  box-shadow: #bfbfbf 3px 3px 14px 0;
  user-select: none;
}
.warehouse-block:hover{
  opacity: 0.9;
  transition: 0.5s;
  transform: scale(1.02);
  box-shadow: #8f8f8f 7px 5px 14px 0;
}
.warehouse-block-active{
  box-shadow: #b1a4cb 7px 5px 14px 0;
  transform: scale(1.04);
  background-color: #9ab7e1;
  color: #ffffff;
}
.warehouse-block-selected{
  color: #ffffff;
  background-color: #4085e3;
}
.position-group{
  display: flex;
  background-color: #EFEFEF;
  border: 1px #EFEFEF solid;
  gap: 1px;
  min-height: 64px;
  flex-flow: wrap;
}
.position{
  width: calc(20% - 1px);
  height: 64px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  user-select: none;
}
.position-item{
  width: 100%;
  background-color: #FFFFFF;
  flex: 1;
  cursor: pointer;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
}
.position-item:hover{
  background-color: #d7dbe3;
}
.position-item-active{
  background-color: #4085e3;
  color: white;
}
.position-item-active:hover{
  background-color: #4085e3;
  opacity: 0.8;
}
Marcus's avatar
Marcus committed
376
</style>