<template>
  <div class="home">
    <div class="header-img">
      <img v-if="!!topBanner" :src="topBanner.imgUrl" @click="handleLink(topBanner)"/>
      <AiEmpty v-else noPermit description="请在web端的'首图设置'中设置banner"/>
    </div>
    <div class="tab-flex">
      <div class="item" v-for="(item, index) in tabs" :key="index" @click="goto(item)">
        <img :src="item.icon" alt="">
        <p>{{ item.text }}</p>
      </div>
    </div>
    <div class="app-list">
      <div class="item" v-for="(item, index) in appList" :key="index" @click="goto(item)">
        <img :src="item.icon" alt="">
        <p>{{ item.text }}</p>
      </div>
    </div>
    <div class="banner-img" v-if="!!middleBanner">
      <img :src="middleBanner.imgUrl" alt="" @click="handleLink(middleBanner)">
    </div>
    <div class="notice" v-if="noticesList.length>0">
      <div class="left">
        <img src="./components/img/notice.png" alt="">
      </div>
      <div class="right" @click="gotoPage(`/apps/AppNotification/AppNotification?last=1`)">
        <p v-for="item in noticesList" :key="item.id">
          <span>最新</span>{{ item.title }}
        </p>
        <!--        <AiNoticeBar :list="noticesList" nodeKey="title" :rows="2" :autoplay="false">-->
        <!--          <template slot-scope="{label}">-->
        <!--            <p><span>最新</span>{{ label }}</p>-->
        <!--          </template>-->
        <!--        </AiNoticeBar>-->
      </div>
    </div>
    <div class="matter">
      <div class="left fill">
        <div flex class="spb">
          <div class="tab" :class="{active:tabIndex==0}" @click="tabIndex=0,getMatters()"
               v-text="`待办事件(${total.matter})`"/>
          <div class="tab" :class="{active:tabIndex==1}" @click="tabIndex=1,getMeetings()"
               v-text="`待参加会议(${total.meeting})`"/>
        </div>
        <p class="text">即刻提醒,及时跟进工作进度</p>
      </div>
      <img class="tabBg" src="./components/img/matter-banner.png" alt="">
    </div>
    <div class="matter-list" v-if="tabIndex==0">
      <template v-if="matterList.length">
        <div class="item" v-for="(item, index) in matterList" :key="index"
             @click="gotoPage(`/apps/AppConflictMediation/detail?id=${item.id}`)">
          <p>
            <span>待处理</span>
            {{ item.content }}
          </p>
          <div flex class="flex">
            <u-icon name="clock" color="#44B6F0" size="40" :label="item.createTime"/>
            <div class="type" v-text="item.groupName"/>
          </div>
        </div>
        <div v-if="total.matter>5" class="loadmore"
             @click="gotoPage(`/apps/AppConflictMediation/AppConflictMediation`)">查看更多
        </div>
      </template>
      <AiEmpty img="https://cdn.cunwuyun.cn/dvcp/h5/homeEmpty.png" v-else description="暂无待办事项"/>
    </div>
    <div class="meet-list" v-if="tabIndex==1">
      <template v-if="meetingList.length>0">
        <div class="item" v-for="(item, index) in meetingList" :key="index">
          <div class="item-content" @click="gotoPage(`/apps/AppMeetingNotice/detail?id=${item.id}`)">
            <p class="title" v-text="item.title"/>
            <div class="time-flex">
              <div class="time">
                <h2>{{ $dateFormat(item.startTime, "HH:mm") }}</h2>
                <p>{{ $dateFormat(item.startTime, "YYYY年MM月DD日 ddd") }}</p>
              </div>
              <img src="./components/img/home-right-big.png" alt="">
              <div class="time">
                <h2>{{ $dateFormat(item.endTime, "HH:mm") }}</h2>
                <p>{{ $dateFormat(item.endTime, "YYYY年MM月DD日 ddd") }}</p>
              </div>
            </div>
            <div class="info">
              <span class="label">发起人员：</span>
              <span class="value">
              <AiOpenData type="userName" :openid="item.wxUserId"/>
            </span>
            </div>
            <div class="info">
              <span class="label">会议地点：</span>
              <span class="value">{{ item.address }}</span>
            </div>
            <img :src="$cdn + tag(item.joinStatus)" alt="" class="status-img">
          </div>
        </div>
      </template>
      <AiEmpty img="https://cdn.cunwuyun.cn/dvcp/h5/homeEmpty.png" v-else description="暂无待参加会议"/>
    </div>
  </div>
</template>

<script>
import {mapActions, mapState} from "vuex";

