<template>
  <div>
    <!-- <div class="right-menu-item hover-effect" @click="handleDrawer">
      <i class="el-icon-message-solid" style="font-size: 24px; line-height: 50px" />
      <el-badge v-if='allUnreadNum > 0' class="mark" :value="allUnreadNum" />
    </div> -->
    <el-dropdown v-if="QRcodeList.length" class="user-container yidong">
      <div class="user right-menu-item hover-effect">
        <span>移动端</span>
      </div>
      <el-dropdown-menu slot="dropdown" class="user-dropdown">
        <el-dropdown-item v-for="(item, index) in QRcodeList" :key="index">
          <div class="QRcode">
            <el-image
              class="QRcode-img"
              :src="$showImgUrl(item.codeUrl)"
              :preview-src-list="[$showImgUrl(item.codeUrl)]"
              fit="fill"
            ></el-image>
            <div>
              <div>{{ item.name }}</div>
              <div class="liveTitle">{{ item.saleName }}</div>
              <div>
                <el-image
                  v-if="$showImgUrl(item.iosIcon)"
                  class="shouji-icon"
                  :src="item.iosIcon"
                  fit="fill"
                ></el-image>
                <el-image
                  v-if="$showImgUrl(item.androidIcon)"
                  class="shouji-icon"
                  :src="item.androidIcon"
                  fit="fill"
                ></el-image>
              </div>
            </div>
          </div>
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <el-drawer
      size="450px"
      :with-header="false"
      :show-close="false"
      :visible.sync="drawer"
      direction="rtl"
      :modal="false"
    >
      <div class="drawer">
        <div :offset="0" class="drawer_left">
          <div class="drawer_top">
            <div class="flex center">
              <div class="radio">状态筛选标签</div>
              <div class="icon_close">
                <i class="el-icon-close" @click="guanbi" />
              </div>
            </div>
            <div>
              <el-button :type="pam.read_flag == '' ? 'primary' : null" size="mini" @click="hadleRead(0)"
                >全部</el-button
              >
              <el-button :type="pam.read_flag == 'NO' ? 'primary' : null" size="mini" @click="hadleRead(1)"
                >未读</el-button
              >
              <el-badge :value="allUnreadNum" class="item" />
              <el-button :type="pam.read_flag == 'YES' ? 'primary' : null" size="mini" @click="hadleRead(2)"
                >已读</el-button
              >
            </div>
            <el-tabs v-model="pam.type" @tab-click="handleClick">
              <el-tab-pane label="通知" name="N"></el-tab-pane>
              <el-tab-pane label="活动" name="A"></el-tab-pane>
              <el-tab-pane label="公告" name="B"></el-tab-pane>
            </el-tabs>
          </div>
          <div v-loading="loading" class="notice" style="position: relative">
            <div style="position: absolute; top: 0; bottom: 0; left: 0; right: 0">
              <v-scroll-view
                :x="false"
                :y="true"
                slidingBgClassName="slidingBgClassName3"
                slidingBlockClassName="slidingBlockClassName3"
              >
                <div style="box-sizing: border-box; padding: 10px">
                  <div
                    v-if="dataList.length"
                    class="item-data"
                    v-for="(item, index) in dataList"
                    :key="index"
                    @click="opendomview(item)"
                  >
                    <div class="item-tag">{{ ['活动', '公告', '通知'][['A', 'B', 'N'].indexOf(item.type)] }}</div>
                    <div class="item-centor">
                      <div class="item-centor">{{ item.content }}</div>
                      <div class="item-time">{{ item.issueTime }}</div>
                    </div>
                  </div>
                  <el-empty v-if="!dataList.length" description="暂无数据"></el-empty>
                </div>
              </v-scroll-view>
            </div>
          </div>
          <el-pagination
            layout="total, prev, pager, next"
            :total="total"
            small
            :page-size="pam.pageSize"
            :current-page="pam.pageNum"
            @current-change="currentChange"
          />
        </div>
      </div>
    </el-drawer>
    <el-drawer
      :title="showRow.title"
      :visible.sync="dialogVisible"
      direction="rtl"
      :before-close="dialogVisibleGuanbi"
      size="450px"
      :modal="false"
    >
      <el-card class="box-card">
        <div v-html="showRow.content"></div>
      </el-card>
    </el-drawer>
  </div>
</template>

