DetailTitle.vue 6.7 KB
<!--
 * @Author: 前端 qianduan01@didihu.com.cn
 * @Date: 2022-10-25 10:12:26
 * @LastEditors: huyue
 * @LastEditTime: 2023-08-24 15:52:39
 * @FilePath: \dj-data-view\src\components\ViewTitle.vue
 * @Description: 页面头部组件
-->
<template>
  <div class="content flex">
    <div class="logo user-select">
      <img style="height: 48px" src="@/assets/images/logo.png" alt="logo" />
    </div>
    <div class="tab">
      <div class="tab-item first-tab active" @click.stop="openSelect">
        <div class="merchant-name">{{ firstTab[dataListObj.labelName] }}</div>
        <img class="arrow-down" src="@/assets/images/title-arrow.png" alt="" />
      </div>
      <SelectBox
        :isShow="isShow"
        :defaultValue="firstTab[dataListObj.valueName]"
        @clickOutside="clickOutside"
        :dataList="merchantList"
        :boxWidth="'26.53vw'"
        isObject
        @selectVal="selectVal"
        :labelName="dataListObj.labelName"
        :valueName="dataListObj.valueName"
      >
        <div slot="search" class="search">
          <input type="text" class="search-input" v-model="search" @input="handleInput" />
          <img class="icon-search" src="@/assets/images/icon-search.png" @click="searchMerchant" alt="" />
        </div>
        <div slot="empty" class="search-empty">
          <div>相关搜索</div>
          <div>为你搜索到0个结果</div>
        </div>
      </SelectBox>
    </div>
    <!-- <div class="view-title user-select">嘀加智慧门店运营看板</div> -->
    <div class="time">
      <div class="top flex">
        {{ weekList[week] }}
        <div class="now">{{ now }}</div>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import utils from '@/utils/util'
export default {
  name: 'DetailTitle',
  props: {
    dataList: {
      type: Array,
      default: () => []
    },
    dataListObj: {
      type: Object,
      default: () => {}
    },
    tabObject: {
      type: Object,
      default: () => {}
    },
    searchType: String
  },
  watch: {
    'dataList'(val) {
      this.merchantList = utils.deepClone(this.dataList)
    }
  },
  data() {
    return {
      isShow: false,
      merchantList: [],
      weekList: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
      firstTab: this.tabObject, // 存储第一个tab下的子菜单对象
      now: new Date().format('yyyy-MM-dd hh:mm:ss'),
      week: new Date().getDay(),
      currentMenu: 'home', // 标记当前是哪个tab菜单
      search: ''
    }
  },
  created() {
  },
  mounted() {
    this.timer()
  },
  methods: {
    timer() {
      setInterval(() => {
        this.now = new Date().format('yyyy-MM-dd hh:mm:ss')
      }, 1e3)
    },
    openSelect() {
      this.isShow = !this.isShow
    },
    // 监听子菜单变化
    selectVal(val) {
      this.firstTab = val
      this.$bus.$emit('selectVal', val)
      this.openSelect()
      this.search = ''
    },
    async searchMerchant() {
      switch (this.searchType) {
        case 'boutique':
          this.searchBoutiqueMerchant()
          break
        case 'solar':
          this.searchSolarMerchant()
          break
      }
    },
    async searchSolarMerchant() {
      const _searchData = await this.api.solar.getMerchant({
        merchantName: this.search
      })
      const _dataList = _searchData.data.dataList
      _dataList.forEach(item => {
        item.merchantname = item.merchantName
        item.merchantid = item.merchantid + ''
      })
      this.merchantList = _dataList
    },
    async searchBoutiqueMerchant() {
      const _searchData = await this.api.boutique.getMerchant({
        merchantName: this.search
      })
      const _dataList = _searchData.data.dataList
      _dataList.forEach(item => {
        item.merchantname = item.merchantName
        item.merchantid = item.merchantid + ''
      })
      this.merchantList = _dataList
    },
    handleInput: utils.debounce(function(e) {
      this.searchMerchant()
    }, 1000 / 25),
    clickOutside() {
      this.isShow = false
    }
  }
}
</script>

<style scoped lang="scss">
.content {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 0 26px 0 24px;
  justify-content: space-between;
  .view-title {
    font-weight: 600;
    font-size: 24px;
    color: #ffffff;
    letter-spacing: 8px;
    text-align: center;
  }
  .time {
    text-align: right;
    font-size: 14px;
    color: #ffffff;
    .top {
      justify-content: flex-end;
      .now {
        width: 10.97vw;
      }
    }
    .icon {
      width: 14px;
      height: 14px;
      margin-right: 8px;
    }
  }
}
.tab {
  position: relative;
  display: flex;
  // align-items: center;
  color: #ffffff;
  font-size: 16px;
  &-item {
    display: flex;
    align-items: center;
    // justify-content: center;
    padding-left: 1.39vw;
    height: 4.44vh;
    box-sizing: border-box;
    margin-right: 0.56vw;
    border: 2px solid;
    border-image: linear-gradient(90deg, #074989, #30dcff, #074989) 1;
    background-image: linear-gradient(180deg, #001948 0%, #00223c 99%);
    cursor: pointer;
  }
  .first-tab {
    position: relative;
    width: 26.53vw;
    box-sizing: border-box;
    .merchant-name {
      max-width: 22.36vw;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      text-align: left;
      color: #5894ff;
      background-image: -webkit-linear-gradient(left, #24d8ff, #7787ff);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
    &.active {
      background-image: url('../assets/images/first-tab-bg.png');
      background-repeat: no-repeat;
      background-size: 100% 100%;
      border: none;
    }
    .arrow-down {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      right: 1.39vw;
      margin-left: 0.28vw;
      width: 1.39vw;
      height: 2.22vh;
    }
    .select-box {
      left: 0;
    }
  }
}
.search {
  position: relative;
  margin-bottom: 2.22vh;
  padding: 0 1.39vw;
  &-input {
    width: 100%;
    background-color: #001b46;
    border: 1px solid #183d6f;
    padding: 0.89vh 2.15vw 0.89vh 0.56vw;
    color: #fff;
    box-sizing: border-box;
  }
  .icon-search {
    position: absolute;
    right: 1.95vw;
    top: 50%;
    transform: translateY(-50%);
    width: 15px;
    height: 15px;
  }
}

.search-empty {
  text-align: center;
}
input:focus-visible {
  border: 1px solid;
  outline-offset: -4vh;
  border-image: linear-gradient(90deg, #074989, #30dcff, #074989) 1 !important;
}
</style>