index.vue 9.39 KB
Newer Older
黄卓's avatar
黄卓 committed
1 2 3
<template>
  <div>
    <el-dialog
huhaiqing's avatar
huhaiqing committed
4
      :title="$t('选择储位')"
黄卓's avatar
黄卓 committed
5 6 7
      :visible.sync="opened"
      width="600px"
      :before-close="handleClose()"
8
      v-bind="$attrs"
黄卓's avatar
黄卓 committed
9
    >
黄卓's avatar
黄卓 committed
10
      <el-tabs v-model="activeName" type="card" @tab-click="activeWarehouse = {}">
黄卓's avatar
黄卓 committed
11 12
        <el-tab-pane :label="item.name" :name="'' + index" v-for="(item, index) in area" :key="index">
          <div>
huhaiqing's avatar
huhaiqing committed
13
            <div style="text-align: center">{{$t('区域')}}</div>
黄卓's avatar
黄卓 committed
14
            <div style="background-color: #efefef;padding: 10px 10px 0;border: #dcdcdc solid 1px;border-radius: 2px">
黄卓's avatar
黄卓 committed
15
              <el-row :gutter="20">
16
               <el-col :span="12" v-for="warehouse in item.children" :key="warehouse.id">
黄卓's avatar
黄卓 committed
17
                 <div
黄卓's avatar
黄卓 committed
18 19
                   class="warehouse-block"
                   :class="{'warehouse-block-selected': warehouse.selected, 'warehouse-block-active': warehouse.id === activeWarehouse.id}"
黄卓's avatar
黄卓 committed
20 21 22 23 24 25 26 27 28
                   @click="handleSelectWarehouse(warehouse)"
                 >
                   {{ warehouse.name }}
                 </div>
               </el-col>
              </el-row>
            </div>
          </div>
          <div>
huhaiqing's avatar
huhaiqing committed
29
            <div style="text-align: center">{{$t('仓位')}}</div>
黄卓's avatar
黄卓 committed
30
            <div class="position-group">
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
              <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>
黄卓's avatar
黄卓 committed
50 51
              </div>
            </div>
黄卓's avatar
黄卓 committed
52 53
          </div>
          <el-divider></el-divider>
huhaiqing's avatar
huhaiqing committed
54
          {{$t('已选择')}}:{{ selected.join(', ') }}
黄卓's avatar
黄卓 committed
55 56 57 58
          <el-divider></el-divider>
        </el-tab-pane>
      </el-tabs>
      <span slot="footer">
huhaiqing's avatar
huhaiqing committed
59 60
        <el-button @click="opened = false">{{$t('关闭')}}</el-button>
        <el-button type="primary" @click="handleSubmit()">{{$t('提交')}}</el-button>
黄卓's avatar
黄卓 committed
61 62 63 64 65 66
      </span>
    </el-dialog>
  </div>
</template>

<script>
67 68
import {getByWarehouseId} from '@/api/ecw/warehouseArea'
import {saveOrUpdateOrderLocation} from "@/api/ecw/order"
黄卓's avatar
黄卓 committed
69 70 71 72 73 74 75 76

export default {
  name: 'WarehouseAreaDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
77
    value: Array,
78 79 80 81
    orderId: Number,
    cityId: {
      type: Number,
      default: undefined
huhaiqing's avatar
huhaiqing committed
82 83 84 85
    },
    warehouseId: {
      type: Number,
      default: undefined
86 87 88 89 90
    },
    // 是否入仓修改
    isEditing: {
      type: Boolean,
      default: false
91
    }
黄卓's avatar
黄卓 committed
92 93 94 95 96 97 98 99
  },

  data() {
    return {
      opened: false,

      area: [],
      activeName: '0',
黄卓's avatar
黄卓 committed
100 101
      selectedWarehouse: [],
      selectedPosition: [],
Marcus's avatar
Marcus committed
102 103
      activeWarehouse: {},
      activeWarehouseId: undefined
黄卓's avatar
黄卓 committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    };
  },

  watch: {
    visible(val) {
      if (val) {
        this.opened = true
      } else {
      }
    },
    opened(val) {
      if (val) {
      } else {
        this.$emit('update:visible', false)
      }
    }
  },

  methods: {
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
    updateArea(){
      this.initArea()
    },
    initArea(){
      return getByWarehouseId({ cityId: this.cityId, warehouseId: this.warehouseId }).then(r => {
        const area = r.data
        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)
              })
            })
          })
        })
        this.area = area
      })
    },
    // 用于储位回显选中
    isSelected(warehouse, area, position = 0){
      return !!this.value.find(e => warehouse === e.wareId && area === e.areaId && position === e.locationId)
    },
Marcus's avatar
Marcus committed
151
    handleSubmit() {
152
      this.$emit('input', this.inputValue)
Marcus's avatar
Marcus committed
153
      this.opened = false
154 155 156 157 158 159 160 161
      if (this.isEditing) {
        this.$nextTick(() => {
          saveOrUpdateOrderLocation({
            "orderId": this.orderId,
            "orderLocationCreateReqVOList": this.inputValue
          })
        })
      }
Marcus's avatar
Marcus committed
162
    },
