<template>
  <div class="app-container" v-loading="loading">
    <el-card class="box-card" header="店铺详情">
      <el-row type="flex">
        <image-preview :src="store.picture" :width="80" :height="80"/>
        <div style="flex: 1;margin-left: 2em">
          <el-descriptions :column="4">
            <el-descriptions-item label="店铺名称">{{store.name | defaultValue}}</el-descriptions-item>
            <el-descriptions-item label="店铺类型">
              <dict-tag :value="store.type" :options="dict.type.ss_store_type" size="small"/>
            </el-descriptions-item>
            <el-descriptions-item label="店铺状态">
              <dict-tag :value="store.status" :options="dict.type.store_status" size="small"/>
            </el-descriptions-item>
            <el-descriptions-item label="是否生效">
              <el-tag :type="store.enabled ? 'success' : 'danger'" size="small">{{store.enabled ? '已生效' : '未生效'}}</el-tag>
            </el-descriptions-item>
            <el-descriptions-item label="创建时间">{{store.createTime | defaultValue}}</el-descriptions-item>
            <el-descriptions-item label="营业时间">
              {{store.businessTimeStart | defaultValue}} 至 {{store.businessTimeEnd | defaultValue}}
            </el-descriptions-item>
            <el-descriptions-item label="所属商户">
              <user-link :id="store.userId" :name="store.userName"/>
            </el-descriptions-item>
            <el-descriptions-item label="联系方式">{{store.contactName | defaultValue}}({{store.contactMobile | defaultValue}})</el-descriptions-item>
            <el-descriptions-item label="店铺地址" :span="2">
              {{store.province}}{{store.city}}{{store.county}}{{store.address}}
            </el-descriptions-item>
          </el-descriptions>
        </div>
      </el-row>
    </el-card>

    <el-row :gutter="16">
      <el-col :span="18">


        <el-card class="box-card" >
          <el-row type="flex">
            <el-statistic
              group-separator=","
              :precision="2"
              :value="store.todayIncome"
              suffix="¥"
              title="今日收入"
            ></el-statistic>
            <el-statistic
              group-separator=","
              :precision="2"
              :value="store.monthIncome"
              suffix="¥"
              title="本月收入"
            ></el-statistic>
            <el-statistic
              group-separator=","
              :precision="2"
              :value="store.lastMonthIncome"
              suffix="¥"
              title="上月收入"
            ></el-statistic>
            <el-statistic
              group-separator=","
              :value="store.deviceCount"
              suffix="台"
              title="设备总数"
            ></el-statistic>
            <el-statistic
              group-separator=","
              :value="store.onlineCount"
              suffix="台"
              title="在线设备"
            ></el-statistic>
            <el-statistic
              group-separator=","
              :value="store.offlineCount"
              suffix="台"
              title="离线设备"
            ></el-statistic>
          </el-row>
        </el-card>
<!--        <el-card class="box-card">-->
<!--          <store-recharge-report :store-id="store.storeId"/>-->
<!--        </el-card>-->
      </el-col>
      <el-col :span="6">
        <el-card class="box-card">
          <place-search-map
            v-if="showMap"
            height="534px"
            :init-lng="store.lng"
            :init-lat="store.lat"
            enable-geo
            marker-type="store"
          />
        </el-card>
      </el-col>
    </el-row>

    <el-card class="box-card">
      <el-tabs>
        <el-tab-pane label="设备列表" :lazy="true">
          <device-list :store-id="store.storeId"/>
        </el-tab-pane>
<!--        <el-tab-pane label="收入记录" :lazy="true">-->
<!--          <recharge-list :store-id="store.storeId"/>-->
<!--        </el-tab-pane>-->
<!--        <el-tab-pane label="变更记录" :lazy="true">-->
<!--          <store-apply :query="{storeId: store.storeId}" :view="views.store"/>-->
<!--        </el-tab-pane>-->
      </el-tabs>
    </el-card>


  </div>
</template>

<script>
import { getStore } from '@/api/rl/store'
import PlaceSearchMap from '@/components/Map/PlaceSearch/PlaceSearchMap.vue'
import DeviceList from '@/views/system/store/components/deviceList.vue'
// import RechargeList from '@/views/system/store/components/rechargeList.vue'
// import StoreRechargeReport from '@/views/system/store/components/storeRechargeReport.vue'
import UserLink from '@/components/Business/SmUser/UserLink.vue'
// import StoreApply from '@/views/system/storeApply/index.vue'
import { views } from '@/utils/constants'

export default {
  name: 'storeDetail',
  computed: {
    views() {
      return views
    }
  },
  components: { UserLink, DeviceList, PlaceSearchMap },
  dicts: ['ss_store_type', 'store_status'],
  data() {
    return {
      loading: false,
      store: {},
      showMap: false,
    }
  },
  created() {
    this.getDetail();
  },
  beforeDestroy() {
    clearInterval(this.timer);
  },
  methods: {
    getDetail() {
      this.loading = true;
      getStore(this.$route.query.storeId).then(res => {
        this.store = res.data;
        this.showMap = true;
      }).finally(() => {
        this.loading = false;
      })
    },
  }
}
</script>

<style scoped>
.remark-text {
  color: #ccc;
  margin-left: 1em;
}
.app-container .box-card:nth-child(n + 1) {
  margin-top: 1em;
}
</style>
