<template>
  <div class="AppPageMerchant">

    <div class="list-content">
      <div class="item" v-for="(item, index) in appList" :key="index" @click="linkTo(item.url)" :style="item.isBottom ? 'border-bottom: 1px solid #eee;' : ''">
        <div class="icon" :style="`backgroundImage: url(${item.icon});`"></div>
        <p>{{item.name}}</p>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'AppPageMerchant',
    appName: '商户入口',
    data() {
      return {
        label: '西城-商户管理',
        appList: [
          {
            name: '商户档案',
            icon: require('./img/shanghudangan.png'),
            url: '../AppMerchantManage/AppMerchantManage',
            isBottom: true
          },
          {
            name: '网格管理',
            icon: require('./img/wanggeguanli.png'),
            url: '../AppMerchanGird/AppMerchanGird',
            isBottom: true
          },
          {
            name: '商户地图',
            icon: require('./img/shanghuditu.png'),
            url: '../AppMerchantMap/AppMerchantMap',
            isBottom: true
          },
          {
            name: '网格统计',
            icon: require('./img/wanggetongji.png'),
            url: '../AppMerchanStatistics/AppMerchanStatistics'
          }
        ],
        isGridMember: false
      }
    },

    onLoad () {
      this.$http.post(`/api/appgirdmemberinfo/checkLogOnUser`).then(res => {
        if (res.code === 0) {
          this.isGridMember = res.data.checkType === '1' || res.data.checkType === '2'
        }
      })
    },

    methods: {
      linkTo (url) {
        if (!this.isGridMember) {
          this.$confirm('没有网格员权限', '温馨提示', {
            confirmText: '去申报'
          }).then(() => {
            uni.navigateTo({
              url: '../AppMerchanGird/AddUser'
            })
          }).catch(() => {
          })

          return
        }

        uni.navigateTo({url})
      }
    }
  }
</script>

<style lang="scss" scoped>
.AppPageMerchant{
  padding: 20px;
  .list-content{
    background-color: #fff;
    border-radius: 16px;
    overflow: hidden;
    .item{
      text-align: center;
      padding-bottom: 38px;
      border-right: 1px solid #eee;
      width: calc(33% - 1px);
      float: left;
      .icon{
        display: inline-block;
        width: 80px;
        height: 80px;
        margin: 40px 0 8px 0;
        background-size: 100% 100%;
        text-align: center;
      }
      p{
        font-size: 28px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #3D434A;
        line-height: 40px;
      }
    }
    .item:nth-of-type(3n) {
      border-right: 0;
    }
  }
}
</style>
