<template>
  <div class="Situation" :style="{paddingTop: (statusBarHeight + 94) + 'px'}">
    <div class="title">
      <div class="left">门店台账</div>
    </div>
    <div class="flex-content">
      <div class="item">
        <div class="left">
          <img src="https://cdn.cunwuyun.cn/wechat/fd-store/situation-mdzsl.png" alt="">
        </div>
        <div class="right">
          <p>门店总数量</p>
          <div>{{numInfo.shopCounts || 0}}</div>
        </div>
      </div>
      <div class="item">
        <div class="left">
          <img src="https://cdn.cunwuyun.cn/wechat/fd-store/situation-zwgs.png" alt="">
        </div>
        <div class="right">
          <p>总网格数</p>
          <div>{{numInfo.girdCounts || 0}}</div>
        </div>
      </div>
      <div class="item">
        <div class="left">
          <img src="https://cdn.cunwuyun.cn/wechat/fd-store/situation-zwgy.png" alt="">
        </div>
        <div class="right">
          <p>总网格员</p>
          <div>{{numInfo.girdPersons || 0}}</div>
        </div>
      </div>
      <div class="item">
        <div class="left">
          <img src="https://cdn.cunwuyun.cn/wechat/fd-store/situation-wxmd.png" alt="">
        </div>
        <div class="right">
          <p>五星门店</p>
          <div>{{numInfo.fiveStarsShops || 0}}</div>
        </div>
      </div>
    </div>
    <div class="title">
      <div class="left">{{monthText}}月的五星门店<span>（排名不分先后）</span></div>
      <div class="right">
        <AiPagePicker type="gird" @select="handleGridSelect" :params="{formType:2}">
          <span :style="searchGird.girdName ? '': 'color:#999'" class="grid-name">{{searchGird.girdName || '请选择网格'}}</span>
          <u-icon name="arrow-down" color="#999" size="28"></u-icon>
        </AiPagePicker>
      </div>
    </div>
    <div class="table">
      <div class="cell cell-th">
        <span class="store-name">门店名称</span>
        <span class="user-name">经营者姓名</span>
        <span class="user-name">经营类型</span>
      </div>
      <div class="cell" @click="toStoreDetail(item.id)" v-for="(item, index) in table" :key="index">
        <span class="store-name">{{ item.shopName }}</span>
        <span class="user-name">{{ item.name }}</span>
        <span class="user-name">{{ $dict.getLabel('operatorType', item.operatorType) }}</span>
      </div>
      <AiEmpty v-if="!table.length" />
    </div>
  </div>
</template>

<script>

export default {
  name: 'Situation',
  appName: '门店情况',
  data() {
    return {
      searchGird: {girdName: ''},
      month: '',
      monthText: '',
      table: [],
      numInfo: {},
      statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
    }
  },
  created() {
    const date = new Date()
    var month = date.getMonth() == 0 ? 12 : date.getMonth()
    this.monthText = month
    month = month > 9 ? month : "0" + month;
    this.month = date.getFullYear() + '-' + month
    this.getTable()
    this.getStatistics()
  },
  methods: {
    handleGridSelect(e) {
      this.searchGird = e
      this.getTable()
    },
    toStoreDetail(id) {
      this.$emit('toStoreDetail', {shopId: id})
    },
    getTable() {
      this.$loading()
      this.$instance.post(`/app/appshoparchives/list`, null, {
        params: {
          current: 1,
          size: 100,
          fiveStartTime: this.month,
          storeLevel: 5,
          girdCode: this.searchGird.girdCode || ''
        }
      }).then(res => {
        if (res?.data) {
          this.table = res.data.records 
        }
      }).finally(() => uni.hideLoading())
    },
    getStatistics() {
      this.$loading()
      this.$instance.post(`/app/appShopStatistics/queryShopDetail`).then(res => {
        if (res?.data) {
          this.numInfo = res.data 
        }
      }).finally(() => uni.hideLoading())
    }
  },

}
</script>

<style lang="scss" scoped>
.Situation {
  height: 100%;
  background-color: #F4F5FA;
  box-sizing: border-box;
  .title {
    line-height: 40px;
    padding: 32px;
    display: flex;
    justify-content: space-between;
    .left {
      font-family: PingFangSC-SNaNpxibold;
      font-weight: 600;
      font-size: 34px;
      color: #333;
      span {
        color: #333;
        font-size: 24px;
        font-weight: 400;
      }
    }
    .right {

    }
  }
  .flex-content {
    padding-left: 32px;
    overflow: hidden;
    .item {
      float: left;
      width: calc(50% - 32px);
      display: flex;
      background: #FFF;
      border-radius: 12px;
      padding: 26px 0 26px 32px;
      box-sizing: border-box;
      .left {
        width: 88px;
        padding-top: 24px;
        img {
          width: 64px;
          height: 64px;
        }
      }
      .right {
        p {
          line-height: 40px;
          font-family: PingFangSC-Regular;
          font-size: 28px;
          color: #999;
          margin-bottom: 8px;
        }
        div {
          line-height: 60px;
          font-family: PingFangSC-Medium;
          font-weight: 500;
          font-size: 44px;
          color: #444;
        }
      }
    }
    .item:nth-of-type(2n-1) {
      margin-right: 32px;
    }
    .item:nth-of-type(1),
    .item:nth-of-type(2) {
      margin-bottom: 32px;
    }
  }
  .table {
    padding: 32px 20px 20px;
    width: calc(100% - 64px);
    margin-left: 32px;
    background-color: #FFF;
    box-sizing: border-box;
    max-height: calc(100% - 620px);
    overflow-y: scroll;
    .cell {
      display: flex;
      padding: 14px 0;
      span {
        font-family: PingFangSC-Regular;
        font-size: 24px;
        color: #222;
        line-height: 44px;
      }
      .store-name {
        flex: 1;
      }
      .user-name {
        flex: 2;
        text-align: center;
      }
      .store-type {
        flex: 1;
        text-align: right;
      }
    }
    .cell-th {
      span {
        font-family: PingFangSC-Medium;
        font-weight: 500;
        color: #666;
      }
    }
    .cell:nth-of-type(2n-1) {
      background-color: #F7F9FF;
    }
  }
  .grid-name {
    font-size: 28px;
    color: #222;
  }
}
</style>