export default {
  name: 'home',
  inject: ['top'],
  data() {
    return {
      tabs: [
        {
          icon: require('./components/img/mdtj.png'),
          text: '矛盾调解',
          app: "AppConflictMediation"
        },
        {
          icon: require('./components/img/wggl.png'),
          text: '网格管理',
          app: "AppGridManagement"
        },
        {
          icon: require('./components/img/tsrq.png'),
          text: '特殊人群',
          app: "AppSpecialPeople"
        },
        {
          icon: require('./components/img/zfww.png'),
          text: '走访慰问',
          app: "AppWalkask"
        }
      ],
      appList: [
        {
          icon: require('./components/img/hytz.png'),
          text: '会议通知',
          app: "AppMeetingNotice"
        },
        {
          icon: require('./components/img/txl.png'),
          text: '电话簿',
          app: "AppMailList"
        },
        {
          icon: require('./components/img/wjbd.png'),
          text: '问卷表单',
          app: "AppAskForm"
        },
        {
          icon: require('./components/img/swjl.png'),
          text: '事务记录',
          app: "AppInterview"
        },
        {
          icon: require('./components/img/yfzr.png'),
          text: '以房找人',
          app: "AppBuilding"
        },
        {
          icon: require('./components/img/jmgl.png'),
          text: '居民管理',
          app: "AppResidentDocument"
        },
        {
          icon: require('./components/img/xtxf.png'),
          text: '协同宣发',
          app: "AppCooperationPropaganda"
        },
        {
          icon: require('./components/img/gd.png'),
          text: '更多',
          app: "more"
        },
      ],
      tabIndex: 0,
      meetingList: [],
      matterList: [],
      noticesList: [],
      loaded: false,
      banners: [],
      total: {
        matter: 0, meeting: 0
      }
    }
  },
  computed: {
    ...mapState(["openUser", "user"]),
    hasMeeting() {
      return this.meetingList?.length > 0
    },
    topBanner() {
      return this.banners.find(e => e.position == 0)
    },
    middleBanner() {
      return this.banners.find(e => e.position == 1)
    }
  },
  methods: {
    ...mapActions(["injectJWeixin"]),
    getMatters() {
      this.$loading()
      this.$http.post("/app/appclapeventinfo/listByGirdMember", null, {
        params: {
          openId: this.user.openId,
          eventStatus: 0,
          size: 5
        }
      }).then(res => {
        this.$hideLoading()
        if (res?.data) {
          this.matterList = res.data.records
          this.total.matter = res.data.total
        }
      })
    },
    getMeetings() {
      this.$loading()
      this.$http.post("/app/appmeetinginfo/list", null, {
        params: {
          listType: "1",
          meetingStatus: "1|2",
          size: 999
        }
      }).then(res => {
        this.$hideLoading()
        if (res?.data) {
          this.meetingList = res.data.records
          this.total.meeting = res.data.total
        }
      })
    },
    tag(status) {
      return {
        "0": "common/1wqr.png",
        "1": "common/1yqr.png",
        "2": "common/1yqj.png",
        "3": "common/toDo.png",
      }[status]
    },
    getNotices() {
      this.$http.post("/app/appannouncement/list-latest", null, {
        params: {size: 2, current: 1}
      }).then(res => {
        if (res && res.data) {
          this.noticesList = res.data.records
        }
      })
    },
    goto(item) {
      if (item.app == "more") {
        this.top.tabClick(1, "application")
      } else if (item.app != "") {
        uni.navigateTo({url: `/apps/${item.app}/${item.app}`})
      } else {
        this.$u.toast("应用开发中~")
      }

    },
    getBanners() {
      this.$http.post("/app/appbanner/listForWx").then(res => {
        if (res?.data) {
          this.banners = res.data
        }
      })
    },
    handleLink(banner) {
      if (!!banner.linkUrl) {
        if (banner.type == 0) {
          location.href = banner.linkUrl
        } else if (banner.type == 1) {
          //小程序跳转暂不处理
        }
      }
    },
    gotoPage(url) {
      uni.navigateTo({url})
    }
  },
  created() {
    document.title = "首页"
    this.getMatters()
    this.getMeetings()
    this.getNotices()
    this.getBanners()
  }
}
</script>

