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

<script>
import { getByWarehouseId } from '@/api/ecw/warehouseArea'

export default {
dcy's avatar
dcy committed
70
  name: 'WarehouseAreaDialog',
dcy's avatar
dcy committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    value: Array,
    orderId: Number,
    cityId: {
      type: Number,
      default: undefined
    },
    warehouseId: {
      type: Number,
      default: undefined
dcy's avatar
dcy committed
85
    }
dcy's avatar
dcy committed
86 87 88 89 90 91 92 93 94 95
  },

  data() {
    return {
      opened: false,

      area: [],
      activeName: '0',
      selectedWarehouse: [],
      selectedPosition: [],
dcy's avatar
dcy committed
96 97
      activeWarehouse: {},
      activeWarehouseId: undefined
dcy's avatar
dcy committed
98 99 100 101 102 103 104 105
    };
  },

  watch: {
    visible(val) {
      if (val) {
        this.opened = true

dcy's avatar
dcy committed
106
        if (this.area.length === 0) getByWarehouseId({cityId: this.cityId,warehouseId: this.warehouseId }).then(r => {
dcy's avatar
dcy committed
107 108 109
          const area = r.data
          area.forEach(e => {
            // 仓库
dcy's avatar
dcy committed
110
            e.children?.forEach(f => {
dcy's avatar
dcy committed
111 112 113 114
              // 区域
              f.selected = false
              if(f.positionList) f.positionList.forEach(g => {
                // 位置
dcy's avatar
dcy committed
115 116
                g.selected = false
                g.children?.forEach(k => {
dcy's avatar
dcy committed
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 145
                  // 子位置
                  k.selected = false
                })
              })
            })
          })
          this.area = area
        })
      } else {
      }
    },
    opened(val) {
      if (val) {
      } else {
        this.$emit('update:visible', false)
      }
    }
  },

  methods: {
    handleSubmit() {
      this.$emit('input', this.inputValue)
      this.opened = false
    },
    handleClose() {},
    handleSelectWarehouse(warehouse) {
      this.activeWarehouse = warehouse
      if (!!warehouse.selected) {
        warehouse.selected = false
dcy's avatar
dcy committed
146 147 148 149 150 151 152 153 154
        return
      } else if(this.activeWarehouseId !== warehouse.id) {
        this.activeWarehouseId = warehouse.id
        console.log(this.inputValue.find(e => e.areaId === warehouse.id), warehouse.id)
        if (this.inputValue.find(e => e.areaId === warehouse.id)){
          return
        }
      }
      warehouse.selected = true
dcy's avatar
dcy committed
155

dcy's avatar
dcy committed
156 157 158 159 160
      // 区域被选,清空该区域下的位置
      if(warehouse.positionList) warehouse.positionList?.forEach(g => {
        g.selected = false
        g.children?.forEach(k => {
          k.selected = false
dcy's avatar
dcy committed
161
        })
dcy's avatar
dcy committed
162
      })
dcy's avatar
dcy committed
163
    },
dcy's avatar
dcy committed
164
    handleSelectPositionChild(position) {
dcy's avatar
dcy committed
165 166 167 168 169 170 171 172
      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
dcy's avatar
dcy committed
173
          parentAre.positionList?.forEach(g => {
dcy's avatar
dcy committed
174
            // 位置
dcy's avatar
dcy committed
175
            g.children?.forEach(k => {
dcy's avatar
dcy committed
176 177 178 179 180 181 182 183 184 185 186 187 188
              // 子位置
              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

dcy's avatar
dcy committed
189 190 191 192 193 194 195 196 197 198 199
      }
    },
    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

dcy's avatar
dcy committed
200 201 202 203 204 205 206 207 208 209 210 211 212
      }
    }
  },

  mounted() {
    console.log('area dialog mounted')
  },

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

dcy's avatar
dcy committed
213
      this.area?.forEach(e => {
dcy's avatar
dcy committed
214
        // 仓库
dcy's avatar
dcy committed
215
        e.children?.forEach(f => {
dcy's avatar
dcy committed
216 217
          // 区域
          if (f.selected) result.push(f.code)
dcy's avatar
dcy committed
218
          else f.positionList?.forEach(g => {
dcy's avatar
dcy committed
219
            // 位置
dcy's avatar
dcy committed
220 221
            if (g.selected) result.push(f.code + g.code)
            else if(g.children) g.children?.forEach(k => {
dcy's avatar
dcy committed
222
              // 子位置
dcy's avatar
dcy committed
223
              if (k.selected) result.push(f.code + k.code)
dcy's avatar
dcy committed
224 225 226 227 228 229 230 231 232 233
            })
          })
        })
      })

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

dcy's avatar
dcy committed
234
      this.area?.forEach(e => {
dcy's avatar
dcy committed
235
        // 仓库
dcy's avatar
dcy committed
236
        e.children?.forEach(f => {
dcy's avatar
dcy committed
237 238 239 240 241 242
          // 区域
          if (f.selected) result.push({
            orderId: this.orderId,
            wareId: f.pid,
            areaId: f.id
          })
dcy's avatar
dcy committed
243 244 245 246
          else {
            f.positionList?.forEach(g => {
              // 位置
              if (g.selected) result.push({
dcy's avatar
dcy committed
247
                orderId: this.orderId,
dcy's avatar
dcy committed
248 249 250 251 252 253 254 255 256 257 258 259
                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
                })
dcy's avatar
dcy committed
260 261
              })
            })
dcy's avatar
dcy committed
262
          }
dcy's avatar
dcy committed
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
        })
      })

      return result
    }
  }
}
</script>

<style scoped>
.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{
Marcus's avatar
Marcus committed
292
  box-shadow: #b1a4cb 7px 5px 14px 0;
dcy's avatar
dcy committed
293
  transform: scale(1.04);
Marcus's avatar
Marcus committed
294 295
  background-color: #9ab7e1;
  color: #ffffff;
dcy's avatar
dcy committed
296 297 298 299 300 301 302 303 304 305 306
}
.warehouse-block-selected{
  color: #ffffff;
  background-color: #4085e3;
}
.position-group{
  display: flex;
  background-color: #EFEFEF;
  border: 1px #EFEFEF solid;
  gap: 1px;
  min-height: 64px;
dcy's avatar
dcy committed
307
  flex-flow: wrap;
dcy's avatar
dcy committed
308 309
}
.position{
dcy's avatar
dcy committed
310
  width: calc(20% - 1px);
dcy's avatar
dcy committed
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
  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;
}
</style>