<template>
  <div class="AppMerchanGrid">
    <template v-if="isGridMember">
      <div class="pad-t32" />
      <div class="select-gird" flex>
        <AiPagePicker type="gird" class="fill" @select="handleSelectGird">
          <div flex>
            <img src="./components/img/gird-icon.png" alt="" class="gird-icon">
            <AiMore v-model="userGird.girdName" icon="arrow-down"/>
          </div>
        </AiPagePicker>
        <span @click="linkTo('./SetGird?id='+userGird.id)" v-if="isGridAdmin&&!!userGird.id">网格配置</span>
      </div>
      <div class="title">网格人员</div>
      <div class="user-content" v-for="(item, index) in dataInfo.parentGirdMembers" :key="item.id">
        <div>
          <!-- <image :src="item.photo" alt="" mode="aspectFill" v-if="item.photo" /> -->
          <img :src="item.photo" alt="" v-if="item.photo">
          <img src="./components/img/big-user.png" alt="" v-else>
        </div>
        <div class="right">
          <div class="name">{{ item.name }}</div>
          <div class="gird">{{ item.checkType == 2 ? '网格长' : '网格员' }}</div>
          <p>{{ item.girdName }}</p>
        </div>
      </div>
      <div class="user-content user-item" v-for="(item, index) in dataInfo.girdMembers" :key="item.id" @click="viewUser(item.wxUserId)">
        <div>
          <!-- <image :src="item.photo" alt="" mode="aspectFill" v-if="item.photo" /> -->
          <img :src="item.photo" alt="" v-if="item.photo">
          <img src="./components/img/big-user.png" alt="" v-else>
        </div>
        <div class="right">
          <div class="name">{{ item.name }}
            <span class="gird">{{ item.checkType == 2 ? '网格长' : '网格员' }}</span>
            <span class="family-btn" @click.stop="linkTo(`./FamilyList?id=${item.id}&girdId=${userGird.id}`)" v-if="item.checkType == 1">责任家庭 ></span>
          </div>
          <p>{{ item.girdName }} </p>
        </div>
      </div>
      <AiEmpty description="暂无数据" class="emptyWrap"
              v-if="dataInfo.parentGirdMembers && !dataInfo.parentGirdMembers.length && !dataInfo.girdMembers.length"></AiEmpty>
      <AiGap h="112"/>
    </template>
    <div v-if="!isGridMember" class="empty">
      <img src="./components/img/no-admin.png" alt="">
      <p>没有网格员权限<br/>无法查看网格信息哦~</p>
      <div class="add-btn" @click="linkTo('./AddUser')">网格员信息申报</div>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'
export default {
  data() {
    return {
      dataInfo: {},
      userGird: {}
    }
  },
  computed: {
    ...mapState(['user']),
    isGridMember() {
      return this.user.girdCheckType > 0
    },
    isGridAdmin() {
      return this.user.girdCheckType == 2
    }
  },
  onLoad() {
    this.handleSelectGird(this.user.gridInfo)
  },
  onShow() {
    document.title = '网格管理'

  },
  mounted() {
    this.getGirdUserList()
    uni.$on('goback', (res) => {
      this.userGird = res
      this.getGirdUserList()
    })
  },
  methods: {
    handleSelectGird(v) {
      this.userGird = v || {}
      this.getGirdUserList()
    },
    getGirdUserList() {
      this.$http.post(`/app/appgirdmemberinfo/listGirdMemberByGirdId?girdId=${this.userGird.id}`).then((res) => {
        if (res.code == 0) {
          this.dataInfo = res.data
        }
      })
    },
    linkTo(url) {
      uni.navigateTo({url})
    },
    viewUser(userid) {
      userid && this.injectJWeixin('openUserProfile').then(() => {
        this.wxInvoke(['openUserProfile', {type: 1, userid}, () => 0])
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.AppMerchanGrid {
  background-color: #f5f5f5;

  .title {
    font-size: 38px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333;
    line-height: 52px;
    padding-left: 32px;
    margin-bottom: 32px;
  }

  .user-content {
    width: calc(100% - 64px);
    margin: 0 0 32px 32px;
    background-color: #fff;
    padding: 32px;
    box-sizing: border-box;
    display: flex;

    img {
      display: inline-block;
      width: 200px;
      height: 200px;
      margin-right: 32px;
    }

    image {
      width: 200px;
      height: 200px;
      margin-right: 32px;
    }

    .right {
      width: 100%;

      .name {
        font-size: 32px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333;
        line-height: 44px;
        margin-bottom: 12px;
      }

      .gird {
        display: inline-block;
        line-height: 44px;
        background: #E8EFFF;
        border-radius: 8px;
        padding: 0 8px;
        font-size: 26px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #26F;
        margin-bottom: 12px;
      }

      p {
        font-size: 26px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #666;
        line-height: 36px;
      }
    }
  }

  .user-item {
    img {
      width: 96px;
      height: 96px;
      border-radius: 50%;
    }

    image {
      width: 96px;
      height: 96px;
      border-radius: 50%;
    }

    .gird {
      display: inline-block;
      margin-left: 16px;
      margin-bottom: 0 !important;
    }

    .name {
      margin-bottom: 8px !important;
    }
  }

  .family-btn {
    font-size: 26px;
    font-family: PingFangSC-Regular, PingFang SC;
    color: #3975C6;
    line-height: 36px;
    float: right;
  }

  .pad-b112 {
    padding-bottom: 112px;
  }
}
.pad-t32 {
  padding-top: 32px;
}

.gird-icon {
  margin-right: 8px;
}

.select-gird {
  width: calc(100% - 60px);
  padding: 24px 32px;
  background: #FFFFFF;
  border-radius: 16px;
  margin: 0 30px 32px;
  box-sizing: border-box;

  img {
    width: 32px;
    height: 32px;
    vertical-align: middle;
  }

  span {
    display: inline-block;
    width: 112px;
    height: 48px;
    font-size: 28px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #3F8DF5;
    line-height: 48px;
  }
}

.tabs {
  width: 100%;
  height: 98px;
  background: #fff;
  border-top: 1px solid #ddd;
  position: fixed;
  bottom: 0;
  left: 0;
  display: flex;

  .item {
    flex: 1;
    text-align: center;

    img {
      width: 56px;
      height: 56px;
      margin-top: 8px;
    }

    p {
      font-size: 22px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #c4cad4;
      line-height: 8px;
    }

    .color-3267F0 {
      color: #3267f0;
    }
  }
}

.empty {
  text-align: center;

  img {
    width: 282px;
    height: 306px;
    margin: 136px auto 0;
  }

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

  .add-btn {
    width: 400px;
    height: 88px;
    line-height: 88px;
    text-align: center;
    border-radius: 8px;
    background-color: #3267f0;
    color: #fff;
    font-size: 30px;
    margin: 200px auto 0;
  }
}
</style>
