qualityControlList.vue 7.28 KB
<template>
  <div class="layout">
    <div
      class="tab"
      ref="tabbox"
    >
      <div
        :class="['tab-item', { 'item-active': windowId == -1 }]"
        @click="windowId = -1"
      >
        质检管理
      </div>
      <template v-for="(i, index) in tab">
        <template>
          <div
            :key="i.id"
            :class="['tab-item', { 'item-active': windowId == i.id }]"
            @click="windowId = i.id"
            :ref="`tab-${index}`"
          >
            {{ i.text }}
            <div
              class="close"
              @click.stop="close(index, i.id)"
            >
              <i class="el-icon-close"></i>
            </div>
          </div>
        </template>
      </template>
      <template v-if="dropdownList.length">
        <div class="arrow-box">
          <el-dropdown
            trigger="click"
            @command="windowId = $event"
          >
            <div class="dropdown-link">
              <i class="el-icon-arrow-down"></i>
            </div>
            <el-dropdown-menu slot="dropdown">
              <template v-for="(i, index) in dropdownList">
                <el-dropdown-item
                  :class="{ 'dropdown-item-active': windowId == i.id }"
                  :key="i.id"
                  :command="i.id"
                >
                  <div class="dropdown-item">
                    {{ i.text }}
                    <div
                      class="close"
                      @click.stop="closeDrop(index)"
                    >
                      <i class="el-icon-close"></i>
                    </div>
                  </div>
                </el-dropdown-item>
              </template>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </template>
    </div>
    <div class="content">
      <quality-index
        v-show="windowId == -1"
        @openWindow="openWindow"
        :show="windowId == -1"
        ref="qualityindex"
      />
      <template v-for="i in [...tab, ...dropdownList]">
        <recep-detail
          :ref="`recep-${i.id}`"
          :key="i.id"
          v-show="windowId == i.id"
          :queryData="i.data"
          :show="windowId == i.id"
        />
      </template>
    </div>
  </div>
</template>

<script type='text/ecmascript-6'>
import qualityIndex from "./components/qualityIndex/index"
import recepDetail from "./components/recepDetail.vue"
import reportTrackPageMixin from "@/mixins/reportTrackPageMixin"
export default {
  mixins: [reportTrackPageMixin],
  name: "",
  components: {
    qualityIndex,
    recepDetail
  },
  data () {
    return {
      tab: [],
      dropdownList: [],
      windowId: -1,
      tabboxWidth: 0,
    }
  },

  // 在beforeDestroy钩子中移除事件监听
  beforeDestroy () {
    window.removeEventListener('popstate', this.preventBack)
    Object.keys(this.$refs).map(key => {
      let ref = this.$refs[key]
      if (Array.isArray(ref)) ref = ref[0]
      ref.onPageHide && ref.onPageHide()
    })
  },
  // 在你的Vue组件的mounted钩子中添加事件监听
  mounted () {
    history.pushState(null, null, document.URL)
    window.addEventListener('popstate', this.preventBack)
    if (this.tabboxWidth == 0) this.tabboxWidth = this.$refs.tabbox.offsetWidth
  },
  methods: {
    preventBack () {

      if (this.windowId !== -1) {
        const [recep] = this.$refs[`recep-${this.windowId}`]
        if (recep && (recep.isQualityVisible || recep.isNewQualityVisible)) recep.closeDialog()
        else this.windowId = -1
      } else {
        const qualityIndexRef = this.$refs.qualityindex
        if (qualityIndexRef.viewType == 2) {
          if (qualityIndexRef.isQualityVisible || qualityIndexRef.isNewQualityVisible) {
            qualityIndexRef.closeDialog()
            history.pushState(null, null, document.URL)
            return
          }
        }
        this.$router.go(-1)
      }
    },
    openWindow (data) {
      let id = `${data.searchdate}_${data.phoneNumber}_${data.merchantNo}}`,
        windowList = [...this.tab, ...this.dropdownList],
        windowItem = windowList.find((e) => e.id == id)
      if (windowItem) return this.windowId = id
      if (windowList.length == 20) return this.$message.error("最多同时打开20个tab")
      let item = {
        text: data.employeeName || '-',
        data,
        id
      }
      if (this.dropdownList.length) this.dropdownList.push(item)
      else {
        this.tab.push(item)
        this.checkEl()
      }
      this.windowId = id
    },
    close (index, id) {
      this.$refs[`recep-${id}`][0].onPageHide()
      this.tab.splice(index, 1)
      if (this.dropdownList.length) {
        this.tab.push(this.dropdownList[0])
        this.closeDrop(0)
      }
      this.windowId = -1
      this.checkEl()
    },
    closeDrop (index) {
      this.dropdownList.splice(index, 1)
    },
    checkEl () {
      let { tab, tabboxWidth } = this,
        len = tab.length - 1
      if (len == -1) return
      this.$nextTick(() => {
        let [el] = this.$refs[`tab-${len}`]
        if (el) {
          const { offsetWidth, offsetLeft } = el
          if (offsetLeft + offsetWidth / 2 > tabboxWidth - 54) {
            this.dropdownList.push(tab[len])
            this.tab.splice(len, 1)
          }
        }
      })
    },

  }
}
</script>

<style scoped lang='scss'>
.layout {
  .tab {
    display: flex;
    align-items: center;
    margin-left: 16px;
    width: calc(100% - 54px);
    box-sizing: border-box;
    &-item {
      width: fit-content;
      height: 40px;
      padding: 0 20px;
      background: #fafafa;
      border-radius: 4px 4px 0 0;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      color: #666666;
      cursor: pointer;
      line-height: 40px;
      margin-right: 1px;
      flex-shrink: 0;
      .close {
        border-radius: 100%;
        padding: 4px;
        margin-left: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        &:hover {
          background-color: #666;
          .el-icon-close {
            color: #fff;
          }
        }
      }
      .el-icon-close {
        font-size: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #666666;
        transform: translateY(1px);
      }
    }
    .item-active {
      font-weight: 500;
      color: #2a58ad;
      background: #ffffff;
    }
    .arrow-box {
      width: 32px;
      height: 40px;
      line-height: 40px;
      text-align: center;
      background: #fafafa;
      cursor: pointer;
      flex-shrink: 0;
      .el-dropdown {
        width: 100%;
      }
    }
  }
  .content {
    position: relative;
    width: 100%;
    height: calc(100vh - 110px);
    // overflow-y: scroll;
    box-sizing: border-box;
    padding-bottom: 70px;
  }
}
::v-deep.dropdown-item {
  display: flex;
  align-items: center;
  justify-content: center;
  .close {
    border-radius: 100%;
    padding: 4px;
    margin-left: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    &:hover {
      background-color: #666;
      .el-icon-close {
        color: #fff;
      }
    }
    i {
      margin-right: 0;
    }
  }
  .el-icon-close {
    font-size: 12px;

    color: #666666;
  }
}
.dropdown-item-active {
  background-color: #eaeef7;
  color: #5579bd;
}
</style>