<script>
import { mapMutations, mapActions, mapGetters } from 'vuex'
import vScrollView from 'v-scroll-view'
// import { notifyMyList, notifyMyRead } from '@/api/notificationCenter/eventAnnouncement'
import { EventBus } from '@/utils/eventBus'
import { commonCompanywechatGet } from '@/api/common'
export default {
  components: { vScrollView },
  data() {
    return {
      drawer: false,
      dataList: [],
      loading: false,
      total: 0,
      pam: {
        type: 'N',
        read_flag: '',
        pageNum: 1,
        pageSize: 20
      },
      dialogVisible: false,
      showRow: {},
      QRcodeList: []
    }
  },
  computed: {
    ...mapGetters(['allUnreadNum']),
    // 用户信息
    userInfo() {
      return JSON.parse(localStorage.getItem('greemall_user'))
    }
  },
  mounted() {
    EventBus.$on('opendomview', this.opendomview)
    EventBus.$on('handleDrawerabcde', this.handleDrawer)
    var this_ = this
    if (this.timeId) {
      clearTimeout(this.timeId)
    }
    ;(function dingshiqingqiu() {
      this_.updateUnreadNotice()
      this_.timeId = setTimeout(dingshiqingqiu, 2000)
    })()
    commonCompanywechatGet({ id: this.userInfo.companyWechatId }).then(res => {
      console.log(res)
      this.QRcodeList = []
      if (res?.data?.qrcode1) {
        this.QRcodeList.push({
          codeUrl: res.data.qrcode1,
          name: '小程序',
          saleName: '',
          iosIcon:
            'https://zf-mall.oss-cn-shenzhen.aliyuncs.com/2024-03/17115930219681afd35b0-8c93-400a-94f8-e49277c88616.png',
          androidIcon:
            'https://zf-mall.oss-cn-shenzhen.aliyuncs.com/2024-03/1711593045466d069e7f6-5c77-40a0-a7b3-6e2b3a6ce0eb.png'
        })
      }
      if (res?.data?.qrcode2) {
        this.QRcodeList.push({
          codeUrl: res.data.qrcode2,
          name: '公众号',
          saleName: '',
          iosIcon:
            'https://zf-mall.oss-cn-shenzhen.aliyuncs.com/2024-03/17115930219681afd35b0-8c93-400a-94f8-e49277c88616.png',
          androidIcon:
            'https://zf-mall.oss-cn-shenzhen.aliyuncs.com/2024-03/1711593045466d069e7f6-5c77-40a0-a7b3-6e2b3a6ce0eb.png'
        })
      }
      if (res?.data?.payQrcode) {
        this.QRcodeList.push({
          codeUrl: res.data.payQrcode,
          name: '收款码',
          saleName: '',
          iosIcon:
            'https://zf-mall.oss-cn-shenzhen.aliyuncs.com/2024-03/17115930219681afd35b0-8c93-400a-94f8-e49277c88616.png',
          androidIcon:
            'https://zf-mall.oss-cn-shenzhen.aliyuncs.com/2024-03/1711593045466d069e7f6-5c77-40a0-a7b3-6e2b3a6ce0eb.png'
        })
      }
    })
  },
  beforeDestroy() {
    if (this.timeId) {
      clearTimeout(this.timeId)
    }
  },
  watch: {
    pam: {
      handler(newVal, oldVal) {
        this.getMessageList()
      },
      deep: true
    }
  },
  methods: {
    ...mapMutations({
      SET_SHOW: 'app/SET_SHOW'
    }),
    ...mapActions({
      updateUnreadNotice: 'app/getUnreadNum'
    }),
    handleClick(val) {
      console.log(val)
    },
    opendomview(row) {
      this.showRow = row
      this.dialogVisible = true
      // notifyMyRead({
      //   id:row.id
      // }).then(res=>{
      //   this.updateUnreadNotice()
      //   if(this.drawer){
      //     this.getMessageList()
      //   }
      // })
    },
    dialogVisibleGuanbi() {
      this.showRow = {}
      this.dialogVisible = false
    },
    // 数据处理
    getMessageList() {
      // notifyMyList({
      //   "pageNum": this.pam.pageNum,
      //   "pageSize": this.pam.pageSize,
      //   "params": (()=>{
      //     var arr = []
      //     if(this.pam.read_flag){
      //       arr.push({ "param": "a.read_flag", "compare": "=", "value": this.pam.read_flag })
      //     }
      //     if(this.pam.type){
      //       arr.push({ "param": "a.type", "compare": "=", "value": this.pam.type })
      //     }
      //     return arr
      //   })(),
      //   "moduleId": "486084326453317-teshu"
      // }).then(res => {
      //   this.dataList = res.data.records
      //   this.total = res.data.total
      // })
    },
    currentChange(v) {
      this.pam.pageNum = v
    },
    // 打开消息弹窗
    handleDrawer() {
      this.drawer = true
      this.getMessageList()
    },
    guanbi() {
      this.drawer = false
      this.pam = {
        read_flag: '',
        pageNum: 1,
        pageSize: 20
      }
    },
    // 状态筛选标签
    hadleRead(index) {
      this.dataList = []
      this.pam.read_flag = ['', 'NO', 'YES'][index]
      this.pam.pageNum = 1
      this.getMessageList()
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/styles/variables.scss';

.item {
  margin-left: -10px;
  margin-top: -10px;
}

.notice_tip {
  font-size: 16px;
}

::v-deep .slidingBgClassName {
  background: rgba(0, 0, 0, 0.0075) !important;
}

::v-deep .slidingBlockClassName {
  background: rgba(0, 0, 0, 0.0125) !important;
}

::v-deep .el-drawer .el-drawer__body {
  overflow: hidden !important;
}

.navbar {
  width: 100%;
  height: 50px;
  overflow: hidden;
  background: #{$navbarBg};
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  display: flex;
  flex-direction: row;
  align-items: center;

  .hamburger-container {
    line-height: 46px;
    height: 100%;
    color: #{$navbarText};
    cursor: pointer;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;
    border-right: 1px solid #eaeaea;

    &:hover {
      background: rgba(0, 0, 0, 0.025);
    }
  }

  ul {
    list-style: none;
    padding: 0;
    line-height: 20px;

    li {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }

  .right-menu {
    height: 100%;
    line-height: 50px;

    & > div {
      float: left;
    }

    &:focus {
      outline: none;
    }

    .user-container {
      height: 50px;

      .user {
        i {
          font-size: 18px;
          margin-right: 5px;
        }

        span {
          font-size: 16px;
        }
      }
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 15px;
      height: 100%;
      font-size: 18px;
      color: #{$navbarText};
      vertical-align: text-bottom;
      border-left: 1px solid #eaeaea;

      &.hover-effect {
        cursor: pointer;
        transition: background 0.3s;

        &:hover {
          background: rgba(0, 0, 0, 0.025);
        }
      }

      .notice-icon {
        padding-top: 0;
        padding-bottom: 0;
      }

      .right-menu-item {
        .notice-icon > i {
          font-size: 18px;
        }

        sup {
          top: 12px;
          right: 25px;
        }
      }
    }
  }

  .flex {
    display: flex;
    justify-content: space-between;
  }

  .dot_title {
    height: 40px;
  }

  .dot::before {
    content: '';
    display: inline-block;
    margin-right: 10px;
    padding: 5px;
    border-radius: 25px;
    background-color: #f00;
  }

  .tip {
    width: 37px;
    height: 20px;
    border-radius: 2px;
    background-color: rgba(255, 0, 0, 1);
    color: rgba(255, 255, 255, 1);
    font-size: 14px;
    text-align: center;
  }

  .drawer_top {
    margin: 0 20px;
  }

  .center {
    align-items: center;
  }

  .notice {
    box-sizing: content-box;
    margin: 0 10px 10px 10px;
    background-color: rgba(255, 255, 255, 1);
    height: calc(100% - 205px);
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
    overflow-x: hidden;

    &_item {
      width: calc(450px - 80px);
      margin: 20px;
      border-bottom: 1px solid #ebeef5;
    }
  }

  .icon {
    &_bell {
      text-align: right;
      cursor: pointer;
    }

    &_close {
      font-size: 25px;
      cursor: pointer;
    }
  }

  .drawer {
    height: 100%;
    display: flex;
    font-size: 14px;

    &_left {
      width: 450px;
      display: inline-block;
    }

    &_right {
      width: 450px;
      margin: 0 20px;
      display: inline-block;

      .radio {
        display: flex;
        justify-content: center;
      }

      &_content {
        height: 855px;
        padding: 0 2px;
        overflow-y: auto;

        &_item {
          display: flex;
          align-items: center;
          margin: 20px 0;
          padding: 0 10px;
          height: 84px;
          font-size: 14px;
          border-radius: 5px;
          background-color: rgba(255, 255, 255, 1);
          box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);

          &_text {
            display: flex;
            flex-direction: column;
            justify-content: space-around;
            flex: 1 1;
            height: 84px;
            padding-left: 20px;
            line-height: 20px;
          }
        }
      }
    }
  }
}

::v-deep .slidingBgClassName3 {
  background: rgba(0, 0, 0, 0.01) !important;
}

::v-deep .slidingBlockClassName3 {
  background: rgba(0, 0, 0, 0.03) !important;
}

.item-data {
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  cursor: pointer;

  .item-tag {
    height: auto;
    box-sizing: border-box;
    padding: 6px;
    background: #e8fffb;
    color: #44d4d0;
    margin-right: 6px;
    line-height: normal;
  }

  .item-centor {
    line-height: normal;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
    flex-wrap: 500;

    .item-time {
      font-size: 12px;
      color: #aaa;
      margin-top: 5px;
      text-indent: 0.8em;
    }
  }

  &:hover {
    background: #e8fffb;
  }
}

ul {
  list-style: none;
  padding: 0;
  line-height: 20px;

  li {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}

.right-menu {
  height: 100%;
  line-height: 50px;

  & > div {
    float: left;
  }

  &:focus {
    outline: none;
  }

  .user-container {
    height: 50px;

    .user {
      i {
        font-size: 18px;
        margin-right: 5px;
      }

      span {
        font-size: 16px;
      }
    }
  }

  .right-menu-item {
    display: inline-block;
    padding: 0 15px;
    height: 100%;
    font-size: 18px;
    color: #{$navbarText};
    vertical-align: text-bottom;
    border-left: 1px solid #eaeaea;

    &.hover-effect {
      cursor: pointer;
      transition: background 0.3s;

      &:hover {
        background: rgba(0, 0, 0, 0.025);
      }
    }

    .notice-icon {
      padding-top: 0;
      padding-bottom: 0;
    }

    .right-menu-item {
      .notice-icon > i {
        font-size: 18px;
      }

      sup {
        top: 12px;
        right: 25px;
      }
    }
  }
}

.flex {
  display: flex;
  justify-content: space-between;
}

.dot_title {
  height: 40px;
}

.dot::before {
  content: '';
  display: inline-block;
  margin-right: 10px;
  padding: 5px;
  border-radius: 25px;
  background-color: #f00;
}

.tip {
  width: 37px;
  height: 20px;
  border-radius: 2px;
  background-color: rgba(255, 0, 0, 1);
  color: rgba(255, 255, 255, 1);
  font-size: 14px;
  text-align: center;
}

.drawer_top {
  margin: 0 20px;
}

.center {
  align-items: center;
}

.notice {
  box-sizing: content-box;
  margin: 0 20px;
  margin-top: 20px;
  background-color: rgba(255, 255, 255, 1);
  height: 690px;
  box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);
  overflow-x: hidden;

  &_item {
    width: calc(450px - 80px);
    margin: 20px;
    border-bottom: 1px solid #ebeef5;
  }
}

.icon {
  &_bell {
    text-align: right;
    cursor: pointer;
  }

  &_close {
    font-size: 25px;
    cursor: pointer;
  }
}

.drawer {
  height: 100%;
  display: flex;
  font-size: 14px;

  &_left {
    width: 450px;
    display: inline-block;
  }

  &_right {
    width: 450px;
    margin: 0 20px;
    display: inline-block;

    .radio {
      display: flex;
      justify-content: center;
    }

    &_content {
      height: 855px;
      padding: 0 2px;
      overflow-y: auto;

      &_item {
        display: flex;
        align-items: center;
        margin: 20px 0;
        padding: 0 10px;
        height: 84px;
        font-size: 14px;
        border-radius: 5px;
        background-color: rgba(255, 255, 255, 1);
        box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.4);

        &_text {
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          flex: 1 1;
          height: 84px;
          padding-left: 20px;
          line-height: 20px;
        }
      }
    }
  }
}

.download {
  width: 595px;
  max-height: 327px;
  background-color: rgba(255, 255, 255, 1);

  .clear {
    cursor: pointer;
  }

  &_title {
    display: flex;
    justify-content: space-between;
    padding: 5px 15px;

    div:last-child {
      display: flex;
      justify-content: flex-end;
      flex: 0 350px;

      div {
        flex: 1;
        font-size: 14px;
      }

      div:last-child {
        flex: 1;
        text-align: right;
      }
    }
  }

  &_item {
    max-height: 280px;
    margin: 15px;
    overflow-y: auto;

    &_content {
      display: flex;
      justify-content: space-between;
      margin: 10px 0;
      padding-bottom: 5px;
      font-size: 14px;
      border-bottom: 1px solid rgba(204, 204, 204, 0.38);

      div:last-child {
        display: flex;
        justify-content: flex-end;
        flex: 0 350px;

        div {
          flex: 1;
        }

        div:last-child {
          flex: 1;
          text-align: right;
        }
      }
    }
  }
}

.el-dropdown-menu {
  padding: 0 !important;
  margin: 0 !important;
  z-index: 9999 !important;
}

::v-deep .el-dropdown-menu__item.is-disabled {
  color: #000;
  padding: 20px;
  border-bottom: 1px solid #ebeef5;
}

.yidong {
  ::v-deep .el-dropdown-menu__item {
    padding: 0;
  }
}

::v-deep ul > li:last-child {
  border-bottom: none !important;
}

.QRcode {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-bottom: 20px;
}

.QRcode-img {
  width: 120px;
  height: 120px;
  margin-right: 5px;
  border: 1px solid #ebeef5;
}

.shouji-icon {
  width: 40px;
  height: 40px;
  margin-right: 10px;
}

.liveTitle {
  color: #f00;
}
</style>