黄卓's avatar
黄卓 committed
163 164
    handleClose() {},
    handleSelectWarehouse(warehouse) {
黄卓's avatar
黄卓 committed
165 166 167
      this.activeWarehouse = warehouse
      if (!!warehouse.selected) {
        warehouse.selected = false
168
        return
Marcus's avatar
Marcus committed
169 170
      } else if(this.activeWarehouseId !== warehouse.id) {
        this.activeWarehouseId = warehouse.id
171 172 173 174 175
        if (this.inputValue.find(e => e.areaId === warehouse.id)){
          return
        }
      }
      warehouse.selected = true
黄卓's avatar
黄卓 committed
176

177 178 179 180 181
      // 区域被选,清空该区域下的位置
      if(warehouse.positionList) warehouse.positionList?.forEach(g => {
        g.selected = false
        g.children?.forEach(k => {
          k.selected = false
黄卓's avatar
黄卓 committed
182
        })
183
      })
黄卓's avatar
黄卓 committed
184
    },
185
    handleSelectPositionChild(position) {
黄卓's avatar
黄卓 committed
186 187 188 189 190 191 192 193
      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
194
          parentAre.positionList?.forEach(g => {
黄卓's avatar
黄卓 committed
195
            // 位置
huhaiqing's avatar
huhaiqing committed
196
            g.children?.forEach(k => {
黄卓's avatar
黄卓 committed
197 198 199 200 201 202 203 204 205 206 207 208 209
              // 子位置
              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

210 211 212 213 214 215 216 217 218 219 220
      }
    },
    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

黄卓's avatar
黄卓 committed
221
      }
黄卓's avatar
黄卓 committed
222 223 224 225 226
    }
  },

  mounted() {
  },
黄卓's avatar
黄卓 committed
227 228

  computed: {
229
    // code array
黄卓's avatar
黄卓 committed
230 231 232
    selected() {
      const result = []

233
      this.area?.forEach(e => {
黄卓's avatar
黄卓 committed
234
        // 仓库
235
        e.children?.forEach(f => {
黄卓's avatar
黄卓 committed
236 237
          // 区域
          if (f.selected) result.push(f.code)
238
          else f.positionList?.forEach(g => {
黄卓's avatar
黄卓 committed
239
            // 位置
240
            if (g.selected) result.push(f.code + g.code)
241
            else if(g.children) g.children?.forEach(k => {
黄卓's avatar
黄卓 committed
242
              // 子位置
243
              if (k.selected) result.push(f.code + k.code)
黄卓's avatar
黄卓 committed
244 245 246 247 248
            })
          })
        })
      })

249 250 251 252 253
      return result
    },
    inputValue(){
      const result = []

254
      this.area?.forEach(e => {
255
        // 仓库
256
        e.children?.forEach(f => {
257 258 259 260 261 262
          // 区域
          if (f.selected) result.push({
            orderId: this.orderId,
            wareId: f.pid,
            areaId: f.id
          })
263 264 265 266
          else {
            f.positionList?.forEach(g => {
              // 位置
              if (g.selected) result.push({
267
                orderId: this.orderId,
268 269 270 271 272 273 274 275 276 277 278 279
                wareId: g.domainId,
                areaId: g.areaId,
                locationId: g.id
              })
              else g.children?.forEach(k => {
                // 子位置
                if (k.selected) result.push({
                  orderId: this.orderId,
                  wareId: k.domainId,
                  areaId: k.areaId,
                  locationId: k.id
                })
280 281
              })
            })
282
          }
283 284 285
        })
      })

黄卓's avatar
黄卓 committed
286 287 288
      return result
    }
  }
黄卓's avatar
黄卓 committed
289 290 291 292 293 294 295 296 297 298
}
</script>

<style scoped>
.warehouse-block{
  background-color: white;
  border-radius: 5px;
  height: 42px;
  line-height: 42px;
  text-align: center;
黄卓's avatar
黄卓 committed
299
  margin-bottom: 15px;
黄卓's avatar
黄卓 committed
300
  cursor: pointer;
黄卓's avatar
黄卓 committed
301 302
  transition: 0.5s;
  box-shadow: #bfbfbf 3px 3px 14px 0;
Marcus's avatar
Marcus committed
303
  user-select: none;
黄卓's avatar
黄卓 committed
304
}
黄卓's avatar
黄卓 committed
305 306 307 308 309 310 311
.warehouse-block:hover{
  opacity: 0.9;
  transition: 0.5s;
  transform: scale(1.02);
  box-shadow: #8f8f8f 7px 5px 14px 0;
}
.warehouse-block-active{
Marcus's avatar
Marcus committed
312
  box-shadow: #b1a4cb 7px 5px 14px 0;
黄卓's avatar
黄卓 committed
313
  transform: scale(1.04);
Marcus's avatar
Marcus committed
314 315
  background-color: #9ab7e1;
  color: #ffffff;
黄卓's avatar
黄卓 committed
316 317
}
.warehouse-block-selected{
黄卓's avatar
黄卓 committed
318 319 320 321 322 323 324 325 326
  color: #ffffff;
  background-color: #4085e3;
}
.position-group{
  display: flex;
  background-color: #EFEFEF;
  border: 1px #EFEFEF solid;
  gap: 1px;
  min-height: 64px;
327
  flex-flow: wrap;
黄卓's avatar
黄卓 committed
328 329
}
.position{
330
  width: calc(20% - 1px);
黄卓's avatar
黄卓 committed
331 332 333 334
  height: 64px;
  display: flex;
  flex-direction: column;
  gap: 1px;
Marcus's avatar
Marcus committed
335
  user-select: none;
黄卓's avatar
黄卓 committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
}
.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;
黄卓's avatar
黄卓 committed
357 358
}
</style>