<template>
  <div class="myStoreList">
    <div class="item" @click="toStoreForm(item.id)" v-for="(item, index) in list" :key="index">
      <div class="top-flex">
        <div class="name">{{ item.shopName }}</div>
        <img :src="item.fileUrl ? item.fileUrl : 'https://cdn.cunwuyun.cn/wechat/fd-store/shop-img.png' "  alt="">
      </div>
      <div class="address">{{ item.address }}</div>
    </div>
    <AiEmpty v-if="!list.length" />
  </div>
</template>

<script>
import {mapState} from 'vuex'
export default {
  name: 'myStoreList',
  appName: '我的门店',
  data() {
    return {
      list: [],
      current: 1,
      pages: 2
    }
  },
  computed: {
    ...mapState(['user'])
  },
  onShow() {
    this.getShopList()
  },
  methods: {
    getShopList() {
      if(this.current > this.pages) return
      this.$loading()
      this.$instance.post(`/app/appshoparchives/list`, null, {
        params: {
          current: this.current, 
          size: 15,
          // phone: 15527637203
          phone: this.user.phone
        }
      }).then(res => {
        if (res?.data) {
          this.list = this.current == 1 ? res.data.records : [this.list, res.data.records].flat()
          this.pages = res.data.pages
        }
      }).finally(() => uni.hideLoading())
    },
    toStoreForm(id) {
      uni.navigateTo({url: `./storeForm?shopId=${id}`})
    }
  },
  onReachBottom() {
    this.current ++
    this.getShopList()
  }
  

}
</script>

<style lang="scss" scoped>
.myStoreList {
  background-color: #F4F5FA;
  padding: 32px;
  .item {
    width: 100%;
    background: #fff;
    border-radius: 32px;
    margin-bottom: 32px;
    .top-flex {
      padding: 24px 32px;
      box-sizing: border-box;
      border-bottom: 1px solid #eee;
      .name {
        display: inline-block;
        width: calc(100% - 128px);
        font-family: PingFangSC-Regular;
        font-size: 30px;
        color: #333;
        line-height: 36px;
      }
      img {
        width: 112px;
        height: 112px;
        border-radius: 50%;
        vertical-align: middle;
      }
    }
    .address {
      padding: 42px 32px 50px 32px;
      box-sizing: border-box;
      font-family: PingFangSC-Regular;
      font-size: 30px;
      color: #666;
      line-height: 36px;
    }
  }
}
</style>