<template>
  <div class="AppWxworkQrcode">
    <div class="header">
      <AiSelect v-model="id" :list="dictList" @name="v=> idName = v">
        <span class="label" v-if="id">{{ idName }}</span>
        <span v-else class="col-666">请选择群聊</span>
        <u-icon name="arrow-down" color="#666" size="24" style="margin-left: 4px"></u-icon>
      </AiSelect>
      <div class="qrcode-content">
        <div class="tips">
          <div class="name-tip" v-if="groupInfo.name">
            <div class="name">{{ groupInfo.name }}</div>
            <!-- <div class="count">({{ groupInfo.personCount }})</div> -->
          </div>
        </div>
      </div>
      
      <div class="jionGroup"> 
        <!-- 长按保存图片或扫码加入群聊 -->
        <!-- 通过扫一扫加入、与通过插件加入只能选一种 -->
        <cell class="group" contactText="点击加入群聊" :url='picUrl' v-if="picUrl"></cell>
      </div>

      

      <div class="pic">
        <img src="https://cdn.cunwuyun.cn/fengdu/mdpi_img-chongqing.png" alt="">
      </div>
    </div>
  </div>
</template>
<script>
import {mapState} from 'vuex'
export default {
  name: "AppWxworkQrcode",
  appName: "居民社群",
  computed: {
    ...mapState(['user'])
  },
  data() {
    return {
      dictList: [],
      id: '',
      current: 0,
      list: [],
      picUrl: '',
      idName: '',
      groupInfo: {},
    }
  },
  onShow() {
    this.getSelect()
  },
  watch: {
    id: {
      handler(v) {
        if(v) {
          this.picUrl = null
          this.$nextTick(()=> {
            this.picUrl = this.list.filter(i=> i.id == v)[0].qrCode
            this.groupInfo = this.list.filter(i => i.id == v)[0]
          }) 
        }
      }
    }
  },
  methods: {
    getSelect() {
      const {areaId} = this.user
      areaId && this.$instance.post(`/app/wxcp/wxgroup/listByAreaId`, null, {
        params: {
          areaId: areaId,
          current: this.current,
          size: 3000,
        }
      }).then(res => {
        if (res?.data) {
          this.list = res.data.records
          this.dictList = res.data.records.map(e=> {
            return {
              value: e.id,
              label: e.name? e.name: '未命名群聊'
            }
          })
        }
      })
    },
  },
}
</script>
<style scoped lang="scss">
.AppWxworkQrcode {
  width: 100%;
  height: 100%;
  padding: 32px;
  box-sizing: border-box;

  ::v-deep .AiSelect {
    width: 100%;
    text-align: center;
    padding: 12% 72px 0;
    box-sizing: border-box;
  }

  ::v-deep .AiSelect .display {
    justify-content: center;
  }

  .jionGroup {
    width: 100%;
    height: 40px;
    line-height: 40px;
    padding: 0 72px;
    box-sizing: border-box;
    color: #666;
    text-align: center;
    font-size: 28px;
  }

  .tishi {
    color: #3D3D3D;
    font-size: 28px;
    font-weight: 400;
    text-align: center;
  }

  .header {
    width: 100%;
    height: 100%;
    background: #FFF;
    border-radius: 16px;

    .qrcode-content {
      width: 542px;
      height: 542px;
      margin: 10% auto 10%;
      border-top: 4px solid #7d87a4;
      padding: 70px 68px;
      box-sizing: border-box;

      .tips {
        width: 406px;
        height: 402px;
        background: url('https://cdn.cunwuyun.cn/fengdu/img-qunliao.png') no-repeat;
        background-size: 100% 100%;
        position: relative;

        .name-tip {
          position: absolute;
          top: 42px;
          left: 86px;
          width: 230px;
          height: 50px;
          line-height: 50px;
          display: flex;
          font-size: 22px;
          font-weight: 600;
          color: #333333;
          .name {
            width: 100%;
            height: 100%;
            line-height: 50px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
          // .count {
          //   width: calc(100% - 165px);
          //   height: 100%;
          //   line-height: 50px;
          // }
        }
      }

      
      

      div {
        font-size: 26px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #333;
        line-height: 36px;
        text-align: center;
      }

      .btn {
        background: #26f;
        color: #fff;
        border-radius: 8px;
      }
    }
  }
  .pic {
    margin-top: 10%;
    width: 100%;
    height: 266px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .col-666 {
    color: #666;
  }
}
</style>
