<template>
  <div class="supermarketList">
    <div class="header">
      <div class="left">
        <AiAreaPicker :name.sync="areaName" v-model="areaId" @input="areaSelect">
          <span v-if="areaName" style="color: #333333;">{{ areaName }}</span>
          <span v-else :style="{color:areaName? '#333333': '#999'}">请选择</span>
          <u-icon name="arrow-down" color="#999" size="24"></u-icon>
        </AiAreaPicker>
      </div>
      <div class="right">
        <u-search placeholder="店铺名称" v-model="shopName" :show-action="false" @search="search" @clear="shopName='',getList()"></u-search>
      </div>
    </div>
    <div class="card-list" v-if="list.length">
      <div class="card" @click="$linkTo(`./integralRanking?shopId=${item.id}`)" v-for="(item,index) in list" :key="index">
        <div class="pic">
          <img :src="item.shopPhoto" alt="">
        </div>
        <div class="info">
          <h3>{{ item.shopName }}</h3>
          <p>{{ item.areaName }}</p>
          <div>{{ item.shopAddress }}</div>
        </div>
      </div>
    </div>
    <AiEmpty class="fill" description="暂无数据" v-else/>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data() {
    return {
      areaId: '',
      areaName: '',
      shopName: '',
      list: [],
      current: 1,
    }
  },
  computed: {
    ...mapState(['global'])
  },
  onShow () {
    this.getList()
  },
  methods: {
    areaSelect(v) {
      this.areaId = v
      this.current = 1
      this.getList()
    },
    search(e) {
      this.shopName = e
      this.getList()
    },
    getList() {
      this.$instance.post(`/appvillagerintegralshop/listForWx`,null,{
        params: {
          areaId: this.areaId,
          current: this.current,
          shopName: this.shopName,
        }
      }).then(res => {
        if(res?.data) {
          this.list = this.current== 1 ?  res.data.records : [...this.list, ...res.data.records]
        }
      })
    },
    onReachBottom() {
      this.current ++ ;
      this.getList()
    }
  }
}
</script>

<style lang="scss" scoped>
.supermarketList {
  .header {
    position: fixed;
    top: 0;
    left: 0;
    height: 120px;
    line-height: 120px;
    background: #FFF;
    padding: 0 32px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    .left {
      width: 300px;
      height: 100%;
      ::v-deep .AiAreaPicker {
        width: 100%;
        height: 100%;
        display: flex;
        span {
          display: inline-block;
          width: 150px;
          height: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .u-icon {
          display: inline-block;
          .u-icon__icon {
            top: -50px !important;
          }
        }
      }
    }
    .right {
      width: 100%;
    }
  }
  .card-list {
    box-sizing: border-box;
    padding: 140px 32px 20px 32px;
    .card {
      background: #FFF;
      padding: 32px;
      box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.04);
      border-radius: 16px;
      display: flex;
      margin-bottom: 24px;
      .pic {
        width: 160px;
        height: 160px;
        margin-right: 20px;
        img { 
          width: 100%;
          height: 100%;
        }
      }
      .info {
        width: calc(100% - 180px);
        h3 {
          color: #333333;
          font-size: 34px;
          font-weight: 500;
        }
        p {
          margin-top: 15px;
          color: #999999;
        }
        div {
          margin-top: 10px;
          color: #999999;
        }
        h3,
        p,
        div {
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;

        }
      }
    }
  }

  ::v-deep .emptyWrap .emptyImg {
    margin-top: 120px;
  }
}
</style>