<style lang="scss" scoped>
.home {
  position: relative;
  overflow-y: auto;
  background-color: #F4F7FD;
  height: 100vh;
  padding-bottom: 100px;
  box-sizing: border-box;

  .header-img {
    width: 100%;

    img {
      width: 100%;
      height: 324px;
    }

    .emptyWrap {
      padding-bottom: 48px;
    }
  }

  .tab-flex {
    width: calc(100vw - 64px);
    background: #FFF;
    box-shadow: 0 2px 4px 0 rgba(146, 211, 255, 0.3);
    border-radius: 16px;
    display: flex;
    position: absolute;
    z-index: 2;
    left: 50%;
    transform: translate(-50%, -48px);

    .item {
      flex: 1;
      text-align: center;
      padding-bottom: 30px;

      img {
        width: 88px;
        height: 88px;
        margin-top: 32px;
      }

      p {
        margin-top: 4px;
        font-size: 28px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #333;
        line-height: 40px;
      }
    }
  }

  .app-list {
    width: 100%;
    background: #FFF;
    border-radius: 16px 16px 0 0;
    padding: 194px 32px 16px;
    box-sizing: border-box;
    overflow: hidden;

    .item {
      width: 25%;
      float: left;
      text-align: center;
      padding-bottom: 32px;

      img {
        width: 48px;
        height: 48px;
      }

      p {
        margin-top: 8px;
        font-size: 28px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #333;
        line-height: 40px;
      }
    }
  }

  .banner-img {
    width: 100%;
    padding: 0 24px 48px;
    background-color: #fff;
    box-sizing: border-box;

    img {
      width: 100%;
      height: 168px;
      border-radius: 16px;
    }
  }

  .notice {
    padding: 24px 58px 22px 32px;
    box-sizing: border-box;
    background-color: #fff;
    display: flex;

    .left {
      width: 94px;

      img {
        width: 68px;
        height: 82px;
        margin-top: 10px;
      }
    }

    .right {
      width: calc(100% - 94px);

      p {
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-bottom: 18px;

        span {
          display: inline-block;
          padding: 0 6px;
          line-height: 36px;
          border-radius: 4px;
          border: 1px solid #23C3E4;
          box-sizing: border-box;
          font-size: 26px;
          font-family: PingFangSC-Regular, PingFang SC;
          color: #23C3E4;
          margin-right: 16px;
        }
      }
    }
  }

  .matter {
    margin-top: 12px;
    background-color: #fff;
    padding: 20px 24px 28px 32px;
    box-sizing: border-box;
    display: flex;

    .left {
      padding-top: 58px;

      div {
        height: 52px;

        .tab {
          z-index: 2;
          font-size: 30px;
          font-family: PingFangSC-Regular, PingFang SC;
          color: #999;
          line-height: 52px;

          &.active {
            font-size: 38px;
            font-weight: bold;
            color: #333;
            background-image: url("./components/circle.svg");
            background-repeat: no-repeat;
            background-position: right top;
            padding: 2px 10px 0 0;
            box-sizing: border-box;
          }
        }
      }

      .text {
        font-size: 26px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #999;
        line-height: 36px;
        margin-top: 8px;
      }
    }

    .tabBg {
      width: 216px;
      height: 128px;
    }
  }

  .matter-list {
    background-color: #fff;

    .item {
      padding: 32px 32px 48px 24px;
      box-sizing: border-box;
      background-color: #fff;
      border-bottom: 1px solid #ddd;

      p {
        width: 100%;
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        font-size: 30px;
        font-family: PingFang-SC-Medium, PingFang-SC;
        font-weight: 500;
        color: #333;
        line-height: 40px;

        span {
          display: inline-block;
          padding: 0 10px;
          font-size: 24px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #FFF;
          line-height: 40px;
          border-radius: 8px;
          margin-right: 16px;
          background-color: #F1826D;
        }
      }

      .flex {
        margin-top: 32px;
        display: flex;
        justify-content: space-between;

        img {
          width: 28px;
          height: 28px;
          margin-right: 4px;
          vertical-align: text-bottom;
        }

        .time {
          font-size: 24px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #666;
          line-height: 34px;
        }

        .type {
          display: inline-block;
          padding: 0 14px;
          font-size: 24px;
          font-family: PingFangSC-Regular, PingFang SC;
          color: #44B6F0;
          line-height: 34px;
          border-radius: 18px;
          border: 1px solid #44B6F0;
        }
      }
    }
  }

  .meet-list {
    background-color: #fff;

    .item {
      padding: 0 32px 32px 32px;

      .item-content {
        padding: 32px 32px 22px 32px;
        background-color: #F7F9FF;
        position: relative;

        .title {
          width: 640px;
          font-size: 32px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #333;
          line-height: 44px;
          padding-right: 80px;
          box-sizing: border-box;
        }

        .time-flex {
          display: flex;
          justify-content: space-between;
          padding: 48px 0;

          img {
            width: 88px;
            height: 88px;
          }

          .time {
            width: 220px;
            text-align: center;

            h2 {
              font-size: 60px;
              font-family: PingFangSC-Medium, PingFang SC;
              font-weight: 500;
              color: #333;
              line-height: 84px;
            }

            p {
              font-size: 22px;
              white-space: nowrap;
              font-family: PingFangSC-Regular, PingFang SC;
              color: #333;
              line-height: 32px;
            }
          }
        }

        .info {
          font-size: 30px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #999999;
          line-height: 42px;
          margin-bottom: 20px;

          .label {
            display: inline-block;
            width: 150px;
            color: #999;
            vertical-align: top;
          }

          .value {
            display: inline-block;
            width: calc(100% - 150px);
            color: #343D65;
          }
        }

        .status-img {
          width: 112px;
          height: 112px;
          position: absolute;
          top: 0;
          right: 0;
        }
      }
    }
  }

  .loadmore {
    text-align: center;
    margin: 44px auto;
    font-size: 30px;
    color: #3F8DF5
  }
}
</style>
